Skip to content

Commit a41b744

Browse files
committed
Merge tag 'kernel.sys.v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux
Pull prctl updates from Christian Brauner: "This contains the missing prctl uapi pieces for PR_SCHED_CORE. In order to activate core scheduling the caller is expected to specify the scope of the new core scheduling domain. For example, passing 2 in the 4th argument of prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, <pid>, 2, 0); would indicate that the new core scheduling domain encompasses all tasks in the process group of <pid>. Specifying 0 would only create a core scheduling domain for the thread identified by <pid> and 2 would encompass the whole thread-group of <pid>. Note, the values 0, 1, and 2 correspond to PIDTYPE_PID, PIDTYPE_TGID, and PIDTYPE_PGID. A first version tried to expose those values directly to which I objected because: - PIDTYPE_* is an enum that is kernel internal which we should not expose to userspace directly. - PIDTYPE_* indicates what a given struct pid is used for it doesn't express a scope. But what the 4th argument of PR_SCHED_CORE prctl() expresses is the scope of the operation, i.e. the scope of the core scheduling domain at creation time. So Eugene's patch now simply introduces three new defines PR_SCHED_CORE_SCOPE_THREAD, PR_SCHED_CORE_SCOPE_THREAD_GROUP, and PR_SCHED_CORE_SCOPE_PROCESS_GROUP. They simply express what happens. This has been on the mailing list for quite a while with all relevant scheduler folks Cced. I announced multiple times that I'd pick this up if I don't see or her anyone else doing it. None of this touches proper scheduler code but only concerns uapi so I think this is fine. With core scheduling being quite common now for vm managers (e.g. moving individual vcpu threads into their own core scheduling domain) and container managers (e.g. moving the init process into its own core scheduling domain and letting all created children inherit it) having to rely on raw numbers passed as the 4th argument in prctl() is a bit annoying and everyone is starting to come up with their own defines" * tag 'kernel.sys.v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux: uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument
2 parents 6752de1 + 61bc346 commit a41b744

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Documentation/admin-guide/hw-vuln/core-scheduling.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ arg3:
6161
``pid`` of the task for which the operation applies.
6262

6363
arg4:
64-
``pid_type`` for which the operation applies. It is of type ``enum pid_type``.
65-
For example, if arg4 is ``PIDTYPE_TGID``, then the operation of this command
64+
``pid_type`` for which the operation applies. It is one of
65+
``PR_SCHED_CORE_SCOPE_``-prefixed macro constants. For example, if arg4
66+
is ``PR_SCHED_CORE_SCOPE_THREAD_GROUP``, then the operation of this command
6667
will be performed for all tasks in the task group of ``pid``.
6768

6869
arg5:

include/uapi/linux/prctl.h

+3
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,8 @@ struct prctl_mm_map {
268268
# define PR_SCHED_CORE_SHARE_TO 2 /* push core_sched cookie to pid */
269269
# define PR_SCHED_CORE_SHARE_FROM 3 /* pull core_sched cookie to pid */
270270
# define PR_SCHED_CORE_MAX 4
271+
# define PR_SCHED_CORE_SCOPE_THREAD 0
272+
# define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1
273+
# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2
271274

272275
#endif /* _LINUX_PRCTL_H */

kernel/sched/core_sched.c

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
135135
if (!static_branch_likely(&sched_smt_present))
136136
return -ENODEV;
137137

138+
BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD != PIDTYPE_PID);
139+
BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD_GROUP != PIDTYPE_TGID);
140+
BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_PROCESS_GROUP != PIDTYPE_PGID);
141+
138142
if (type > PIDTYPE_PGID || cmd >= PR_SCHED_CORE_MAX || pid < 0 ||
139143
(cmd != PR_SCHED_CORE_GET && uaddr))
140144
return -EINVAL;

0 commit comments

Comments
 (0)