1 // SPDX-License-Identifier: GPL-2.0
5 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance
10 #include <subcmd/parse-options.h>
11 #include "../util/cloexec.h"
26 #include <sys/resource.h>
28 #include <sys/prctl.h>
29 #include <sys/types.h>
30 #include <linux/kernel.h>
31 #include <linux/time64.h>
32 #include <linux/numa.h>
33 #include <linux/zalloc.h>
35 #include "../util/header.h"
36 #include "../util/mutex.h"
41 # define RUSAGE_THREAD 1
45 * Regular printout to the terminal, suppressed if -q is specified:
47 #define tprintf(x...) do { if (g && g->p.show_details >= 0) printf(x); } while (0)
53 #define dprintf(x...) do { if (g && g->p.show_details >= 1) printf(x); } while (0)
57 cpu_set_t *bind_cpumask;
63 unsigned int loops_done;
69 struct mutex *process_lock;
72 /* Parameters set by options: */
75 /* Startup synchronization: */
76 bool serialize_startup;
82 /* Working set sizes: */
83 const char *mb_global_str;
84 const char *mb_proc_str;
85 const char *mb_proc_locked_str;
86 const char *mb_thread_str;
90 double mb_proc_locked;
93 /* Access patterns to the working set: */
97 bool data_zero_memset;
103 /* Working set initialization: */
115 long bytes_process_locked;
121 bool show_convergence;
122 bool measure_convergence;
128 /* Affinity options -C and -N: */
134 /* Global, read-writable area, accessible to all processes and threads: */
139 struct mutex startup_mutex;
140 struct cond startup_cond;
141 int nr_tasks_started;
143 struct mutex start_work_mutex;
144 struct cond start_work_cond;
145 int nr_tasks_working;
148 struct mutex stop_work_mutex;
151 struct thread_data *threads;
153 /* Convergence latency measurement: */
162 static struct global_info *g = NULL;
164 static int parse_cpus_opt(const struct option *opt, const char *arg, int unset);
165 static int parse_nodes_opt(const struct option *opt, const char *arg, int unset);
169 static const struct option options[] = {
170 OPT_INTEGER('p', "nr_proc" , &p0.nr_proc, "number of processes"),
171 OPT_INTEGER('t', "nr_threads" , &p0.nr_threads, "number of threads per process"),
173 OPT_STRING('G', "mb_global" , &p0.mb_global_str, "MB", "global memory (MBs)"),
174 OPT_STRING('P', "mb_proc" , &p0.mb_proc_str, "MB", "process memory (MBs)"),
175 OPT_STRING('L', "mb_proc_locked", &p0.mb_proc_locked_str,"MB", "process serialized/locked memory access (MBs), <= process_memory"),
176 OPT_STRING('T', "mb_thread" , &p0.mb_thread_str, "MB", "thread memory (MBs)"),
178 OPT_UINTEGER('l', "nr_loops" , &p0.nr_loops, "max number of loops to run (default: unlimited)"),
179 OPT_UINTEGER('s', "nr_secs" , &p0.nr_secs, "max number of seconds to run (default: 5 secs)"),
180 OPT_UINTEGER('u', "usleep" , &p0.sleep_usecs, "usecs to sleep per loop iteration"),
182 OPT_BOOLEAN('R', "data_reads" , &p0.data_reads, "access the data via reads (can be mixed with -W)"),
183 OPT_BOOLEAN('W', "data_writes" , &p0.data_writes, "access the data via writes (can be mixed with -R)"),
184 OPT_BOOLEAN('B', "data_backwards", &p0.data_backwards, "access the data backwards as well"),
185 OPT_BOOLEAN('Z', "data_zero_memset", &p0.data_zero_memset,"access the data via glibc bzero only"),
186 OPT_BOOLEAN('r', "data_rand_walk", &p0.data_rand_walk, "access the data with random (32bit LFSR) walk"),
189 OPT_BOOLEAN('z', "init_zero" , &p0.init_zero, "bzero the initial allocations"),
190 OPT_BOOLEAN('I', "init_random" , &p0.init_random, "randomize the contents of the initial allocations"),
191 OPT_BOOLEAN('0', "init_cpu0" , &p0.init_cpu0, "do the initial allocations on CPU#0"),
192 OPT_INTEGER('x', "perturb_secs", &p0.perturb_secs, "perturb thread 0/0 every X secs, to test convergence stability"),
194 OPT_INCR ('d', "show_details" , &p0.show_details, "Show details"),
195 OPT_INCR ('a', "all" , &p0.run_all, "Run all tests in the suite"),
196 OPT_INTEGER('H', "thp" , &p0.thp, "MADV_NOHUGEPAGE < 0 < MADV_HUGEPAGE"),
197 OPT_BOOLEAN('c', "show_convergence", &p0.show_convergence, "show convergence details, "
198 "convergence is reached when each process (all its threads) is running on a single NUMA node."),
199 OPT_BOOLEAN('m', "measure_convergence", &p0.measure_convergence, "measure convergence latency"),
200 OPT_BOOLEAN('q', "quiet" , &p0.show_quiet, "quiet mode"),
201 OPT_BOOLEAN('S', "serialize-startup", &p0.serialize_startup,"serialize thread startup"),
203 /* Special option string parsing callbacks: */
204 OPT_CALLBACK('C', "cpus", NULL, "cpu[,cpu2,...cpuN]",
205 "bind the first N tasks to these specific cpus (the rest is unbound)",
207 OPT_CALLBACK('M', "memnodes", NULL, "node[,node2,...nodeN]",
208 "bind the first N tasks to these specific memory nodes (the rest is unbound)",
213 static const char * const bench_numa_usage[] = {
214 "perf bench numa <options>",
218 static const char * const numa_usage[] = {
219 "perf bench numa mem [<options>]",
224 * To get number of numa nodes present.
226 static int nr_numa_nodes(void)
230 for (i = 0; i < g->p.nr_nodes; i++) {
231 if (numa_bitmask_isbitset(numa_nodes_ptr, i))
239 * To check if given numa node is present.
241 static int is_node_present(int node)
243 return numa_bitmask_isbitset(numa_nodes_ptr, node);
247 * To check given numa node has cpus.
249 static bool node_has_cpus(int node)
251 struct bitmask *cpumask = numa_allocate_cpumask();
252 bool ret = false; /* fall back to nocpus */
256 if (!numa_node_to_cpus(node, cpumask)) {
257 for (cpu = 0; cpu < (int)cpumask->size; cpu++) {
258 if (numa_bitmask_isbitset(cpumask, cpu)) {
264 numa_free_cpumask(cpumask);
269 static cpu_set_t *bind_to_cpu(int target_cpu)
271 int nrcpus = numa_num_possible_cpus();
272 cpu_set_t *orig_mask, *mask;
275 orig_mask = CPU_ALLOC(nrcpus);
277 size = CPU_ALLOC_SIZE(nrcpus);
278 CPU_ZERO_S(size, orig_mask);
280 if (sched_getaffinity(0, size, orig_mask))
283 mask = CPU_ALLOC(nrcpus);
287 CPU_ZERO_S(size, mask);
289 if (target_cpu == -1) {
292 for (cpu = 0; cpu < g->p.nr_cpus; cpu++)
293 CPU_SET_S(cpu, size, mask);
295 if (target_cpu < 0 || target_cpu >= g->p.nr_cpus)
298 CPU_SET_S(target_cpu, size, mask);
301 if (sched_setaffinity(0, size, mask))
311 /* BUG_ON due to failure in allocation of orig_mask/mask */
316 static cpu_set_t *bind_to_node(int target_node)
318 int nrcpus = numa_num_possible_cpus();
320 cpu_set_t *orig_mask, *mask;
323 orig_mask = CPU_ALLOC(nrcpus);
325 size = CPU_ALLOC_SIZE(nrcpus);
326 CPU_ZERO_S(size, orig_mask);
328 if (sched_getaffinity(0, size, orig_mask))
331 mask = CPU_ALLOC(nrcpus);
335 CPU_ZERO_S(size, mask);
337 if (target_node == NUMA_NO_NODE) {
338 for (cpu = 0; cpu < g->p.nr_cpus; cpu++)
339 CPU_SET_S(cpu, size, mask);
341 struct bitmask *cpumask = numa_allocate_cpumask();
346 if (!numa_node_to_cpus(target_node, cpumask)) {
347 for (cpu = 0; cpu < (int)cpumask->size; cpu++) {
348 if (numa_bitmask_isbitset(cpumask, cpu))
349 CPU_SET_S(cpu, size, mask);
352 numa_free_cpumask(cpumask);
355 if (sched_setaffinity(0, size, mask))
365 /* BUG_ON due to failure in allocation of orig_mask/mask */
370 static void bind_to_cpumask(cpu_set_t *mask)
373 size_t size = CPU_ALLOC_SIZE(numa_num_possible_cpus());
375 ret = sched_setaffinity(0, size, mask);
382 static void mempol_restore(void)
386 ret = set_mempolicy(MPOL_DEFAULT, NULL, g->p.nr_nodes-1);
391 static void bind_to_memnode(int node)
393 struct bitmask *node_mask;
396 if (node == NUMA_NO_NODE)
399 node_mask = numa_allocate_nodemask();
402 numa_bitmask_clearall(node_mask);
403 numa_bitmask_setbit(node_mask, node);
405 ret = set_mempolicy(MPOL_BIND, node_mask->maskp, node_mask->size + 1);
406 dprintf("binding to node %d, mask: %016lx => %d\n", node, *node_mask->maskp, ret);
408 numa_bitmask_free(node_mask);
412 #define HPSIZE (2*1024*1024)
414 #define set_taskname(fmt...) \
418 snprintf(name, 20, fmt); \
419 prctl(PR_SET_NAME, name); \
422 static u8 *alloc_data(ssize_t bytes0, int map_flags,
423 int init_zero, int init_cpu0, int thp, int init_random)
425 cpu_set_t *orig_mask = NULL;
433 /* Allocate and initialize all memory on CPU#0: */
435 int node = numa_node_of_cpu(0);
437 orig_mask = bind_to_node(node);
438 bind_to_memnode(node);
441 bytes = bytes0 + HPSIZE;
443 buf = (void *)mmap(0, bytes, PROT_READ|PROT_WRITE, MAP_ANON|map_flags, -1, 0);
444 BUG_ON(buf == (void *)-1);
446 if (map_flags == MAP_PRIVATE) {
448 ret = madvise(buf, bytes, MADV_HUGEPAGE);
449 if (ret && !g->print_once) {
451 printf("WARNING: Could not enable THP - do: 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled'\n");
455 ret = madvise(buf, bytes, MADV_NOHUGEPAGE);
456 if (ret && !g->print_once) {
458 printf("WARNING: Could not disable THP: run a CONFIG_TRANSPARENT_HUGEPAGE kernel?\n");
466 /* Initialize random contents, different in each word: */
468 u64 *wbuf = (void *)buf;
472 for (i = 0; i < bytes/8; i++)
477 /* Align to 2MB boundary: */
478 buf = (void *)(((unsigned long)buf + HPSIZE-1) & ~(HPSIZE-1));
480 /* Restore affinity: */
482 bind_to_cpumask(orig_mask);
490 static void free_data(void *data, ssize_t bytes)
497 ret = munmap(data, bytes);
502 * Create a shared memory buffer that can be shared between processes, zeroed:
504 static void * zalloc_shared_data(ssize_t bytes)
506 return alloc_data(bytes, MAP_SHARED, 1, g->p.init_cpu0, g->p.thp, g->p.init_random);
510 * Create a shared memory buffer that can be shared between processes:
512 static void * setup_shared_data(ssize_t bytes)
514 return alloc_data(bytes, MAP_SHARED, 0, g->p.init_cpu0, g->p.thp, g->p.init_random);
518 * Allocate process-local memory - this will either be shared between
519 * threads of this process, or only be accessed by this thread:
521 static void * setup_private_data(ssize_t bytes)
523 return alloc_data(bytes, MAP_PRIVATE, 0, g->p.init_cpu0, g->p.thp, g->p.init_random);
526 static int parse_cpu_list(const char *arg)
528 p0.cpu_list_str = strdup(arg);
530 dprintf("got CPU list: {%s}\n", p0.cpu_list_str);
535 static int parse_setup_cpu_list(void)
537 struct thread_data *td;
541 if (!g->p.cpu_list_str)
544 dprintf("g->p.nr_tasks: %d\n", g->p.nr_tasks);
546 str0 = str = strdup(g->p.cpu_list_str);
551 tprintf("# binding tasks to CPUs:\n");
555 int bind_cpu, bind_cpu_0, bind_cpu_1;
556 char *tok, *tok_end, *tok_step, *tok_len, *tok_mul;
561 tok = strsep(&str, ",");
565 tok_end = strstr(tok, "-");
567 dprintf("\ntoken: {%s}, end: {%s}\n", tok, tok_end);
569 /* Single CPU specified: */
570 bind_cpu_0 = bind_cpu_1 = atol(tok);
572 /* CPU range specified (for example: "5-11"): */
573 bind_cpu_0 = atol(tok);
574 bind_cpu_1 = atol(tok_end + 1);
578 tok_step = strstr(tok, "#");
580 step = atol(tok_step + 1);
581 BUG_ON(step <= 0 || step >= g->p.nr_cpus);
586 * Eg: "--cpus 8_4-16#4" means: '--cpus 8_4,12_4,16_4',
587 * where the _4 means the next 4 CPUs are allowed.
590 tok_len = strstr(tok, "_");
592 bind_len = atol(tok_len + 1);
593 BUG_ON(bind_len <= 0 || bind_len > g->p.nr_cpus);
596 /* Multiplicator shortcut, "0x8" is a shortcut for: "0,0,0,0,0,0,0,0" */
598 tok_mul = strstr(tok, "x");
600 mul = atol(tok_mul + 1);
604 dprintf("CPUs: %d_%d-%d#%dx%d\n", bind_cpu_0, bind_len, bind_cpu_1, step, mul);
606 if (bind_cpu_0 >= g->p.nr_cpus || bind_cpu_1 >= g->p.nr_cpus) {
607 printf("\nTest not applicable, system has only %d CPUs.\n", g->p.nr_cpus);
611 if (is_cpu_online(bind_cpu_0) != 1 || is_cpu_online(bind_cpu_1) != 1) {
612 printf("\nTest not applicable, bind_cpu_0 or bind_cpu_1 is offline\n");
616 BUG_ON(bind_cpu_0 < 0 || bind_cpu_1 < 0);
617 BUG_ON(bind_cpu_0 > bind_cpu_1);
619 for (bind_cpu = bind_cpu_0; bind_cpu <= bind_cpu_1; bind_cpu += step) {
620 size_t size = CPU_ALLOC_SIZE(g->p.nr_cpus);
623 for (i = 0; i < mul; i++) {
626 if (t >= g->p.nr_tasks) {
627 printf("\n# NOTE: ignoring bind CPUs starting at CPU#%d\n #", bind_cpu);
635 tprintf("%2d/%d", bind_cpu, bind_len);
637 tprintf("%2d", bind_cpu);
640 td->bind_cpumask = CPU_ALLOC(g->p.nr_cpus);
641 BUG_ON(!td->bind_cpumask);
642 CPU_ZERO_S(size, td->bind_cpumask);
643 for (cpu = bind_cpu; cpu < bind_cpu+bind_len; cpu++) {
644 if (cpu < 0 || cpu >= g->p.nr_cpus) {
645 CPU_FREE(td->bind_cpumask);
648 CPU_SET_S(cpu, size, td->bind_cpumask);
658 if (t < g->p.nr_tasks)
659 printf("# NOTE: %d tasks bound, %d tasks unbound\n", t, g->p.nr_tasks - t);
665 static int parse_cpus_opt(const struct option *opt __maybe_unused,
666 const char *arg, int unset __maybe_unused)
671 return parse_cpu_list(arg);
674 static int parse_node_list(const char *arg)
676 p0.node_list_str = strdup(arg);
678 dprintf("got NODE list: {%s}\n", p0.node_list_str);
683 static int parse_setup_node_list(void)
685 struct thread_data *td;
689 if (!g->p.node_list_str)
692 dprintf("g->p.nr_tasks: %d\n", g->p.nr_tasks);
694 str0 = str = strdup(g->p.node_list_str);
699 tprintf("# binding tasks to NODEs:\n");
703 int bind_node, bind_node_0, bind_node_1;
704 char *tok, *tok_end, *tok_step, *tok_mul;
708 tok = strsep(&str, ",");
712 tok_end = strstr(tok, "-");
714 dprintf("\ntoken: {%s}, end: {%s}\n", tok, tok_end);
716 /* Single NODE specified: */
717 bind_node_0 = bind_node_1 = atol(tok);
719 /* NODE range specified (for example: "5-11"): */
720 bind_node_0 = atol(tok);
721 bind_node_1 = atol(tok_end + 1);
725 tok_step = strstr(tok, "#");
727 step = atol(tok_step + 1);
728 BUG_ON(step <= 0 || step >= g->p.nr_nodes);
731 /* Multiplicator shortcut, "0x8" is a shortcut for: "0,0,0,0,0,0,0,0" */
733 tok_mul = strstr(tok, "x");
735 mul = atol(tok_mul + 1);
739 dprintf("NODEs: %d-%d #%d\n", bind_node_0, bind_node_1, step);
741 if (bind_node_0 >= g->p.nr_nodes || bind_node_1 >= g->p.nr_nodes) {
742 printf("\nTest not applicable, system has only %d nodes.\n", g->p.nr_nodes);
746 BUG_ON(bind_node_0 < 0 || bind_node_1 < 0);
747 BUG_ON(bind_node_0 > bind_node_1);
749 for (bind_node = bind_node_0; bind_node <= bind_node_1; bind_node += step) {
752 for (i = 0; i < mul; i++) {
753 if (t >= g->p.nr_tasks || !node_has_cpus(bind_node)) {
754 printf("\n# NOTE: ignoring bind NODEs starting at NODE#%d\n", bind_node);
760 tprintf(" %2d", bind_node);
762 tprintf(",%2d", bind_node);
764 td->bind_node = bind_node;
773 if (t < g->p.nr_tasks)
774 printf("# NOTE: %d tasks mem-bound, %d tasks unbound\n", t, g->p.nr_tasks - t);
780 static int parse_nodes_opt(const struct option *opt __maybe_unused,
781 const char *arg, int unset __maybe_unused)
786 return parse_node_list(arg);
789 static inline uint32_t lfsr_32(uint32_t lfsr)
791 const uint32_t taps = BIT(1) | BIT(5) | BIT(6) | BIT(31);
792 return (lfsr>>1) ^ ((0x0u - (lfsr & 0x1u)) & taps);
796 * Make sure there's real data dependency to RAM (when read
797 * accesses are enabled), so the compiler, the CPU and the
798 * kernel (KSM, zero page, etc.) cannot optimize away RAM
801 static inline u64 access_data(u64 *data, u64 val)
805 if (g->p.data_writes)
811 * The worker process does two types of work, a forwards going
812 * loop and a backwards going loop.
814 * We do this so that on multiprocessor systems we do not create
815 * a 'train' of processing, with highly synchronized processes,
816 * skewing the whole benchmark.
818 static u64 do_work(u8 *__data, long bytes, int nr, int nr_max, int loop, u64 val)
820 long words = bytes/sizeof(u64);
821 u64 *data = (void *)__data;
822 long chunk_0, chunk_1;
827 BUG_ON(!data && words);
828 BUG_ON(data && !words);
833 /* Very simple memset() work variant: */
834 if (g->p.data_zero_memset && !g->p.data_rand_walk) {
839 /* Spread out by PID/TID nr and by loop nr: */
840 chunk_0 = words/nr_max;
841 chunk_1 = words/g->p.nr_loops;
842 off = nr*chunk_0 + loop*chunk_1;
847 if (g->p.data_rand_walk) {
848 u32 lfsr = nr + loop + val;
851 for (i = 0; i < words/1024; i++) {
854 lfsr = lfsr_32(lfsr);
856 start = lfsr % words;
857 end = min(start + 1024, words-1);
859 if (g->p.data_zero_memset) {
860 bzero(data + start, (end-start) * sizeof(u64));
862 for (j = start; j < end; j++)
863 val = access_data(data + j, val);
866 } else if (!g->p.data_backwards || (nr + loop) & 1) {
867 /* Process data forwards: */
874 if (unlikely(d >= d1))
876 if (unlikely(d == d0))
879 val = access_data(d, val);
884 /* Process data backwards: */
891 if (unlikely(d < data))
893 if (unlikely(d == d0))
896 val = access_data(d, val);
905 static void update_curr_cpu(int task_nr, unsigned long bytes_worked)
909 cpu = sched_getcpu();
911 g->threads[task_nr].curr_cpu = cpu;
912 prctl(0, bytes_worked);
916 * Count the number of nodes a process's threads
919 * A count of 1 means that the process is compressed
920 * to a single node. A count of g->p.nr_nodes means it's
921 * spread out on the whole system.
923 static int count_process_nodes(int process_nr)
929 node_present = (char *)malloc(g->p.nr_nodes * sizeof(char));
930 BUG_ON(!node_present);
931 for (nodes = 0; nodes < g->p.nr_nodes; nodes++)
932 node_present[nodes] = 0;
934 for (t = 0; t < g->p.nr_threads; t++) {
935 struct thread_data *td;
939 task_nr = process_nr*g->p.nr_threads + t;
940 td = g->threads + task_nr;
942 node = numa_node_of_cpu(td->curr_cpu);
943 if (node < 0) /* curr_cpu was likely still -1 */ {
948 node_present[node] = 1;
953 for (n = 0; n < g->p.nr_nodes; n++)
954 nodes += node_present[n];
961 * Count the number of distinct process-threads a node contains.
963 * A count of 1 means that the node contains only a single
964 * process. If all nodes on the system contain at most one
965 * process then we are well-converged.
967 static int count_node_processes(int node)
972 for (p = 0; p < g->p.nr_proc; p++) {
973 for (t = 0; t < g->p.nr_threads; t++) {
974 struct thread_data *td;
978 task_nr = p*g->p.nr_threads + t;
979 td = g->threads + task_nr;
981 n = numa_node_of_cpu(td->curr_cpu);
992 static void calc_convergence_compression(int *strong)
994 unsigned int nodes_min, nodes_max;
1000 for (p = 0; p < g->p.nr_proc; p++) {
1001 unsigned int nodes = count_process_nodes(p);
1008 nodes_min = min(nodes, nodes_min);
1009 nodes_max = max(nodes, nodes_max);
1012 /* Strong convergence: all threads compress on a single node: */
1013 if (nodes_min == 1 && nodes_max == 1) {
1017 tprintf(" {%d-%d}", nodes_min, nodes_max);
1021 static void calc_convergence(double runtime_ns_max, double *convergence)
1023 unsigned int loops_done_min, loops_done_max;
1036 if (!g->p.show_convergence && !g->p.measure_convergence)
1039 nodes = (int *)malloc(g->p.nr_nodes * sizeof(int));
1041 for (node = 0; node < g->p.nr_nodes; node++)
1044 loops_done_min = -1;
1047 for (t = 0; t < g->p.nr_tasks; t++) {
1048 struct thread_data *td = g->threads + t;
1049 unsigned int loops_done;
1053 /* Not all threads have written it yet: */
1057 node = numa_node_of_cpu(cpu);
1061 loops_done = td->loops_done;
1062 loops_done_min = min(loops_done, loops_done_min);
1063 loops_done_max = max(loops_done, loops_done_max);
1067 nr_min = g->p.nr_tasks;
1070 for (node = 0; node < g->p.nr_nodes; node++) {
1071 if (!is_node_present(node))
1074 nr_min = min(nr, nr_min);
1075 nr_max = max(nr, nr_max);
1078 BUG_ON(nr_min > nr_max);
1080 BUG_ON(sum > g->p.nr_tasks);
1082 if (0 && (sum < g->p.nr_tasks)) {
1088 * Count the number of distinct process groups present
1089 * on nodes - when we are converged this will decrease
1094 for (node = 0; node < g->p.nr_nodes; node++) {
1097 if (!is_node_present(node))
1099 processes = count_node_processes(node);
1101 tprintf(" %2d/%-2d", nr, processes);
1103 process_groups += processes;
1106 distance = nr_max - nr_min;
1108 tprintf(" [%2d/%-2d]", distance, process_groups);
1110 tprintf(" l:%3d-%-3d (%3d)",
1111 loops_done_min, loops_done_max, loops_done_max-loops_done_min);
1113 if (loops_done_min && loops_done_max) {
1114 double skew = 1.0 - (double)loops_done_min/loops_done_max;
1116 tprintf(" [%4.1f%%]", skew * 100.0);
1119 calc_convergence_compression(&strong);
1121 if (strong && process_groups == g->p.nr_proc) {
1122 if (!*convergence) {
1123 *convergence = runtime_ns_max;
1124 tprintf(" (%6.1fs converged)\n", *convergence / NSEC_PER_SEC);
1125 if (g->p.measure_convergence) {
1126 g->all_converged = true;
1127 g->stop_work = true;
1132 tprintf(" (%6.1fs de-converged)", runtime_ns_max / NSEC_PER_SEC);
1141 static void show_summary(double runtime_ns_max, int l, double *convergence)
1143 tprintf("\r # %5.1f%% [%.1f mins]",
1144 (double)(l+1)/g->p.nr_loops*100.0, runtime_ns_max / NSEC_PER_SEC / 60.0);
1146 calc_convergence(runtime_ns_max, convergence);
1148 if (g->p.show_details >= 0)
1152 static void *worker_thread(void *__tdata)
1154 struct thread_data *td = __tdata;
1155 struct timeval start0, start, stop, diff;
1156 int process_nr = td->process_nr;
1157 int thread_nr = td->thread_nr;
1158 unsigned long last_perturbance;
1159 int task_nr = td->task_nr;
1160 int details = g->p.show_details;
1161 int first_task, last_task;
1162 double convergence = 0;
1164 double runtime_ns_max;
1168 u64 bytes_done, secs;
1171 struct rusage rusage;
1173 bind_to_cpumask(td->bind_cpumask);
1174 bind_to_memnode(td->bind_node);
1176 set_taskname("thread %d/%d", process_nr, thread_nr);
1178 global_data = g->data;
1179 process_data = td->process_data;
1180 thread_data = setup_private_data(g->p.bytes_thread);
1185 if (process_nr == g->p.nr_proc-1 && thread_nr == g->p.nr_threads-1)
1189 if (process_nr == 0 && thread_nr == 0)
1193 printf("# thread %2d / %2d global mem: %p, process mem: %p, thread mem: %p\n",
1194 process_nr, thread_nr, global_data, process_data, thread_data);
1197 if (g->p.serialize_startup) {
1198 mutex_lock(&g->startup_mutex);
1199 g->nr_tasks_started++;
1200 /* The last thread wakes the main process. */
1201 if (g->nr_tasks_started == g->p.nr_tasks)
1202 cond_signal(&g->startup_cond);
1204 mutex_unlock(&g->startup_mutex);
1206 /* Here we will wait for the main process to start us all at once: */
1207 mutex_lock(&g->start_work_mutex);
1208 g->start_work = false;
1209 g->nr_tasks_working++;
1210 while (!g->start_work)
1211 cond_wait(&g->start_work_cond, &g->start_work_mutex);
1213 mutex_unlock(&g->start_work_mutex);
1216 gettimeofday(&start0, NULL);
1218 start = stop = start0;
1219 last_perturbance = start.tv_sec;
1221 for (l = 0; l < g->p.nr_loops; l++) {
1227 val += do_work(global_data, g->p.bytes_global, process_nr, g->p.nr_proc, l, val);
1228 val += do_work(process_data, g->p.bytes_process, thread_nr, g->p.nr_threads, l, val);
1229 val += do_work(thread_data, g->p.bytes_thread, 0, 1, l, val);
1231 if (g->p.sleep_usecs) {
1232 mutex_lock(td->process_lock);
1233 usleep(g->p.sleep_usecs);
1234 mutex_unlock(td->process_lock);
1237 * Amount of work to be done under a process-global lock:
1239 if (g->p.bytes_process_locked) {
1240 mutex_lock(td->process_lock);
1241 val += do_work(process_data, g->p.bytes_process_locked, thread_nr, g->p.nr_threads, l, val);
1242 mutex_unlock(td->process_lock);
1245 work_done = g->p.bytes_global + g->p.bytes_process +
1246 g->p.bytes_process_locked + g->p.bytes_thread;
1248 update_curr_cpu(task_nr, work_done);
1249 bytes_done += work_done;
1251 if (details < 0 && !g->p.perturb_secs && !g->p.measure_convergence && !g->p.nr_secs)
1256 gettimeofday(&stop, NULL);
1258 /* Check whether our max runtime timed out: */
1260 timersub(&stop, &start0, &diff);
1261 if ((u32)diff.tv_sec >= g->p.nr_secs) {
1262 g->stop_work = true;
1267 /* Update the summary at most once per second: */
1268 if (start.tv_sec == stop.tv_sec)
1272 * Perturb the first task's equilibrium every g->p.perturb_secs seconds,
1273 * by migrating to CPU#0:
1275 if (first_task && g->p.perturb_secs && (int)(stop.tv_sec - last_perturbance) >= g->p.perturb_secs) {
1276 cpu_set_t *orig_mask;
1280 last_perturbance = stop.tv_sec;
1283 * Depending on where we are running, move into
1284 * the other half of the system, to create some
1287 this_cpu = g->threads[task_nr].curr_cpu;
1288 if (this_cpu < g->p.nr_cpus/2)
1289 target_cpu = g->p.nr_cpus-1;
1293 orig_mask = bind_to_cpu(target_cpu);
1295 /* Here we are running on the target CPU already */
1297 printf(" (injecting perturbalance, moved to CPU#%d)\n", target_cpu);
1299 bind_to_cpumask(orig_mask);
1300 CPU_FREE(orig_mask);
1304 timersub(&stop, &start, &diff);
1305 runtime_ns_max = diff.tv_sec * NSEC_PER_SEC;
1306 runtime_ns_max += diff.tv_usec * NSEC_PER_USEC;
1309 printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016"PRIx64"]\n",
1310 process_nr, thread_nr, runtime_ns_max / bytes_done, val);
1317 timersub(&stop, &start0, &diff);
1318 runtime_ns_max = diff.tv_sec * NSEC_PER_SEC;
1319 runtime_ns_max += diff.tv_usec * NSEC_PER_USEC;
1321 show_summary(runtime_ns_max, l, &convergence);
1324 gettimeofday(&stop, NULL);
1325 timersub(&stop, &start0, &diff);
1326 td->runtime_ns = diff.tv_sec * NSEC_PER_SEC;
1327 td->runtime_ns += diff.tv_usec * NSEC_PER_USEC;
1328 secs = td->runtime_ns / NSEC_PER_SEC;
1329 td->speed_gbs = secs ? bytes_done / secs / 1e9 : 0;
1331 getrusage(RUSAGE_THREAD, &rusage);
1332 td->system_time_ns = rusage.ru_stime.tv_sec * NSEC_PER_SEC;
1333 td->system_time_ns += rusage.ru_stime.tv_usec * NSEC_PER_USEC;
1334 td->user_time_ns = rusage.ru_utime.tv_sec * NSEC_PER_SEC;
1335 td->user_time_ns += rusage.ru_utime.tv_usec * NSEC_PER_USEC;
1337 free_data(thread_data, g->p.bytes_thread);
1339 mutex_lock(&g->stop_work_mutex);
1340 g->bytes_done += bytes_done;
1341 mutex_unlock(&g->stop_work_mutex);
1347 * A worker process starts a couple of threads:
1349 static void worker_process(int process_nr)
1351 struct mutex process_lock;
1352 struct thread_data *td;
1353 pthread_t *pthreads;
1359 mutex_init(&process_lock);
1360 set_taskname("process %d", process_nr);
1363 * Pick up the memory policy and the CPU binding of our first thread,
1364 * so that we initialize memory accordingly:
1366 task_nr = process_nr*g->p.nr_threads;
1367 td = g->threads + task_nr;
1369 bind_to_memnode(td->bind_node);
1370 bind_to_cpumask(td->bind_cpumask);
1372 pthreads = zalloc(g->p.nr_threads * sizeof(pthread_t));
1373 process_data = setup_private_data(g->p.bytes_process);
1375 if (g->p.show_details >= 3) {
1376 printf(" # process %2d global mem: %p, process mem: %p\n",
1377 process_nr, g->data, process_data);
1380 for (t = 0; t < g->p.nr_threads; t++) {
1381 task_nr = process_nr*g->p.nr_threads + t;
1382 td = g->threads + task_nr;
1384 td->process_data = process_data;
1385 td->process_nr = process_nr;
1387 td->task_nr = task_nr;
1390 td->process_lock = &process_lock;
1392 ret = pthread_create(pthreads + t, NULL, worker_thread, td);
1396 for (t = 0; t < g->p.nr_threads; t++) {
1397 ret = pthread_join(pthreads[t], NULL);
1401 free_data(process_data, g->p.bytes_process);
1405 static void print_summary(void)
1407 if (g->p.show_details < 0)
1411 printf(" # %d %s will execute (on %d nodes, %d CPUs):\n",
1412 g->p.nr_tasks, g->p.nr_tasks == 1 ? "task" : "tasks", nr_numa_nodes(), g->p.nr_cpus);
1413 printf(" # %5dx %5ldMB global shared mem operations\n",
1414 g->p.nr_loops, g->p.bytes_global/1024/1024);
1415 printf(" # %5dx %5ldMB process shared mem operations\n",
1416 g->p.nr_loops, g->p.bytes_process/1024/1024);
1417 printf(" # %5dx %5ldMB thread local mem operations\n",
1418 g->p.nr_loops, g->p.bytes_thread/1024/1024);
1422 printf("\n ###\n"); fflush(stdout);
1425 static void init_thread_data(void)
1427 ssize_t size = sizeof(*g->threads)*g->p.nr_tasks;
1430 g->threads = zalloc_shared_data(size);
1432 for (t = 0; t < g->p.nr_tasks; t++) {
1433 struct thread_data *td = g->threads + t;
1434 size_t cpuset_size = CPU_ALLOC_SIZE(g->p.nr_cpus);
1437 /* Allow all nodes by default: */
1438 td->bind_node = NUMA_NO_NODE;
1440 /* Allow all CPUs by default: */
1441 td->bind_cpumask = CPU_ALLOC(g->p.nr_cpus);
1442 BUG_ON(!td->bind_cpumask);
1443 CPU_ZERO_S(cpuset_size, td->bind_cpumask);
1444 for (cpu = 0; cpu < g->p.nr_cpus; cpu++)
1445 CPU_SET_S(cpu, cpuset_size, td->bind_cpumask);
1449 static void deinit_thread_data(void)
1451 ssize_t size = sizeof(*g->threads)*g->p.nr_tasks;
1454 /* Free the bind_cpumask allocated for thread_data */
1455 for (t = 0; t < g->p.nr_tasks; t++) {
1456 struct thread_data *td = g->threads + t;
1457 CPU_FREE(td->bind_cpumask);
1460 free_data(g->threads, size);
1463 static int init(void)
1465 g = (void *)alloc_data(sizeof(*g), MAP_SHARED, 1, 0, 0 /* THP */, 0);
1467 /* Copy over options: */
1470 g->p.nr_cpus = numa_num_configured_cpus();
1472 g->p.nr_nodes = numa_max_node() + 1;
1474 /* char array in count_process_nodes(): */
1475 BUG_ON(g->p.nr_nodes < 0);
1477 if (g->p.show_quiet && !g->p.show_details)
1478 g->p.show_details = -1;
1480 /* Some memory should be specified: */
1481 if (!g->p.mb_global_str && !g->p.mb_proc_str && !g->p.mb_thread_str)
1484 if (g->p.mb_global_str) {
1485 g->p.mb_global = atof(g->p.mb_global_str);
1486 BUG_ON(g->p.mb_global < 0);
1489 if (g->p.mb_proc_str) {
1490 g->p.mb_proc = atof(g->p.mb_proc_str);
1491 BUG_ON(g->p.mb_proc < 0);
1494 if (g->p.mb_proc_locked_str) {
1495 g->p.mb_proc_locked = atof(g->p.mb_proc_locked_str);
1496 BUG_ON(g->p.mb_proc_locked < 0);
1497 BUG_ON(g->p.mb_proc_locked > g->p.mb_proc);
1500 if (g->p.mb_thread_str) {
1501 g->p.mb_thread = atof(g->p.mb_thread_str);
1502 BUG_ON(g->p.mb_thread < 0);
1505 BUG_ON(g->p.nr_threads <= 0);
1506 BUG_ON(g->p.nr_proc <= 0);
1508 g->p.nr_tasks = g->p.nr_proc*g->p.nr_threads;
1510 g->p.bytes_global = g->p.mb_global *1024L*1024L;
1511 g->p.bytes_process = g->p.mb_proc *1024L*1024L;
1512 g->p.bytes_process_locked = g->p.mb_proc_locked *1024L*1024L;
1513 g->p.bytes_thread = g->p.mb_thread *1024L*1024L;
1515 g->data = setup_shared_data(g->p.bytes_global);
1517 /* Startup serialization: */
1518 mutex_init_pshared(&g->start_work_mutex);
1519 cond_init_pshared(&g->start_work_cond);
1520 mutex_init_pshared(&g->startup_mutex);
1521 cond_init_pshared(&g->startup_cond);
1522 mutex_init_pshared(&g->stop_work_mutex);
1527 if (parse_setup_cpu_list() || parse_setup_node_list())
1536 static void deinit(void)
1538 free_data(g->data, g->p.bytes_global);
1541 deinit_thread_data();
1543 free_data(g, sizeof(*g));
1548 * Print a short or long result, depending on the verbosity setting:
1550 static void print_res(const char *name, double val,
1551 const char *txt_unit, const char *txt_short, const char *txt_long)
1556 if (!g->p.show_quiet)
1557 printf(" %-30s %15.3f, %-15s %s\n", name, val, txt_unit, txt_short);
1559 printf(" %14.3f %s\n", val, txt_long);
1562 static int __bench_numa(const char *name)
1564 struct timeval start, stop, diff;
1565 u64 runtime_ns_min, runtime_ns_sum;
1566 pid_t *pids, pid, wpid;
1567 double delta_runtime;
1569 double runtime_sec_max;
1570 double runtime_sec_min;
1578 pids = zalloc(g->p.nr_proc * sizeof(*pids));
1581 if (g->p.serialize_startup) {
1583 tprintf(" # Startup synchronization: ..."); fflush(stdout);
1586 gettimeofday(&start, NULL);
1588 for (i = 0; i < g->p.nr_proc; i++) {
1590 dprintf(" # process %2d: PID %d\n", i, pid);
1594 /* Child process: */
1603 if (g->p.serialize_startup) {
1604 bool threads_ready = false;
1608 * Wait for all the threads to start up. The last thread will
1609 * signal this process.
1611 mutex_lock(&g->startup_mutex);
1612 while (g->nr_tasks_started != g->p.nr_tasks)
1613 cond_wait(&g->startup_cond, &g->startup_mutex);
1615 mutex_unlock(&g->startup_mutex);
1617 /* Wait for all threads to be at the start_work_cond. */
1618 while (!threads_ready) {
1619 mutex_lock(&g->start_work_mutex);
1620 threads_ready = (g->nr_tasks_working == g->p.nr_tasks);
1621 mutex_unlock(&g->start_work_mutex);
1626 gettimeofday(&stop, NULL);
1628 timersub(&stop, &start, &diff);
1630 startup_sec = diff.tv_sec * NSEC_PER_SEC;
1631 startup_sec += diff.tv_usec * NSEC_PER_USEC;
1632 startup_sec /= NSEC_PER_SEC;
1634 tprintf(" threads initialized in %.6f seconds.\n", startup_sec);
1638 /* Start all threads running. */
1639 mutex_lock(&g->start_work_mutex);
1640 g->start_work = true;
1641 mutex_unlock(&g->start_work_mutex);
1642 cond_broadcast(&g->start_work_cond);
1644 gettimeofday(&start, NULL);
1647 /* Parent process: */
1650 for (i = 0; i < g->p.nr_proc; i++) {
1651 wpid = waitpid(pids[i], &wait_stat, 0);
1653 BUG_ON(!WIFEXITED(wait_stat));
1658 runtime_ns_min = -1LL;
1660 for (t = 0; t < g->p.nr_tasks; t++) {
1661 u64 thread_runtime_ns = g->threads[t].runtime_ns;
1663 runtime_ns_sum += thread_runtime_ns;
1664 runtime_ns_min = min(thread_runtime_ns, runtime_ns_min);
1667 gettimeofday(&stop, NULL);
1668 timersub(&stop, &start, &diff);
1670 BUG_ON(bench_format != BENCH_FORMAT_DEFAULT);
1672 tprintf("\n ###\n");
1675 runtime_sec_max = diff.tv_sec * NSEC_PER_SEC;
1676 runtime_sec_max += diff.tv_usec * NSEC_PER_USEC;
1677 runtime_sec_max /= NSEC_PER_SEC;
1679 runtime_sec_min = runtime_ns_min / NSEC_PER_SEC;
1681 bytes = g->bytes_done;
1682 runtime_avg = (double)runtime_ns_sum / g->p.nr_tasks / NSEC_PER_SEC;
1684 if (g->p.measure_convergence) {
1685 print_res(name, runtime_sec_max,
1686 "secs,", "NUMA-convergence-latency", "secs latency to NUMA-converge");
1689 print_res(name, runtime_sec_max,
1690 "secs,", "runtime-max/thread", "secs slowest (max) thread-runtime");
1692 print_res(name, runtime_sec_min,
1693 "secs,", "runtime-min/thread", "secs fastest (min) thread-runtime");
1695 print_res(name, runtime_avg,
1696 "secs,", "runtime-avg/thread", "secs average thread-runtime");
1698 delta_runtime = (runtime_sec_max - runtime_sec_min)/2.0;
1699 print_res(name, delta_runtime / runtime_sec_max * 100.0,
1700 "%,", "spread-runtime/thread", "% difference between max/avg runtime");
1702 print_res(name, bytes / g->p.nr_tasks / 1e9,
1703 "GB,", "data/thread", "GB data processed, per thread");
1705 print_res(name, bytes / 1e9,
1706 "GB,", "data-total", "GB data processed, total");
1708 print_res(name, runtime_sec_max * NSEC_PER_SEC / (bytes / g->p.nr_tasks),
1709 "nsecs,", "runtime/byte/thread","nsecs/byte/thread runtime");
1711 print_res(name, bytes / g->p.nr_tasks / 1e9 / runtime_sec_max,
1712 "GB/sec,", "thread-speed", "GB/sec/thread speed");
1714 print_res(name, bytes / runtime_sec_max / 1e9,
1715 "GB/sec,", "total-speed", "GB/sec total speed");
1717 if (g->p.show_details >= 2) {
1718 char tname[14 + 2 * 11 + 1];
1719 struct thread_data *td;
1720 for (p = 0; p < g->p.nr_proc; p++) {
1721 for (t = 0; t < g->p.nr_threads; t++) {
1722 memset(tname, 0, sizeof(tname));
1723 td = g->threads + p*g->p.nr_threads + t;
1724 snprintf(tname, sizeof(tname), "process%d:thread%d", p, t);
1725 print_res(tname, td->speed_gbs,
1726 "GB/sec", "thread-speed", "GB/sec/thread speed");
1727 print_res(tname, td->system_time_ns / NSEC_PER_SEC,
1728 "secs", "thread-system-time", "system CPU time/thread");
1729 print_res(tname, td->user_time_ns / NSEC_PER_SEC,
1730 "secs", "thread-user-time", "user CPU time/thread");
1744 static int command_size(const char **argv)
1753 BUG_ON(size >= MAX_ARGS);
1758 static void init_params(struct params *p, const char *name, int argc, const char **argv)
1762 printf("\n # Running %s \"perf bench numa", name);
1764 for (i = 0; i < argc; i++)
1765 printf(" %s", argv[i]);
1769 memset(p, 0, sizeof(*p));
1771 /* Initialize nonzero defaults: */
1773 p->serialize_startup = 1;
1774 p->data_reads = true;
1775 p->data_writes = true;
1776 p->data_backwards = true;
1777 p->data_rand_walk = true;
1779 p->init_random = true;
1780 p->mb_global_str = "1";
1784 p->run_all = argc == 1;
1787 static int run_bench_numa(const char *name, const char **argv)
1789 int argc = command_size(argv);
1791 init_params(&p0, name, argc, argv);
1792 argc = parse_options(argc, argv, options, bench_numa_usage, 0);
1796 if (__bench_numa(name))
1805 #define OPT_BW_RAM "-s", "20", "-zZq", "--thp", " 1", "--no-data_rand_walk"
1806 #define OPT_BW_RAM_NOTHP OPT_BW_RAM, "--thp", "-1"
1808 #define OPT_CONV "-s", "100", "-zZ0qcm", "--thp", " 1"
1809 #define OPT_CONV_NOTHP OPT_CONV, "--thp", "-1"
1811 #define OPT_BW "-s", "20", "-zZ0q", "--thp", " 1"
1812 #define OPT_BW_NOTHP OPT_BW, "--thp", "-1"
1815 * The built-in test-suite executed by "perf bench numa -a".
1817 * (A minimum of 4 nodes and 16 GB of RAM is recommended.)
1819 static const char *tests[][MAX_ARGS] = {
1820 /* Basic single-stream NUMA bandwidth measurements: */
1821 { "RAM-bw-local,", "mem", "-p", "1", "-t", "1", "-P", "1024",
1822 "-C" , "0", "-M", "0", OPT_BW_RAM },
1823 { "RAM-bw-local-NOTHP,",
1824 "mem", "-p", "1", "-t", "1", "-P", "1024",
1825 "-C" , "0", "-M", "0", OPT_BW_RAM_NOTHP },
1826 { "RAM-bw-remote,", "mem", "-p", "1", "-t", "1", "-P", "1024",
1827 "-C" , "0", "-M", "1", OPT_BW_RAM },
1829 /* 2-stream NUMA bandwidth measurements: */
1830 { "RAM-bw-local-2x,", "mem", "-p", "2", "-t", "1", "-P", "1024",
1831 "-C", "0,2", "-M", "0x2", OPT_BW_RAM },
1832 { "RAM-bw-remote-2x,", "mem", "-p", "2", "-t", "1", "-P", "1024",
1833 "-C", "0,2", "-M", "1x2", OPT_BW_RAM },
1835 /* Cross-stream NUMA bandwidth measurement: */
1836 { "RAM-bw-cross,", "mem", "-p", "2", "-t", "1", "-P", "1024",
1837 "-C", "0,8", "-M", "1,0", OPT_BW_RAM },
1839 /* Convergence latency measurements: */
1840 { " 1x3-convergence,", "mem", "-p", "1", "-t", "3", "-P", "512", OPT_CONV },
1841 { " 1x4-convergence,", "mem", "-p", "1", "-t", "4", "-P", "512", OPT_CONV },
1842 { " 1x6-convergence,", "mem", "-p", "1", "-t", "6", "-P", "1020", OPT_CONV },
1843 { " 2x3-convergence,", "mem", "-p", "2", "-t", "3", "-P", "1020", OPT_CONV },
1844 { " 3x3-convergence,", "mem", "-p", "3", "-t", "3", "-P", "1020", OPT_CONV },
1845 { " 4x4-convergence,", "mem", "-p", "4", "-t", "4", "-P", "512", OPT_CONV },
1846 { " 4x4-convergence-NOTHP,",
1847 "mem", "-p", "4", "-t", "4", "-P", "512", OPT_CONV_NOTHP },
1848 { " 4x6-convergence,", "mem", "-p", "4", "-t", "6", "-P", "1020", OPT_CONV },
1849 { " 4x8-convergence,", "mem", "-p", "4", "-t", "8", "-P", "512", OPT_CONV },
1850 { " 8x4-convergence,", "mem", "-p", "8", "-t", "4", "-P", "512", OPT_CONV },
1851 { " 8x4-convergence-NOTHP,",
1852 "mem", "-p", "8", "-t", "4", "-P", "512", OPT_CONV_NOTHP },
1853 { " 3x1-convergence,", "mem", "-p", "3", "-t", "1", "-P", "512", OPT_CONV },
1854 { " 4x1-convergence,", "mem", "-p", "4", "-t", "1", "-P", "512", OPT_CONV },
1855 { " 8x1-convergence,", "mem", "-p", "8", "-t", "1", "-P", "512", OPT_CONV },
1856 { "16x1-convergence,", "mem", "-p", "16", "-t", "1", "-P", "256", OPT_CONV },
1857 { "32x1-convergence,", "mem", "-p", "32", "-t", "1", "-P", "128", OPT_CONV },
1859 /* Various NUMA process/thread layout bandwidth measurements: */
1860 { " 2x1-bw-process,", "mem", "-p", "2", "-t", "1", "-P", "1024", OPT_BW },
1861 { " 3x1-bw-process,", "mem", "-p", "3", "-t", "1", "-P", "1024", OPT_BW },
1862 { " 4x1-bw-process,", "mem", "-p", "4", "-t", "1", "-P", "1024", OPT_BW },
1863 { " 8x1-bw-process,", "mem", "-p", "8", "-t", "1", "-P", " 512", OPT_BW },
1864 { " 8x1-bw-process-NOTHP,",
1865 "mem", "-p", "8", "-t", "1", "-P", " 512", OPT_BW_NOTHP },
1866 { "16x1-bw-process,", "mem", "-p", "16", "-t", "1", "-P", "256", OPT_BW },
1868 { " 1x4-bw-thread,", "mem", "-p", "1", "-t", "4", "-T", "256", OPT_BW },
1869 { " 1x8-bw-thread,", "mem", "-p", "1", "-t", "8", "-T", "256", OPT_BW },
1870 { "1x16-bw-thread,", "mem", "-p", "1", "-t", "16", "-T", "128", OPT_BW },
1871 { "1x32-bw-thread,", "mem", "-p", "1", "-t", "32", "-T", "64", OPT_BW },
1873 { " 2x3-bw-process,", "mem", "-p", "2", "-t", "3", "-P", "512", OPT_BW },
1874 { " 4x4-bw-process,", "mem", "-p", "4", "-t", "4", "-P", "512", OPT_BW },
1875 { " 4x6-bw-process,", "mem", "-p", "4", "-t", "6", "-P", "512", OPT_BW },
1876 { " 4x8-bw-process,", "mem", "-p", "4", "-t", "8", "-P", "512", OPT_BW },
1877 { " 4x8-bw-process-NOTHP,",
1878 "mem", "-p", "4", "-t", "8", "-P", "512", OPT_BW_NOTHP },
1879 { " 3x3-bw-process,", "mem", "-p", "3", "-t", "3", "-P", "512", OPT_BW },
1880 { " 5x5-bw-process,", "mem", "-p", "5", "-t", "5", "-P", "512", OPT_BW },
1882 { "2x16-bw-process,", "mem", "-p", "2", "-t", "16", "-P", "512", OPT_BW },
1883 { "1x32-bw-process,", "mem", "-p", "1", "-t", "32", "-P", "2048", OPT_BW },
1885 { "numa02-bw,", "mem", "-p", "1", "-t", "32", "-T", "32", OPT_BW },
1886 { "numa02-bw-NOTHP,", "mem", "-p", "1", "-t", "32", "-T", "32", OPT_BW_NOTHP },
1887 { "numa01-bw-thread,", "mem", "-p", "2", "-t", "16", "-T", "192", OPT_BW },
1888 { "numa01-bw-thread-NOTHP,",
1889 "mem", "-p", "2", "-t", "16", "-T", "192", OPT_BW_NOTHP },
1892 static int bench_all(void)
1894 int nr = ARRAY_SIZE(tests);
1898 ret = system("echo ' #'; echo ' # Running test on: '$(uname -a); echo ' #'");
1901 for (i = 0; i < nr; i++) {
1902 run_bench_numa(tests[i][0], tests[i] + 1);
1910 int bench_numa(int argc, const char **argv)
1912 init_params(&p0, "main,", argc, argv);
1913 argc = parse_options(argc, argv, options, bench_numa_usage, 0);
1920 if (__bench_numa(NULL))
1926 usage_with_options(numa_usage, options);