From: Andi Kleen <ak@linux.intel.com>
To: cpw@sgi.com
Subject: [PATCH 1/8] Add support for a "same" numamask  to numactl
Date: Wed, 14 Dec 2011 11:38:31 -0800

With more complicated node masks it gets a bit annoying
to type them multiple times, e.g. for -c and -m. Add
a "same" alias that just refers to the previous nodemask.

Since this is only well defined on the command line implement
it in numactl only.
---
 numactl.8 |    4 +++-
 numactl.c |   22 ++++++++++++++++++----
 2 files changed, 21 insertions(+), 5 deletions(-)

Index: numactl-dev/numactl.8
===================================================================
--- numactl-dev.orig/numactl.8
+++ numactl-dev/numactl.8
@@ -95,7 +95,9 @@ may be specifed as +N,N,N or  +N-N or +N
 the node numbers are relative to the process' set of allowed nodes in its
 current cpuset.
 A !N-N notation indicates the inverse of N-N, in other words all nodes
-except N-N.  If used with + notation, specify !+N-N.
+except N-N.  If used with + notation, specify !+N-N. When
+.I same
+is specified the previous nodemask specified on the command line is used.
 .TP
 .B \-\-membind=nodes, \-m nodes
 Only allocate memory from nodes.  Allocation will fail when there
Index: numactl-dev/numactl.c
===================================================================
--- numactl-dev.orig/numactl.c
+++ numactl-dev/numactl.c
@@ -366,6 +366,20 @@ void check_shmbeyond(char *msg)
 	}
 }
 
+static struct bitmask *numactl_parse_nodestring(char *s)
+{
+	static char *last;
+
+	if (s[0] == 's' && !strcmp(s, "same")) {
+		if (!last)
+			usage_msg("same needs previous node specification");
+		s = last;
+	} else {
+		last = s;
+	}
+	return numa_parse_nodestring(s);
+}
+
 int main(int ac, char **av)
 {
 	int c, i, nnodes=0;
@@ -386,7 +400,7 @@ int main(int ac, char **av)
 			exit(0);
 		case 'i': /* --interleave */
 			checknuma();
-			mask = numa_parse_nodestring(optarg);
+			mask = numactl_parse_nodestring(optarg);
 			if (!mask) {
 				printf ("<%s> is invalid\n", optarg);
 				usage();
@@ -404,7 +418,7 @@ int main(int ac, char **av)
 		case 'c': /* --cpubind */
 			dontshm("-c/--cpubind/--cpunodebind");
 			checknuma();
-			mask = numa_parse_nodestring(optarg);
+			mask = numactl_parse_nodestring(optarg);
 			if (!mask) {
 				printf ("<%s> is invalid\n", optarg);
 				usage();
@@ -435,7 +449,7 @@ int main(int ac, char **av)
 		case 'm': /* --membind */
 			checknuma();
 			setpolicy(MPOL_BIND);
-			mask = numa_parse_nodestring(optarg);
+			mask = numactl_parse_nodestring(optarg);
 			if (!mask) {
 				printf ("<%s> is invalid\n", optarg);
 				usage();
@@ -453,7 +467,7 @@ int main(int ac, char **av)
 		case 'p': /* --preferred */
 			checknuma();
 			setpolicy(MPOL_PREFERRED);
-			mask = numa_parse_nodestring(optarg);
+			mask = numactl_parse_nodestring(optarg);
 			if (!mask) {
 				printf ("<%s> is invalid\n", optarg);
 				usage();
