[Glibc-bsd-commits] r4881 - trunk/glibc-ports/kfreebsd
Petr Salinger
ps-guest at alioth.debian.org
Thu Aug 8 15:54:54 UTC 2013
Author: ps-guest
Date: 2013-08-08 15:54:54 +0000 (Thu, 08 Aug 2013)
New Revision: 4881
Added:
trunk/glibc-ports/kfreebsd/cpuset-kern.h
Modified:
trunk/glibc-ports/kfreebsd/sched_getaffinity.c
trunk/glibc-ports/kfreebsd/sched_setaffinity.c
Log:
affinity - kernel and user uses different value for self
Added: trunk/glibc-ports/kfreebsd/cpuset-kern.h
===================================================================
--- trunk/glibc-ports/kfreebsd/cpuset-kern.h (rev 0)
+++ trunk/glibc-ports/kfreebsd/cpuset-kern.h 2013-08-08 15:54:54 UTC (rev 4881)
@@ -0,0 +1,52 @@
+/* Copyright (C) 2013 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. */
+
+/* From <sys/cpuset.h> */
+
+
+/*
+ * Valid cpulevel_t values.
+ */
+#define CPU_LEVEL_ROOT 1 /* All system cpus. */
+#define CPU_LEVEL_CPUSET 2 /* Available cpus for which. */
+#define CPU_LEVEL_WHICH 3 /* Actual mask/id for which. */
+
+/*
+ * Valid cpuwhich_t values.
+ */
+#define CPU_WHICH_TID 1 /* Specifies a thread id. */
+#define CPU_WHICH_PID 2 /* Specifies a process id. */
+#define CPU_WHICH_CPUSET 3 /* Specifies a set id. */
+#define CPU_WHICH_IRQ 4 /* Specifies an irq #. */
+#define CPU_WHICH_JAIL 5 /* Specifies a jail id. */
+
+/*
+ * Reserved cpuset identifiers.
+ */
+#define CPUSET_INVALID -1
+#define CPUSET_DEFAULT 0
+
+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)
+
+
+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)
+
Modified: trunk/glibc-ports/kfreebsd/sched_getaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/sched_getaffinity.c 2013-08-07 22:30:21 UTC (rev 4880)
+++ trunk/glibc-ports/kfreebsd/sched_getaffinity.c 2013-08-08 15:54:54 UTC (rev 4881)
@@ -23,24 +23,25 @@
#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. */
+#include "cpuset-kern.h"
-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;
+ int64_t id;
- if (pid == 0)
+ if (pid < 0)
{
- pid = __getpid();
+ __set_errno(ESRCH);
+ return -1;
}
+ if (pid == 0) // user level "self"
+ id = -1; // kernel level "self"
+ else
+ id = pid;
+
if (cpusetsize > sizeof(cpu_set_t))
{
/* Clean the rest of the memory the kernel won't do. */
@@ -50,7 +51,7 @@
}
res = INLINE_SYSCALL (cpuset_getaffinity, 5, CPU_LEVEL_WHICH,
- CPU_WHICH_PID, pid, cpusetsize, cpuset);
+ CPU_WHICH_PID, id, cpusetsize, cpuset);
if (errno == ERANGE)
{
Modified: trunk/glibc-ports/kfreebsd/sched_setaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/sched_setaffinity.c 2013-08-07 22:30:21 UTC (rev 4880)
+++ trunk/glibc-ports/kfreebsd/sched_setaffinity.c 2013-08-08 15:54:54 UTC (rev 4881)
@@ -23,27 +23,27 @@
#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. */
+#include "cpuset-kern.h"
-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;
+ int64_t id;
- if (pid == 0)
+ if (pid < 0)
{
- pid = __getpid();
+ __set_errno(ESRCH);
+ return -1;
}
+ if (pid == 0) // user level "self"
+ id = -1; // kernel level "self"
+ else
+ id = pid;
res = INLINE_SYSCALL (cpuset_setaffinity, 5, CPU_LEVEL_WHICH,
- CPU_WHICH_PID, pid, cpusetsize, cpuset);
+ CPU_WHICH_PID, id, cpusetsize, cpuset);
if (errno == ERANGE || errno == EDEADLK)
{
More information about the Glibc-bsd-commits
mailing list