[Glibc-bsd-commits] r2512 - in trunk/glibc-ports/kfreebsd: . bits sys

Aurelien Jarno aurel32 at alioth.debian.org
Fri May 15 14:32:11 UTC 2009


Author: aurel32
Date: 2009-05-15 14:32:11 +0000 (Fri, 15 May 2009)
New Revision: 2512

Added:
   trunk/glibc-ports/kfreebsd/sched_getaffinity.c
   trunk/glibc-ports/kfreebsd/sched_setaffinity.c
Modified:
   trunk/glibc-ports/kfreebsd/Makefile
   trunk/glibc-ports/kfreebsd/Versions
   trunk/glibc-ports/kfreebsd/bits/sched.h
   trunk/glibc-ports/kfreebsd/sys/syscall.h
Log:
Add support for sched_getaffinity() and sched_setaffinity(), using the
syscalls added in FreeBSD 7.1.

We are changing the size of structure cpu_set_t, and therefore strictly
speaking breaking the ABI. However, given the new structure is smaller 
than the old one, and the the old sched_[gs]etaffinity() functions where
stubs only, it should not cause any problem.



Modified: trunk/glibc-ports/kfreebsd/Makefile
===================================================================
--- trunk/glibc-ports/kfreebsd/Makefile	2009-05-15 14:29:45 UTC (rev 2511)
+++ trunk/glibc-ports/kfreebsd/Makefile	2009-05-15 14:32:11 UTC (rev 2512)
@@ -88,6 +88,8 @@
 ifeq ($(subdir),posix)
 # For <unistd.h>.
 sysdep_routines += sys_getlogin sys_pread sys_pwrite sys_setlogin sys_read sys_write
+# for <sched.h>
+sysdep_routines += sys_cpuset_getaffinity sys_cpuset_setaffinity
 endif
 
 ifeq ($(subdir),inet)

Modified: trunk/glibc-ports/kfreebsd/Versions
===================================================================
--- trunk/glibc-ports/kfreebsd/Versions	2009-05-15 14:29:45 UTC (rev 2511)
+++ trunk/glibc-ports/kfreebsd/Versions	2009-05-15 14:32:11 UTC (rev 2512)
@@ -94,6 +94,7 @@
      # misc fixes for FreeBSD:
     __syscall_freebsd6_lseek; __syscall_freebsd6_pread; __syscall_freebsd6_pwrite;
     __syscall_connect; __syscall_sendto;
+    __syscall_cpuset_getaffinity ; __syscall_cpuset_setaffinity;
     __sigprocmask; __ioctl;
      # global variable used in brk()
     _end;

Modified: trunk/glibc-ports/kfreebsd/bits/sched.h
===================================================================
--- trunk/glibc-ports/kfreebsd/bits/sched.h	2009-05-15 14:29:45 UTC (rev 2511)
+++ trunk/glibc-ports/kfreebsd/bits/sched.h	2009-05-15 14:32:11 UTC (rev 2512)
@@ -1,6 +1,7 @@
 /* Definitions of constants and data structure for POSIX 1003.1b-1993
    scheduling interface.
-   Copyright (C) 1996, 1997, 2001, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1996-1999,2001-2003,2005,2006,2007,2008
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -83,7 +84,7 @@
 #if defined _SCHED_H && !defined __cpu_set_t_defined
 # define __cpu_set_t_defined
 /* Size definition for CPU sets.  */
-# define __CPU_SETSIZE	1024
+# define __CPU_SETSIZE	128
 # define __NCPUBITS	(8 * sizeof (__cpu_mask))
 
 /* Type for array elements in 'cpu_set_t'.  */
@@ -108,26 +109,31 @@
   do {									      \
     size_t __i;								      \
     size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
-    cpu_set_t *__arr = (cpusetp);					      \
+    __cpu_mask *__bits = (cpusetp)->__bits;				      \
     for (__i = 0; __i < __imax; ++__i)					      \
-      __arr->__bits[__i] = 0;						      \
+      __bits[__i] = 0;							      \
   } while (0)
 # endif
 # define __CPU_SET_S(cpu, setsize, cpusetp) \
   (__extension__							      \
    ({ size_t __cpu = (cpu);						      \
       __cpu < 8 * (setsize)						      \
-      ? ((cpusetp)->__bits[__CPUELT (__cpu)] |= __CPUMASK (__cpu)) : 0; }))
+      ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]		      \
+	 |= __CPUMASK (__cpu))						      \
+      : 0; }))
 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
   (__extension__							      \
    ({ size_t __cpu = (cpu);						      \
       __cpu < 8 * (setsize)						      \
-      ? ((cpusetp)->__bits[__CPUELT (__cpu)] &= ~__CPUMASK (__cpu)) : 0; }))
+      ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]		      \
+	 &= ~__CPUMASK (__cpu))						      \
+      : 0; }))
 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
   (__extension__							      \
    ({ size_t __cpu = (cpu);						      \
       __cpu < 8 * (setsize)						      \
-      ? (((cpusetp)->__bits[__CPUELT (__cpu)] & __CPUMASK (__cpu))) != 0      \
+      ? ((((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]	      \
+	  & __CPUMASK (__cpu))) != 0					      \
       : 0; }))
 
 # define __CPU_COUNT_S(setsize, cpusetp) \
@@ -139,12 +145,12 @@
 # else
 #  define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
   (__extension__							      \
-   ({ cpu_set_t *__arr1 = (cpusetp1);					      \
-      cpu_set_t *__arr2 = (cpusetp2);					      \
+   ({ __cpu_mask *__arr1 = (cpusetp1)->__bits;				      \
+      __cpu_mask *__arr2 = (cpusetp2)->__bits;				      \
       size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
       size_t __i;							      \
       for (__i = 0; __i < __imax; ++__i)				      \
-	if (__arr1->__bits[__i] != __arr2->__bits[__i])			      \
+	if (__bits[__i] != __bits[__i])					      \
 	  break;							      \
       __i == __imax; }))
 # endif
@@ -152,16 +158,16 @@
 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
   (__extension__							      \
    ({ cpu_set_t *__dest = (destset);					      \
-      cpu_set_t *__arr1 = (srcset1);					      \
-      cpu_set_t *__arr2 = (srcset2);					      \
+      __cpu_mask *__arr1 = (srcset1)->__bits;				      \
+      __cpu_mask *__arr2 = (srcset2)->__bits;				      \
       size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
       size_t __i;							      \
       for (__i = 0; __i < __imax; ++__i)				      \
-	__dest->__bits[__i] = __arr1->__bits[__i] op __arr2->__bits[__i];     \
+	((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i];    \
       __dest; }))
 
 # define __CPU_ALLOC_SIZE(count) \
-  ((((count) + __NCPUBITS - 1) / __NCPUBITS) * 8)
+  ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
 # define __CPU_ALLOC(count) __sched_cpualloc (count)
 # define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
 

Added: trunk/glibc-ports/kfreebsd/sched_getaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/sched_getaffinity.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/sched_getaffinity.c	2009-05-15 14:32:11 UTC (rev 2512)
@@ -0,0 +1,64 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* From <sys/cpuset.h> */
+#define CPU_LEVEL_WHICH         3       /* Actual mask/id for which. */
+#define CPU_WHICH_PID           2       /* Specifies a process id. */
+
+extern int __syscall_cpuset_getaffinity(int level, int which, int64_t id,
+					size_t setsize, cpu_set_t *mask);
+libc_hidden_proto(__syscall_cpuset_getaffinity)
+
+int
+__libc_sched_getaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *cpuset)
+{
+  int res;
+
+  if (pid == 0)
+    {
+      pid = __getpid();
+    }
+
+  if (cpusetsize > sizeof(cpu_set_t))
+    {
+      /* Clean the rest of the memory the kernel won't do.  */
+      memset ((char *) cpuset + sizeof(cpu_set_t), '\0', cpusetsize - sizeof(cpu_set_t));
+
+      cpusetsize = sizeof(cpu_set_t);
+    }
+
+  res = INLINE_SYSCALL (cpuset_getaffinity, 5, CPU_LEVEL_WHICH,
+			CPU_WHICH_PID, pid, cpusetsize, cpuset);
+
+  if (errno == ERANGE)
+    {
+      __set_errno(EINVAL);
+    }
+
+  return res;
+}
+
+strong_alias (__libc_sched_getaffinity, __sched_getaffinity)
+weak_alias (__sched_getaffinity, sched_getaffinity)

Added: trunk/glibc-ports/kfreebsd/sched_setaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/sched_setaffinity.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/sched_setaffinity.c	2009-05-15 14:32:11 UTC (rev 2512)
@@ -0,0 +1,57 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* From <sys/cpuset.h> */
+#define CPU_LEVEL_WHICH         3       /* Actual mask/id for which. */
+#define CPU_WHICH_PID           2       /* Specifies a process id. */
+
+extern int __syscall_cpuset_setaffinity(int level, int which, int64_t id,
+					size_t setsize, const cpu_set_t *mask);
+libc_hidden_proto(__syscall_cpuset_setaffinity)
+
+int
+__libc_sched_setaffinity (pid_t pid, size_t cpusetsize, const cpu_set_t *cpuset)
+{
+  int res;
+
+  if (pid == 0)
+    {
+      pid = __getpid();
+    }
+
+
+  res = INLINE_SYSCALL (cpuset_setaffinity, 5, CPU_LEVEL_WHICH,
+			CPU_WHICH_PID, pid, cpusetsize, cpuset);
+
+  if (errno == ERANGE || errno == EDEADLK)
+    {
+      __set_errno(EINVAL);
+    }
+
+  return res;
+}
+
+strong_alias (__libc_sched_setaffinity, __sched_setaffinity)
+weak_alias (__sched_setaffinity, sched_setaffinity)

Modified: trunk/glibc-ports/kfreebsd/sys/syscall.h
===================================================================
--- trunk/glibc-ports/kfreebsd/sys/syscall.h	2009-05-15 14:29:45 UTC (rev 2511)
+++ trunk/glibc-ports/kfreebsd/sys/syscall.h	2009-05-15 14:32:11 UTC (rev 2512)
@@ -414,6 +414,11 @@
 #define	SYS_truncate	479
 #define	SYS_ftruncate	480
 #define	SYS_thr_kill2	481
-#define	SYS_MAXSYSCALL	482
+#define SYS_cpuset      484
+#define SYS_cpuset_setid        485
+#define SYS_cpuset_getid        486
+#define SYS_cpuset_getaffinity  487
+#define SYS_cpuset_setaffinity  488
+#define SYS_MAXSYSCALL  489
 
 #endif




More information about the Glibc-bsd-commits mailing list