Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F97600748
D38209.id116002.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.id116002.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_TIDPID,
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_TIDPID,
pid == 0 ? -1 : pid, sizeof(cpuset_t), &c);
if (error == -1 && errno == EDEADLK)
errno = EINVAL;
diff --git a/lib/libc/sys/cpuset.2 b/lib/libc/sys/cpuset.2
--- a/lib/libc/sys/cpuset.2
+++ b/lib/libc/sys/cpuset.2
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 3, 2017
+.Dd January 29, 2023
.Dt CPUSET 2
.Os
.Sh NAME
@@ -100,6 +100,7 @@
.Bl -column CPU_WHICH_INTRHANDLER -offset indent
.It Dv CPU_WHICH_TID Ta "id is lwpid_t (thread id)"
.It Dv CPU_WHICH_PID Ta "id is pid_t (process id)"
+.It Dv CPU_WHICH_TIDPID Ta "id is either a thread or process id"
.It Dv CPU_WHICH_JAIL Ta "id is jid (jail id)"
.It Dv CPU_WHICH_CPUSET Ta "id is a cpusetid_t (cpuset id)"
.It Dv CPU_WHICH_IRQ Ta "id is an irq number"
@@ -115,6 +116,7 @@
of
.Dv CPU_WHICH_TID ,
.Dv CPU_WHICH_PID ,
+.Dv CPU_WHICH_TIDPID ,
or
.Dv CPU_WHICH_CPUSET
to mean the current thread, process, or current thread's
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
@@ -927,6 +927,22 @@
return (ESRCH);
p = td->td_proc;
break;
+ case CPU_WHICH_TIDPID:
+ 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);
@@ -1739,7 +1755,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_TIDPID)
+ return (ECAPMODE);
+ if (id != -1 && which == CPU_WHICH_TIDPID &&
+ id != td->td_tid && id != td->td_proc->p_pid)
return (ECAPMODE);
if (id != -1 &&
!(which == CPU_WHICH_TID && id == td->td_tid) &&
@@ -1986,6 +2006,19 @@
thread_unlock(ttd);
}
break;
+ case CPU_WHICH_TIDPID:
+ if (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);
+ thread_unlock(ttd);
+ }
+ break;
case CPU_WHICH_CPUSET:
case CPU_WHICH_JAIL:
CPU_COPY(&set->cs_mask, mask);
@@ -2135,6 +2168,13 @@
case CPU_WHICH_PID:
error = cpuset_setproc(id, NULL, mask, NULL, false);
break;
+ case CPU_WHICH_TIDPID:
+ if (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:
error = cpuset_which(which, id, &p, &ttd, &set);
diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h
--- a/sys/sys/cpuset.h
+++ b/sys/sys/cpuset.h
@@ -109,6 +109,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_TIDPID 9 /* Specifies a process or thread id. */
/*
* Reserved cpuset identifiers.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 1, 7:12 AM (2 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
13236992
Default Alt Text
D38209.id116002.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