If the PF_NO_SETAFFINITY process flag is set, the user may not know why the affinity is not settable. Write a respective message and do not attempt to set the affinity of this process. Signed-off-by: Carsten Emde <C.Emde@xxxxxxxxx> --- schedutils/taskset.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) Index: util-linux/schedutils/taskset.c =================================================================== --- util-linux.orig/schedutils/taskset.c +++ util-linux/schedutils/taskset.c @@ -35,6 +35,11 @@ #include "c.h" #include "closestream.h" +#ifndef PF_NO_SETAFFINITY +#define PF_NO_SETAFFINITY 0x04000000 +#endif +#define PF_NO_SETAFFINITY_ITEM 9 + struct taskset { pid_t pid; /* task PID */ cpu_set_t *set; /* task CPU mask */ @@ -114,6 +119,8 @@ static void __attribute__((__noreturn__) static void do_taskset(struct taskset *ts, size_t setsize, cpu_set_t *set) { + char statfilename[32]; + /* read the current mask */ if (ts->pid) { if (sched_getaffinity(ts->pid, ts->setsize, ts->set) < 0) @@ -124,6 +131,52 @@ static void do_taskset(struct taskset *t if (ts->get_only) return; + /* check whether settable */ + if (snprintf(statfilename, sizeof(statfilename), "/proc/%d/stat", ts->pid) > 0) { + int statfd; + char *nosetwarning = + "warning: affinity cannot be set due to PF_NO_SETAFFINITY flag set\n"; + + if ((statfd = open(statfilename, O_RDONLY)) > 0) { + char stat[1024]; + int got; + + if ((got = read(statfd, stat, sizeof(stat))) > 0) { + char *endptr, *token = stat; + int flags, item = PF_NO_SETAFFINITY_ITEM-1; + + token[got] = '\0'; + while (token != NULL && --item > 0) { + token = strchr(token, ' '); + if (token != NULL) + token++; + if (*token != '\0' && *token == '(') { + token = strchr(token, ')'); + if (token != NULL && *token != '\0') + token++; + if (*token != '\0') + token++; + } + } + if (item == 0 && token != NULL && *token != '\0') { + char *nextspace = strchr(token, ' '); + + if (nextspace != NULL) + *nextspace = '\0'; + flags = strtol(token, &endptr, 10); + if (endptr == token + strlen(token)) { + if (flags & PF_NO_SETAFFINITY) { + fputs(nosetwarning, stderr); + errno = EINVAL; + err_affinity(ts->pid, 1); + } + } + } + } + close(statfd); + } + } + /* set new mask */ if (sched_setaffinity(ts->pid, setsize, set) < 0) err_affinity(ts->pid, 1);