Page MenuHomeFreeBSD

D38555.id117192.diff
No OneTemporary

D38555.id117192.diff

diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c
--- a/lib/libc/gen/sched_getaffinity.c
+++ b/lib/libc/gen/sched_getaffinity.c
@@ -26,16 +26,31 @@
* SUCH DAMAGE.
*/
+#define _WANT_P_OSREL
+#include <sys/param.h>
#include <errno.h>
#include <sched.h>
#include <string.h>
+#include "libc_private.h"
+
+#define TIDPID_PID_MAX 99999
+
int
sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset)
{
+ cpuwhich_t which;
int error;
- error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID,
+ if (__getosreldate() < P_OSREL_TIDPID) {
+ if (pid == 0 || pid > TIDPID_PID_MAX)
+ which = CPU_WHICH_TID;
+ else
+ which = CPU_WHICH_PID;
+ } else
+ which = CPU_WHICH_TIDPID;
+
+ error = cpuset_getaffinity(CPU_LEVEL_WHICH, which,
pid == 0 ? -1 : pid, cpusetsz, cpuset);
if (error == -1 && errno == ERANGE)
errno = EINVAL;
diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c
--- a/lib/libc/gen/sched_setaffinity.c
+++ b/lib/libc/gen/sched_setaffinity.c
@@ -26,20 +26,34 @@
* SUCH DAMAGE.
*/
+#define _WANT_P_OSREL
#include <sys/param.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <sched.h>
#include <string.h>
+#include "libc_private.h"
+
+#define TIDPID_PID_MAX 99999
+
int
sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset)
{
static int mp_maxid;
+ cpuwhich_t which;
cpuset_t c;
int error, lbs, cpu;
size_t len, sz;
+ if (__getosreldate() < P_OSREL_TIDPID) {
+ if (pid == 0 || pid > TIDPID_PID_MAX)
+ which = CPU_WHICH_TID;
+ else
+ which = CPU_WHICH_PID;
+ } else
+ which = CPU_WHICH_TIDPID;
+
sz = cpusetsz > sizeof(cpuset_t) ? sizeof(cpuset_t) : cpusetsz;
memset(&c, 0, sizeof(c));
memcpy(&c, cpuset, sz);
@@ -58,7 +72,7 @@
if (cpu > mp_maxid)
CPU_CLR(cpu, &c);
}
- error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID,
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, which,
pid == 0 ? -1 : pid, sizeof(cpuset_t), &c);
if (error == -1 && errno == EDEADLK)
errno = EINVAL;
diff --git a/sys/sys/param.h b/sys/sys/param.h
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -107,6 +107,7 @@
#define P_OSREL_CK_SUPERBLOCK 1300000
#define P_OSREL_CK_INODE 1300005
#define P_OSREL_POWERPC_NEW_AUX_ARGS 1300070
+#define P_OSREL_TIDPID 1400079
#define P_OSREL_MAJOR(x) ((x) / 100000)
#endif

File Metadata

Mime Type
text/plain
Expires
Sun, Feb 1, 12:25 PM (5 m, 47 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28365177
Default Alt Text
D38555.id117192.diff (2 KB)

Event Timeline