Skip to content

Commit

Permalink
numact: Add --cpu-compress option
Browse files Browse the repository at this point in the history
Only compress cpu ranges when this option is set. Otherwise report the
old output. This prevents breaking existing scripts, including
test/checktopology.
  • Loading branch information
Andi Kleen committed Jan 6, 2024
1 parent 5441552 commit 1109fa0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
6 changes: 4 additions & 2 deletions numactl.8
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ numactl \- Control NUMA policy for processes or shared memory
.br
.B numactl \-\-show
.br
.B numactl \-\-hardware
.B numactl \-\-hardware [\-\-cpu-compress]
.br
.B numactl
[
Expand Down Expand Up @@ -190,7 +190,9 @@ Relative notation may be used.
Show NUMA policy settings of the current process.
.TP
.B \-\-hardware, \-H
Show inventory of available nodes on the system.
Show inventory of available nodes on the system. When the
.B \-\-cpu-compress
option is set show cpu ranges. This is not default not break any existing scripts.
.TP 0
Numactl can set up policy for a SYSV shared memory segment or a file in shmfs/hugetlbfs.

Expand Down
33 changes: 29 additions & 4 deletions numactl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#define ALL 1

int exitcode;
int cpu_compress;

enum {
CPU_COMPRESS = 300,
};

static struct option opts[] = {
{"all", 0, 0, 'a'},
Expand All @@ -59,6 +64,7 @@ static struct option opts[] = {
{"shmid", 1, 0, 'I'},
{"huge", 0, 0, 'u'},
{"touch", 0, 0, 'T'},
{"cpu-compress", 0, 0, CPU_COMPRESS },
{"verify", 0, 0, 'V'}, /* undocumented - for debugging */
{ 0 }
};
Expand All @@ -72,7 +78,7 @@ static void usage(void)
" [--membind= | -m <nodes>] [--localalloc | -l] command args ...\n"
" [--localalloc | -l] command args ...\n"
" numactl [--show | -s]\n"
" numactl [--hardware | -H]\n"
" numactl [--hardware | -H] [--cpu-compress]\n"
" numactl [--length | -L <length>] [--offset | -o <offset>] [--shmmode | -M <shmmode>]\n"
" [--strict | -t]\n"
" [--shmid | -I <id>] --shm | -S <shmkeyfile>\n"
Expand Down Expand Up @@ -241,6 +247,13 @@ static void print_node_cpus(int node)
}

while (i < cpus->size) {
if (!cpu_compress) {
if (numa_bitmask_isbitset(cpus, i))
printf(" %d", i);
i++;
continue;
}

start = -1;

// Find the start and end of a range of available CPUs.
Expand Down Expand Up @@ -268,7 +281,10 @@ static void print_node_cpus(int node)
segment++;
}

printf(" (%d)\n", count);
if (!cpu_compress)
printf("\n");
else
printf(" (%d)\n", count);

out:
numa_free_cpumask(cpus);
Expand Down Expand Up @@ -461,6 +477,7 @@ int main(int ac, char **av)
int do_dump = 0;
int parse_all = 0;
int numa_balancing = 0;
int do_hardware = 0;

get_short_opts(opts,shortopts);
while ((c = getopt_long(ac, av, shortopts, opts, NULL)) != -1) {
Expand All @@ -470,8 +487,8 @@ int main(int ac, char **av)
exit(0);
case 'H': /* --hardware */
nopolicy();
hardware();
exit(0);
do_hardware = 1;
break;
case 'b': /* --balancing */
nopolicy();
numa_balancing = 1;
Expand Down Expand Up @@ -684,11 +701,19 @@ int main(int ac, char **av)
check_all_parse(did_node_cpu_parse);
parse_all = 1;
break;
case CPU_COMPRESS:
cpu_compress = 1;
break;
default:
usage();
}
}

if (do_hardware) {
hardware();
exit(0);
}

numa_bitmask_free(mask);

av += optind;
Expand Down

0 comments on commit 1109fa0

Please sign in to comment.