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
This commit is contained in:
parent
5f6c3061af
commit
54d4ba7f22
|
@ -8,6 +8,7 @@
|
|||
#include <sys/syscall.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "event.h"
|
||||
|
@ -20,7 +21,8 @@ int perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu,
|
|||
group_fd, flags);
|
||||
}
|
||||
|
||||
void event_init_opts(struct event *e, u64 config, int type, char *name)
|
||||
static void __event_init_opts(struct event *e, u64 config,
|
||||
int type, char *name, bool sampling)
|
||||
{
|
||||
memset(e, 0, sizeof(*e));
|
||||
|
||||
|
@ -32,6 +34,16 @@ void event_init_opts(struct event *e, u64 config, int type, char *name)
|
|||
/* This has to match the structure layout in the header */
|
||||
e->attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | \
|
||||
PERF_FORMAT_TOTAL_TIME_RUNNING;
|
||||
if (sampling) {
|
||||
e->attr.sample_period = 1000;
|
||||
e->attr.sample_type = PERF_SAMPLE_REGS_INTR;
|
||||
e->attr.disabled = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void event_init_opts(struct event *e, u64 config, int type, char *name)
|
||||
{
|
||||
__event_init_opts(e, config, type, name, false);
|
||||
}
|
||||
|
||||
void event_init_named(struct event *e, u64 config, char *name)
|
||||
|
@ -44,6 +56,11 @@ void event_init(struct event *e, u64 config)
|
|||
event_init_opts(e, config, PERF_TYPE_RAW, "event");
|
||||
}
|
||||
|
||||
void event_init_sampling(struct event *e, u64 config)
|
||||
{
|
||||
__event_init_opts(e, config, PERF_TYPE_RAW, "event", true);
|
||||
}
|
||||
|
||||
#define PERF_CURRENT_PID 0
|
||||
#define PERF_NO_PID -1
|
||||
#define PERF_NO_CPU -1
|
||||
|
|
|
@ -32,6 +32,7 @@ struct event {
|
|||
void event_init(struct event *e, u64 config);
|
||||
void event_init_named(struct event *e, u64 config, char *name);
|
||||
void event_init_opts(struct event *e, u64 config, int type, char *name);
|
||||
void event_init_sampling(struct event *e, u64 config);
|
||||
int event_open_with_options(struct event *e, pid_t pid, int cpu, int group_fd);
|
||||
int event_open_with_group(struct event *e, int group_fd);
|
||||
int event_open_with_pid(struct event *e, pid_t pid);
|
||||
|
|
Loading…
Reference in New Issue