2019-07-21 11:24:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2019-07-21 11:24:48 +00:00
|
|
|
#include <errno.h>
|
2019-07-21 11:24:21 +00:00
|
|
|
#include <perf/evsel.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <internal/evsel.h>
|
2019-07-21 11:24:33 +00:00
|
|
|
#include <linux/zalloc.h>
|
2019-07-21 11:24:36 +00:00
|
|
|
#include <stdlib.h>
|
2019-07-21 11:24:48 +00:00
|
|
|
#include <internal/xyarray.h>
|
|
|
|
#include <linux/string.h>
|
2019-07-21 11:24:24 +00:00
|
|
|
|
2019-07-21 11:24:29 +00:00
|
|
|
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
|
2019-07-21 11:24:24 +00:00
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&evsel->node);
|
2019-07-21 11:24:29 +00:00
|
|
|
evsel->attr = *attr;
|
2019-07-21 11:24:24 +00:00
|
|
|
}
|
2019-07-21 11:24:33 +00:00
|
|
|
|
|
|
|
struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel = zalloc(sizeof(*evsel));
|
|
|
|
|
|
|
|
if (evsel != NULL)
|
|
|
|
perf_evsel__init(evsel, attr);
|
|
|
|
|
|
|
|
return evsel;
|
|
|
|
}
|
2019-07-21 11:24:36 +00:00
|
|
|
|
|
|
|
void perf_evsel__delete(struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
free(evsel);
|
|
|
|
}
|
2019-07-21 11:24:48 +00:00
|
|
|
|
|
|
|
#define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
|
|
|
|
|
|
|
|
int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
|
|
|
|
{
|
|
|
|
evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int));
|
|
|
|
|
|
|
|
if (evsel->fd) {
|
|
|
|
int cpu, thread;
|
|
|
|
for (cpu = 0; cpu < ncpus; cpu++) {
|
|
|
|
for (thread = 0; thread < nthreads; thread++) {
|
|
|
|
FD(evsel, cpu, thread) = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return evsel->fd != NULL ? 0 : -ENOMEM;
|
|
|
|
}
|