Skip to contentSkip to conversation

ltp/numa: use string to describe operation

PATCH New Li Wang 2 participants 5 messages May 19, 2017 – May 24, 2017

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v3 3/3 ltp/numa: use string to describe operation

---
 testcases/kernel/numa/numa01.sh      | 24 +++++++++---------------
 testcases/kernel/numa/support_numa.c | 23 +++++++++--------------
 2 files changed, 18 insertions(+), 29 deletions(-)
testcases/kernel/numa/numa01.sh +9 -15
index 93d74cc..4eda3f1 100755
@@ -86,12 +86,6 @@ setup()
 	export PAGE_SIZE=$(getconf PAGE_SIZE)
 	export HPAGE_SIZE=$(awk '/Hugepagesize:/ {print $2}' /proc/meminfo)
 
-	# arguments to memory exercise program support_numa.c
-	ALLOC_1MB=1
-	SHARE_1MB=2
-	HUGE_PAGE=3
-	PAUSE=4
-
 	total_nodes=0
 
 	nodes_list=$(numactl --show | grep nodebind | cut -d ':' -f 2)
@@ -112,7 +106,7 @@ test1()
 	Mem_curr=0
 
 	for node in $nodes_list; do
-		numactl --cpunodebind=$node --membind=$node support_numa $ALLOC_1MB &
+		numactl --cpunodebind=$node --membind=$node support_numa alloc_1MB &
 		pid=$!
 
 		wait_for_support_numa $pid
@@ -146,7 +140,7 @@ test2()
 			Preferred_node=$(echo $nodes_list | cut -d ' ' -f $((COUNTER+1)))
 		fi
 
-		numactl --cpunodebind=$node --preferred=$Preferred_node support_numa $ALLOC_1MB &
+		numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_1MB &
 		pid=$!
 
 		wait_for_support_numa $pid
@@ -182,7 +176,7 @@ test3()
 			Preferred_node=$(echo $nodes_list | cut -d ' ' -f $((COUNTER+1)))
 		fi
 
-		numactl --cpunodebind=$node --preferred=$Preferred_node support_numa $SHARE_1MB &
+		numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_1MB_shared &
 		pid=$!
 
 		wait_for_support_numa $pid
@@ -209,7 +203,7 @@ test4()
 	# Memory will be allocated using round robin on nodes.
 	Exp_incr=$(echo "$MB / $total_nodes" |bc)
 
-	numactl --interleave=all support_numa $ALLOC_1MB &
+	numactl --interleave=all support_numa alloc_1MB &
 	pid=$!
 
 	wait_for_support_numa $pid
@@ -236,7 +230,7 @@ test5()
 	# Memory will be allocated using round robin on nodes.
 	Exp_incr=$(echo "$MB / $total_nodes" |bc)
 
-	numactl --interleave=all support_numa $SHARE_1MB &
+	numactl --interleave=all support_numa alloc_1MB_shared &
 	pid=$!
 
 	wait_for_support_numa $pid
@@ -267,7 +261,7 @@ test6()
 	no_of_cpus=$(tst_ncpus)
 	# not sure whether cpu's can't be in odd number
 	run_on_cpu=$(($((no_of_cpus+1))/2))
-	numactl --physcpubind=$run_on_cpu support_numa $PAUSE & #just waits for sigint
+	numactl --physcpubind=$run_on_cpu support_numa pause & #just waits for sigint
 	pid=$!
 	var=`awk '{ print $2 }' /proc/$pid/stat`
 	while [ $var = '(numactl)' ]; do
@@ -295,7 +289,7 @@ test7()
 	Mem_curr=0
 
 	for node in $nodes_list; do
-		numactl --cpunodebind=$node --localalloc support_numa $ALLOC_1MB &
+		numactl --cpunodebind=$node --localalloc support_numa alloc_1MB &
 		pid=$!
 
 		wait_for_support_numa $pid
@@ -388,7 +382,7 @@ test10()
 			Preferred_node=$(echo $nodes_list | cut -d ' ' -f $((COUNTER+1)))
 		fi
 
-		numactl --preferred=$node support_numa $ALLOC_1MB &
+		numactl --preferred=$node support_numa alloc_1MB &
 		pid=$!
 
 		wait_for_support_numa $pid
@@ -432,7 +426,7 @@ test11()
 			return
 		fi
 
-		numactl --cpunodebind=$node --membind=$node support_numa $HUGE_PAGE &
+		numactl --cpunodebind=$node --membind=$node support_numa alloc_1huge_page &
 		pid=$!
 		wait_for_support_numa $pid
 
testcases/kernel/numa/support_numa.c +9 -14
index 97f3008..b6aa8bd 100644
@@ -50,10 +50,10 @@
 static void help(void)
 {
 	printf("Input:	Describe input arguments to this program\n");
-	printf("	argv[1] == 1 then allocate 1MB of memory\n");
-	printf("	argv[1] == 2 then allocate 1MB of share memory\n");
-	printf("        argv[1] == 3 then allocate 1HUGE PAGE SIZE of memory\n");
-	printf("        argv[1] == 4 then pause the program to catch sigint\n");
+	printf("	argv[1] == \"alloc_1MB\" then allocate 1MB of memory\n");
+	printf("	argv[1] == \"alloc_1MB_shared\" then allocate 1MB of share memory\n");
+	printf("        argv[1] == \"alloc_1huge_page\" then allocate 1HUGE PAGE SIZE of memory\n");
+	printf("        argv[1] == \"pause\" then pause the program to catch sigint\n");
 	printf("Exit:	On failure - Exits with non-zero value\n");
 	printf("	On success - exits with 0 exit value\n");
 
@@ -97,8 +97,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	switch (atoi(argv[1])) {
-	case 1:
+	if (!strcmp(argv[1], "alloc_1MB")) {
 		buf = malloc(MB);
 		if (!buf) {
 			fprintf(stderr, "Memory is not available\n");
@@ -112,8 +111,7 @@ int main(int argc, char *argv[])
 		raise(SIGSTOP);
 
 		free(buf);
-		break;
-	case 2:
+	} else if (!strcmp(argv[1], "alloc_1MB_shared")) {
 		fd = open(TEST_SFILE, O_RDWR | O_CREAT, 0666);
 		/* Writing 1MB of random data into this file [32 * 32768 = 1024 * 1024] */
 		for (i = 0; i < 32768; i++){
@@ -139,8 +137,7 @@ int main(int argc, char *argv[])
 		munmap(buf, sb.st_size);
 		close(fd);
 		remove(TEST_SFILE);
-		break;
-	case 3:
+	} else if (!strcmp(argv[1], "alloc_1huge_page")) {
 		hpsz = read_hugepagesize();
 		if (hpsz == 0)
 			exit(1);
@@ -159,11 +156,9 @@ int main(int argc, char *argv[])
 		raise(SIGSTOP);
 
 		munmap(buf, hpsz);
-		break;
-	case 4:
+	} else if (!strcmp(argv[1], "pause")) {
 		raise(SIGSTOP);
-		break;
-	default:
+	} else {
 		help();
 	}
 
Signature · 1 line
2.9.3
#1 lore raw

PATCH v3 3/3 ltp/numa: use string to describe operation

Hi!
I've tested and pushed the patchset, thanks.

And also found that memhog test fails on first iteration (when the memhog binary is not in the page cache) because the test script runs too fast and looks at the statistics even befor the memmhog binary has a chance to run. The problem can be simulated for me by dropping caches by

echo 3 > /proc/sys/vm/drop_caches

then running the test.

I guess that the best solution would be to wait for the memhog to print at least one dot before we start the actuall test. Unfortunatelly I cannot think of any better solution than redirectiong the output to a file and then checking the content in the script in a loop.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH v3 3/3 ltp/numa: use string to describe operation

Quoted 8 lines · Cyril Hrubis

Hi!
I've tested and pushed the patchset, thanks.

And also found that memhog test fails on first iteration (when the memhog binary is not in the page cache) because the test script runs too fast and looks at the statistics even befor the memmhog binary has a chance to run. The problem can be simulated for me by dropping caches by

Quoted 8 lines

echo 3 > /proc/sys/vm/drop_caches

then running the test.

I guess that the best solution would be to wait for the memhog to print at least one dot before we start the actuall test. Unfortunatelly I cannot think of any better solution than redirectiong the output to a file and then checking the content in the script in a loop.

Although I didn't hit this problem, I believe the situation is easy to reproduce. As you said above, something changes like:

$ git diff
testcases/kernel/numa/numa01.sh +12 -1
index 4eda3f1..e3fe854 100755
@@ -315,9 +315,20 @@ test8()
        # Memory will be allocated using round robin on nodes.
        Exp_incr=$(echo "$MB / $total_nodes" |bc)
 
-       numactl --interleave=all memhog -r1000000 1MB 2>&1 >/dev/null &
+       numactl --interleave=all memhog -r1000000 1MB 2>&1 >ltp_numa_test8.log &
        pid=$!
 
+       local retries=20
+       while [ $retries -gt 0 ]; do
+
+               if grep -m1 -q '.' ltp_numa_test8.log; then
+                       break
+               fi
+
+               retries=$((retries-1))
+               tst_sleep 50ms
+       done
+
        for node in $nodes_list; do
                Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc)
 

Comment?

Signature · 3 lines
Regards,
Li Wang
Email: [email protected]
#3 lore raw

PATCH v3 3/3 ltp/numa: use string to describe operation

Hi!

Quoted 16 lines
$ git diff
testcases/kernel/numa/numa01.sh +4 -1
index 4eda3f1..e3fe854 100755
@@ -315,9 +315,20 @@ test8()
        # Memory will be allocated using round robin on nodes.
        Exp_incr=$(echo "$MB / $total_nodes" |bc)
 
-       numactl --interleave=all memhog -r1000000 1MB 2>&1 >/dev/null &
+       numactl --interleave=all memhog -r1000000 1MB 2>&1 >ltp_numa_test8.log &
        pid=$!
 
+       local retries=20
+       while [ $retries -gt 0 ]; do
+

testcases/kernel/numa/numa01.sh test8() · line 333

Quoted 10 lines
testcases/kernel/numa/numa01.sh +8 -0
+               if grep -m1 -q '.' ltp_numa_test8.log; then
+                       break
+               fi
+
+               retries=$((retries-1))
+               tst_sleep 50ms
+       done
+
        for node in $nodes_list; do
                Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc)

This fixes the problem for me, can you, pretty please, send a signed patch?

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#4 lore raw

PATCH v3 3/3 ltp/numa: use string to describe operation

Quoted 14 lines · Cyril Hrubis

Hi!

Quoted 13 lines
$ git diff
testcases/kernel/numa/numa01.sh +1 -1
index 4eda3f1..e3fe854 100755
@@ -315,9 +315,20 @@ test8()
        # Memory will be allocated using round robin on nodes.
        Exp_incr=$(echo "$MB / $total_nodes" |bc)
 
-       numactl --interleave=all memhog -r1000000 1MB 2>&1 >/dev/null &
+       numactl --interleave=all memhog -r1000000 1MB 2>&1 >ltp_numa_test8.log &
        pid=$!
 
Quoted 16 lines

testcases/kernel/numa/numa01.sh test8() · line 333

Quoted 13 lines
testcases/kernel/numa/numa01.sh +11 -0
+       local retries=20
+       while [ $retries -gt 0 ]; do
+
+               if grep -m1 -q '.' ltp_numa_test8.log; then
+                       break
+               fi
+
+               retries=$((retries-1))
+               tst_sleep 50ms
+       done
+
        for node in $nodes_list; do
                Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc)

This fixes the problem for me, can you, pretty please, send a signed patch?

Sure, my pleasure.

Signature · 3 lines
Regards,
Li Wang
Email: [email protected]