1 // SPDX-License-Identifier: GPL-2.0
5 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance
9 /* For the CLR_() macros */
12 #include <subcmd/parse-options.h>
13 #include "../util/cloexec.h"
28 #include <sys/resource.h>
30 #include <sys/prctl.h>
31 #include <sys/types.h>
32 #include <linux/kernel.h>
33 #include <linux/time64.h>
34 #include <linux/numa.h>
35 #include <linux/zalloc.h>
41 # define RUSAGE_THREAD 1
45 * Regular printout to the terminal, supressed 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 pthread_mutex_t
*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 pthread_mutex_t startup_mutex
;
140 pthread_cond_t startup_cond
;
141 int nr_tasks_started
;
143 pthread_mutex_t start_work_mutex
;
144 pthread_cond_t start_work_cond
;
145 int nr_tasks_working
;
148 pthread_mutex_t 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 cpu_set_t orig_mask
, mask
;
274 ret
= sched_getaffinity(0, sizeof(orig_mask
), &orig_mask
);
279 if (target_cpu
== -1) {
282 for (cpu
= 0; cpu
< g
->p
.nr_cpus
; cpu
++)
285 BUG_ON(target_cpu
< 0 || target_cpu
>= g
->p
.nr_cpus
);
286 CPU_SET(target_cpu
, &mask
);
289 ret
= sched_setaffinity(0, sizeof(mask
), &mask
);
295 static cpu_set_t
bind_to_node(int target_node
)
297 cpu_set_t orig_mask
, mask
;
301 ret
= sched_getaffinity(0, sizeof(orig_mask
), &orig_mask
);
306 if (target_node
== NUMA_NO_NODE
) {
307 for (cpu
= 0; cpu
< g
->p
.nr_cpus
; cpu
++)
310 struct bitmask
*cpumask
= numa_allocate_cpumask();
313 if (!numa_node_to_cpus(target_node
, cpumask
)) {
314 for (cpu
= 0; cpu
< (int)cpumask
->size
; cpu
++) {
315 if (numa_bitmask_isbitset(cpumask
, cpu
))
319 numa_free_cpumask(cpumask
);
322 ret
= sched_setaffinity(0, sizeof(mask
), &mask
);
328 static void bind_to_cpumask(cpu_set_t mask
)
332 ret
= sched_setaffinity(0, sizeof(mask
), &mask
);
336 static void mempol_restore(void)
340 ret
= set_mempolicy(MPOL_DEFAULT
, NULL
, g
->p
.nr_nodes
-1);
345 static void bind_to_memnode(int node
)
347 unsigned long nodemask
;
350 if (node
== NUMA_NO_NODE
)
353 BUG_ON(g
->p
.nr_nodes
> (int)sizeof(nodemask
)*8);
354 nodemask
= 1L << node
;
356 ret
= set_mempolicy(MPOL_BIND
, &nodemask
, sizeof(nodemask
)*8);
357 dprintf("binding to node %d, mask: %016lx => %d\n", node
, nodemask
, ret
);
362 #define HPSIZE (2*1024*1024)
364 #define set_taskname(fmt...) \
368 snprintf(name, 20, fmt); \
369 prctl(PR_SET_NAME, name); \
372 static u8
*alloc_data(ssize_t bytes0
, int map_flags
,
373 int init_zero
, int init_cpu0
, int thp
, int init_random
)
383 /* Allocate and initialize all memory on CPU#0: */
385 int node
= numa_node_of_cpu(0);
387 orig_mask
= bind_to_node(node
);
388 bind_to_memnode(node
);
391 bytes
= bytes0
+ HPSIZE
;
393 buf
= (void *)mmap(0, bytes
, PROT_READ
|PROT_WRITE
, MAP_ANON
|map_flags
, -1, 0);
394 BUG_ON(buf
== (void *)-1);
396 if (map_flags
== MAP_PRIVATE
) {
398 ret
= madvise(buf
, bytes
, MADV_HUGEPAGE
);
399 if (ret
&& !g
->print_once
) {
401 printf("WARNING: Could not enable THP - do: 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled'\n");
405 ret
= madvise(buf
, bytes
, MADV_NOHUGEPAGE
);
406 if (ret
&& !g
->print_once
) {
408 printf("WARNING: Could not disable THP: run a CONFIG_TRANSPARENT_HUGEPAGE kernel?\n");
416 /* Initialize random contents, different in each word: */
418 u64
*wbuf
= (void *)buf
;
422 for (i
= 0; i
< bytes
/8; i
++)
427 /* Align to 2MB boundary: */
428 buf
= (void *)(((unsigned long)buf
+ HPSIZE
-1) & ~(HPSIZE
-1));
430 /* Restore affinity: */
432 bind_to_cpumask(orig_mask
);
439 static void free_data(void *data
, ssize_t bytes
)
446 ret
= munmap(data
, bytes
);
451 * Create a shared memory buffer that can be shared between processes, zeroed:
453 static void * zalloc_shared_data(ssize_t bytes
)
455 return alloc_data(bytes
, MAP_SHARED
, 1, g
->p
.init_cpu0
, g
->p
.thp
, g
->p
.init_random
);
459 * Create a shared memory buffer that can be shared between processes:
461 static void * setup_shared_data(ssize_t bytes
)
463 return alloc_data(bytes
, MAP_SHARED
, 0, g
->p
.init_cpu0
, g
->p
.thp
, g
->p
.init_random
);
467 * Allocate process-local memory - this will either be shared between
468 * threads of this process, or only be accessed by this thread:
470 static void * setup_private_data(ssize_t bytes
)
472 return alloc_data(bytes
, MAP_PRIVATE
, 0, g
->p
.init_cpu0
, g
->p
.thp
, g
->p
.init_random
);
476 * Return a process-shared (global) mutex:
478 static void init_global_mutex(pthread_mutex_t
*mutex
)
480 pthread_mutexattr_t attr
;
482 pthread_mutexattr_init(&attr
);
483 pthread_mutexattr_setpshared(&attr
, PTHREAD_PROCESS_SHARED
);
484 pthread_mutex_init(mutex
, &attr
);
488 * Return a process-shared (global) condition variable:
490 static void init_global_cond(pthread_cond_t
*cond
)
492 pthread_condattr_t attr
;
494 pthread_condattr_init(&attr
);
495 pthread_condattr_setpshared(&attr
, PTHREAD_PROCESS_SHARED
);
496 pthread_cond_init(cond
, &attr
);
499 static int parse_cpu_list(const char *arg
)
501 p0
.cpu_list_str
= strdup(arg
);
503 dprintf("got CPU list: {%s}\n", p0
.cpu_list_str
);
508 static int parse_setup_cpu_list(void)
510 struct thread_data
*td
;
514 if (!g
->p
.cpu_list_str
)
517 dprintf("g->p.nr_tasks: %d\n", g
->p
.nr_tasks
);
519 str0
= str
= strdup(g
->p
.cpu_list_str
);
524 tprintf("# binding tasks to CPUs:\n");
528 int bind_cpu
, bind_cpu_0
, bind_cpu_1
;
529 char *tok
, *tok_end
, *tok_step
, *tok_len
, *tok_mul
;
534 tok
= strsep(&str
, ",");
538 tok_end
= strstr(tok
, "-");
540 dprintf("\ntoken: {%s}, end: {%s}\n", tok
, tok_end
);
542 /* Single CPU specified: */
543 bind_cpu_0
= bind_cpu_1
= atol(tok
);
545 /* CPU range specified (for example: "5-11"): */
546 bind_cpu_0
= atol(tok
);
547 bind_cpu_1
= atol(tok_end
+ 1);
551 tok_step
= strstr(tok
, "#");
553 step
= atol(tok_step
+ 1);
554 BUG_ON(step
<= 0 || step
>= g
->p
.nr_cpus
);
559 * Eg: "--cpus 8_4-16#4" means: '--cpus 8_4,12_4,16_4',
560 * where the _4 means the next 4 CPUs are allowed.
563 tok_len
= strstr(tok
, "_");
565 bind_len
= atol(tok_len
+ 1);
566 BUG_ON(bind_len
<= 0 || bind_len
> g
->p
.nr_cpus
);
569 /* Multiplicator shortcut, "0x8" is a shortcut for: "0,0,0,0,0,0,0,0" */
571 tok_mul
= strstr(tok
, "x");
573 mul
= atol(tok_mul
+ 1);
577 dprintf("CPUs: %d_%d-%d#%dx%d\n", bind_cpu_0
, bind_len
, bind_cpu_1
, step
, mul
);
579 if (bind_cpu_0
>= g
->p
.nr_cpus
|| bind_cpu_1
>= g
->p
.nr_cpus
) {
580 printf("\nTest not applicable, system has only %d CPUs.\n", g
->p
.nr_cpus
);
584 BUG_ON(bind_cpu_0
< 0 || bind_cpu_1
< 0);
585 BUG_ON(bind_cpu_0
> bind_cpu_1
);
587 for (bind_cpu
= bind_cpu_0
; bind_cpu
<= bind_cpu_1
; bind_cpu
+= step
) {
590 for (i
= 0; i
< mul
; i
++) {
593 if (t
>= g
->p
.nr_tasks
) {
594 printf("\n# NOTE: ignoring bind CPUs starting at CPU#%d\n #", bind_cpu
);
602 tprintf("%2d/%d", bind_cpu
, bind_len
);
604 tprintf("%2d", bind_cpu
);
607 CPU_ZERO(&td
->bind_cpumask
);
608 for (cpu
= bind_cpu
; cpu
< bind_cpu
+bind_len
; cpu
++) {
609 BUG_ON(cpu
< 0 || cpu
>= g
->p
.nr_cpus
);
610 CPU_SET(cpu
, &td
->bind_cpumask
);
620 if (t
< g
->p
.nr_tasks
)
621 printf("# NOTE: %d tasks bound, %d tasks unbound\n", t
, g
->p
.nr_tasks
- t
);
627 static int parse_cpus_opt(const struct option
*opt __maybe_unused
,
628 const char *arg
, int unset __maybe_unused
)
633 return parse_cpu_list(arg
);
636 static int parse_node_list(const char *arg
)
638 p0
.node_list_str
= strdup(arg
);
640 dprintf("got NODE list: {%s}\n", p0
.node_list_str
);
645 static int parse_setup_node_list(void)
647 struct thread_data
*td
;
651 if (!g
->p
.node_list_str
)
654 dprintf("g->p.nr_tasks: %d\n", g
->p
.nr_tasks
);
656 str0
= str
= strdup(g
->p
.node_list_str
);
661 tprintf("# binding tasks to NODEs:\n");
665 int bind_node
, bind_node_0
, bind_node_1
;
666 char *tok
, *tok_end
, *tok_step
, *tok_mul
;
670 tok
= strsep(&str
, ",");
674 tok_end
= strstr(tok
, "-");
676 dprintf("\ntoken: {%s}, end: {%s}\n", tok
, tok_end
);
678 /* Single NODE specified: */
679 bind_node_0
= bind_node_1
= atol(tok
);
681 /* NODE range specified (for example: "5-11"): */
682 bind_node_0
= atol(tok
);
683 bind_node_1
= atol(tok_end
+ 1);
687 tok_step
= strstr(tok
, "#");
689 step
= atol(tok_step
+ 1);
690 BUG_ON(step
<= 0 || step
>= g
->p
.nr_nodes
);
693 /* Multiplicator shortcut, "0x8" is a shortcut for: "0,0,0,0,0,0,0,0" */
695 tok_mul
= strstr(tok
, "x");
697 mul
= atol(tok_mul
+ 1);
701 dprintf("NODEs: %d-%d #%d\n", bind_node_0
, bind_node_1
, step
);
703 if (bind_node_0
>= g
->p
.nr_nodes
|| bind_node_1
>= g
->p
.nr_nodes
) {
704 printf("\nTest not applicable, system has only %d nodes.\n", g
->p
.nr_nodes
);
708 BUG_ON(bind_node_0
< 0 || bind_node_1
< 0);
709 BUG_ON(bind_node_0
> bind_node_1
);
711 for (bind_node
= bind_node_0
; bind_node
<= bind_node_1
; bind_node
+= step
) {
714 for (i
= 0; i
< mul
; i
++) {
715 if (t
>= g
->p
.nr_tasks
|| !node_has_cpus(bind_node
)) {
716 printf("\n# NOTE: ignoring bind NODEs starting at NODE#%d\n", bind_node
);
722 tprintf(" %2d", bind_node
);
724 tprintf(",%2d", bind_node
);
726 td
->bind_node
= bind_node
;
735 if (t
< g
->p
.nr_tasks
)
736 printf("# NOTE: %d tasks mem-bound, %d tasks unbound\n", t
, g
->p
.nr_tasks
- t
);
742 static int parse_nodes_opt(const struct option
*opt __maybe_unused
,
743 const char *arg
, int unset __maybe_unused
)
748 return parse_node_list(arg
);
751 #define BIT(x) (1ul << x)
753 static inline uint32_t lfsr_32(uint32_t lfsr
)
755 const uint32_t taps
= BIT(1) | BIT(5) | BIT(6) | BIT(31);
756 return (lfsr
>>1) ^ ((0x0u
- (lfsr
& 0x1u
)) & taps
);
760 * Make sure there's real data dependency to RAM (when read
761 * accesses are enabled), so the compiler, the CPU and the
762 * kernel (KSM, zero page, etc.) cannot optimize away RAM
765 static inline u64
access_data(u64
*data
, u64 val
)
769 if (g
->p
.data_writes
)
775 * The worker process does two types of work, a forwards going
776 * loop and a backwards going loop.
778 * We do this so that on multiprocessor systems we do not create
779 * a 'train' of processing, with highly synchronized processes,
780 * skewing the whole benchmark.
782 static u64
do_work(u8
*__data
, long bytes
, int nr
, int nr_max
, int loop
, u64 val
)
784 long words
= bytes
/sizeof(u64
);
785 u64
*data
= (void *)__data
;
786 long chunk_0
, chunk_1
;
791 BUG_ON(!data
&& words
);
792 BUG_ON(data
&& !words
);
797 /* Very simple memset() work variant: */
798 if (g
->p
.data_zero_memset
&& !g
->p
.data_rand_walk
) {
803 /* Spread out by PID/TID nr and by loop nr: */
804 chunk_0
= words
/nr_max
;
805 chunk_1
= words
/g
->p
.nr_loops
;
806 off
= nr
*chunk_0
+ loop
*chunk_1
;
811 if (g
->p
.data_rand_walk
) {
812 u32 lfsr
= nr
+ loop
+ val
;
815 for (i
= 0; i
< words
/1024; i
++) {
818 lfsr
= lfsr_32(lfsr
);
820 start
= lfsr
% words
;
821 end
= min(start
+ 1024, words
-1);
823 if (g
->p
.data_zero_memset
) {
824 bzero(data
+ start
, (end
-start
) * sizeof(u64
));
826 for (j
= start
; j
< end
; j
++)
827 val
= access_data(data
+ j
, val
);
830 } else if (!g
->p
.data_backwards
|| (nr
+ loop
) & 1) {
831 /* Process data forwards: */
838 if (unlikely(d
>= d1
))
840 if (unlikely(d
== d0
))
843 val
= access_data(d
, val
);
848 /* Process data backwards: */
855 if (unlikely(d
< data
))
857 if (unlikely(d
== d0
))
860 val
= access_data(d
, val
);
869 static void update_curr_cpu(int task_nr
, unsigned long bytes_worked
)
873 cpu
= sched_getcpu();
875 g
->threads
[task_nr
].curr_cpu
= cpu
;
876 prctl(0, bytes_worked
);
879 #define MAX_NR_NODES 64
882 * Count the number of nodes a process's threads
885 * A count of 1 means that the process is compressed
886 * to a single node. A count of g->p.nr_nodes means it's
887 * spread out on the whole system.
889 static int count_process_nodes(int process_nr
)
891 char node_present
[MAX_NR_NODES
] = { 0, };
895 for (t
= 0; t
< g
->p
.nr_threads
; t
++) {
896 struct thread_data
*td
;
900 task_nr
= process_nr
*g
->p
.nr_threads
+ t
;
901 td
= g
->threads
+ task_nr
;
903 node
= numa_node_of_cpu(td
->curr_cpu
);
904 if (node
< 0) /* curr_cpu was likely still -1 */
907 node_present
[node
] = 1;
912 for (n
= 0; n
< MAX_NR_NODES
; n
++)
913 nodes
+= node_present
[n
];
919 * Count the number of distinct process-threads a node contains.
921 * A count of 1 means that the node contains only a single
922 * process. If all nodes on the system contain at most one
923 * process then we are well-converged.
925 static int count_node_processes(int node
)
930 for (p
= 0; p
< g
->p
.nr_proc
; p
++) {
931 for (t
= 0; t
< g
->p
.nr_threads
; t
++) {
932 struct thread_data
*td
;
936 task_nr
= p
*g
->p
.nr_threads
+ t
;
937 td
= g
->threads
+ task_nr
;
939 n
= numa_node_of_cpu(td
->curr_cpu
);
950 static void calc_convergence_compression(int *strong
)
952 unsigned int nodes_min
, nodes_max
;
958 for (p
= 0; p
< g
->p
.nr_proc
; p
++) {
959 unsigned int nodes
= count_process_nodes(p
);
966 nodes_min
= min(nodes
, nodes_min
);
967 nodes_max
= max(nodes
, nodes_max
);
970 /* Strong convergence: all threads compress on a single node: */
971 if (nodes_min
== 1 && nodes_max
== 1) {
975 tprintf(" {%d-%d}", nodes_min
, nodes_max
);
979 static void calc_convergence(double runtime_ns_max
, double *convergence
)
981 unsigned int loops_done_min
, loops_done_max
;
983 int nodes
[MAX_NR_NODES
];
994 if (!g
->p
.show_convergence
&& !g
->p
.measure_convergence
)
997 for (node
= 0; node
< g
->p
.nr_nodes
; node
++)
1000 loops_done_min
= -1;
1003 for (t
= 0; t
< g
->p
.nr_tasks
; t
++) {
1004 struct thread_data
*td
= g
->threads
+ t
;
1005 unsigned int loops_done
;
1009 /* Not all threads have written it yet: */
1013 node
= numa_node_of_cpu(cpu
);
1017 loops_done
= td
->loops_done
;
1018 loops_done_min
= min(loops_done
, loops_done_min
);
1019 loops_done_max
= max(loops_done
, loops_done_max
);
1023 nr_min
= g
->p
.nr_tasks
;
1026 for (node
= 0; node
< g
->p
.nr_nodes
; node
++) {
1027 if (!is_node_present(node
))
1030 nr_min
= min(nr
, nr_min
);
1031 nr_max
= max(nr
, nr_max
);
1034 BUG_ON(nr_min
> nr_max
);
1036 BUG_ON(sum
> g
->p
.nr_tasks
);
1038 if (0 && (sum
< g
->p
.nr_tasks
))
1042 * Count the number of distinct process groups present
1043 * on nodes - when we are converged this will decrease
1048 for (node
= 0; node
< g
->p
.nr_nodes
; node
++) {
1051 if (!is_node_present(node
))
1053 processes
= count_node_processes(node
);
1055 tprintf(" %2d/%-2d", nr
, processes
);
1057 process_groups
+= processes
;
1060 distance
= nr_max
- nr_min
;
1062 tprintf(" [%2d/%-2d]", distance
, process_groups
);
1064 tprintf(" l:%3d-%-3d (%3d)",
1065 loops_done_min
, loops_done_max
, loops_done_max
-loops_done_min
);
1067 if (loops_done_min
&& loops_done_max
) {
1068 double skew
= 1.0 - (double)loops_done_min
/loops_done_max
;
1070 tprintf(" [%4.1f%%]", skew
* 100.0);
1073 calc_convergence_compression(&strong
);
1075 if (strong
&& process_groups
== g
->p
.nr_proc
) {
1076 if (!*convergence
) {
1077 *convergence
= runtime_ns_max
;
1078 tprintf(" (%6.1fs converged)\n", *convergence
/ NSEC_PER_SEC
);
1079 if (g
->p
.measure_convergence
) {
1080 g
->all_converged
= true;
1081 g
->stop_work
= true;
1086 tprintf(" (%6.1fs de-converged)", runtime_ns_max
/ NSEC_PER_SEC
);
1093 static void show_summary(double runtime_ns_max
, int l
, double *convergence
)
1095 tprintf("\r # %5.1f%% [%.1f mins]",
1096 (double)(l
+1)/g
->p
.nr_loops
*100.0, runtime_ns_max
/ NSEC_PER_SEC
/ 60.0);
1098 calc_convergence(runtime_ns_max
, convergence
);
1100 if (g
->p
.show_details
>= 0)
1104 static void *worker_thread(void *__tdata
)
1106 struct thread_data
*td
= __tdata
;
1107 struct timeval start0
, start
, stop
, diff
;
1108 int process_nr
= td
->process_nr
;
1109 int thread_nr
= td
->thread_nr
;
1110 unsigned long last_perturbance
;
1111 int task_nr
= td
->task_nr
;
1112 int details
= g
->p
.show_details
;
1113 int first_task
, last_task
;
1114 double convergence
= 0;
1116 double runtime_ns_max
;
1120 u64 bytes_done
, secs
;
1123 struct rusage rusage
;
1125 bind_to_cpumask(td
->bind_cpumask
);
1126 bind_to_memnode(td
->bind_node
);
1128 set_taskname("thread %d/%d", process_nr
, thread_nr
);
1130 global_data
= g
->data
;
1131 process_data
= td
->process_data
;
1132 thread_data
= setup_private_data(g
->p
.bytes_thread
);
1137 if (process_nr
== g
->p
.nr_proc
-1 && thread_nr
== g
->p
.nr_threads
-1)
1141 if (process_nr
== 0 && thread_nr
== 0)
1145 printf("# thread %2d / %2d global mem: %p, process mem: %p, thread mem: %p\n",
1146 process_nr
, thread_nr
, global_data
, process_data
, thread_data
);
1149 if (g
->p
.serialize_startup
) {
1150 pthread_mutex_lock(&g
->startup_mutex
);
1151 g
->nr_tasks_started
++;
1152 /* The last thread wakes the main process. */
1153 if (g
->nr_tasks_started
== g
->p
.nr_tasks
)
1154 pthread_cond_signal(&g
->startup_cond
);
1156 pthread_mutex_unlock(&g
->startup_mutex
);
1158 /* Here we will wait for the main process to start us all at once: */
1159 pthread_mutex_lock(&g
->start_work_mutex
);
1160 g
->start_work
= false;
1161 g
->nr_tasks_working
++;
1162 while (!g
->start_work
)
1163 pthread_cond_wait(&g
->start_work_cond
, &g
->start_work_mutex
);
1165 pthread_mutex_unlock(&g
->start_work_mutex
);
1168 gettimeofday(&start0
, NULL
);
1170 start
= stop
= start0
;
1171 last_perturbance
= start
.tv_sec
;
1173 for (l
= 0; l
< g
->p
.nr_loops
; l
++) {
1179 val
+= do_work(global_data
, g
->p
.bytes_global
, process_nr
, g
->p
.nr_proc
, l
, val
);
1180 val
+= do_work(process_data
, g
->p
.bytes_process
, thread_nr
, g
->p
.nr_threads
, l
, val
);
1181 val
+= do_work(thread_data
, g
->p
.bytes_thread
, 0, 1, l
, val
);
1183 if (g
->p
.sleep_usecs
) {
1184 pthread_mutex_lock(td
->process_lock
);
1185 usleep(g
->p
.sleep_usecs
);
1186 pthread_mutex_unlock(td
->process_lock
);
1189 * Amount of work to be done under a process-global lock:
1191 if (g
->p
.bytes_process_locked
) {
1192 pthread_mutex_lock(td
->process_lock
);
1193 val
+= do_work(process_data
, g
->p
.bytes_process_locked
, thread_nr
, g
->p
.nr_threads
, l
, val
);
1194 pthread_mutex_unlock(td
->process_lock
);
1197 work_done
= g
->p
.bytes_global
+ g
->p
.bytes_process
+
1198 g
->p
.bytes_process_locked
+ g
->p
.bytes_thread
;
1200 update_curr_cpu(task_nr
, work_done
);
1201 bytes_done
+= work_done
;
1203 if (details
< 0 && !g
->p
.perturb_secs
&& !g
->p
.measure_convergence
&& !g
->p
.nr_secs
)
1208 gettimeofday(&stop
, NULL
);
1210 /* Check whether our max runtime timed out: */
1212 timersub(&stop
, &start0
, &diff
);
1213 if ((u32
)diff
.tv_sec
>= g
->p
.nr_secs
) {
1214 g
->stop_work
= true;
1219 /* Update the summary at most once per second: */
1220 if (start
.tv_sec
== stop
.tv_sec
)
1224 * Perturb the first task's equilibrium every g->p.perturb_secs seconds,
1225 * by migrating to CPU#0:
1227 if (first_task
&& g
->p
.perturb_secs
&& (int)(stop
.tv_sec
- last_perturbance
) >= g
->p
.perturb_secs
) {
1228 cpu_set_t orig_mask
;
1232 last_perturbance
= stop
.tv_sec
;
1235 * Depending on where we are running, move into
1236 * the other half of the system, to create some
1239 this_cpu
= g
->threads
[task_nr
].curr_cpu
;
1240 if (this_cpu
< g
->p
.nr_cpus
/2)
1241 target_cpu
= g
->p
.nr_cpus
-1;
1245 orig_mask
= bind_to_cpu(target_cpu
);
1247 /* Here we are running on the target CPU already */
1249 printf(" (injecting perturbalance, moved to CPU#%d)\n", target_cpu
);
1251 bind_to_cpumask(orig_mask
);
1255 timersub(&stop
, &start
, &diff
);
1256 runtime_ns_max
= diff
.tv_sec
* NSEC_PER_SEC
;
1257 runtime_ns_max
+= diff
.tv_usec
* NSEC_PER_USEC
;
1260 printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016"PRIx64
"]\n",
1261 process_nr
, thread_nr
, runtime_ns_max
/ bytes_done
, val
);
1268 timersub(&stop
, &start0
, &diff
);
1269 runtime_ns_max
= diff
.tv_sec
* NSEC_PER_SEC
;
1270 runtime_ns_max
+= diff
.tv_usec
* NSEC_PER_USEC
;
1272 show_summary(runtime_ns_max
, l
, &convergence
);
1275 gettimeofday(&stop
, NULL
);
1276 timersub(&stop
, &start0
, &diff
);
1277 td
->runtime_ns
= diff
.tv_sec
* NSEC_PER_SEC
;
1278 td
->runtime_ns
+= diff
.tv_usec
* NSEC_PER_USEC
;
1279 secs
= td
->runtime_ns
/ NSEC_PER_SEC
;
1280 td
->speed_gbs
= secs
? bytes_done
/ secs
/ 1e9
: 0;
1282 getrusage(RUSAGE_THREAD
, &rusage
);
1283 td
->system_time_ns
= rusage
.ru_stime
.tv_sec
* NSEC_PER_SEC
;
1284 td
->system_time_ns
+= rusage
.ru_stime
.tv_usec
* NSEC_PER_USEC
;
1285 td
->user_time_ns
= rusage
.ru_utime
.tv_sec
* NSEC_PER_SEC
;
1286 td
->user_time_ns
+= rusage
.ru_utime
.tv_usec
* NSEC_PER_USEC
;
1288 free_data(thread_data
, g
->p
.bytes_thread
);
1290 pthread_mutex_lock(&g
->stop_work_mutex
);
1291 g
->bytes_done
+= bytes_done
;
1292 pthread_mutex_unlock(&g
->stop_work_mutex
);
1298 * A worker process starts a couple of threads:
1300 static void worker_process(int process_nr
)
1302 pthread_mutex_t process_lock
;
1303 struct thread_data
*td
;
1304 pthread_t
*pthreads
;
1310 pthread_mutex_init(&process_lock
, NULL
);
1311 set_taskname("process %d", process_nr
);
1314 * Pick up the memory policy and the CPU binding of our first thread,
1315 * so that we initialize memory accordingly:
1317 task_nr
= process_nr
*g
->p
.nr_threads
;
1318 td
= g
->threads
+ task_nr
;
1320 bind_to_memnode(td
->bind_node
);
1321 bind_to_cpumask(td
->bind_cpumask
);
1323 pthreads
= zalloc(g
->p
.nr_threads
* sizeof(pthread_t
));
1324 process_data
= setup_private_data(g
->p
.bytes_process
);
1326 if (g
->p
.show_details
>= 3) {
1327 printf(" # process %2d global mem: %p, process mem: %p\n",
1328 process_nr
, g
->data
, process_data
);
1331 for (t
= 0; t
< g
->p
.nr_threads
; t
++) {
1332 task_nr
= process_nr
*g
->p
.nr_threads
+ t
;
1333 td
= g
->threads
+ task_nr
;
1335 td
->process_data
= process_data
;
1336 td
->process_nr
= process_nr
;
1338 td
->task_nr
= task_nr
;
1341 td
->process_lock
= &process_lock
;
1343 ret
= pthread_create(pthreads
+ t
, NULL
, worker_thread
, td
);
1347 for (t
= 0; t
< g
->p
.nr_threads
; t
++) {
1348 ret
= pthread_join(pthreads
[t
], NULL
);
1352 free_data(process_data
, g
->p
.bytes_process
);
1356 static void print_summary(void)
1358 if (g
->p
.show_details
< 0)
1362 printf(" # %d %s will execute (on %d nodes, %d CPUs):\n",
1363 g
->p
.nr_tasks
, g
->p
.nr_tasks
== 1 ? "task" : "tasks", nr_numa_nodes(), g
->p
.nr_cpus
);
1364 printf(" # %5dx %5ldMB global shared mem operations\n",
1365 g
->p
.nr_loops
, g
->p
.bytes_global
/1024/1024);
1366 printf(" # %5dx %5ldMB process shared mem operations\n",
1367 g
->p
.nr_loops
, g
->p
.bytes_process
/1024/1024);
1368 printf(" # %5dx %5ldMB thread local mem operations\n",
1369 g
->p
.nr_loops
, g
->p
.bytes_thread
/1024/1024);
1373 printf("\n ###\n"); fflush(stdout
);
1376 static void init_thread_data(void)
1378 ssize_t size
= sizeof(*g
->threads
)*g
->p
.nr_tasks
;
1381 g
->threads
= zalloc_shared_data(size
);
1383 for (t
= 0; t
< g
->p
.nr_tasks
; t
++) {
1384 struct thread_data
*td
= g
->threads
+ t
;
1387 /* Allow all nodes by default: */
1388 td
->bind_node
= NUMA_NO_NODE
;
1390 /* Allow all CPUs by default: */
1391 CPU_ZERO(&td
->bind_cpumask
);
1392 for (cpu
= 0; cpu
< g
->p
.nr_cpus
; cpu
++)
1393 CPU_SET(cpu
, &td
->bind_cpumask
);
1397 static void deinit_thread_data(void)
1399 ssize_t size
= sizeof(*g
->threads
)*g
->p
.nr_tasks
;
1401 free_data(g
->threads
, size
);
1404 static int init(void)
1406 g
= (void *)alloc_data(sizeof(*g
), MAP_SHARED
, 1, 0, 0 /* THP */, 0);
1408 /* Copy over options: */
1411 g
->p
.nr_cpus
= numa_num_configured_cpus();
1413 g
->p
.nr_nodes
= numa_max_node() + 1;
1415 /* char array in count_process_nodes(): */
1416 BUG_ON(g
->p
.nr_nodes
> MAX_NR_NODES
|| g
->p
.nr_nodes
< 0);
1418 if (g
->p
.show_quiet
&& !g
->p
.show_details
)
1419 g
->p
.show_details
= -1;
1421 /* Some memory should be specified: */
1422 if (!g
->p
.mb_global_str
&& !g
->p
.mb_proc_str
&& !g
->p
.mb_thread_str
)
1425 if (g
->p
.mb_global_str
) {
1426 g
->p
.mb_global
= atof(g
->p
.mb_global_str
);
1427 BUG_ON(g
->p
.mb_global
< 0);
1430 if (g
->p
.mb_proc_str
) {
1431 g
->p
.mb_proc
= atof(g
->p
.mb_proc_str
);
1432 BUG_ON(g
->p
.mb_proc
< 0);
1435 if (g
->p
.mb_proc_locked_str
) {
1436 g
->p
.mb_proc_locked
= atof(g
->p
.mb_proc_locked_str
);
1437 BUG_ON(g
->p
.mb_proc_locked
< 0);
1438 BUG_ON(g
->p
.mb_proc_locked
> g
->p
.mb_proc
);
1441 if (g
->p
.mb_thread_str
) {
1442 g
->p
.mb_thread
= atof(g
->p
.mb_thread_str
);
1443 BUG_ON(g
->p
.mb_thread
< 0);
1446 BUG_ON(g
->p
.nr_threads
<= 0);
1447 BUG_ON(g
->p
.nr_proc
<= 0);
1449 g
->p
.nr_tasks
= g
->p
.nr_proc
*g
->p
.nr_threads
;
1451 g
->p
.bytes_global
= g
->p
.mb_global
*1024L*1024L;
1452 g
->p
.bytes_process
= g
->p
.mb_proc
*1024L*1024L;
1453 g
->p
.bytes_process_locked
= g
->p
.mb_proc_locked
*1024L*1024L;
1454 g
->p
.bytes_thread
= g
->p
.mb_thread
*1024L*1024L;
1456 g
->data
= setup_shared_data(g
->p
.bytes_global
);
1458 /* Startup serialization: */
1459 init_global_mutex(&g
->start_work_mutex
);
1460 init_global_cond(&g
->start_work_cond
);
1461 init_global_mutex(&g
->startup_mutex
);
1462 init_global_cond(&g
->startup_cond
);
1463 init_global_mutex(&g
->stop_work_mutex
);
1468 if (parse_setup_cpu_list() || parse_setup_node_list())
1477 static void deinit(void)
1479 free_data(g
->data
, g
->p
.bytes_global
);
1482 deinit_thread_data();
1484 free_data(g
, sizeof(*g
));
1489 * Print a short or long result, depending on the verbosity setting:
1491 static void print_res(const char *name
, double val
,
1492 const char *txt_unit
, const char *txt_short
, const char *txt_long
)
1497 if (!g
->p
.show_quiet
)
1498 printf(" %-30s %15.3f, %-15s %s\n", name
, val
, txt_unit
, txt_short
);
1500 printf(" %14.3f %s\n", val
, txt_long
);
1503 static int __bench_numa(const char *name
)
1505 struct timeval start
, stop
, diff
;
1506 u64 runtime_ns_min
, runtime_ns_sum
;
1507 pid_t
*pids
, pid
, wpid
;
1508 double delta_runtime
;
1510 double runtime_sec_max
;
1511 double runtime_sec_min
;
1519 pids
= zalloc(g
->p
.nr_proc
* sizeof(*pids
));
1522 if (g
->p
.serialize_startup
) {
1524 tprintf(" # Startup synchronization: ..."); fflush(stdout
);
1527 gettimeofday(&start
, NULL
);
1529 for (i
= 0; i
< g
->p
.nr_proc
; i
++) {
1531 dprintf(" # process %2d: PID %d\n", i
, pid
);
1535 /* Child process: */
1544 if (g
->p
.serialize_startup
) {
1545 bool threads_ready
= false;
1549 * Wait for all the threads to start up. The last thread will
1550 * signal this process.
1552 pthread_mutex_lock(&g
->startup_mutex
);
1553 while (g
->nr_tasks_started
!= g
->p
.nr_tasks
)
1554 pthread_cond_wait(&g
->startup_cond
, &g
->startup_mutex
);
1556 pthread_mutex_unlock(&g
->startup_mutex
);
1558 /* Wait for all threads to be at the start_work_cond. */
1559 while (!threads_ready
) {
1560 pthread_mutex_lock(&g
->start_work_mutex
);
1561 threads_ready
= (g
->nr_tasks_working
== g
->p
.nr_tasks
);
1562 pthread_mutex_unlock(&g
->start_work_mutex
);
1567 gettimeofday(&stop
, NULL
);
1569 timersub(&stop
, &start
, &diff
);
1571 startup_sec
= diff
.tv_sec
* NSEC_PER_SEC
;
1572 startup_sec
+= diff
.tv_usec
* NSEC_PER_USEC
;
1573 startup_sec
/= NSEC_PER_SEC
;
1575 tprintf(" threads initialized in %.6f seconds.\n", startup_sec
);
1579 /* Start all threads running. */
1580 pthread_mutex_lock(&g
->start_work_mutex
);
1581 g
->start_work
= true;
1582 pthread_mutex_unlock(&g
->start_work_mutex
);
1583 pthread_cond_broadcast(&g
->start_work_cond
);
1585 gettimeofday(&start
, NULL
);
1588 /* Parent process: */
1591 for (i
= 0; i
< g
->p
.nr_proc
; i
++) {
1592 wpid
= waitpid(pids
[i
], &wait_stat
, 0);
1594 BUG_ON(!WIFEXITED(wait_stat
));
1599 runtime_ns_min
= -1LL;
1601 for (t
= 0; t
< g
->p
.nr_tasks
; t
++) {
1602 u64 thread_runtime_ns
= g
->threads
[t
].runtime_ns
;
1604 runtime_ns_sum
+= thread_runtime_ns
;
1605 runtime_ns_min
= min(thread_runtime_ns
, runtime_ns_min
);
1608 gettimeofday(&stop
, NULL
);
1609 timersub(&stop
, &start
, &diff
);
1611 BUG_ON(bench_format
!= BENCH_FORMAT_DEFAULT
);
1613 tprintf("\n ###\n");
1616 runtime_sec_max
= diff
.tv_sec
* NSEC_PER_SEC
;
1617 runtime_sec_max
+= diff
.tv_usec
* NSEC_PER_USEC
;
1618 runtime_sec_max
/= NSEC_PER_SEC
;
1620 runtime_sec_min
= runtime_ns_min
/ NSEC_PER_SEC
;
1622 bytes
= g
->bytes_done
;
1623 runtime_avg
= (double)runtime_ns_sum
/ g
->p
.nr_tasks
/ NSEC_PER_SEC
;
1625 if (g
->p
.measure_convergence
) {
1626 print_res(name
, runtime_sec_max
,
1627 "secs,", "NUMA-convergence-latency", "secs latency to NUMA-converge");
1630 print_res(name
, runtime_sec_max
,
1631 "secs,", "runtime-max/thread", "secs slowest (max) thread-runtime");
1633 print_res(name
, runtime_sec_min
,
1634 "secs,", "runtime-min/thread", "secs fastest (min) thread-runtime");
1636 print_res(name
, runtime_avg
,
1637 "secs,", "runtime-avg/thread", "secs average thread-runtime");
1639 delta_runtime
= (runtime_sec_max
- runtime_sec_min
)/2.0;
1640 print_res(name
, delta_runtime
/ runtime_sec_max
* 100.0,
1641 "%,", "spread-runtime/thread", "% difference between max/avg runtime");
1643 print_res(name
, bytes
/ g
->p
.nr_tasks
/ 1e9
,
1644 "GB,", "data/thread", "GB data processed, per thread");
1646 print_res(name
, bytes
/ 1e9
,
1647 "GB,", "data-total", "GB data processed, total");
1649 print_res(name
, runtime_sec_max
* NSEC_PER_SEC
/ (bytes
/ g
->p
.nr_tasks
),
1650 "nsecs,", "runtime/byte/thread","nsecs/byte/thread runtime");
1652 print_res(name
, bytes
/ g
->p
.nr_tasks
/ 1e9
/ runtime_sec_max
,
1653 "GB/sec,", "thread-speed", "GB/sec/thread speed");
1655 print_res(name
, bytes
/ runtime_sec_max
/ 1e9
,
1656 "GB/sec,", "total-speed", "GB/sec total speed");
1658 if (g
->p
.show_details
>= 2) {
1659 char tname
[14 + 2 * 10 + 1];
1660 struct thread_data
*td
;
1661 for (p
= 0; p
< g
->p
.nr_proc
; p
++) {
1662 for (t
= 0; t
< g
->p
.nr_threads
; t
++) {
1663 memset(tname
, 0, sizeof(tname
));
1664 td
= g
->threads
+ p
*g
->p
.nr_threads
+ t
;
1665 snprintf(tname
, sizeof(tname
), "process%d:thread%d", p
, t
);
1666 print_res(tname
, td
->speed_gbs
,
1667 "GB/sec", "thread-speed", "GB/sec/thread speed");
1668 print_res(tname
, td
->system_time_ns
/ NSEC_PER_SEC
,
1669 "secs", "thread-system-time", "system CPU time/thread");
1670 print_res(tname
, td
->user_time_ns
/ NSEC_PER_SEC
,
1671 "secs", "thread-user-time", "user CPU time/thread");
1685 static int command_size(const char **argv
)
1694 BUG_ON(size
>= MAX_ARGS
);
1699 static void init_params(struct params
*p
, const char *name
, int argc
, const char **argv
)
1703 printf("\n # Running %s \"perf bench numa", name
);
1705 for (i
= 0; i
< argc
; i
++)
1706 printf(" %s", argv
[i
]);
1710 memset(p
, 0, sizeof(*p
));
1712 /* Initialize nonzero defaults: */
1714 p
->serialize_startup
= 1;
1715 p
->data_reads
= true;
1716 p
->data_writes
= true;
1717 p
->data_backwards
= true;
1718 p
->data_rand_walk
= true;
1720 p
->init_random
= true;
1721 p
->mb_global_str
= "1";
1725 p
->run_all
= argc
== 1;
1728 static int run_bench_numa(const char *name
, const char **argv
)
1730 int argc
= command_size(argv
);
1732 init_params(&p0
, name
, argc
, argv
);
1733 argc
= parse_options(argc
, argv
, options
, bench_numa_usage
, 0);
1737 if (__bench_numa(name
))
1746 #define OPT_BW_RAM "-s", "20", "-zZq", "--thp", " 1", "--no-data_rand_walk"
1747 #define OPT_BW_RAM_NOTHP OPT_BW_RAM, "--thp", "-1"
1749 #define OPT_CONV "-s", "100", "-zZ0qcm", "--thp", " 1"
1750 #define OPT_CONV_NOTHP OPT_CONV, "--thp", "-1"
1752 #define OPT_BW "-s", "20", "-zZ0q", "--thp", " 1"
1753 #define OPT_BW_NOTHP OPT_BW, "--thp", "-1"
1756 * The built-in test-suite executed by "perf bench numa -a".
1758 * (A minimum of 4 nodes and 16 GB of RAM is recommended.)
1760 static const char *tests
[][MAX_ARGS
] = {
1761 /* Basic single-stream NUMA bandwidth measurements: */
1762 { "RAM-bw-local,", "mem", "-p", "1", "-t", "1", "-P", "1024",
1763 "-C" , "0", "-M", "0", OPT_BW_RAM
},
1764 { "RAM-bw-local-NOTHP,",
1765 "mem", "-p", "1", "-t", "1", "-P", "1024",
1766 "-C" , "0", "-M", "0", OPT_BW_RAM_NOTHP
},
1767 { "RAM-bw-remote,", "mem", "-p", "1", "-t", "1", "-P", "1024",
1768 "-C" , "0", "-M", "1", OPT_BW_RAM
},
1770 /* 2-stream NUMA bandwidth measurements: */
1771 { "RAM-bw-local-2x,", "mem", "-p", "2", "-t", "1", "-P", "1024",
1772 "-C", "0,2", "-M", "0x2", OPT_BW_RAM
},
1773 { "RAM-bw-remote-2x,", "mem", "-p", "2", "-t", "1", "-P", "1024",
1774 "-C", "0,2", "-M", "1x2", OPT_BW_RAM
},
1776 /* Cross-stream NUMA bandwidth measurement: */
1777 { "RAM-bw-cross,", "mem", "-p", "2", "-t", "1", "-P", "1024",
1778 "-C", "0,8", "-M", "1,0", OPT_BW_RAM
},
1780 /* Convergence latency measurements: */
1781 { " 1x3-convergence,", "mem", "-p", "1", "-t", "3", "-P", "512", OPT_CONV
},
1782 { " 1x4-convergence,", "mem", "-p", "1", "-t", "4", "-P", "512", OPT_CONV
},
1783 { " 1x6-convergence,", "mem", "-p", "1", "-t", "6", "-P", "1020", OPT_CONV
},
1784 { " 2x3-convergence,", "mem", "-p", "2", "-t", "3", "-P", "1020", OPT_CONV
},
1785 { " 3x3-convergence,", "mem", "-p", "3", "-t", "3", "-P", "1020", OPT_CONV
},
1786 { " 4x4-convergence,", "mem", "-p", "4", "-t", "4", "-P", "512", OPT_CONV
},
1787 { " 4x4-convergence-NOTHP,",
1788 "mem", "-p", "4", "-t", "4", "-P", "512", OPT_CONV_NOTHP
},
1789 { " 4x6-convergence,", "mem", "-p", "4", "-t", "6", "-P", "1020", OPT_CONV
},
1790 { " 4x8-convergence,", "mem", "-p", "4", "-t", "8", "-P", "512", OPT_CONV
},
1791 { " 8x4-convergence,", "mem", "-p", "8", "-t", "4", "-P", "512", OPT_CONV
},
1792 { " 8x4-convergence-NOTHP,",
1793 "mem", "-p", "8", "-t", "4", "-P", "512", OPT_CONV_NOTHP
},
1794 { " 3x1-convergence,", "mem", "-p", "3", "-t", "1", "-P", "512", OPT_CONV
},
1795 { " 4x1-convergence,", "mem", "-p", "4", "-t", "1", "-P", "512", OPT_CONV
},
1796 { " 8x1-convergence,", "mem", "-p", "8", "-t", "1", "-P", "512", OPT_CONV
},
1797 { "16x1-convergence,", "mem", "-p", "16", "-t", "1", "-P", "256", OPT_CONV
},
1798 { "32x1-convergence,", "mem", "-p", "32", "-t", "1", "-P", "128", OPT_CONV
},
1800 /* Various NUMA process/thread layout bandwidth measurements: */
1801 { " 2x1-bw-process,", "mem", "-p", "2", "-t", "1", "-P", "1024", OPT_BW
},
1802 { " 3x1-bw-process,", "mem", "-p", "3", "-t", "1", "-P", "1024", OPT_BW
},
1803 { " 4x1-bw-process,", "mem", "-p", "4", "-t", "1", "-P", "1024", OPT_BW
},
1804 { " 8x1-bw-process,", "mem", "-p", "8", "-t", "1", "-P", " 512", OPT_BW
},
1805 { " 8x1-bw-process-NOTHP,",
1806 "mem", "-p", "8", "-t", "1", "-P", " 512", OPT_BW_NOTHP
},
1807 { "16x1-bw-process,", "mem", "-p", "16", "-t", "1", "-P", "256", OPT_BW
},
1809 { " 1x4-bw-thread,", "mem", "-p", "1", "-t", "4", "-T", "256", OPT_BW
},
1810 { " 1x8-bw-thread,", "mem", "-p", "1", "-t", "8", "-T", "256", OPT_BW
},
1811 { "1x16-bw-thread,", "mem", "-p", "1", "-t", "16", "-T", "128", OPT_BW
},
1812 { "1x32-bw-thread,", "mem", "-p", "1", "-t", "32", "-T", "64", OPT_BW
},
1814 { " 2x3-bw-process,", "mem", "-p", "2", "-t", "3", "-P", "512", OPT_BW
},
1815 { " 4x4-bw-process,", "mem", "-p", "4", "-t", "4", "-P", "512", OPT_BW
},
1816 { " 4x6-bw-process,", "mem", "-p", "4", "-t", "6", "-P", "512", OPT_BW
},
1817 { " 4x8-bw-process,", "mem", "-p", "4", "-t", "8", "-P", "512", OPT_BW
},
1818 { " 4x8-bw-process-NOTHP,",
1819 "mem", "-p", "4", "-t", "8", "-P", "512", OPT_BW_NOTHP
},
1820 { " 3x3-bw-process,", "mem", "-p", "3", "-t", "3", "-P", "512", OPT_BW
},
1821 { " 5x5-bw-process,", "mem", "-p", "5", "-t", "5", "-P", "512", OPT_BW
},
1823 { "2x16-bw-process,", "mem", "-p", "2", "-t", "16", "-P", "512", OPT_BW
},
1824 { "1x32-bw-process,", "mem", "-p", "1", "-t", "32", "-P", "2048", OPT_BW
},
1826 { "numa02-bw,", "mem", "-p", "1", "-t", "32", "-T", "32", OPT_BW
},
1827 { "numa02-bw-NOTHP,", "mem", "-p", "1", "-t", "32", "-T", "32", OPT_BW_NOTHP
},
1828 { "numa01-bw-thread,", "mem", "-p", "2", "-t", "16", "-T", "192", OPT_BW
},
1829 { "numa01-bw-thread-NOTHP,",
1830 "mem", "-p", "2", "-t", "16", "-T", "192", OPT_BW_NOTHP
},
1833 static int bench_all(void)
1835 int nr
= ARRAY_SIZE(tests
);
1839 ret
= system("echo ' #'; echo ' # Running test on: '$(uname -a); echo ' #'");
1842 for (i
= 0; i
< nr
; i
++) {
1843 run_bench_numa(tests
[i
][0], tests
[i
] + 1);
1851 int bench_numa(int argc
, const char **argv
)
1853 init_params(&p0
, "main,", argc
, argv
);
1854 argc
= parse_options(argc
, argv
, options
, bench_numa_usage
, 0);
1861 if (__bench_numa(NULL
))
1867 usage_with_options(numa_usage
, options
);