Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Make context_switch do something with no args

For ease of use make the context_switch test do something useful when
called with no arguments.

Default to a 30 second run, using threads, doing yield, and use any
online cpu. Make it print out what it's doing to avoid confusion.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: Anton Blanchard <anton@samba.org>

+24 -9
+1
tools/testing/selftests/powerpc/benchmarks/Makefile
··· 6 6 7 7 $(TEST_PROGS): ../harness.c 8 8 9 + context_switch: ../utils.c 9 10 context_switch: LDLIBS += -lpthread 10 11 11 12 include ../../lib.mk
+23 -9
tools/testing/selftests/powerpc/benchmarks/context_switch.c
··· 26 26 #include <sys/shm.h> 27 27 #include <linux/futex.h> 28 28 29 - static unsigned int timeout = INT_MAX; 29 + #include "../utils.h" 30 + 31 + static unsigned int timeout = 30; 30 32 31 33 static int touch_vdso; 32 34 struct timeval tv; ··· 365 363 static void usage(void) 366 364 { 367 365 fprintf(stderr, "Usage: context_switch2 <options> CPU1 CPU2\n\n"); 368 - fprintf(stderr, "\t\t--test=X\tpipe, futex or yield\n"); 366 + fprintf(stderr, "\t\t--test=X\tpipe, futex or yield (default)\n"); 369 367 fprintf(stderr, "\t\t--process\tUse processes (default threads)\n"); 370 - fprintf(stderr, "\t\t--timeout=X\tDuration in seconds to run\n"); 368 + fprintf(stderr, "\t\t--timeout=X\tDuration in seconds to run (default 30)\n"); 371 369 fprintf(stderr, "\t\t--vdso\t\ttouch VDSO\n"); 372 370 fprintf(stderr, "\t\t--fp\t\ttouch FP\n"); 373 371 #ifdef __powerpc__ ··· 379 377 int main(int argc, char *argv[]) 380 378 { 381 379 signed char c; 382 - struct actions *actions = &pipe_actions; 380 + struct actions *actions = &yield_actions; 383 381 int cpu1; 384 382 int cpu2; 385 383 static void (*start_fn)(void *(*fn)(void *), void *arg, unsigned long cpu); ··· 430 428 start_fn = start_thread_on; 431 429 432 430 if (((argc - optind) != 2)) { 433 - usage(); 434 - exit(1); 431 + cpu1 = cpu2 = pick_online_cpu(); 432 + } else { 433 + cpu1 = atoi(argv[optind++]); 434 + cpu2 = atoi(argv[optind++]); 435 435 } 436 + 437 + printf("Using %s with ", processes ? "processes" : "threads"); 438 + 439 + if (actions == &pipe_actions) 440 + printf("pipe"); 441 + else if (actions == &yield_actions) 442 + printf("yield"); 443 + else 444 + printf("futex"); 445 + 446 + printf(" on cpus %d/%d touching FP:%s altivec:%s vector:%s vdso:%s\n", 447 + cpu1, cpu2, touch_fp ? "yes" : "no", touch_altivec ? "yes" : "no", 448 + touch_vector ? "yes" : "no", touch_vdso ? "yes" : "no"); 436 449 437 450 /* Create a new process group so we can signal everyone for exit */ 438 451 setpgid(getpid(), getpid()); 439 452 440 453 signal(SIGUSR1, sigusr1_handler); 441 - 442 - cpu1 = atoi(argv[optind++]); 443 - cpu2 = atoi(argv[optind++]); 444 454 445 455 actions->setup(cpu1, cpu2); 446 456