clarify the usage and behavior of the taskset command
cover clarify the usage and behavior of the taskset command
From: Alison Chaiken <[email protected]>
The following changes since commit f9596dd4807f4d8da5bda14cd65efc0e5c375cac:
Merge branch 'waitpid' of https://github.com/t-8ch/util-linux (2023-01-06 17:05:04 +0100)
are available in the Git repository at:
git://github.com/chaiken/util-linux.git schedutils
for you to fetch changes up to be71e7c656a47e996eebff855119c9f1a2141cd5:
schedutils: better illustrate the usage of cpu-lists with taskset (2023-01-07 09:41:16 -0800)
Alison Chaiken (3):
schedutils: clarify confusing mask example in taskset man page
schedutils: clarify meaning of taskset return code
schedutils: better illustrate the usage of cpu-lists with taskset
schedutils/taskset.1.adoc | 42 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/3 schedutils: clarify confusing mask example in taskset man page
From: Alison Chaiken <[email protected]>
Omit "0x" from a mask example which is clearly hexadecimal rather than omitting it from "32", which could be a decimal representation.
--- schedutils/taskset.1.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
schedutils/taskset.1.adoc +2 -2
@@ -52,10 +52,10 @@ is processor #0, *0x00000003*:: is processors #0 and #1, -*0xFFFFFFFF*:: +*FFFFFFFF*:: is processors #0 through #31, -*32*:: +*0x32*:: is processors #1, #4, and #5, *--cpu-list 0-2,6*::
Signature · 1 line
2.32.0
Re: [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page
Hi,
Quoted 27 lines · CET,
From: Alison Chaiken <[email protected]>
Omit "0x" from a mask example which is clearly hexadecimal rather than omitting it from "32", which could be a decimal representation.
--- schedutils/taskset.1.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)schedutils/taskset.1.adoc +2
-2@@ -52,10 +52,10 @@ is processor #0, *0x00000003*:: is processors #0 and #1, -*0xFFFFFFFF*:: +*FFFFFFFF*:: is processors #0 through #31, -*32*:: +*0x32*:: is processors #1, #4, and #5, *--cpu-list 0-2,6*::Signature · 1 line
2.32.0
I'd keep the 0x prefix simply for consistency reasons. It's easy for the eye to recognize the character sequence as a number and looks cleaner in general.
The second change, however, I think is right for the very same reason.
--
Best Regards,
Tom Schwindl
PATCH 2/3 schedutils: clarify meaning of taskset return code
In reply to [email protected]From: Alison Chaiken <[email protected]>
Make clear that an EXIT_SUCCESS value returned by taskset does not mean that a thread has actually migrated to a core matching the affinity request.
--- schedutils/taskset.1.adoc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
schedutils/taskset.1.adoc +29 -1
@@ -42,7 +42,7 @@ taskset - set or retrieve a process's CPU affinity == DESCRIPTION -The *taskset* command is used to set or retrieve the CPU affinity of a running process given its _pid_, or to launch a new _command_ with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications. +The *taskset* command is used to set or retrieve the CPU affinity of a running process given its _pid_, or to launch a new _command_ with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications. The affinity of some processes like kernel per-CPU threads cannot be set. The CPU affinity is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. Not all CPUs may exist on a given system but a mask may specify more CPUs than are present. A retrieved mask will reflect only the bits that correspond to CPUs physically on the system. If an invalid mask is given (i.e., one that corresponds to no valid CPUs on the current system) an error is returned. The masks may be specified in hexadecimal (with or without a leading "0x"), or as a CPU list with the *--cpu-list* option. For example,
@@ -97,6 +97,34 @@ Or set it{colon}:: A user can change the CPU affinity of a process belonging to the same user. A user must possess *CAP_SYS_NICE* to change the CPU affinity of a process belonging to another user. A user can retrieve the affinity mask of any process. +== RETURN VALUE + +*Taskset* returns 0 in its affinity-getting mode as long as the provided PID exists. + +*Taskset* returns 0 in its affinity-setting mode as long as the underlying *sched_setaffinity()* system call does. The success of the command does not guarantee that the specified thread has actually migrated to the indicated CPU(s), but only that the thread will not migrate to a CPU outside the new affinity mask. For example, the affinity of the kernel thread kswapd can be set, but the thread may not immediately migrate and is not guaranteed to ever do so: + +$ ps ax -o comm,psr,pid | grep kswapd + +kswapd0 4 82 + +$ sudo taskset -p 1 82 + +pid 82's current affinity mask: 1 + +pid 82's new affinity mask: 1 + +$ echo $? + +0 + +$ ps ax -o comm,psr,pid | grep kswapd + +kswapd0 4 82 + +$ taskset -p 82 + +pid 82's current affinity mask: 1 + + +In contrast, when the user specifies an illegal affinity, taskset will print an error and return 1: + +$ ps ax -o comm,psr,pid | grep ksoftirqd/0 + +ksoftirqd/0 0 14 + +$ sudo taskset -p 1 14 + +pid 14's current affinity mask: 1 + +taskset: failed to set pid 14's affinity: Invalid argument + +$ echo $? + +1 + + == AUTHORS Written by Robert M. Love.
Signature · 1 line
2.32.0
PATCH 3/3 schedutils: better illustrate the usage of cpu-lists with taskset
In reply to [email protected]From: Alison Chaiken <[email protected]>
Provide a few examples of how to use the cpu-list variant of the taskset command.
--- schedutils/taskset.1.adoc | 8 ++++++++ 1 file changed, 8 insertions(+)
schedutils/taskset.1.adoc +8 -0
@@ -93,6 +93,14 @@ You can also retrieve the CPU affinity of an existing task{colon}:: Or set it{colon}:: *taskset -p* _mask pid_ +//TRANSLATORS: Keep {colon} untranslated. +When a cpu-list is specified for an existing process, the 'p' and 'c' options must be grouped together{colon}:: +*taskset -pc* _cpu-list pid_ + +//TRANSLATORS: Keep {colon} untranslated. +The *--cpu-list* form is applicable only for launching new commands{colon}:: +*taskset --cpu-list* _cpu-list command_ + == PERMISSIONS A user can change the CPU affinity of a process belonging to the same user. A user must possess *CAP_SYS_NICE* to change the CPU affinity of a process belonging to another user. A user can retrieve the affinity mask of any process.
Signature · 1 line
2.32.0