Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc/pmu: Add event_init_sampling function

Extended event_init_opts() to include initialization of sampling
testcases. Patch adds an event_init_sampling() wrapper to initialize
event attribute fields for sampling events. This includes initializing
sample period, sample type and event type.

Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220127072012.662451-6-kjain@linux.ibm.com

authored by

Madhavan Srinivasan and committed by
Michael Ellerman
54d4ba7f 5f6c3061

+19 -1
+18 -1
tools/testing/selftests/powerpc/pmu/event.c
··· 8 8 #include <sys/syscall.h> 9 9 #include <string.h> 10 10 #include <stdio.h> 11 + #include <stdbool.h> 11 12 #include <sys/ioctl.h> 12 13 13 14 #include "event.h" ··· 21 20 group_fd, flags); 22 21 } 23 22 24 - void event_init_opts(struct event *e, u64 config, int type, char *name) 23 + static void __event_init_opts(struct event *e, u64 config, 24 + int type, char *name, bool sampling) 25 25 { 26 26 memset(e, 0, sizeof(*e)); 27 27 ··· 34 32 /* This has to match the structure layout in the header */ 35 33 e->attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | \ 36 34 PERF_FORMAT_TOTAL_TIME_RUNNING; 35 + if (sampling) { 36 + e->attr.sample_period = 1000; 37 + e->attr.sample_type = PERF_SAMPLE_REGS_INTR; 38 + e->attr.disabled = 1; 39 + } 40 + } 41 + 42 + void event_init_opts(struct event *e, u64 config, int type, char *name) 43 + { 44 + __event_init_opts(e, config, type, name, false); 37 45 } 38 46 39 47 void event_init_named(struct event *e, u64 config, char *name) ··· 54 42 void event_init(struct event *e, u64 config) 55 43 { 56 44 event_init_opts(e, config, PERF_TYPE_RAW, "event"); 45 + } 46 + 47 + void event_init_sampling(struct event *e, u64 config) 48 + { 49 + __event_init_opts(e, config, PERF_TYPE_RAW, "event", true); 57 50 } 58 51 59 52 #define PERF_CURRENT_PID 0
+1
tools/testing/selftests/powerpc/pmu/event.h
··· 32 32 void event_init(struct event *e, u64 config); 33 33 void event_init_named(struct event *e, u64 config, char *name); 34 34 void event_init_opts(struct event *e, u64 config, int type, char *name); 35 + void event_init_sampling(struct event *e, u64 config); 35 36 int event_open_with_options(struct event *e, pid_t pid, int cpu, int group_fd); 36 37 int event_open_with_group(struct event *e, int group_fd); 37 38 int event_open_with_pid(struct event *e, pid_t pid);