2017-11-01 15:07:57 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-04-25 21:31:02 +02:00
|
|
|
#include <linux/types.h>
|
2019-08-30 14:45:20 -03:00
|
|
|
#include <limits.h>
|
2013-08-31 21:50:53 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/prctl.h>
|
2019-07-21 13:24:30 +02:00
|
|
|
#include <perf/cpumap.h>
|
2019-07-21 13:24:43 +02:00
|
|
|
#include <perf/evlist.h>
|
2019-10-07 14:53:17 +02:00
|
|
|
#include <perf/mmap.h>
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2019-08-29 15:56:40 -03:00
|
|
|
#include "debug.h"
|
2013-08-31 21:50:53 +03:00
|
|
|
#include "parse-events.h"
|
|
|
|
|
#include "evlist.h"
|
|
|
|
|
#include "evsel.h"
|
2019-08-22 15:40:29 -03:00
|
|
|
#include "record.h"
|
2013-08-31 21:50:53 +03:00
|
|
|
#include "thread_map.h"
|
|
|
|
|
#include "tests.h"
|
2019-09-23 12:20:38 -03:00
|
|
|
#include "util/mmap.h"
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
#define CHECK__(x) { \
|
|
|
|
|
while ((x) < 0) { \
|
|
|
|
|
pr_debug(#x " failed!\n"); \
|
|
|
|
|
goto out_err; \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CHECK_NOT_NULL__(x) { \
|
|
|
|
|
while ((x) == NULL) { \
|
|
|
|
|
pr_debug(#x " failed!\n"); \
|
|
|
|
|
goto out_err; \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 13:23:52 +02:00
|
|
|
static int find_comm(struct evlist *evlist, const char *comm)
|
2013-08-31 21:50:53 +03:00
|
|
|
{
|
|
|
|
|
union perf_event *event;
|
2019-07-27 20:30:53 +02:00
|
|
|
struct mmap *md;
|
2013-08-31 21:50:53 +03:00
|
|
|
int i, found;
|
|
|
|
|
|
|
|
|
|
found = 0;
|
2019-07-30 13:04:59 +02:00
|
|
|
for (i = 0; i < evlist->core.nr_mmaps; i++) {
|
2018-03-01 18:09:03 -05:00
|
|
|
md = &evlist->mmap[i];
|
2019-10-07 14:53:18 +02:00
|
|
|
if (perf_mmap__read_init(&md->core) < 0)
|
2018-03-01 18:09:03 -05:00
|
|
|
continue;
|
2019-10-07 14:53:20 +02:00
|
|
|
while ((event = perf_mmap__read_event(&md->core)) != NULL) {
|
2013-08-31 21:50:53 +03:00
|
|
|
if (event->header.type == PERF_RECORD_COMM &&
|
|
|
|
|
(pid_t)event->comm.pid == getpid() &&
|
|
|
|
|
(pid_t)event->comm.tid == getpid() &&
|
|
|
|
|
strcmp(event->comm.comm, comm) == 0)
|
|
|
|
|
found += 1;
|
2019-10-07 14:53:17 +02:00
|
|
|
perf_mmap__consume(&md->core);
|
2013-08-31 21:50:53 +03:00
|
|
|
}
|
2019-10-07 14:53:19 +02:00
|
|
|
perf_mmap__read_done(&md->core);
|
2013-08-31 21:50:53 +03:00
|
|
|
}
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test__keep_tracking - test using a dummy software event to keep tracking.
|
|
|
|
|
*
|
|
|
|
|
* This function implements a test that checks that tracking events continue
|
|
|
|
|
* when an event is disabled but a dummy software event is not disabled. If the
|
|
|
|
|
* test passes %0 is returned, otherwise %-1 is returned.
|
|
|
|
|
*/
|
2021-11-03 23:41:51 -07:00
|
|
|
static int test__keep_tracking(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
2013-08-31 21:50:53 +03:00
|
|
|
{
|
2013-12-19 14:43:45 -03:00
|
|
|
struct record_opts opts = {
|
2013-08-31 21:50:53 +03:00
|
|
|
.mmap_pages = UINT_MAX,
|
|
|
|
|
.user_freq = UINT_MAX,
|
|
|
|
|
.user_interval = ULLONG_MAX,
|
|
|
|
|
.target = {
|
|
|
|
|
.uses_mmap = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
2019-07-21 13:23:50 +02:00
|
|
|
struct perf_thread_map *threads = NULL;
|
2019-07-21 13:23:49 +02:00
|
|
|
struct perf_cpu_map *cpus = NULL;
|
2019-07-21 13:23:52 +02:00
|
|
|
struct evlist *evlist = NULL;
|
2019-07-21 13:23:51 +02:00
|
|
|
struct evsel *evsel = NULL;
|
2013-08-31 21:50:53 +03:00
|
|
|
int found, err = -1;
|
|
|
|
|
const char *comm;
|
|
|
|
|
|
|
|
|
|
threads = thread_map__new(-1, getpid(), UINT_MAX);
|
|
|
|
|
CHECK_NOT_NULL__(threads);
|
|
|
|
|
|
2019-07-21 13:24:30 +02:00
|
|
|
cpus = perf_cpu_map__new(NULL);
|
2013-08-31 21:50:53 +03:00
|
|
|
CHECK_NOT_NULL__(cpus);
|
|
|
|
|
|
2019-07-21 13:23:55 +02:00
|
|
|
evlist = evlist__new();
|
2013-08-31 21:50:53 +03:00
|
|
|
CHECK_NOT_NULL__(evlist);
|
|
|
|
|
|
2019-07-21 13:24:43 +02:00
|
|
|
perf_evlist__set_maps(&evlist->core, cpus, threads);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2015-04-22 21:10:16 +02:00
|
|
|
CHECK__(parse_events(evlist, "dummy:u", NULL));
|
|
|
|
|
CHECK__(parse_events(evlist, "cycles:u", NULL));
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2020-11-30 15:07:49 -03:00
|
|
|
evlist__config(evlist, &opts, NULL);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2019-09-03 10:39:52 +02:00
|
|
|
evsel = evlist__first(evlist);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2019-07-21 13:24:29 +02:00
|
|
|
evsel->core.attr.comm = 1;
|
|
|
|
|
evsel->core.attr.disabled = 1;
|
|
|
|
|
evsel->core.attr.enable_on_exec = 0;
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2019-07-21 13:24:06 +02:00
|
|
|
if (evlist__open(evlist) < 0) {
|
2015-11-03 10:44:42 +00:00
|
|
|
pr_debug("Unable to open dummy and cycles event\n");
|
|
|
|
|
err = TEST_SKIP;
|
2013-08-31 21:50:53 +03:00
|
|
|
goto out_err;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 12:45:35 +02:00
|
|
|
CHECK__(evlist__mmap(evlist, UINT_MAX));
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* First, test that a 'comm' event can be found when the event is
|
|
|
|
|
* enabled.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-21 13:24:08 +02:00
|
|
|
evlist__enable(evlist);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
comm = "Test COMM 1";
|
|
|
|
|
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
|
|
|
|
|
|
2019-07-21 13:24:09 +02:00
|
|
|
evlist__disable(evlist);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
found = find_comm(evlist, comm);
|
|
|
|
|
if (found != 1) {
|
|
|
|
|
pr_debug("First time, failed to find tracking event.\n");
|
|
|
|
|
goto out_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Secondly, test that a 'comm' event can be found when the event is
|
|
|
|
|
* disabled with the dummy event still enabled.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-21 13:24:08 +02:00
|
|
|
evlist__enable(evlist);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2019-09-03 10:39:52 +02:00
|
|
|
evsel = evlist__last(evlist);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
2019-07-21 13:24:03 +02:00
|
|
|
CHECK__(evsel__disable(evsel));
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
comm = "Test COMM 2";
|
|
|
|
|
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
|
|
|
|
|
|
2019-07-21 13:24:09 +02:00
|
|
|
evlist__disable(evlist);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
found = find_comm(evlist, comm);
|
|
|
|
|
if (found != 1) {
|
2019-09-10 16:29:02 +01:00
|
|
|
pr_debug("Second time, failed to find tracking event.\n");
|
2013-08-31 21:50:53 +03:00
|
|
|
goto out_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
|
if (evlist) {
|
2019-07-21 13:24:09 +02:00
|
|
|
evlist__disable(evlist);
|
2019-07-21 13:23:56 +02:00
|
|
|
evlist__delete(evlist);
|
2014-01-03 15:56:06 -03:00
|
|
|
}
|
2021-03-01 23:04:04 +09:00
|
|
|
perf_cpu_map__put(cpus);
|
|
|
|
|
perf_thread_map__put(threads);
|
2013-08-31 21:50:53 +03:00
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2021-11-03 23:41:50 -07:00
|
|
|
|
|
|
|
|
DEFINE_SUITE("Use a dummy software event to keep tracking", keep_tracking);
|