Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147708815
D38209.id115775.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D38209.id115775.diff
View Options
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
@@ -35,7 +35,7 @@
{
int error;
- error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
+ error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDORPID,
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
@@ -58,7 +58,7 @@
if (cpu > mp_maxid)
CPU_CLR(cpu, &c);
}
- error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDORPID,
pid == 0 ? -1 : pid, sizeof(cpuset_t), &c);
if (error == -1 && errno == EDEADLK)
errno = EINVAL;
diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c
--- a/sys/kern/kern_cpuset.c
+++ b/sys/kern/kern_cpuset.c
@@ -921,6 +921,22 @@
return (ESRCH);
p = td->td_proc;
break;
+ case CPU_WHICH_TIDORPID:
+ if (id == -1) {
+ PROC_LOCK(curproc);
+ td = curthread;
+ p = curproc;
+ } else if (id > PID_MAX) {
+ td = tdfind(id, -1);
+ if (td == NULL)
+ return (ESRCH);
+ p = td->td_proc;
+ } else {
+ p = pfind(id);
+ if (p == NULL)
+ return (ESRCH);
+ }
+ break;
case CPU_WHICH_CPUSET:
if (id == -1) {
thread_lock(curthread);
@@ -1733,7 +1749,11 @@
if (IN_CAPABILITY_MODE(td)) {
if (level != CPU_LEVEL_WHICH)
return (ECAPMODE);
- if (which != CPU_WHICH_TID && which != CPU_WHICH_PID)
+ if (which != CPU_WHICH_TID && which != CPU_WHICH_PID &&
+ which != CPU_WHICH_TIDORPID)
+ return (ECAPMODE);
+ if (id != -1 && which == CPU_WHICH_TIDORPID &&
+ !(id == td->td_tid || id == td->td_proc->p_pid))
return (ECAPMODE);
if (id != -1 &&
!(which == CPU_WHICH_TID && id == td->td_tid) &&
@@ -1968,12 +1988,17 @@
break;
case CPU_LEVEL_WHICH:
switch (which) {
- case CPU_WHICH_TID:
- thread_lock(ttd);
- CPU_COPY(&ttd->td_cpuset->cs_mask, mask);
- thread_unlock(ttd);
- break;
+ case CPU_WHICH_TIDORPID:
case CPU_WHICH_PID:
+ case CPU_WHICH_TID:
+ if (which == CPU_WHICH_TID ||
+ (which == CPU_WHICH_TIDORPID &&
+ (id > PID_MAX || id == -1))) {
+ thread_lock(ttd);
+ CPU_COPY(&ttd->td_cpuset->cs_mask, mask);
+ thread_unlock(ttd);
+ break;
+ }
FOREACH_THREAD_IN_PROC(p, ttd) {
thread_lock(ttd);
CPU_OR(mask, mask, &ttd->td_cpuset->cs_mask);
@@ -2123,11 +2148,16 @@
break;
case CPU_LEVEL_WHICH:
switch (which) {
+ case CPU_WHICH_TIDORPID:
case CPU_WHICH_TID:
- error = cpuset_setthread(id, mask);
- break;
case CPU_WHICH_PID:
- error = cpuset_setproc(id, NULL, mask, NULL, false);
+ if (which == CPU_WHICH_TID ||
+ (which == CPU_WHICH_TIDORPID &&
+ (id > PID_MAX || id == -1)))
+ error = cpuset_setthread(id, mask);
+ else
+ error = cpuset_setproc(id, NULL, mask,
+ NULL, false);
break;
case CPU_WHICH_CPUSET:
case CPU_WHICH_JAIL:
diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h
--- a/sys/sys/cpuset.h
+++ b/sys/sys/cpuset.h
@@ -115,6 +115,7 @@
#define CPU_WHICH_DOMAIN 6 /* Specifies a NUMA domain id. */
#define CPU_WHICH_INTRHANDLER 7 /* Specifies an irq # (not ithread). */
#define CPU_WHICH_ITHREAD 8 /* Specifies an irq's ithread. */
+#define CPU_WHICH_TIDORPID 9 /* Specifies a process or thread id. */
/*
* Reserved cpuset identifiers.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 14, 3:00 AM (6 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29647918
Default Alt Text
D38209.id115775.diff (3 KB)
Attached To
Mode
D38209: cpuset: Fix sched_[g|s]etaffinity() for better compatibility with Linux.
Attached
Detach File
Event Timeline
Log In to Comment