2014-04-26 02:31:02 +07:00
|
|
|
#include <linux/types.h>
|
2013-08-07 18:38:45 +07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "parse-events.h"
|
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "thread_map.h"
|
|
|
|
#include "cpumap.h"
|
|
|
|
#include "machine.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "thread.h"
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#define BUFSZ 1024
|
|
|
|
#define READLEN 128
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
struct state {
|
|
|
|
u64 done[1024];
|
|
|
|
size_t done_cnt;
|
|
|
|
};
|
|
|
|
|
2013-08-07 18:38:45 +07:00
|
|
|
static unsigned int hex(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
return c - '0';
|
|
|
|
if (c >= 'a' && c <= 'f')
|
|
|
|
return c - 'a' + 10;
|
|
|
|
return c - 'A' + 10;
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:19:14 +07:00
|
|
|
static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
|
|
|
|
size_t len)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
const char *p;
|
2015-09-02 15:19:14 +07:00
|
|
|
size_t i, j = 0;
|
2013-08-07 18:38:45 +07:00
|
|
|
|
|
|
|
/* Skip to a colon */
|
|
|
|
p = strchr(line, ':');
|
|
|
|
if (!p)
|
2015-09-02 15:19:14 +07:00
|
|
|
return 0;
|
2013-08-07 18:38:45 +07:00
|
|
|
i = p + 1 - line;
|
|
|
|
|
|
|
|
/* Read bytes */
|
2015-09-02 15:19:14 +07:00
|
|
|
while (j < len) {
|
2013-08-07 18:38:45 +07:00
|
|
|
char c1, c2;
|
|
|
|
|
|
|
|
/* Skip spaces */
|
|
|
|
for (; i < line_len; i++) {
|
|
|
|
if (!isspace(line[i]))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Get 2 hex digits */
|
|
|
|
if (i >= line_len || !isxdigit(line[i]))
|
|
|
|
break;
|
|
|
|
c1 = line[i++];
|
|
|
|
if (i >= line_len || !isxdigit(line[i]))
|
|
|
|
break;
|
|
|
|
c2 = line[i++];
|
|
|
|
/* Followed by a space */
|
|
|
|
if (i < line_len && line[i] && !isspace(line[i]))
|
|
|
|
break;
|
|
|
|
/* Store byte */
|
2015-09-02 15:19:14 +07:00
|
|
|
*(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
|
|
|
|
buf += 1;
|
|
|
|
j++;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
2015-09-02 15:19:14 +07:00
|
|
|
/* return number of successfully read bytes */
|
|
|
|
return j;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
2015-09-02 15:19:14 +07:00
|
|
|
static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
2015-09-02 15:19:14 +07:00
|
|
|
size_t line_len, off_last = 0;
|
2013-08-07 18:38:45 +07:00
|
|
|
ssize_t ret;
|
|
|
|
int err = 0;
|
2015-09-02 15:19:16 +07:00
|
|
|
u64 addr, last_addr = start_addr;
|
2015-09-02 15:19:14 +07:00
|
|
|
|
|
|
|
while (off_last < *len) {
|
|
|
|
size_t off, read_bytes, written_bytes;
|
|
|
|
unsigned char tmp[BUFSZ];
|
2013-08-07 18:38:45 +07: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 15:19:14 +07:00
|
|
|
|
|
|
|
/* read objdump data into temporary buffer */
|
|
|
|
read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
|
|
|
|
if (!read_bytes)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sscanf(line, "%"PRIx64, &addr) != 1)
|
|
|
|
continue;
|
2015-09-02 15:19:16 +07:00
|
|
|
if (addr < last_addr) {
|
|
|
|
pr_debug("addr going backwards, read beyond section?\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_addr = addr;
|
2015-09-02 15:19:14 +07: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 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
2015-09-02 15:19:14 +07:00
|
|
|
/* len returns number of bytes that could not be read */
|
|
|
|
*len -= off_last;
|
|
|
|
|
2013-08-07 18:38:45 +07: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 18:23:32 +07:00
|
|
|
fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
|
2013-08-07 18:38:45 +07: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 18:38:53 +07:00
|
|
|
/* Ignore objdump errors */
|
|
|
|
strcat(cmd, " 2>/dev/null");
|
|
|
|
|
2013-08-07 18:38:45 +07:00
|
|
|
f = popen(cmd, "r");
|
|
|
|
if (!f) {
|
|
|
|
pr_debug("popen failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:19:14 +07:00
|
|
|
ret = read_objdump_output(f, buf, &len, addr);
|
2013-08-07 18:38:45 +07:00
|
|
|
if (len) {
|
|
|
|
pr_debug("objdump read too few bytes\n");
|
|
|
|
if (!ret)
|
|
|
|
ret = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
pclose(f);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:19:17 +07: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 18:38:45 +07:00
|
|
|
static int read_object_code(u64 addr, size_t len, u8 cpumode,
|
2014-10-24 03:21:54 +07:00
|
|
|
struct thread *thread, struct state *state)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
struct addr_location al;
|
|
|
|
unsigned char buf1[BUFSZ];
|
|
|
|
unsigned char buf2[BUFSZ];
|
|
|
|
size_t ret_len;
|
|
|
|
u64 objdump_addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
|
|
|
|
|
2014-10-23 22:50:25 +07:00
|
|
|
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al);
|
2013-08-07 18:38:45 +07:00
|
|
|
if (!al.map || !al.map->dso) {
|
|
|
|
pr_debug("thread__find_addr_map failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug("File is: %s\n", al.map->dso->long_name);
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
|
|
|
|
!dso__is_kcore(al.map->dso)) {
|
2013-08-07 18:38:45 +07: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 */
|
2014-10-24 03:21:54 +07:00
|
|
|
ret_len = dso__data_read_offset(al.map->dso, thread->mg->machine,
|
|
|
|
al.addr, buf1, len);
|
2013-08-07 18:38:45 +07: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.
|
|
|
|
*/
|
|
|
|
if (map__load(al.map, NULL))
|
|
|
|
return -1;
|
|
|
|
|
2013-08-07 18:38:53 +07: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;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:45 +07:00
|
|
|
/* Read the object code using objdump */
|
|
|
|
objdump_addr = map__rip_2objdump(al.map, al.addr);
|
|
|
|
ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len);
|
|
|
|
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 18:38:53 +07:00
|
|
|
if (len) {
|
2013-08-07 18:38:45 +07:00
|
|
|
pr_debug("Reducing len to %zu\n", len);
|
2013-08-07 18:38:53 +07: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 18:38:45 +07:00
|
|
|
return -1;
|
2013-08-07 18:38:53 +07:00
|
|
|
}
|
2013-08-07 18:38:45 +07: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 15:19:17 +07:00
|
|
|
pr_debug("buf1 (dso):\n");
|
|
|
|
dump_buf(buf1, len);
|
|
|
|
pr_debug("buf2 (objdump):\n");
|
|
|
|
dump_buf(buf2, len);
|
2013-08-07 18:38:45 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pr_debug("Bytes read match those read by objdump\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int process_sample_event(struct machine *machine,
|
|
|
|
struct perf_evlist *evlist,
|
2013-08-07 18:38:53 +07:00
|
|
|
union perf_event *event, struct state *state)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
struct perf_sample sample;
|
|
|
|
struct thread *thread;
|
|
|
|
u8 cpumode;
|
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-07 06:43:22 +07:00
|
|
|
int ret;
|
2013-08-07 18:38:45 +07:00
|
|
|
|
|
|
|
if (perf_evlist__parse_sample(evlist, event, &sample)) {
|
|
|
|
pr_debug("perf_evlist__parse_sample failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-12 07:56:42 +07:00
|
|
|
thread = machine__findnew_thread(machine, sample.pid, sample.tid);
|
2013-08-07 18:38:45 +07:00
|
|
|
if (!thread) {
|
|
|
|
pr_debug("machine__findnew_thread failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
|
|
|
|
|
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-07 06:43:22 +07:00
|
|
|
ret = read_object_code(sample.ip, READLEN, cpumode, thread, state);
|
|
|
|
thread__put(thread);
|
|
|
|
return ret;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int process_event(struct machine *machine, struct perf_evlist *evlist,
|
2013-08-07 18:38:53 +07:00
|
|
|
union perf_event *event, struct state *state)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
if (event->header.type == PERF_RECORD_SAMPLE)
|
2013-08-07 18:38:53 +07:00
|
|
|
return process_sample_event(machine, evlist, event, state);
|
2013-08-07 18:38:45 +07:00
|
|
|
|
2013-11-12 14:59:33 +07: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 18:38:45 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
static int process_events(struct machine *machine, struct perf_evlist *evlist,
|
|
|
|
struct state *state)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
union perf_event *event;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++) {
|
|
|
|
while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
|
2013-08-07 18:38:53 +07:00
|
|
|
ret = process_event(machine, evlist, event, state);
|
2013-10-24 14:43:33 +07:00
|
|
|
perf_evlist__mmap_consume(evlist, i);
|
2013-08-07 18:38:45 +07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 11:32:12 +07:00
|
|
|
int buf[40960], i;
|
2013-08-07 18:38:45 +07:00
|
|
|
|
2013-08-14 11:32:12 +07:00
|
|
|
for (i = 0; i < (int)ARRAY_SIZE(buf); i++)
|
|
|
|
buf[i] = ARRAY_SIZE(buf) - i - 1;
|
2013-08-07 18:38:45 +07:00
|
|
|
|
2013-08-14 11:32:12 +07:00
|
|
|
qsort(buf, ARRAY_SIZE(buf), sizeof(int), comp);
|
2013-08-07 18:38:45 +07:00
|
|
|
|
2013-08-14 11:32:12 +07:00
|
|
|
for (i = 0; i < (int)ARRAY_SIZE(buf); i++) {
|
2013-08-07 18:38:45 +07: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_something(void)
|
|
|
|
{
|
|
|
|
fs_something();
|
|
|
|
|
|
|
|
sort_something();
|
|
|
|
|
|
|
|
syscall_something();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TEST_CODE_READING_OK,
|
|
|
|
TEST_CODE_READING_NO_VMLINUX,
|
2013-08-07 18:38:53 +07:00
|
|
|
TEST_CODE_READING_NO_KCORE,
|
2013-08-07 18:38:45 +07:00
|
|
|
TEST_CODE_READING_NO_ACCESS,
|
2013-08-07 18:38:53 +07:00
|
|
|
TEST_CODE_READING_NO_KERNEL_OBJ,
|
2013-08-07 18:38:45 +07:00
|
|
|
};
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
static int do_test_code_reading(bool try_kcore)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
struct machine *machine;
|
|
|
|
struct thread *thread;
|
2013-12-20 00:43:45 +07:00
|
|
|
struct record_opts opts = {
|
2013-08-07 18:38:45 +07:00
|
|
|
.mmap_pages = UINT_MAX,
|
|
|
|
.user_freq = UINT_MAX,
|
|
|
|
.user_interval = ULLONG_MAX,
|
2016-02-18 23:45:25 +07:00
|
|
|
.freq = 500,
|
2013-08-07 18:38:45 +07:00
|
|
|
.target = {
|
|
|
|
.uses_mmap = true,
|
|
|
|
},
|
|
|
|
};
|
2013-08-07 18:38:53 +07:00
|
|
|
struct state state = {
|
|
|
|
.done_cnt = 0,
|
|
|
|
};
|
2013-08-07 18:38:45 +07:00
|
|
|
struct thread_map *threads = NULL;
|
|
|
|
struct cpu_map *cpus = NULL;
|
|
|
|
struct perf_evlist *evlist = NULL;
|
|
|
|
struct perf_evsel *evsel = NULL;
|
|
|
|
int err = -1, ret;
|
|
|
|
pid_t pid;
|
|
|
|
struct map *map;
|
2013-08-07 18:38:53 +07:00
|
|
|
bool have_vmlinux, have_kcore, excl_kernel = false;
|
2013-08-07 18:38:45 +07:00
|
|
|
|
|
|
|
pid = getpid();
|
|
|
|
|
2015-12-03 15:34:14 +07:00
|
|
|
machine = machine__new_host();
|
2013-08-07 18:38:45 +07:00
|
|
|
|
|
|
|
ret = machine__create_kernel_maps(machine);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("machine__create_kernel_maps failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
/* Force the use of kallsyms instead of vmlinux to try kcore */
|
|
|
|
if (try_kcore)
|
|
|
|
symbol_conf.kallsyms_name = "/proc/kallsyms";
|
|
|
|
|
2013-08-07 18:38:45 +07:00
|
|
|
/* Load kernel map */
|
2015-09-30 21:54:04 +07:00
|
|
|
map = machine__kernel_map(machine);
|
2013-08-07 18:38:45 +07:00
|
|
|
ret = map__load(map, NULL);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("map__load failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
2013-08-07 18:38:53 +07: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 18:38:45 +07: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,
|
2015-06-17 20:51:11 +07:00
|
|
|
perf_event__process, machine, false, 500);
|
2013-08-07 18:38:45 +07:00
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("perf_event__synthesize_thread_map failed\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:23:03 +07:00
|
|
|
thread = machine__findnew_thread(machine, pid, pid);
|
2013-08-07 18:38:45 +07: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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
cpus = cpu_map__new(NULL);
|
|
|
|
if (!cpus) {
|
|
|
|
pr_debug("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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
evlist = perf_evlist__new();
|
|
|
|
if (!evlist) {
|
|
|
|
pr_debug("perf_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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
|
|
|
|
|
|
|
if (excl_kernel)
|
|
|
|
str = "cycles:u";
|
|
|
|
else
|
|
|
|
str = "cycles";
|
|
|
|
pr_debug("Parsing event '%s'\n", str);
|
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
|
|
|
ret = parse_events(evlist, str, NULL);
|
2013-08-07 18:38:45 +07: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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__config(evlist, &opts);
|
|
|
|
|
|
|
|
evsel = perf_evlist__first(evlist);
|
|
|
|
|
|
|
|
evsel->attr.comm = 1;
|
|
|
|
evsel->attr.disabled = 1;
|
|
|
|
evsel->attr.enable_on_exec = 0;
|
|
|
|
|
|
|
|
ret = perf_evlist__open(evlist);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (!excl_kernel) {
|
|
|
|
excl_kernel = true;
|
2015-12-03 15:34:15 +07:00
|
|
|
/*
|
|
|
|
* Both cpus and threads are now owned by evlist
|
|
|
|
* and will be freed by following perf_evlist__set_maps
|
|
|
|
* call. Getting refference to keep them alive.
|
|
|
|
*/
|
|
|
|
cpu_map__get(cpus);
|
|
|
|
thread_map__get(threads);
|
2014-04-10 16:02:54 +07:00
|
|
|
perf_evlist__set_maps(evlist, NULL, NULL);
|
2013-08-07 18:38:45 +07:00
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
evlist = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-18 23:40:57 +07:00
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
char errbuf[512];
|
|
|
|
perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf));
|
|
|
|
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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = perf_evlist__mmap(evlist, UINT_MAX, false);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug("perf_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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__enable(evlist);
|
|
|
|
|
|
|
|
do_something();
|
|
|
|
|
|
|
|
perf_evlist__disable(evlist);
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
ret = process_events(machine, evlist, &state);
|
2013-08-07 18:38:45 +07: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-07 06:43:22 +07:00
|
|
|
goto out_put;
|
2013-08-07 18:38:45 +07:00
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
if (!have_vmlinux && !have_kcore && !try_kcore)
|
|
|
|
err = TEST_CODE_READING_NO_KERNEL_OBJ;
|
|
|
|
else if (!have_vmlinux && !try_kcore)
|
2013-08-07 18:38:45 +07: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-07 06:43:22 +07:00
|
|
|
out_put:
|
|
|
|
thread__put(thread);
|
2013-08-07 18:38:45 +07:00
|
|
|
out_err:
|
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-07 06:43:22 +07:00
|
|
|
|
2013-08-07 18:38:45 +07:00
|
|
|
if (evlist) {
|
|
|
|
perf_evlist__delete(evlist);
|
2014-01-04 01:56:06 +07:00
|
|
|
} else {
|
2015-06-23 05:36:04 +07:00
|
|
|
cpu_map__put(cpus);
|
2015-06-23 05:36:05 +07:00
|
|
|
thread_map__put(threads);
|
2014-01-04 01:56:06 +07:00
|
|
|
}
|
2013-08-07 18:38:45 +07:00
|
|
|
machine__delete_threads(machine);
|
2015-12-03 15:34:14 +07:00
|
|
|
machine__delete(machine);
|
2013-08-07 18:38:45 +07:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
perf tests: Pass the subtest index to each test routine
Some tests have sub-tests we want to run, so allow passing this.
Wang tried to avoid having to touch all tests, but then, having the
test.func in an anonymous union makes the build fail on older compilers,
like the one in RHEL6, where:
test a = {
.func = foo,
};
fails.
To fix it leave the func pointer in the main structure and pass the subtest
index to all tests, end result function is the same, but we have just one
function pointer, not two, with and without the subtest index as an argument.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-5genj0ficwdmelpoqlds0u4y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-11-19 22:01:48 +07:00
|
|
|
int test__code_reading(int subtest __maybe_unused)
|
2013-08-07 18:38:45 +07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2013-08-07 18:38:53 +07:00
|
|
|
ret = do_test_code_reading(false);
|
|
|
|
if (!ret)
|
|
|
|
ret = do_test_code_reading(true);
|
2013-08-07 18:38:45 +07:00
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case TEST_CODE_READING_OK:
|
|
|
|
return 0;
|
|
|
|
case TEST_CODE_READING_NO_VMLINUX:
|
2015-11-03 17:44:42 +07:00
|
|
|
pr_debug("no vmlinux\n");
|
2013-08-07 18:38:45 +07:00
|
|
|
return 0;
|
2013-08-07 18:38:53 +07:00
|
|
|
case TEST_CODE_READING_NO_KCORE:
|
2015-11-03 17:44:42 +07:00
|
|
|
pr_debug("no kcore\n");
|
2013-08-07 18:38:53 +07:00
|
|
|
return 0;
|
2013-08-07 18:38:45 +07:00
|
|
|
case TEST_CODE_READING_NO_ACCESS:
|
2015-11-03 17:44:42 +07:00
|
|
|
pr_debug("no access\n");
|
2013-08-07 18:38:45 +07:00
|
|
|
return 0;
|
2013-08-07 18:38:53 +07:00
|
|
|
case TEST_CODE_READING_NO_KERNEL_OBJ:
|
2015-11-03 17:44:42 +07:00
|
|
|
pr_debug("no kernel obj\n");
|
2013-08-07 18:38:53 +07:00
|
|
|
return 0;
|
2013-08-07 18:38:45 +07:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|