util-linux: add chisol tool to configure task isolation Add chisol tool to configure task isolation. See chisol -h for details. For example, to launch a version of oslat that activates task isolation: chisol -q vmstat_sync -I conf ./oslat -f 1 -c 5 -D 5m -q vmstat_sync: enable quiescing of per-CPU vmstats -I conf: inherit task isolation configuration. To launch an unmodified application: ./chisol -q vmstat_sync -a -I active command args Signed-off-by: Marcelo Tosatti Index: util-linux/schedutils/chisol.c =================================================================== --- /dev/null +++ util-linux/schedutils/chisol.c @@ -0,0 +1,306 @@ +/* + * chisol.c - change task isolation parameters + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2021 Marcelo Tosatti + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nls.h" +#include "strutils.h" +#include "xalloc.h" +#include "procutils.h" +#include "c.h" +#include "closestream.h" + +static void __attribute__((__noreturn__)) usage(void) +{ + FILE *out = stdout; + fprintf(out, + _("Usage: %s [options] cmd [args...]]\n\n"), + program_invocation_short_name); + + fputs(USAGE_SEPARATOR, out); + fputs(_("Change task isolation parameters.\n"), out); + fputs(USAGE_SEPARATOR, out); + + fprintf(out, _( + "Options:\n" + " -q, --quiesce configure quiescing of particular activities\n" + " (to list supported activities see --info)\n" + " -i, --info show supported task isolation features\n" + " -a, --activate activate isolation before exec\n" + " -I, --inherit set inheritance across fork/exec.\n" + " Two modes are available: conf, where only task\n" + " isolation configuration is inherited, or active,\n" + " where configuration and activation are inherited.\n" + )); + printf(USAGE_HELP_OPTIONS(20)); + + fputs(USAGE_SEPARATOR, out); + fprintf(out, _( + "Configure task isolation and run a new command:\n" + " %1$s -q vmstat_sync cmd\n" + "Configure, activate task isolation and run a new command:\n" + " %1$s -a -q vmstat_sync cmd\n" + "To query the supported task isolation features:\n" + " %1$s -i\n"), + program_invocation_short_name); + + printf(USAGE_MAN_TAIL("chisol(1)")); + exit(EXIT_SUCCESS); +} + +struct isol_feat_name { + int val; + char *name; +}; + +struct isol_feat_name featnames[] = { + { ISOL_F_QUIESCE, "quiesce" }, +}; + +struct isol_feat_name qfeatnames[] = { + { ISOL_F_QUIESCE_VMSTATS, "vmstat_sync" }, +}; + +#define SSZ sizeof(struct isol_feat_name) + +static char *featname(int val, struct isol_feat_name *fnames, + unsigned int nrentries) +{ + unsigned int i; + char *name; + + for (i = 0; i < nrentries; i++) { + struct isol_feat_name *f = &fnames[i]; + + if (f->val == val) + return strdup(f->name); + } + + name = malloc(100); + snprintf(name, 100, "0x%x\n", val); + + return name; +} + +static void __attribute__((__noreturn__)) task_isol_info(void) +{ + int ret; + unsigned int i, j; + unsigned long long feats = 0; + + FILE *out = stdout; + + /* Retrieve supported task isolation features */ + ret = prctl(PR_ISOL_FEAT_GET, 0, &feats, 0, 0); + if (ret == -1) { + perror(_("prctl PR_ISOL_FEAT_GET")); + exit(EXIT_FAILURE); + } + + for (i = 0; i < 16; i++) { + if (feats & (1<