util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] clarify the usage and behavior of the taskset command
@ 2023-01-07 19:47 alison
  2023-01-07 19:47 ` [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page alison
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: alison @ 2023-01-07 19:47 UTC (permalink / raw)
  To: util-linux; +Cc: kzak, achaiken, alison

From: Alison Chaiken <achaiken@aurora.tech>

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(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page
  2023-01-07 19:47 [PATCH 0/3] clarify the usage and behavior of the taskset command alison
@ 2023-01-07 19:47 ` alison
  2023-01-10 17:25   ` Tom Schwindl
  2023-01-07 19:47 ` [PATCH 2/3] schedutils: clarify meaning of taskset return code alison
  2023-01-07 19:47 ` [PATCH 3/3] schedutils: better illustrate the usage of cpu-lists with taskset alison
  2 siblings, 1 reply; 5+ messages in thread
From: alison @ 2023-01-07 19:47 UTC (permalink / raw)
  To: util-linux; +Cc: kzak, achaiken, alison

From: Alison Chaiken <alison@she-devel.com>

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(-)

diff --git a/schedutils/taskset.1.adoc b/schedutils/taskset.1.adoc
index c10cc62a2..efbab08dc 100644
--- a/schedutils/taskset.1.adoc
+++ b/schedutils/taskset.1.adoc
@@ -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*::
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] schedutils: clarify meaning of taskset return code
  2023-01-07 19:47 [PATCH 0/3] clarify the usage and behavior of the taskset command alison
  2023-01-07 19:47 ` [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page alison
@ 2023-01-07 19:47 ` alison
  2023-01-07 19:47 ` [PATCH 3/3] schedutils: better illustrate the usage of cpu-lists with taskset alison
  2 siblings, 0 replies; 5+ messages in thread
From: alison @ 2023-01-07 19:47 UTC (permalink / raw)
  To: util-linux; +Cc: kzak, achaiken, alison

From: Alison Chaiken <alison@she-devel.com>

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(-)

diff --git a/schedutils/taskset.1.adoc b/schedutils/taskset.1.adoc
index efbab08dc..9609e0c9c 100644
--- a/schedutils/taskset.1.adoc
+++ b/schedutils/taskset.1.adoc
@@ -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.
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] schedutils: better illustrate the usage of cpu-lists with taskset
  2023-01-07 19:47 [PATCH 0/3] clarify the usage and behavior of the taskset command alison
  2023-01-07 19:47 ` [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page alison
  2023-01-07 19:47 ` [PATCH 2/3] schedutils: clarify meaning of taskset return code alison
@ 2023-01-07 19:47 ` alison
  2 siblings, 0 replies; 5+ messages in thread
From: alison @ 2023-01-07 19:47 UTC (permalink / raw)
  To: util-linux; +Cc: kzak, achaiken, alison

From: Alison Chaiken <alison@she-devel.com>

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(+)

diff --git a/schedutils/taskset.1.adoc b/schedutils/taskset.1.adoc
index 9609e0c9c..56084fd3c 100644
--- a/schedutils/taskset.1.adoc
+++ b/schedutils/taskset.1.adoc
@@ -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.
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page
  2023-01-07 19:47 ` [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page alison
@ 2023-01-10 17:25   ` Tom Schwindl
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Schwindl @ 2023-01-10 17:25 UTC (permalink / raw)
  To: alison, util-linux; +Cc: kzak, achaiken

Hi,

On Sat Jan 7, 2023 at 8:47 PM CET,  wrote:
> From: Alison Chaiken <alison@she-devel.com>
>
> 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(-)
>
> diff --git a/schedutils/taskset.1.adoc b/schedutils/taskset.1.adoc
> index c10cc62a2..efbab08dc 100644
> --- a/schedutils/taskset.1.adoc
> +++ b/schedutils/taskset.1.adoc
> @@ -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*::
> -- 
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-10 17:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-07 19:47 [PATCH 0/3] clarify the usage and behavior of the taskset command alison
2023-01-07 19:47 ` [PATCH 1/3] schedutils: clarify confusing mask example in taskset man page alison
2023-01-10 17:25   ` Tom Schwindl
2023-01-07 19:47 ` [PATCH 2/3] schedutils: clarify meaning of taskset return code alison
2023-01-07 19:47 ` [PATCH 3/3] schedutils: better illustrate the usage of cpu-lists with taskset alison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).