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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-18 13:46:11 +00:00
|
|
|
#include <errno.h>
|
2017-04-17 14:39:06 +00:00
|
|
|
#include <linux/kernel.h>
|
2014-04-25 19:31:02 +00:00
|
|
|
#include <linux/types.h>
|
2017-04-17 18:23:08 +00:00
|
|
|
#include <inttypes.h>
|
2013-08-07 11:38:45 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-04-19 21:51:14 +00:00
|
|
|
#include <sys/param.h>
|
2019-07-21 11:24:30 +00:00
|
|
|
#include <perf/cpumap.h>
|
2019-07-21 11:24:43 +00:00
|
|
|
#include <perf/evlist.h>
|
2019-10-07 12:53:17 +00:00
|
|
|
#include <perf/mmap.h>
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2019-08-29 18:56:40 +00:00
|
|
|
#include "debug.h"
|
2019-08-30 14:11:01 +00:00
|
|
|
#include "dso.h"
|
2019-08-30 17:45:20 +00:00
|
|
|
#include "env.h"
|
2013-08-07 11:38:45 +00:00
|
|
|
#include "parse-events.h"
|
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "thread_map.h"
|
|
|
|
#include "machine.h"
|
2019-01-27 12:42:37 +00:00
|
|
|
#include "map.h"
|
2019-01-27 23:03:34 +00:00
|
|
|
#include "symbol.h"
|
2013-08-07 11:38:45 +00:00
|
|
|
#include "event.h"
|
2019-08-22 18:40:29 +00:00
|
|
|
#include "record.h"
|
2019-09-23 15:20:38 +00:00
|
|
|
#include "util/mmap.h"
|
2021-02-03 21:15:37 +00:00
|
|
|
#include "util/string2.h"
|
2019-09-18 14:36:13 +00:00
|
|
|
#include "util/synthetic-events.h"
|
2022-11-30 06:29:33 +00:00
|
|
|
#include "util/util.h"
|
2013-08-07 11:38:45 +00:00
|
|
|
#include "thread.h"
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
|
tools perf: Move from sane_ctype.h obtained from git to the Linux's original
We got the sane_ctype.h headers from git and kept using it so far, but
since that code originally came from the kernel sources to the git
sources, perhaps its better to just use the one in the kernel, so that
we can leverage tools/perf/check_headers.sh to be notified when our copy
gets out of sync, i.e. when fixes or goodies are added to the code we've
copied.
This will help with things like tools/lib/string.c where we want to have
more things in common with the kernel, such as strim(), skip_spaces(),
etc so as to go on removing the things that we have in tools/perf/util/
and instead using the code in the kernel, indirectly and removing things
like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements
are made to the original code.
Hopefully this also should help with reducing the difference of code
hosted in tools/ to the one in the kernel proper.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxygn12@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-06-25 20:27:31 +00:00
|
|
|
#include <linux/ctype.h>
|
2017-04-17 19:10:49 +00:00
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
#define BUFSZ 1024
|
|
|
|
#define READLEN 128
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
struct state {
|
|
|
|
u64 done[1024];
|
|
|
|
size_t done_cnt;
|
|
|
|
};
|
|
|
|
|
2016-01-12 10:07:44 +00:00
|
|
|
static size_t read_objdump_chunk(const char **line, unsigned char **buf,
|
|
|
|
size_t *buf_len)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
2016-01-12 10:07:44 +00:00
|
|
|
size_t bytes_read = 0;
|
|
|
|
unsigned char *chunk_start = *buf;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
/* Read bytes */
|
2016-01-12 10:07:44 +00:00
|
|
|
while (*buf_len > 0) {
|
2013-08-07 11:38:45 +00:00
|
|
|
char c1, c2;
|
|
|
|
|
|
|
|
/* Get 2 hex digits */
|
2016-01-12 10:07:44 +00:00
|
|
|
c1 = *(*line)++;
|
|
|
|
if (!isxdigit(c1))
|
2013-08-07 11:38:45 +00:00
|
|
|
break;
|
2016-01-12 10:07:44 +00:00
|
|
|
c2 = *(*line)++;
|
|
|
|
if (!isxdigit(c2))
|
2013-08-07 11:38:45 +00:00
|
|
|
break;
|
2016-01-12 10:07:44 +00:00
|
|
|
|
|
|
|
/* Store byte and advance buf */
|
|
|
|
**buf = (hex(c1) << 4) | hex(c2);
|
|
|
|
(*buf)++;
|
|
|
|
(*buf_len)--;
|
|
|
|
bytes_read++;
|
|
|
|
|
|
|
|
/* End of chunk? */
|
|
|
|
if (isspace(**line))
|
2013-08-07 11:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-01-12 10:07:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* objdump will display raw insn as LE if code endian
|
|
|
|
* is LE and bytes_per_chunk > 1. In that case reverse
|
|
|
|
* the chunk we just read.
|
|
|
|
*
|
|
|
|
* see disassemble_bytes() at binutils/objdump.c for details
|
|
|
|
* how objdump chooses display endian)
|
|
|
|
*/
|
2022-11-30 06:29:33 +00:00
|
|
|
if (bytes_read > 1 && !host_is_bigendian()) {
|
2016-01-12 10:07:44 +00:00
|
|
|
unsigned char *chunk_end = chunk_start + bytes_read - 1;
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
while (chunk_start < chunk_end) {
|
|
|
|
tmp = *chunk_start;
|
|
|
|
*chunk_start = *chunk_end;
|
|
|
|
*chunk_end = tmp;
|
|
|
|
chunk_start++;
|
|
|
|
chunk_end--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t read_objdump_line(const char *line, unsigned char *buf,
|
|
|
|
size_t buf_len)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
size_t ret, bytes_read = 0;
|
|
|
|
|
|
|
|
/* Skip to a colon */
|
|
|
|
p = strchr(line, ':');
|
|
|
|
if (!p)
|
|
|
|
return 0;
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Skip initial spaces */
|
|
|
|
while (*p) {
|
|
|
|
if (!isspace(*p))
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = read_objdump_chunk(&p, &buf, &buf_len);
|
|
|
|
bytes_read += ret;
|
|
|
|
p++;
|
|
|
|
} while (ret > 0);
|
|
|
|
|
2015-09-02 08:19:14 +00:00
|
|
|
/* return number of successfully read bytes */
|
2016-01-12 10:07:44 +00:00
|
|
|
return bytes_read;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 08:19:14 +00:00
|
|
|
static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
2015-09-02 08:19:14 +00:00
|
|
|
size_t line_len, off_last = 0;
|
2013-08-07 11:38:45 +00:00
|
|
|
ssize_t ret;
|
|
|
|
int err = 0;
|
2015-09-02 08:19:16 +00:00
|
|
|
u64 addr, last_addr = start_addr;
|
2015-09-02 08:19:14 +00:00
|
|
|
|
|
|
|
while (off_last < *len) {
|
|
|
|
size_t off, read_bytes, written_bytes;
|
|
|
|
unsigned char tmp[BUFSZ];
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
ret = getline(&line, &line_len, f);
|
|
|
|
if (feof(f))
|
|
|
|
break;
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("getline failed\n");
|
|
|
|
err = -1;
|
|
|
|
break;
|
|
|
|
}
|
2015-09-02 08:19:14 +00:00
|
|
|
|
|
|
|
/* read objdump data into temporary buffer */
|
2016-01-12 10:07:44 +00:00
|
|
|
read_bytes = read_objdump_line(line, tmp, sizeof(tmp));
|
2015-09-02 08:19:14 +00:00
|
|
|
if (!read_bytes)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sscanf(line, "%"PRIx64, &addr) != 1)
|
|
|
|
continue;
|
2015-09-02 08:19:16 +00:00
|
|
|
if (addr < last_addr) {
|
|
|
|
pr_debug("addr going backwards, read beyond section?\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_addr = addr;
|
2015-09-02 08:19:14 +00:00
|
|
|
|
|
|
|
/* copy it from temporary buffer to 'buf' according
|
|
|
|
* to address on current objdump line */
|
|
|
|
off = addr - start_addr;
|
|
|
|
if (off >= *len)
|
|
|
|
break;
|
|
|
|
written_bytes = MIN(read_bytes, *len - off);
|
|
|
|
memcpy(buf + off, tmp, written_bytes);
|
|
|
|
off_last = off + written_bytes;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 08:19:14 +00:00
|
|
|
/* len returns number of bytes that could not be read */
|
|
|
|
*len -= off_last;
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
free(line);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_via_objdump(const char *filename, u64 addr, void *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
char cmd[PATH_MAX * 2];
|
|
|
|
const char *fmt;
|
|
|
|
FILE *f;
|
|
|
|
int ret;
|
|
|
|
|
2015-09-03 11:23:32 +00:00
|
|
|
fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
|
2013-08-07 11:38:45 +00:00
|
|
|
ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
|
|
|
|
filename);
|
|
|
|
if (ret <= 0 || (size_t)ret >= sizeof(cmd))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
pr_debug("Objdump command is: %s\n", cmd);
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
/* Ignore objdump errors */
|
|
|
|
strcat(cmd, " 2>/dev/null");
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
f = popen(cmd, "r");
|
|
|
|
if (!f) {
|
|
|
|
pr_debug("popen failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-02 08:19:14 +00:00
|
|
|
ret = read_objdump_output(f, buf, &len, addr);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (len) {
|
2016-01-12 10:07:44 +00:00
|
|
|
pr_debug("objdump read too few bytes: %zd\n", len);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
pclose(f);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-02 08:19:17 +00:00
|
|
|
static void dump_buf(unsigned char *buf, size_t len)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
pr_debug("0x%02x ", buf[i]);
|
|
|
|
if (i % 16 == 15)
|
|
|
|
pr_debug("\n");
|
|
|
|
}
|
|
|
|
pr_debug("\n");
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
static int read_object_code(u64 addr, size_t len, u8 cpumode,
|
2014-10-23 20:21:54 +00:00
|
|
|
struct thread *thread, struct state *state)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
struct addr_location al;
|
2021-09-06 15:22:38 +00:00
|
|
|
unsigned char buf1[BUFSZ] = {0};
|
|
|
|
unsigned char buf2[BUFSZ] = {0};
|
2013-08-07 11:38:45 +00:00
|
|
|
size_t ret_len;
|
|
|
|
u64 objdump_addr;
|
2017-06-08 07:31:07 +00:00
|
|
|
const char *objdump_name;
|
|
|
|
char decomp_name[KMOD_DECOMP_LEN];
|
2018-08-17 09:48:01 +00:00
|
|
|
bool decomp = false;
|
2013-08-07 11:38:45 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
|
|
|
|
|
2018-04-24 14:58:56 +00:00
|
|
|
if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
|
2017-08-31 09:14:56 +00:00
|
|
|
if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
|
|
|
|
pr_debug("Hypervisor address can not be resolved - skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-24 13:49:50 +00:00
|
|
|
pr_debug("thread__find_map failed\n");
|
2013-08-07 11:38:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug("File is: %s\n", al.map->dso->long_name);
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
|
|
|
|
!dso__is_kcore(al.map->dso)) {
|
2013-08-07 11:38:45 +00:00
|
|
|
pr_debug("Unexpected kernel address - skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug("On file address is: %#"PRIx64"\n", al.addr);
|
|
|
|
|
|
|
|
if (len > BUFSZ)
|
|
|
|
len = BUFSZ;
|
|
|
|
|
|
|
|
/* Do not go off the map */
|
|
|
|
if (addr + len > al.map->end)
|
|
|
|
len = al.map->end - addr;
|
|
|
|
|
|
|
|
/* Read the object code using perf */
|
2019-11-26 01:07:43 +00:00
|
|
|
ret_len = dso__data_read_offset(al.map->dso, thread->maps->machine,
|
2014-10-23 20:21:54 +00:00
|
|
|
al.addr, buf1, len);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret_len != len) {
|
|
|
|
pr_debug("dso__data_read_offset failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converting addresses for use by objdump requires more information.
|
|
|
|
* map__load() does that. See map__rip_2objdump() for details.
|
|
|
|
*/
|
2016-09-01 22:25:52 +00:00
|
|
|
if (map__load(al.map))
|
2013-08-07 11:38:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
/* objdump struggles with kcore - try each map only once */
|
|
|
|
if (dso__is_kcore(al.map->dso)) {
|
|
|
|
size_t d;
|
|
|
|
|
|
|
|
for (d = 0; d < state->done_cnt; d++) {
|
|
|
|
if (state->done[d] == al.map->start) {
|
|
|
|
pr_debug("kcore map tested already");
|
|
|
|
pr_debug(" - skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state->done_cnt >= ARRAY_SIZE(state->done)) {
|
|
|
|
pr_debug("Too many kcore maps - skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
state->done[state->done_cnt++] = al.map->start;
|
|
|
|
}
|
|
|
|
|
2017-06-08 07:31:07 +00:00
|
|
|
objdump_name = al.map->dso->long_name;
|
|
|
|
if (dso__needs_decompress(al.map->dso)) {
|
|
|
|
if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
|
|
|
|
decomp_name,
|
|
|
|
sizeof(decomp_name)) < 0) {
|
|
|
|
pr_debug("decompression failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-08-17 09:48:01 +00:00
|
|
|
decomp = true;
|
2017-06-08 07:31:07 +00:00
|
|
|
objdump_name = decomp_name;
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
/* Read the object code using objdump */
|
|
|
|
objdump_addr = map__rip_2objdump(al.map, al.addr);
|
2017-06-08 07:31:07 +00:00
|
|
|
ret = read_via_objdump(objdump_name, objdump_addr, buf2, len);
|
|
|
|
|
2018-08-17 09:48:01 +00:00
|
|
|
if (decomp)
|
2017-06-08 07:31:07 +00:00
|
|
|
unlink(objdump_name);
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret > 0) {
|
|
|
|
/*
|
|
|
|
* The kernel maps are inaccurate - assume objdump is right in
|
|
|
|
* that case.
|
|
|
|
*/
|
|
|
|
if (cpumode == PERF_RECORD_MISC_KERNEL ||
|
|
|
|
cpumode == PERF_RECORD_MISC_GUEST_KERNEL) {
|
|
|
|
len -= ret;
|
2013-08-07 11:38:53 +00:00
|
|
|
if (len) {
|
2013-08-07 11:38:45 +00:00
|
|
|
pr_debug("Reducing len to %zu\n", len);
|
2013-08-07 11:38:53 +00:00
|
|
|
} else if (dso__is_kcore(al.map->dso)) {
|
|
|
|
/*
|
|
|
|
* objdump cannot handle very large segments
|
|
|
|
* that may be found in kcore.
|
|
|
|
*/
|
|
|
|
pr_debug("objdump failed for kcore");
|
|
|
|
pr_debug(" - skipping\n");
|
|
|
|
return 0;
|
|
|
|
} else {
|
2013-08-07 11:38:45 +00:00
|
|
|
return -1;
|
2013-08-07 11:38:53 +00:00
|
|
|
}
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("read_via_objdump failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The results should be identical */
|
|
|
|
if (memcmp(buf1, buf2, len)) {
|
|
|
|
pr_debug("Bytes read differ from those read by objdump\n");
|
2015-09-02 08:19:17 +00:00
|
|
|
pr_debug("buf1 (dso):\n");
|
|
|
|
dump_buf(buf1, len);
|
|
|
|
pr_debug("buf2 (objdump):\n");
|
|
|
|
dump_buf(buf2, len);
|
2013-08-07 11:38:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pr_debug("Bytes read match those read by objdump\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int process_sample_event(struct machine *machine,
|
2019-07-21 11:23:52 +00:00
|
|
|
struct evlist *evlist,
|
2013-08-07 11:38:53 +00:00
|
|
|
union perf_event *event, struct state *state)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
struct perf_sample sample;
|
|
|
|
struct thread *thread;
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
int ret;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2020-11-30 12:43:07 +00:00
|
|
|
if (evlist__parse_sample(evlist, event, &sample)) {
|
|
|
|
pr_debug("evlist__parse_sample failed\n");
|
2013-08-07 11:38:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-12 00:56:42 +00:00
|
|
|
thread = machine__findnew_thread(machine, sample.pid, sample.tid);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (!thread) {
|
|
|
|
pr_debug("machine__findnew_thread failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:23:43 +00:00
|
|
|
ret = read_object_code(sample.ip, READLEN, sample.cpumode, thread, state);
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
thread__put(thread);
|
|
|
|
return ret;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:23:52 +00:00
|
|
|
static int process_event(struct machine *machine, struct evlist *evlist,
|
2013-08-07 11:38:53 +00:00
|
|
|
union perf_event *event, struct state *state)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
if (event->header.type == PERF_RECORD_SAMPLE)
|
2013-08-07 11:38:53 +00:00
|
|
|
return process_sample_event(machine, evlist, event, state);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2013-11-12 07:59:33 +00:00
|
|
|
if (event->header.type == PERF_RECORD_THROTTLE ||
|
|
|
|
event->header.type == PERF_RECORD_UNTHROTTLE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (event->header.type < PERF_RECORD_MAX) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = machine__process_event(machine, event, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
pr_debug("machine__process_event failed, event type %u\n",
|
|
|
|
event->header.type);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-21 11:23:52 +00:00
|
|
|
static int process_events(struct machine *machine, struct evlist *evlist,
|
2013-08-07 11:38:53 +00:00
|
|
|
struct state *state)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
union perf_event *event;
|
2019-07-27 18:30:53 +00:00
|
|
|
struct mmap *md;
|
2013-08-07 11:38:45 +00:00
|
|
|
int i, ret;
|
|
|
|
|
2019-07-30 11:04:59 +00:00
|
|
|
for (i = 0; i < evlist->core.nr_mmaps; i++) {
|
2018-03-01 23:09:02 +00:00
|
|
|
md = &evlist->mmap[i];
|
2019-10-07 12:53:18 +00:00
|
|
|
if (perf_mmap__read_init(&md->core) < 0)
|
2018-03-01 23:09:02 +00:00
|
|
|
continue;
|
|
|
|
|
2019-10-07 12:53:20 +00:00
|
|
|
while ((event = perf_mmap__read_event(&md->core)) != NULL) {
|
2013-08-07 11:38:53 +00:00
|
|
|
ret = process_event(machine, evlist, event, state);
|
2019-10-07 12:53:17 +00:00
|
|
|
perf_mmap__consume(&md->core);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-10-07 12:53:19 +00:00
|
|
|
perf_mmap__read_done(&md->core);
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int comp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return *(int *)a - *(int *)b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_sort_something(void)
|
|
|
|
{
|
2013-08-14 04:32:12 +00:00
|
|
|
int buf[40960], i;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2013-08-14 04:32:12 +00:00
|
|
|
for (i = 0; i < (int)ARRAY_SIZE(buf); i++)
|
|
|
|
buf[i] = ARRAY_SIZE(buf) - i - 1;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2013-08-14 04:32:12 +00:00
|
|
|
qsort(buf, ARRAY_SIZE(buf), sizeof(int), comp);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2013-08-14 04:32:12 +00:00
|
|
|
for (i = 0; i < (int)ARRAY_SIZE(buf); i++) {
|
2013-08-07 11:38:45 +00:00
|
|
|
if (buf[i] != i) {
|
|
|
|
pr_debug("qsort failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sort_something(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
do_sort_something();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syscall_something(void)
|
|
|
|
{
|
|
|
|
int pipefd[2];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
if (pipe(pipefd) < 0) {
|
|
|
|
pr_debug("pipe failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
close(pipefd[1]);
|
|
|
|
close(pipefd[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fs_something(void)
|
|
|
|
{
|
|
|
|
const char *test_file_name = "temp-perf-code-reading-test-file--";
|
|
|
|
FILE *f;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
f = fopen(test_file_name, "w+");
|
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
unlink(test_file_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:45:20 +00:00
|
|
|
#ifdef __s390x__
|
|
|
|
#include "header.h" // for get_cpuid()
|
|
|
|
#endif
|
|
|
|
|
2018-02-13 15:14:19 +00:00
|
|
|
static const char *do_determine_event(bool excl_kernel)
|
|
|
|
{
|
|
|
|
const char *event = excl_kernel ? "cycles:u" : "cycles";
|
|
|
|
|
|
|
|
#ifdef __s390x__
|
|
|
|
char cpuid[128], model[16], model_c[16], cpum_cf_v[16];
|
|
|
|
unsigned int family;
|
|
|
|
int ret, cpum_cf_a;
|
|
|
|
|
|
|
|
if (get_cpuid(cpuid, sizeof(cpuid)))
|
|
|
|
goto out_clocks;
|
|
|
|
ret = sscanf(cpuid, "%*[^,],%u,%[^,],%[^,],%[^,],%x", &family, model_c,
|
|
|
|
model, cpum_cf_v, &cpum_cf_a);
|
|
|
|
if (ret != 5) /* Not available */
|
|
|
|
goto out_clocks;
|
|
|
|
if (excl_kernel && (cpum_cf_a & 4))
|
|
|
|
return event;
|
|
|
|
if (!excl_kernel && (cpum_cf_a & 2))
|
|
|
|
return event;
|
|
|
|
|
|
|
|
/* Fall through: missing authorization */
|
|
|
|
out_clocks:
|
|
|
|
event = excl_kernel ? "cpu-clock:u" : "cpu-clock";
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
static void do_something(void)
|
|
|
|
{
|
|
|
|
fs_something();
|
|
|
|
|
|
|
|
sort_something();
|
|
|
|
|
|
|
|
syscall_something();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TEST_CODE_READING_OK,
|
|
|
|
TEST_CODE_READING_NO_VMLINUX,
|
2013-08-07 11:38:53 +00:00
|
|
|
TEST_CODE_READING_NO_KCORE,
|
2013-08-07 11:38:45 +00:00
|
|
|
TEST_CODE_READING_NO_ACCESS,
|
2013-08-07 11:38:53 +00:00
|
|
|
TEST_CODE_READING_NO_KERNEL_OBJ,
|
2013-08-07 11:38:45 +00:00
|
|
|
};
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
static int do_test_code_reading(bool try_kcore)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
struct machine *machine;
|
|
|
|
struct thread *thread;
|
2013-12-19 17:43:45 +00:00
|
|
|
struct record_opts opts = {
|
2013-08-07 11:38:45 +00:00
|
|
|
.mmap_pages = UINT_MAX,
|
|
|
|
.user_freq = UINT_MAX,
|
|
|
|
.user_interval = ULLONG_MAX,
|
2016-02-18 16:45:25 +00:00
|
|
|
.freq = 500,
|
2013-08-07 11:38:45 +00:00
|
|
|
.target = {
|
|
|
|
.uses_mmap = true,
|
|
|
|
},
|
|
|
|
};
|
2013-08-07 11:38:53 +00:00
|
|
|
struct state state = {
|
|
|
|
.done_cnt = 0,
|
|
|
|
};
|
2019-07-21 11:23:50 +00:00
|
|
|
struct perf_thread_map *threads = NULL;
|
2019-07-21 11:23:49 +00:00
|
|
|
struct perf_cpu_map *cpus = NULL;
|
2019-07-21 11:23:52 +00:00
|
|
|
struct evlist *evlist = NULL;
|
2019-07-21 11:23:51 +00:00
|
|
|
struct evsel *evsel = NULL;
|
2013-08-07 11:38:45 +00:00
|
|
|
int err = -1, ret;
|
|
|
|
pid_t pid;
|
|
|
|
struct map *map;
|
2013-08-07 11:38:53 +00:00
|
|
|
bool have_vmlinux, have_kcore, excl_kernel = false;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
pid = getpid();
|
|
|
|
|
2015-12-03 08:34:14 +00:00
|
|
|
machine = machine__new_host();
|
2018-06-05 07:30:00 +00:00
|
|
|
machine->env = &perf_env;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
ret = machine__create_kernel_maps(machine);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("machine__create_kernel_maps failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
/* Force the use of kallsyms instead of vmlinux to try kcore */
|
|
|
|
if (try_kcore)
|
|
|
|
symbol_conf.kallsyms_name = "/proc/kallsyms";
|
|
|
|
|
2013-08-07 11:38:45 +00:00
|
|
|
/* Load kernel map */
|
2015-09-30 14:54:04 +00:00
|
|
|
map = machine__kernel_map(machine);
|
2016-09-01 22:25:52 +00:00
|
|
|
ret = map__load(map);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("map__load failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
2013-08-07 11:38:53 +00:00
|
|
|
have_vmlinux = dso__is_vmlinux(map->dso);
|
|
|
|
have_kcore = dso__is_kcore(map->dso);
|
|
|
|
|
|
|
|
/* 2nd time through we just try kcore */
|
|
|
|
if (try_kcore && !have_kcore)
|
|
|
|
return TEST_CODE_READING_NO_KCORE;
|
|
|
|
|
|
|
|
/* No point getting kernel events if there is no kernel object */
|
|
|
|
if (!have_vmlinux && !have_kcore)
|
2013-08-07 11:38:45 +00:00
|
|
|
excl_kernel = true;
|
|
|
|
|
|
|
|
threads = thread_map__new_by_tid(pid);
|
|
|
|
if (!threads) {
|
|
|
|
pr_debug("thread_map__new_by_tid failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = perf_event__synthesize_thread_map(NULL, threads,
|
2021-08-11 04:46:57 +00:00
|
|
|
perf_event__process, machine,
|
|
|
|
true, false);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("perf_event__synthesize_thread_map failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:23:03 +00:00
|
|
|
thread = machine__findnew_thread(machine, pid, pid);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (!thread) {
|
|
|
|
pr_debug("machine__findnew_thread failed\n");
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:24:30 +00:00
|
|
|
cpus = perf_cpu_map__new(NULL);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (!cpus) {
|
2019-07-21 11:24:30 +00:00
|
|
|
pr_debug("perf_cpu_map__new failed\n");
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
const char *str;
|
|
|
|
|
2019-07-21 11:23:55 +00:00
|
|
|
evlist = evlist__new();
|
2013-08-07 11:38:45 +00:00
|
|
|
if (!evlist) {
|
2020-11-30 18:04:05 +00:00
|
|
|
pr_debug("evlist__new failed\n");
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:24:43 +00:00
|
|
|
perf_evlist__set_maps(&evlist->core, cpus, threads);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2018-02-13 15:14:19 +00:00
|
|
|
str = do_determine_event(excl_kernel);
|
2013-08-07 11:38:45 +00:00
|
|
|
pr_debug("Parsing event '%s'\n", str);
|
2022-08-09 08:07:02 +00:00
|
|
|
ret = parse_event(evlist, str);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("parse_events failed\n");
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 18:07:49 +00:00
|
|
|
evlist__config(evlist, &opts, NULL);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2019-09-03 08:39:52 +00:00
|
|
|
evsel = evlist__first(evlist);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2019-07-21 11:24:29 +00:00
|
|
|
evsel->core.attr.comm = 1;
|
|
|
|
evsel->core.attr.disabled = 1;
|
|
|
|
evsel->core.attr.enable_on_exec = 0;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2019-07-21 11:24:06 +00:00
|
|
|
ret = evlist__open(evlist);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
if (!excl_kernel) {
|
|
|
|
excl_kernel = true;
|
2015-12-03 08:34:15 +00:00
|
|
|
/*
|
|
|
|
* Both cpus and threads are now owned by evlist
|
|
|
|
* and will be freed by following perf_evlist__set_maps
|
2021-03-23 16:09:15 +00:00
|
|
|
* call. Getting reference to keep them alive.
|
2015-12-03 08:34:15 +00:00
|
|
|
*/
|
2019-07-21 11:24:17 +00:00
|
|
|
perf_cpu_map__get(cpus);
|
2019-07-21 11:24:20 +00:00
|
|
|
perf_thread_map__get(threads);
|
2019-07-21 11:24:43 +00:00
|
|
|
perf_evlist__set_maps(&evlist->core, NULL, NULL);
|
2019-07-21 11:23:56 +00:00
|
|
|
evlist__delete(evlist);
|
2013-08-07 11:38:45 +00:00
|
|
|
evlist = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-18 16:40:57 +00:00
|
|
|
|
2017-02-17 08:17:38 +00:00
|
|
|
if (verbose > 0) {
|
2016-02-18 16:40:57 +00:00
|
|
|
char errbuf[512];
|
2020-06-17 12:19:46 +00:00
|
|
|
evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf));
|
2016-02-18 16:40:57 +00:00
|
|
|
pr_debug("perf_evlist__open() failed!\n%s\n", errbuf);
|
|
|
|
}
|
|
|
|
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-28 10:45:35 +00:00
|
|
|
ret = evlist__mmap(evlist, UINT_MAX);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0) {
|
2019-07-28 10:45:35 +00:00
|
|
|
pr_debug("evlist__mmap failed\n");
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:24:08 +00:00
|
|
|
evlist__enable(evlist);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
do_something();
|
|
|
|
|
2019-07-21 11:24:09 +00:00
|
|
|
evlist__disable(evlist);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
ret = process_events(machine, evlist, &state);
|
2013-08-07 11:38:45 +00:00
|
|
|
if (ret < 0)
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-08-07 11:38:45 +00:00
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
if (!have_vmlinux && !have_kcore && !try_kcore)
|
|
|
|
err = TEST_CODE_READING_NO_KERNEL_OBJ;
|
|
|
|
else if (!have_vmlinux && !try_kcore)
|
2013-08-07 11:38:45 +00:00
|
|
|
err = TEST_CODE_READING_NO_VMLINUX;
|
|
|
|
else if (excl_kernel)
|
|
|
|
err = TEST_CODE_READING_NO_ACCESS;
|
|
|
|
else
|
|
|
|
err = TEST_CODE_READING_OK;
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
out_put:
|
|
|
|
thread__put(thread);
|
2013-08-07 11:38:45 +00:00
|
|
|
out_err:
|
2021-03-01 14:04:03 +00:00
|
|
|
evlist__delete(evlist);
|
|
|
|
perf_cpu_map__put(cpus);
|
|
|
|
perf_thread_map__put(threads);
|
2013-08-07 11:38:45 +00:00
|
|
|
machine__delete_threads(machine);
|
2015-12-03 08:34:14 +00:00
|
|
|
machine__delete(machine);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-11-04 06:41:51 +00:00
|
|
|
static int test__code_reading(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
2013-08-07 11:38:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2013-08-07 11:38:53 +00:00
|
|
|
ret = do_test_code_reading(false);
|
|
|
|
if (!ret)
|
|
|
|
ret = do_test_code_reading(true);
|
2013-08-07 11:38:45 +00:00
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case TEST_CODE_READING_OK:
|
|
|
|
return 0;
|
|
|
|
case TEST_CODE_READING_NO_VMLINUX:
|
2015-11-03 10:44:42 +00:00
|
|
|
pr_debug("no vmlinux\n");
|
2013-08-07 11:38:45 +00:00
|
|
|
return 0;
|
2013-08-07 11:38:53 +00:00
|
|
|
case TEST_CODE_READING_NO_KCORE:
|
2015-11-03 10:44:42 +00:00
|
|
|
pr_debug("no kcore\n");
|
2013-08-07 11:38:53 +00:00
|
|
|
return 0;
|
2013-08-07 11:38:45 +00:00
|
|
|
case TEST_CODE_READING_NO_ACCESS:
|
2015-11-03 10:44:42 +00:00
|
|
|
pr_debug("no access\n");
|
2013-08-07 11:38:45 +00:00
|
|
|
return 0;
|
2013-08-07 11:38:53 +00:00
|
|
|
case TEST_CODE_READING_NO_KERNEL_OBJ:
|
2015-11-03 10:44:42 +00:00
|
|
|
pr_debug("no kernel obj\n");
|
2013-08-07 11:38:53 +00:00
|
|
|
return 0;
|
2013-08-07 11:38:45 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
2021-11-04 06:41:50 +00:00
|
|
|
|
|
|
|
DEFINE_SUITE("Object code reading", code_reading);
|