Linux Perf
numa.c File Reference
#include <inttypes.h>
#include <pthread.h>
#include "../perf.h"
#include "../builtin.h"
#include "../util/util.h"
#include <subcmd/parse-options.h>
#include "../util/cloexec.h"
#include "bench.h"
#include <errno.h>
#include <sched.h>
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <linux/kernel.h>
#include <linux/time64.h>
#include <numa.h>
#include <numaif.h>
Include dependency graph for numa.c:

Go to the source code of this file.

Classes

struct  thread_data
 
struct  params
 
struct  global_info
 

Macros

#define tprintf(x...)   do { if (g && g->p.show_details >= 0) printf(x); } while (0)
 
#define dprintf(x...)   do { if (g && g->p.show_details >= 1) printf(x); } while (0)
 
#define HPSIZE   (2*1024*1024)
 
#define set_taskname(fmt...)
 
#define BIT(x)   (1ul << x)
 
#define MAX_NR_NODES   64
 
#define MAX_ARGS   50
 
#define OPT_BW_RAM   "-s", "20", "-zZq", "--thp", " 1", "--no-data_rand_walk"
 
#define OPT_BW_RAM_NOTHP   OPT_BW_RAM, "--thp", "-1"
 
#define OPT_CONV   "-s", "100", "-zZ0qcm", "--thp", " 1"
 
#define OPT_CONV_NOTHP   OPT_CONV, "--thp", "-1"
 
#define OPT_BW   "-s", "20", "-zZ0q", "--thp", " 1"
 
#define OPT_BW_NOTHP   OPT_BW, "--thp", "-1"
 

Functions

static int parse_cpus_opt (const struct option *opt, const char *arg, int unset)
 
static int parse_nodes_opt (const struct option *opt, const char *arg, int unset)
 
static int nr_numa_nodes (void)
 
static int is_node_present (int node)
 
static bool node_has_cpus (int node)
 
static cpu_set_t bind_to_cpu (int target_cpu)
 
static cpu_set_t bind_to_node (int target_node)
 
static void bind_to_cpumask (cpu_set_t mask)
 
static void mempol_restore (void)
 
static void bind_to_memnode (int node)
 
static u8 * alloc_data (ssize_t bytes0, int map_flags, int init_zero, int init_cpu0, int thp, int init_random)
 
static void free_data (void *data, ssize_t bytes)
 
static void * zalloc_shared_data (ssize_t bytes)
 
static void * setup_shared_data (ssize_t bytes)
 
static void * setup_private_data (ssize_t bytes)
 
static void init_global_mutex (pthread_mutex_t *mutex)
 
static int parse_cpu_list (const char *arg)
 
static int parse_setup_cpu_list (void)
 
static int parse_cpus_opt (const struct option *opt __maybe_unused, const char *arg, int unset __maybe_unused)
 
static int parse_node_list (const char *arg)
 
static int parse_setup_node_list (void)
 
static int parse_nodes_opt (const struct option *opt __maybe_unused, const char *arg, int unset __maybe_unused)
 
static uint32_t lfsr_32 (uint32_t lfsr)
 
static u64 access_data (u64 *data, u64 val)
 
static u64 do_work (u8 *__data, long bytes, int nr, int nr_max, int loop, u64 val)
 
static void update_curr_cpu (int task_nr, unsigned long bytes_worked)
 
static int count_process_nodes (int process_nr)
 
static int count_node_processes (int node)
 
static void calc_convergence_compression (int *strong)
 
static void calc_convergence (double runtime_ns_max, double *convergence)
 
static void show_summary (double runtime_ns_max, int l, double *convergence)
 
static void * worker_thread (void *__tdata)
 
static void worker_process (int process_nr)
 
static void print_summary (void)
 
static void init_thread_data (void)
 
static void deinit_thread_data (void)
 
static int init (void)
 
static void deinit (void)
 
static void print_res (const char *name, double val, const char *txt_unit, const char *txt_short, const char *txt_long)
 
static int __bench_numa (const char *name)
 
static int command_size (const char **argv)
 
static void init_params (struct params *p, const char *name, int argc, const char **argv)
 
static int run_bench_numa (const char *name, const char **argv)
 
static int bench_all (void)
 
int bench_numa (int argc, const char **argv)
 

Variables

static struct global_infog = NULL
 
struct params p0
 
static const struct option options []
 
static const char *const bench_numa_usage []
 
static const char *const numa_usage []
 
static const char * tests [][MAX_ARGS]
 

Macro Definition Documentation

◆ BIT

#define BIT (   x)    (1ul << x)

Definition at line 731 of file numa.c.

◆ dprintf

#define dprintf (   x...)    do { if (g && g->p.show_details >= 1) printf(x); } while (0)

Definition at line 50 of file numa.c.

◆ HPSIZE

#define HPSIZE   (2*1024*1024)

Definition at line 354 of file numa.c.

◆ MAX_ARGS

#define MAX_ARGS   50

Definition at line 1651 of file numa.c.

◆ MAX_NR_NODES

#define MAX_NR_NODES   64

Definition at line 860 of file numa.c.

◆ OPT_BW

#define OPT_BW   "-s", "20", "-zZ0q", "--thp", " 1"

Definition at line 1720 of file numa.c.

◆ OPT_BW_NOTHP

#define OPT_BW_NOTHP   OPT_BW, "--thp", "-1"

Definition at line 1721 of file numa.c.

◆ OPT_BW_RAM

#define OPT_BW_RAM   "-s", "20", "-zZq", "--thp", " 1", "--no-data_rand_walk"

Definition at line 1714 of file numa.c.

◆ OPT_BW_RAM_NOTHP

#define OPT_BW_RAM_NOTHP   OPT_BW_RAM, "--thp", "-1"

Definition at line 1715 of file numa.c.

◆ OPT_CONV

#define OPT_CONV   "-s", "100", "-zZ0qcm", "--thp", " 1"

Definition at line 1717 of file numa.c.

◆ OPT_CONV_NOTHP

#define OPT_CONV_NOTHP   OPT_CONV, "--thp", "-1"

Definition at line 1718 of file numa.c.

◆ set_taskname

#define set_taskname (   fmt...)
Value:
do { \
char name[20]; \
\
snprintf(name, 20, fmt); \
prctl(PR_SET_NAME, name); \
} while (0)
#define PR_SET_NAME
Definition: builtin-sched.c:41
const char * name
const char * fmt
Definition: dso.c:193

Definition at line 356 of file numa.c.

◆ tprintf

#define tprintf (   x...)    do { if (g && g->p.show_details >= 0) printf(x); } while (0)

Definition at line 44 of file numa.c.

Function Documentation

◆ __bench_numa()

static int __bench_numa ( const char *  name)
static

Definition at line 1479 of file numa.c.

Here is the call graph for this function:

◆ access_data()

static u64 access_data ( u64 *  data,
u64  val 
)
inlinestatic

Definition at line 745 of file numa.c.

◆ alloc_data()

static u8* alloc_data ( ssize_t  bytes0,
int  map_flags,
int  init_zero,
int  init_cpu0,
int  thp,
int  init_random 
)
static

Definition at line 364 of file numa.c.

Here is the call graph for this function:

◆ bench_all()

static int bench_all ( void  )
static

Definition at line 1801 of file numa.c.

Here is the call graph for this function:

◆ bench_numa()

int bench_numa ( int  argc,
const char **  argv 
)

Definition at line 1819 of file numa.c.

Here is the call graph for this function:

◆ bind_to_cpu()

static cpu_set_t bind_to_cpu ( int  target_cpu)
static

Definition at line 260 of file numa.c.

◆ bind_to_cpumask()

static void bind_to_cpumask ( cpu_set_t  mask)
static

Definition at line 320 of file numa.c.

◆ bind_to_memnode()

static void bind_to_memnode ( int  node)
static

Definition at line 337 of file numa.c.

◆ bind_to_node()

static cpu_set_t bind_to_node ( int  target_node)
static

Definition at line 286 of file numa.c.

Here is the call graph for this function:

◆ calc_convergence()

static void calc_convergence ( double  runtime_ns_max,
double *  convergence 
)
static

Definition at line 960 of file numa.c.

Here is the call graph for this function:

◆ calc_convergence_compression()

static void calc_convergence_compression ( int *  strong)
static

Definition at line 931 of file numa.c.

Here is the call graph for this function:

◆ command_size()

static int command_size ( const char **  argv)
static

Definition at line 1653 of file numa.c.

◆ count_node_processes()

static int count_node_processes ( int  node)
static

Definition at line 906 of file numa.c.

◆ count_process_nodes()

static int count_process_nodes ( int  process_nr)
static

Definition at line 870 of file numa.c.

◆ deinit()

static void deinit ( void  )
static

Definition at line 1453 of file numa.c.

Here is the call graph for this function:

◆ deinit_thread_data()

static void deinit_thread_data ( void  )
static

Definition at line 1374 of file numa.c.

Here is the call graph for this function:

◆ do_work()

static u64 do_work ( u8 *  __data,
long  bytes,
int  nr,
int  nr_max,
int  loop,
u64  val 
)
static

Definition at line 762 of file numa.c.

Here is the call graph for this function:

◆ free_data()

static void free_data ( void *  data,
ssize_t  bytes 
)
static

Definition at line 429 of file numa.c.

◆ init()

static int init ( void  )
static

Definition at line 1381 of file numa.c.

Here is the call graph for this function:

◆ init_global_mutex()

static void init_global_mutex ( pthread_mutex_t *  mutex)
static

Definition at line 468 of file numa.c.

◆ init_params()

static void init_params ( struct params p,
const char *  name,
int  argc,
const char **  argv 
)
static

Definition at line 1667 of file numa.c.

Here is the call graph for this function:

◆ init_thread_data()

static void init_thread_data ( void  )
static

Definition at line 1353 of file numa.c.

Here is the call graph for this function:

◆ is_node_present()

static int is_node_present ( int  node)
static

Definition at line 237 of file numa.c.

◆ lfsr_32()

static uint32_t lfsr_32 ( uint32_t  lfsr)
inlinestatic

Definition at line 733 of file numa.c.

◆ mempol_restore()

static void mempol_restore ( void  )
static

Definition at line 328 of file numa.c.

◆ node_has_cpus()

static bool node_has_cpus ( int  node)
static

Definition at line 245 of file numa.c.

◆ nr_numa_nodes()

static int nr_numa_nodes ( void  )
static

Definition at line 222 of file numa.c.

◆ parse_cpu_list()

static int parse_cpu_list ( const char *  arg)
static

Definition at line 477 of file numa.c.

◆ parse_cpus_opt() [1/2]

static int parse_cpus_opt ( const struct option *  opt,
const char *  arg,
int  unset 
)
static

◆ parse_cpus_opt() [2/2]

static int parse_cpus_opt ( const struct option *opt  __maybe_unused,
const char *  arg,
int unset  __maybe_unused 
)
static

Definition at line 605 of file numa.c.

Here is the call graph for this function:

◆ parse_node_list()

static int parse_node_list ( const char *  arg)
static

Definition at line 614 of file numa.c.

◆ parse_nodes_opt() [1/2]

static int parse_nodes_opt ( const struct option *  opt,
const char *  arg,
int  unset 
)
static

◆ parse_nodes_opt() [2/2]

static int parse_nodes_opt ( const struct option *opt  __maybe_unused,
const char *  arg,
int unset  __maybe_unused 
)
static

Definition at line 720 of file numa.c.

Here is the call graph for this function:

◆ parse_setup_cpu_list()

static int parse_setup_cpu_list ( void  )
static

Definition at line 486 of file numa.c.

Here is the call graph for this function:

◆ parse_setup_node_list()

static int parse_setup_node_list ( void  )
static

Definition at line 623 of file numa.c.

Here is the call graph for this function:

◆ print_res()

static void print_res ( const char *  name,
double  val,
const char *  txt_unit,
const char *  txt_short,
const char *  txt_long 
)
static

Definition at line 1467 of file numa.c.

◆ print_summary()

static void print_summary ( void  )
static

Definition at line 1333 of file numa.c.

Here is the call graph for this function:

◆ run_bench_numa()

static int run_bench_numa ( const char *  name,
const char **  argv 
)
static

Definition at line 1696 of file numa.c.

Here is the call graph for this function:

◆ setup_private_data()

static void* setup_private_data ( ssize_t  bytes)
static

Definition at line 460 of file numa.c.

Here is the call graph for this function:

◆ setup_shared_data()

static void* setup_shared_data ( ssize_t  bytes)
static

Definition at line 451 of file numa.c.

Here is the call graph for this function:

◆ show_summary()

static void show_summary ( double  runtime_ns_max,
int  l,
double *  convergence 
)
static

Definition at line 1074 of file numa.c.

Here is the call graph for this function:

◆ update_curr_cpu()

static void update_curr_cpu ( int  task_nr,
unsigned long  bytes_worked 
)
static

Definition at line 850 of file numa.c.

Here is the call graph for this function:

◆ worker_process()

static void worker_process ( int  process_nr)
static

Definition at line 1277 of file numa.c.

Here is the call graph for this function:

◆ worker_thread()

static void* worker_thread ( void *  __tdata)
static

Definition at line 1085 of file numa.c.

Here is the call graph for this function:

◆ zalloc_shared_data()

static void* zalloc_shared_data ( ssize_t  bytes)
static

Definition at line 443 of file numa.c.

Here is the call graph for this function:

Variable Documentation

◆ bench_numa_usage

const char* const bench_numa_usage[]
static
Initial value:
= {
"perf bench numa <options>",
NULL
}

Definition at line 209 of file numa.c.

◆ g

struct global_info* g = NULL
static

Definition at line 158 of file numa.c.

◆ numa_usage

const char* const numa_usage[]
static
Initial value:
= {
"perf bench numa mem [<options>]",
NULL
}

Definition at line 214 of file numa.c.

◆ options

const struct option options[]
static

Definition at line 165 of file numa.c.

◆ p0

struct params p0

Definition at line 163 of file numa.c.

◆ tests

const char* tests[][MAX_ARGS]
static

Definition at line 1728 of file numa.c.