24 #include <vpp/app/version.h> 25 #include <linux/limits.h> 47 #if defined(__x86_64__) 49 asm volatile (
"mov $1, %%eax; cpuid; mov %%eax, %0":
"=r" (cpuid)::
"%eax",
50 "%edx",
"%ecx",
"%rbx");
59 u32 n_models,
u8 model,
u8 stepping)
62 for (i = 0; i < n_models; i++)
64 if (mt[i].model != model)
67 if (mt[i].has_stepping)
69 if (mt[i].stepping != stepping)
80 u8 model,
u8 stepping)
129 model = ((cpuid >> 12) & 0xf0) | ((cpuid >> 4) & 0xf);
130 stepping = cpuid & 0xf;
223 if (
unformat (line_input,
"timeout %u", &timeout_seconds))
225 else if (
unformat (line_input,
"instructions-per-clock"))
227 ec.
name =
"instructions";
228 ec.
pe_type = PERF_TYPE_HARDWARE;
229 ec.
pe_config = PERF_COUNT_HW_INSTRUCTIONS;
232 ec.
name =
"cpu-cycles";
233 ec.
pe_type = PERF_TYPE_HARDWARE;
237 else if (
unformat (line_input,
"branch-mispredict-rate"))
239 ec.
name =
"branch-misses";
240 ec.
pe_type = PERF_TYPE_HARDWARE;
241 ec.
pe_config = PERF_COUNT_HW_BRANCH_MISSES;
244 ec.
name =
"branches";
245 ec.
pe_type = PERF_TYPE_HARDWARE;
246 ec.
pe_config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
249 else if (
unformat (line_input,
"threads %U",
252 else if (
unformat (line_input,
"thread %U",
259 #define _(type,event,str) \ 260 else if (unformat (line_input, str)) \ 264 ec.pe_config = event; \ 265 vec_add1 (pm->single_events_to_collect, ec); \ 281 if (last_set != ~0 && last_set >= num_threads)
303 vlib_cli_output (vm,
"Start collection for %d events, wait %.2f seconds",
332 .short_help =
"set pmc [threads n,n1-n2] c1... [see \"show pmc events\"]",
353 int verbose __attribute__ ((unused)) = va_arg (*args,
int);
359 s =
format (s,
"%=40s%=20s%=16s%=16s%=16s",
360 "Name",
"Counter",
"Count",
"Pkts",
"Counts/Pkt");
388 s =
format (s,
"%-40s%+20s%+16llu%+16llu%+16.2e\n",
389 name,
"instructions-per-clock",
404 mispredict_rate = 0.0;
406 s =
format (s,
"%-40s%+20s%+16llu%+16llu%+16.2e\n",
407 name,
"branch-mispredict-rate",
419 s =
format (s,
"%-40s%+20s%+16llu%+16llu%+16.2e",
430 int verbose = va_arg (*args,
int);
432 #define _(type,config,name) \ 434 s = format (s, "\n %s", name); \ 436 s = format (s, "\n %s (%d, %d)", name, type, config); 454 return strcmp ((
char *) nvp1->
name, (
char *) nvp2->
name);
478 int verbose = va_arg (*args,
int);
487 vec_add2 (sort_nvps, sn, 1);
524 else if (
unformat (input,
"verbose"))
558 vec_add1 (captures, *c);
567 for (i = 0; i <
vec_len (captures); i++)
583 .short_help =
"show pmc [verbose]",
621 .short_help =
"clear the performance monitor counters",
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
perfmon_capture_t * capture_pool
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static clib_error_t * set_pmc_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u64 * vectors_this_counter
perfmon_event_config_t * paired_events_to_collect
perfmon_thread_t ** threads
static int capture_name_sort(void *a1, void *a2)
vnet_main_t * vnet_get_main(void)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_node_registration_t perfmon_periodic_node
(constructor) VLIB_REGISTER_NODE (perfmon_periodic_node)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
uword unformat_processor_event(unformat_input_t *input, va_list *args)
u32 mispredict_event_index
#define hash_set_mem(h, key, value)
#define hash_get_pair_mem(h, key)
#define clib_bitmap_zero(v)
Clear a bitmap.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
#define clib_error_return(e, args...)
static clib_error_t * show_pmc_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 * thread_and_node_name
#define hash_create_string(elts, value_bytes)
static u8 * format_pmc_event(u8 *s, va_list *args)
perfmon_intel_pmc_event_t * events
static perfmon_intel_pmc_event_t * perfmon_find_table_by_model_stepping(perfmon_main_t *pm, u8 model, u8 stepping)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static uword clib_bitmap_last_set(uword *ai)
Return the higest numbered set bit in a bitmap.
uword * pmc_event_by_name
perfmon_intel_pmc_cpu_model_t * models
perfmon_intel_pmc_event_t * perfmon_table
static u8 * format_capture(u8 *s, va_list *args)
#define hash_foreach_mem(key_var, value_var, h, body)
vlib_log_class_t log_class
#define pool_free(p)
Free a pool.
static u32 get_cpuid(void)
static clib_error_t * clear_pmc_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
static int sort_nvps_by_name(void *a1, void *a2)
#define VLIB_CLI_COMMAND(x,...)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
perfmon_event_config_t * single_events_to_collect
#define vec_append(v1, v2)
Append v2 after v1.
static u8 * format_processor_events(u8 *s, va_list *args)
static clib_error_t * perfmon_init(vlib_main_t *vm)
perfmon_main_t perfmon_main
void perfmon_register_intel_pmc(perfmon_intel_pmc_cpu_model_t *m, int n_models, perfmon_intel_pmc_event_t *e, int n_events)
#define foreach_perfmon_event
uword * capture_by_thread_and_node_name
static u8 * format_generic_events(u8 *s, va_list *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
perfmon_intel_pmc_registration_t * perfmon_tables
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
static void * clib_mem_alloc_aligned(uword size, uword align)
static vlib_thread_main_t * vlib_get_thread_main()
#define vec_foreach(var, vec)
Vector iterator.
#define vlib_log_err(...)
static int perfmon_cpu_model_matches(perfmon_intel_pmc_cpu_model_t *mt, u32 n_models, u8 model, u8 stepping)
#define CLIB_CACHE_LINE_BYTES
static uword pool_elts(void *v)
Number of active elements in a pool.