License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-08-16 02:08:36 +07:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/prctl.h>
|
2017-04-18 20:46:11 +07:00
|
|
|
#include <errno.h>
|
2019-08-31 00:45:20 +07:00
|
|
|
#include <limits.h>
|
2014-08-16 02:08:36 +07:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
2019-07-04 21:32:27 +07:00
|
|
|
#include <linux/zalloc.h>
|
2019-07-21 18:24:30 +07:00
|
|
|
#include <perf/cpumap.h>
|
2019-07-21 18:24:43 +07:00
|
|
|
#include <perf/evlist.h>
|
2014-08-16 02:08:36 +07:00
|
|
|
|
2019-08-30 01:56:40 +07:00
|
|
|
#include "debug.h"
|
2014-08-16 02:08:36 +07:00
|
|
|
#include "parse-events.h"
|
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "thread_map.h"
|
2019-08-23 01:40:29 +07:00
|
|
|
#include "record.h"
|
2014-08-16 02:08:36 +07:00
|
|
|
#include "tests.h"
|
2019-09-23 22:20:38 +07:00
|
|
|
#include "util/mmap.h"
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
static int spin_sleep(void)
|
|
|
|
{
|
|
|
|
struct timeval start, now, diff, maxtime;
|
|
|
|
struct timespec ts;
|
|
|
|
int err, i;
|
|
|
|
|
|
|
|
maxtime.tv_sec = 0;
|
|
|
|
maxtime.tv_usec = 50000;
|
|
|
|
|
|
|
|
err = gettimeofday(&start, NULL);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Spin for 50ms */
|
|
|
|
while (1) {
|
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
err = gettimeofday(&now, NULL);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
timersub(&now, &start, &diff);
|
|
|
|
if (timercmp(&diff, &maxtime, > /* For checkpatch */))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts.tv_nsec = 50 * 1000 * 1000;
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
|
|
|
|
/* Sleep for 50ms */
|
|
|
|
err = nanosleep(&ts, NULL);
|
|
|
|
if (err == EINTR)
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct switch_tracking {
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *switch_evsel;
|
|
|
|
struct evsel *cycles_evsel;
|
2014-08-16 02:08:36 +07:00
|
|
|
pid_t *tids;
|
|
|
|
int nr_tids;
|
|
|
|
int comm_seen[4];
|
|
|
|
int cycles_before_comm_1;
|
|
|
|
int cycles_between_comm_2_and_comm_3;
|
|
|
|
int cycles_after_comm_4;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int check_comm(struct switch_tracking *switch_tracking,
|
|
|
|
union perf_event *event, const char *comm, int nr)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
if (switch_tracking->comm_seen[nr]) {
|
|
|
|
pr_debug("Duplicate comm event\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch_tracking->comm_seen[nr] = 1;
|
|
|
|
pr_debug3("comm event: %s nr: %d\n", event->comm.comm, nr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_cpu(struct switch_tracking *switch_tracking, int cpu)
|
|
|
|
{
|
|
|
|
int i, nr = cpu + 1;
|
|
|
|
|
|
|
|
if (cpu < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!switch_tracking->tids) {
|
|
|
|
switch_tracking->tids = calloc(nr, sizeof(pid_t));
|
|
|
|
if (!switch_tracking->tids)
|
|
|
|
return -1;
|
|
|
|
for (i = 0; i < nr; i++)
|
|
|
|
switch_tracking->tids[i] = -1;
|
|
|
|
switch_tracking->nr_tids = nr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu >= switch_tracking->nr_tids) {
|
|
|
|
void *addr;
|
|
|
|
|
|
|
|
addr = realloc(switch_tracking->tids, nr * sizeof(pid_t));
|
|
|
|
if (!addr)
|
|
|
|
return -1;
|
|
|
|
switch_tracking->tids = addr;
|
|
|
|
for (i = switch_tracking->nr_tids; i < nr; i++)
|
|
|
|
switch_tracking->tids[i] = -1;
|
|
|
|
switch_tracking->nr_tids = nr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:52 +07:00
|
|
|
static int process_sample_event(struct evlist *evlist,
|
2014-08-16 02:08:36 +07:00
|
|
|
union perf_event *event,
|
|
|
|
struct switch_tracking *switch_tracking)
|
|
|
|
{
|
|
|
|
struct perf_sample sample;
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *evsel;
|
2014-08-16 02:08:36 +07:00
|
|
|
pid_t next_tid, prev_tid;
|
|
|
|
int cpu, err;
|
|
|
|
|
|
|
|
if (perf_evlist__parse_sample(evlist, event, &sample)) {
|
|
|
|
pr_debug("perf_evlist__parse_sample failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
evsel = perf_evlist__id2evsel(evlist, sample.id);
|
|
|
|
if (evsel == switch_tracking->switch_evsel) {
|
|
|
|
next_tid = perf_evsel__intval(evsel, &sample, "next_pid");
|
|
|
|
prev_tid = perf_evsel__intval(evsel, &sample, "prev_pid");
|
|
|
|
cpu = sample.cpu;
|
|
|
|
pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n",
|
|
|
|
cpu, prev_tid, next_tid);
|
|
|
|
err = check_cpu(switch_tracking, cpu);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
/*
|
|
|
|
* Check for no missing sched_switch events i.e. that the
|
2019-08-06 16:35:19 +07:00
|
|
|
* evsel->core.system_wide flag has worked.
|
2014-08-16 02:08:36 +07:00
|
|
|
*/
|
|
|
|
if (switch_tracking->tids[cpu] != -1 &&
|
|
|
|
switch_tracking->tids[cpu] != prev_tid) {
|
|
|
|
pr_debug("Missing sched_switch events\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch_tracking->tids[cpu] = next_tid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evsel == switch_tracking->cycles_evsel) {
|
|
|
|
pr_debug3("cycles event\n");
|
|
|
|
if (!switch_tracking->comm_seen[0])
|
|
|
|
switch_tracking->cycles_before_comm_1 = 1;
|
|
|
|
if (switch_tracking->comm_seen[1] &&
|
|
|
|
!switch_tracking->comm_seen[2])
|
|
|
|
switch_tracking->cycles_between_comm_2_and_comm_3 = 1;
|
|
|
|
if (switch_tracking->comm_seen[3])
|
|
|
|
switch_tracking->cycles_after_comm_4 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:52 +07:00
|
|
|
static int process_event(struct evlist *evlist, union perf_event *event,
|
2014-08-16 02:08:36 +07:00
|
|
|
struct switch_tracking *switch_tracking)
|
|
|
|
{
|
|
|
|
if (event->header.type == PERF_RECORD_SAMPLE)
|
|
|
|
return process_sample_event(evlist, event, switch_tracking);
|
|
|
|
|
|
|
|
if (event->header.type == PERF_RECORD_COMM) {
|
|
|
|
int err, done = 0;
|
|
|
|
|
|
|
|
err = check_comm(switch_tracking, event, "Test COMM 1", 0);
|
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
done += err;
|
|
|
|
err = check_comm(switch_tracking, event, "Test COMM 2", 1);
|
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
done += err;
|
|
|
|
err = check_comm(switch_tracking, event, "Test COMM 3", 2);
|
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
done += err;
|
|
|
|
err = check_comm(switch_tracking, event, "Test COMM 4", 3);
|
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
done += err;
|
|
|
|
if (done != 1) {
|
|
|
|
pr_debug("Unexpected comm event\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct event_node {
|
|
|
|
struct list_head list;
|
|
|
|
union perf_event *event;
|
|
|
|
u64 event_time;
|
|
|
|
};
|
|
|
|
|
2019-07-21 18:23:52 +07:00
|
|
|
static int add_event(struct evlist *evlist, struct list_head *events,
|
2014-08-16 02:08:36 +07:00
|
|
|
union perf_event *event)
|
|
|
|
{
|
|
|
|
struct perf_sample sample;
|
|
|
|
struct event_node *node;
|
|
|
|
|
|
|
|
node = malloc(sizeof(struct event_node));
|
|
|
|
if (!node) {
|
|
|
|
pr_debug("malloc failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
node->event = event;
|
|
|
|
list_add(&node->list, events);
|
|
|
|
|
|
|
|
if (perf_evlist__parse_sample(evlist, event, &sample)) {
|
|
|
|
pr_debug("perf_evlist__parse_sample failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sample.time) {
|
|
|
|
pr_debug("event with no time\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->event_time = sample.time;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_event_nodes(struct list_head *events)
|
|
|
|
{
|
|
|
|
struct event_node *node;
|
|
|
|
|
|
|
|
while (!list_empty(events)) {
|
|
|
|
node = list_entry(events->next, struct event_node, list);
|
2019-07-04 22:13:46 +07:00
|
|
|
list_del_init(&node->list);
|
2014-08-16 02:08:36 +07:00
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compar(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct event_node *nodea = a;
|
|
|
|
const struct event_node *nodeb = b;
|
|
|
|
s64 cmp = nodea->event_time - nodeb->event_time;
|
|
|
|
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:52 +07:00
|
|
|
static int process_events(struct evlist *evlist,
|
2014-08-16 02:08:36 +07:00
|
|
|
struct switch_tracking *switch_tracking)
|
|
|
|
{
|
|
|
|
union perf_event *event;
|
|
|
|
unsigned pos, cnt = 0;
|
|
|
|
LIST_HEAD(events);
|
|
|
|
struct event_node *events_array, *node;
|
2019-07-28 01:30:53 +07:00
|
|
|
struct mmap *md;
|
2014-08-16 02:08:36 +07:00
|
|
|
int i, ret;
|
|
|
|
|
2019-07-30 18:04:59 +07:00
|
|
|
for (i = 0; i < evlist->core.nr_mmaps; i++) {
|
2018-03-02 06:09:09 +07:00
|
|
|
md = &evlist->mmap[i];
|
2018-03-06 22:36:07 +07:00
|
|
|
if (perf_mmap__read_init(md) < 0)
|
2018-03-02 06:09:09 +07:00
|
|
|
continue;
|
|
|
|
|
2018-03-06 22:36:06 +07:00
|
|
|
while ((event = perf_mmap__read_event(md)) != NULL) {
|
2014-08-16 02:08:36 +07:00
|
|
|
cnt += 1;
|
|
|
|
ret = add_event(evlist, &events, event);
|
2018-03-06 22:36:05 +07:00
|
|
|
perf_mmap__consume(md);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (ret < 0)
|
|
|
|
goto out_free_nodes;
|
|
|
|
}
|
2018-03-02 06:09:09 +07:00
|
|
|
perf_mmap__read_done(md);
|
2014-08-16 02:08:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
events_array = calloc(cnt, sizeof(struct event_node));
|
|
|
|
if (!events_array) {
|
|
|
|
pr_debug("calloc failed\n");
|
|
|
|
ret = -1;
|
|
|
|
goto out_free_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
list_for_each_entry(node, &events, list)
|
|
|
|
events_array[pos++] = *node;
|
|
|
|
|
|
|
|
qsort(events_array, cnt, sizeof(struct event_node), compar);
|
|
|
|
|
|
|
|
for (pos = 0; pos < cnt; pos++) {
|
|
|
|
ret = process_event(evlist, events_array[pos].event,
|
|
|
|
switch_tracking);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
pr_debug("%u events recorded\n", cnt);
|
|
|
|
free(events_array);
|
|
|
|
out_free_nodes:
|
|
|
|
free_event_nodes(&events);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test__switch_tracking - test using sched_switch and tracking events.
|
|
|
|
*
|
|
|
|
* This function implements a test that checks that sched_switch events and
|
|
|
|
* tracking events can be recorded for a workload (current process) using the
|
2019-08-06 16:35:19 +07:00
|
|
|
* evsel->core.system_wide and evsel->tracking flags (respectively) with other events
|
2014-08-16 02:08:36 +07:00
|
|
|
* sometimes enabled or disabled.
|
|
|
|
*/
|
2017-08-04 01:16:31 +07:00
|
|
|
int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_unused)
|
2014-08-16 02:08:36 +07:00
|
|
|
{
|
|
|
|
const char *sched_switch = "sched:sched_switch";
|
|
|
|
struct switch_tracking switch_tracking = { .tids = NULL, };
|
|
|
|
struct record_opts opts = {
|
|
|
|
.mmap_pages = UINT_MAX,
|
|
|
|
.user_freq = UINT_MAX,
|
|
|
|
.user_interval = ULLONG_MAX,
|
|
|
|
.freq = 4000,
|
|
|
|
.target = {
|
|
|
|
.uses_mmap = true,
|
|
|
|
},
|
|
|
|
};
|
2019-07-21 18:23:50 +07:00
|
|
|
struct perf_thread_map *threads = NULL;
|
2019-07-21 18:23:49 +07:00
|
|
|
struct perf_cpu_map *cpus = NULL;
|
2019-07-21 18:23:52 +07:00
|
|
|
struct evlist *evlist = NULL;
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *evsel, *cpu_clocks_evsel, *cycles_evsel;
|
|
|
|
struct evsel *switch_evsel, *tracking_evsel;
|
2014-08-16 02:08:36 +07:00
|
|
|
const char *comm;
|
|
|
|
int err = -1;
|
|
|
|
|
|
|
|
threads = thread_map__new(-1, getpid(), UINT_MAX);
|
|
|
|
if (!threads) {
|
|
|
|
pr_debug("thread_map__new failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:30 +07:00
|
|
|
cpus = perf_cpu_map__new(NULL);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (!cpus) {
|
2019-07-21 18:24:30 +07:00
|
|
|
pr_debug("perf_cpu_map__new failed!\n");
|
2014-08-16 02:08:36 +07:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:55 +07:00
|
|
|
evlist = evlist__new();
|
2014-08-16 02:08:36 +07:00
|
|
|
if (!evlist) {
|
2019-07-21 18:23:55 +07:00
|
|
|
pr_debug("evlist__new failed!\n");
|
2014-08-16 02:08:36 +07:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:43 +07:00
|
|
|
perf_evlist__set_maps(&evlist->core, cpus, threads);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
/* First event */
|
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function.
Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};
where 'idx' is the position in the string where the parsing failed,
'str' contains dynamically allocated error string describing the error
and 'help' is optional help string.
The change contains reporting function, which currently does not display
anything. The code changes to supply error data for specific event types
are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...
The output functions cut the beginning of the event string so the error
starts up to 10th character and cut the end of the string of it crosses
the terminal width.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-2-git-send-email-jolsa@kernel.org
[ Renamed 'error' variables to 'err', not to clash with util.h error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-23 02:10:16 +07:00
|
|
|
err = parse_events(evlist, "cpu-clock:u", NULL);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("Failed to parse event dummy:u\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:39:52 +07:00
|
|
|
cpu_clocks_evsel = evlist__last(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
/* Second event */
|
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function.
Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};
where 'idx' is the position in the string where the parsing failed,
'str' contains dynamically allocated error string describing the error
and 'help' is optional help string.
The change contains reporting function, which currently does not display
anything. The code changes to supply error data for specific event types
are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...
The output functions cut the beginning of the event string so the error
starts up to 10th character and cut the end of the string of it crosses
the terminal width.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-2-git-send-email-jolsa@kernel.org
[ Renamed 'error' variables to 'err', not to clash with util.h error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-23 02:10:16 +07:00
|
|
|
err = parse_events(evlist, "cycles:u", NULL);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("Failed to parse event cycles:u\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:39:52 +07:00
|
|
|
cycles_evsel = evlist__last(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
/* Third event */
|
|
|
|
if (!perf_evlist__can_select_event(evlist, sched_switch)) {
|
2015-11-03 17:44:42 +07:00
|
|
|
pr_debug("No sched_switch\n");
|
2014-08-16 02:08:36 +07:00
|
|
|
err = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function.
Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};
where 'idx' is the position in the string where the parsing failed,
'str' contains dynamically allocated error string describing the error
and 'help' is optional help string.
The change contains reporting function, which currently does not display
anything. The code changes to supply error data for specific event types
are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...
The output functions cut the beginning of the event string so the error
starts up to 10th character and cut the end of the string of it crosses
the terminal width.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-2-git-send-email-jolsa@kernel.org
[ Renamed 'error' variables to 'err', not to clash with util.h error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-23 02:10:16 +07:00
|
|
|
err = parse_events(evlist, sched_switch, NULL);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("Failed to parse event %s\n", sched_switch);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:39:52 +07:00
|
|
|
switch_evsel = evlist__last(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
perf_evsel__set_sample_bit(switch_evsel, CPU);
|
|
|
|
perf_evsel__set_sample_bit(switch_evsel, TIME);
|
|
|
|
|
2019-08-06 16:35:19 +07:00
|
|
|
switch_evsel->core.system_wide = true;
|
2014-08-16 02:08:36 +07:00
|
|
|
switch_evsel->no_aux_samples = true;
|
|
|
|
switch_evsel->immediate = true;
|
|
|
|
|
|
|
|
/* Test moving an event to the front */
|
2019-09-03 15:39:52 +07:00
|
|
|
if (cycles_evsel == evlist__first(evlist)) {
|
2014-08-16 02:08:36 +07:00
|
|
|
pr_debug("cycles event already at front");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
perf_evlist__to_front(evlist, cycles_evsel);
|
2019-09-03 15:39:52 +07:00
|
|
|
if (cycles_evsel != evlist__first(evlist)) {
|
2014-08-16 02:08:36 +07:00
|
|
|
pr_debug("Failed to move cycles event to front");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
perf_evsel__set_sample_bit(cycles_evsel, CPU);
|
|
|
|
perf_evsel__set_sample_bit(cycles_evsel, TIME);
|
|
|
|
|
|
|
|
/* Fourth event */
|
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function.
Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};
where 'idx' is the position in the string where the parsing failed,
'str' contains dynamically allocated error string describing the error
and 'help' is optional help string.
The change contains reporting function, which currently does not display
anything. The code changes to supply error data for specific event types
are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...
The output functions cut the beginning of the event string so the error
starts up to 10th character and cut the end of the string of it crosses
the terminal width.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-2-git-send-email-jolsa@kernel.org
[ Renamed 'error' variables to 'err', not to clash with util.h error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-23 02:10:16 +07:00
|
|
|
err = parse_events(evlist, "dummy:u", NULL);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("Failed to parse event dummy:u\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:39:52 +07:00
|
|
|
tracking_evsel = evlist__last(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
perf_evlist__set_tracking_event(evlist, tracking_evsel);
|
|
|
|
|
2019-07-21 18:24:29 +07:00
|
|
|
tracking_evsel->core.attr.freq = 0;
|
|
|
|
tracking_evsel->core.attr.sample_period = 1;
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
perf_evsel__set_sample_bit(tracking_evsel, TIME);
|
|
|
|
|
|
|
|
/* Config events */
|
2016-04-12 04:15:29 +07:00
|
|
|
perf_evlist__config(evlist, &opts, NULL);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
/* Check moved event is still at the front */
|
2019-09-03 15:39:52 +07:00
|
|
|
if (cycles_evsel != evlist__first(evlist)) {
|
2014-08-16 02:08:36 +07:00
|
|
|
pr_debug("Front event no longer at front");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check tracking event is tracking */
|
2019-07-21 18:24:29 +07:00
|
|
|
if (!tracking_evsel->core.attr.mmap || !tracking_evsel->core.attr.comm) {
|
2014-08-16 02:08:36 +07:00
|
|
|
pr_debug("Tracking event not tracking\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check non-tracking events are not tracking */
|
2016-06-23 21:26:15 +07:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2014-08-16 02:08:36 +07:00
|
|
|
if (evsel != tracking_evsel) {
|
2019-07-21 18:24:29 +07:00
|
|
|
if (evsel->core.attr.mmap || evsel->core.attr.comm) {
|
2014-08-16 02:08:36 +07:00
|
|
|
pr_debug("Non-tracking event is tracking\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:06 +07:00
|
|
|
if (evlist__open(evlist) < 0) {
|
2015-11-03 17:44:42 +07:00
|
|
|
pr_debug("Not supported\n");
|
2014-08-16 02:08:36 +07:00
|
|
|
err = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-07-28 17:45:35 +07:00
|
|
|
err = evlist__mmap(evlist, UINT_MAX);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
2019-07-28 17:45:35 +07:00
|
|
|
pr_debug("evlist__mmap failed!\n");
|
2014-08-16 02:08:36 +07:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:08 +07:00
|
|
|
evlist__enable(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
2019-07-21 18:24:03 +07:00
|
|
|
err = evsel__disable(cpu_clocks_evsel);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("perf_evlist__disable_event failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = spin_sleep();
|
|
|
|
if (err) {
|
|
|
|
pr_debug("spin_sleep failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
comm = "Test COMM 1";
|
|
|
|
err = prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0);
|
|
|
|
if (err) {
|
|
|
|
pr_debug("PR_SET_NAME failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:03 +07:00
|
|
|
err = evsel__disable(cycles_evsel);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("perf_evlist__disable_event failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
comm = "Test COMM 2";
|
|
|
|
err = prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0);
|
|
|
|
if (err) {
|
|
|
|
pr_debug("PR_SET_NAME failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = spin_sleep();
|
|
|
|
if (err) {
|
|
|
|
pr_debug("spin_sleep failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
comm = "Test COMM 3";
|
|
|
|
err = prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0);
|
|
|
|
if (err) {
|
|
|
|
pr_debug("PR_SET_NAME failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:02 +07:00
|
|
|
err = evsel__enable(cycles_evsel);
|
2014-08-16 02:08:36 +07:00
|
|
|
if (err) {
|
|
|
|
pr_debug("perf_evlist__disable_event failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
comm = "Test COMM 4";
|
|
|
|
err = prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0);
|
|
|
|
if (err) {
|
|
|
|
pr_debug("PR_SET_NAME failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = spin_sleep();
|
|
|
|
if (err) {
|
|
|
|
pr_debug("spin_sleep failed!\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:24:09 +07:00
|
|
|
evlist__disable(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
|
|
|
|
switch_tracking.switch_evsel = switch_evsel;
|
|
|
|
switch_tracking.cycles_evsel = cycles_evsel;
|
|
|
|
|
|
|
|
err = process_events(evlist, &switch_tracking);
|
|
|
|
|
|
|
|
zfree(&switch_tracking.tids);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Check all 4 comm events were seen i.e. that evsel->tracking works */
|
|
|
|
if (!switch_tracking.comm_seen[0] || !switch_tracking.comm_seen[1] ||
|
|
|
|
!switch_tracking.comm_seen[2] || !switch_tracking.comm_seen[3]) {
|
|
|
|
pr_debug("Missing comm events\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check cycles event got enabled */
|
|
|
|
if (!switch_tracking.cycles_before_comm_1) {
|
|
|
|
pr_debug("Missing cycles events\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check cycles event got disabled */
|
|
|
|
if (switch_tracking.cycles_between_comm_2_and_comm_3) {
|
|
|
|
pr_debug("cycles events even though event was disabled\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check cycles event got enabled again */
|
|
|
|
if (!switch_tracking.cycles_after_comm_4) {
|
|
|
|
pr_debug("Missing cycles events\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (evlist) {
|
2019-07-21 18:24:09 +07:00
|
|
|
evlist__disable(evlist);
|
2019-07-21 18:23:56 +07:00
|
|
|
evlist__delete(evlist);
|
2014-08-16 02:08:36 +07:00
|
|
|
} else {
|
2019-07-21 18:24:17 +07:00
|
|
|
perf_cpu_map__put(cpus);
|
2019-07-21 18:24:20 +07:00
|
|
|
perf_thread_map__put(threads);
|
2014-08-16 02:08:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
err = -1;
|
|
|
|
goto out;
|
|
|
|
}
|