Linux Perf
mem-functions.c File Reference
#include "debug.h"
#include "../perf.h"
#include "../util/util.h"
#include <subcmd/parse-options.h>
#include "../util/header.h"
#include "../util/cloexec.h"
#include "../util/string2.h"
#include "bench.h"
#include "mem-memcpy-arch.h"
#include "mem-memset-arch.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <errno.h>
#include <linux/time64.h>
Include dependency graph for mem-functions.c:

Go to the source code of this file.

Classes

struct  function
 
struct  bench_mem_info
 

Macros

#define K   1024
 
#define print_bps(x)
 

Typedefs

typedef void *(* memcpy_t) (void *, const void *, size_t)
 
typedef void *(* memset_t) (void *, int, size_t)
 

Functions

static int init_cycles (void)
 
static u64 get_cycles (void)
 
static double timeval2double (struct timeval *ts)
 
static void __bench_mem_function (struct bench_mem_info *info, int r_idx, size_t size, double size_total)
 
static int bench_mem_common (int argc, const char **argv, struct bench_mem_info *info)
 
static u64 do_memcpy_cycles (const struct function *r, size_t size, void *src, void *dst)
 
static double do_memcpy_gettimeofday (const struct function *r, size_t size, void *src, void *dst)
 
int bench_mem_memcpy (int argc, const char **argv)
 
static u64 do_memset_cycles (const struct function *r, size_t size, void *src __maybe_unused, void *dst)
 
static double do_memset_gettimeofday (const struct function *r, size_t size, void *src __maybe_unused, void *dst)
 
int bench_mem_memset (int argc, const char **argv)
 

Variables

static const char * size_str = "1MB"
 
static const char * function_str = "all"
 
static int nr_loops = 1
 
static bool use_cycles
 
static int cycles_fd
 
static const struct option options []
 
static struct perf_event_attr cycle_attr
 
struct function memcpy_functions []
 
static const char *const bench_mem_memcpy_usage []
 
static const char *const bench_mem_memset_usage []
 
static const struct function memset_functions []
 

Macro Definition Documentation

◆ K

#define K   1024

Definition at line 28 of file mem-functions.c.

◆ print_bps

#define print_bps (   x)
Value:
do { \
if (x < K) \
printf(" %14lf bytes/sec\n", x); \
else if (x < K * K) \
printf(" %14lfd KB/sec\n", x / K); \
else if (x < K * K * K) \
printf(" %14lf MB/sec\n", x / K / K); \
else \
printf(" %14lf GB/sec\n", x / K / K / K); \
} while (0)
#define K
Definition: mem-functions.c:28

Definition at line 98 of file mem-functions.c.

Typedef Documentation

◆ memcpy_t

typedef void*(* memcpy_t) (void *, const void *, size_t)

Definition at line 53 of file mem-functions.c.

◆ memset_t

typedef void*(* memset_t) (void *, int, size_t)

Definition at line 54 of file mem-functions.c.

Function Documentation

◆ __bench_mem_function()

static void __bench_mem_function ( struct bench_mem_info info,
int  r_idx,
size_t  size,
double  size_total 
)
static

Definition at line 117 of file mem-functions.c.

Here is the call graph for this function:

◆ bench_mem_common()

static int bench_mem_common ( int  argc,
const char **  argv,
struct bench_mem_info info 
)
static

Definition at line 175 of file mem-functions.c.

Here is the call graph for this function:

◆ bench_mem_memcpy()

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

Definition at line 289 of file mem-functions.c.

Here is the call graph for this function:

◆ bench_mem_memset()

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

Definition at line 363 of file mem-functions.c.

Here is the call graph for this function:

◆ do_memcpy_cycles()

static u64 do_memcpy_cycles ( const struct function r,
size_t  size,
void *  src,
void *  dst 
)
static

Definition at line 225 of file mem-functions.c.

Here is the call graph for this function:

◆ do_memcpy_gettimeofday()

static double do_memcpy_gettimeofday ( const struct function r,
size_t  size,
void *  src,
void *  dst 
)
static

Definition at line 248 of file mem-functions.c.

Here is the call graph for this function:

◆ do_memset_cycles()

static u64 do_memset_cycles ( const struct function r,
size_t  size,
void *src  __maybe_unused,
void *  dst 
)
static

Definition at line 302 of file mem-functions.c.

Here is the call graph for this function:

◆ do_memset_gettimeofday()

static double do_memset_gettimeofday ( const struct function r,
size_t  size,
void *src  __maybe_unused,
void *  dst 
)
static

Definition at line 322 of file mem-functions.c.

Here is the call graph for this function:

◆ get_cycles()

static u64 get_cycles ( void  )
static

Definition at line 82 of file mem-functions.c.

◆ init_cycles()

static int init_cycles ( void  )
static

Definition at line 70 of file mem-functions.c.

Here is the call graph for this function:

◆ timeval2double()

static double timeval2double ( struct timeval *  ts)
static

Definition at line 93 of file mem-functions.c.

Variable Documentation

◆ bench_mem_memcpy_usage

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

Definition at line 284 of file mem-functions.c.

◆ bench_mem_memset_usage

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

Definition at line 344 of file mem-functions.c.

◆ cycle_attr

struct perf_event_attr cycle_attr
static
Initial value:
= {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES
}

Definition at line 65 of file mem-functions.c.

◆ cycles_fd

int cycles_fd
static

Definition at line 34 of file mem-functions.c.

◆ function_str

const char* function_str = "all"
static

Definition at line 31 of file mem-functions.c.

◆ memcpy_functions

struct function memcpy_functions[]
Initial value:
= {
{ .name = "default",
.desc = "Default memcpy() provided by glibc",
.fn.memcpy = memcpy },
{ .name = NULL, }
}
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms

Definition at line 270 of file mem-functions.c.

◆ memset_functions

const struct function memset_functions[]
static
Initial value:
= {
{ .name = "default",
.desc = "Default memset() provided by glibc",
.fn.memset = memset },
{ .name = NULL, }
}
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms

Definition at line 349 of file mem-functions.c.

◆ nr_loops

int nr_loops = 1
static

Definition at line 32 of file mem-functions.c.

◆ options

const struct option options[]
static
Initial value:
= {
OPT_STRING('s', "size", &size_str, "1MB",
"Specify the size of the memory buffers. "
"Available units: B, KB, MB, GB and TB (case insensitive)"),
OPT_STRING('f', "function", &function_str, "all",
"Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
OPT_INTEGER('l', "nr_loops", &nr_loops,
"Specify the number of loops to run. (default: 1)"),
OPT_BOOLEAN('c', "cycles", &use_cycles,
"Use a cycles event instead of gettimeofday() to measure performance"),
}
static const char * size_str
Definition: mem-functions.c:30
static const char * function_str
Definition: mem-functions.c:31
static bool use_cycles
Definition: mem-functions.c:33
static int nr_loops
Definition: mem-functions.c:32

Definition at line 36 of file mem-functions.c.

◆ size_str

const char* size_str = "1MB"
static

Definition at line 30 of file mem-functions.c.

◆ use_cycles

bool use_cycles
static

Definition at line 33 of file mem-functions.c.