提交 69e8f5b1 编写于 作者: I Ingo Molnar

Merge tag 'perf-core-for-mingo' of...

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

User visible changes:

  * Fix mmap return address truncation to 32-bit in 'perf trace'. (Chang Hyun Park)

  * Support operations for shared futexes. (Davidlohr Bueso)

  * Fix error message for --filter option not coming after tracepoint. (Arnaldo Carvalho de Melo)

Infrastructure changes:

  * Refactor unit and scale function parameters for PMU parsing routines. (Matt Fleming)

  * Improve DSO long names lookup with rbtree, resulting in great speedup for
    workloads with lots of DSOs. (Waiman Long)

  * Fix build breakage on arm64 targets. (Will Deacon)
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <libunwind.h> #include <libunwind.h>
#include "perf_regs.h" #include "perf_regs.h"
#include "../../util/unwind.h" #include "../../util/unwind.h"
#include "../../util/debug.h"
int libunwind__arch_reg_id(int regnum) int libunwind__arch_reg_id(int regnum)
{ {
......
...@@ -26,6 +26,7 @@ static unsigned int nsecs = 10; ...@@ -26,6 +26,7 @@ static unsigned int nsecs = 10;
/* amount of futexes per thread */ /* amount of futexes per thread */
static unsigned int nfutexes = 1024; static unsigned int nfutexes = 1024;
static bool fshared = false, done = false, silent = false; static bool fshared = false, done = false, silent = false;
static int futex_flag = 0;
struct timeval start, end, runtime; struct timeval start, end, runtime;
static pthread_mutex_t thread_lock; static pthread_mutex_t thread_lock;
...@@ -75,8 +76,7 @@ static void *workerfn(void *arg) ...@@ -75,8 +76,7 @@ static void *workerfn(void *arg)
* such as internal waitqueue handling, thus enlarging * such as internal waitqueue handling, thus enlarging
* the critical region protected by hb->lock. * the critical region protected by hb->lock.
*/ */
ret = futex_wait(&w->futex[i], 1234, NULL, ret = futex_wait(&w->futex[i], 1234, NULL, futex_flag);
fshared ? 0 : FUTEX_PRIVATE_FLAG);
if (!silent && if (!silent &&
(!ret || errno != EAGAIN || errno != EWOULDBLOCK)) (!ret || errno != EAGAIN || errno != EWOULDBLOCK))
warn("Non-expected futex return call"); warn("Non-expected futex return call");
...@@ -135,6 +135,9 @@ int bench_futex_hash(int argc, const char **argv, ...@@ -135,6 +135,9 @@ int bench_futex_hash(int argc, const char **argv,
if (!worker) if (!worker)
goto errmem; goto errmem;
if (!fshared)
futex_flag = FUTEX_PRIVATE_FLAG;
printf("Run summary [PID %d]: %d threads, each operating on %d [%s] futexes for %d secs.\n\n", printf("Run summary [PID %d]: %d threads, each operating on %d [%s] futexes for %d secs.\n\n",
getpid(), nthreads, nfutexes, fshared ? "shared":"private", nsecs); getpid(), nthreads, nfutexes, fshared ? "shared":"private", nsecs);
......
...@@ -30,16 +30,18 @@ static u_int32_t futex1 = 0, futex2 = 0; ...@@ -30,16 +30,18 @@ static u_int32_t futex1 = 0, futex2 = 0;
static unsigned int nrequeue = 1; static unsigned int nrequeue = 1;
static pthread_t *worker; static pthread_t *worker;
static bool done = 0, silent = 0; static bool done = false, silent = false, fshared = false;
static pthread_mutex_t thread_lock; static pthread_mutex_t thread_lock;
static pthread_cond_t thread_parent, thread_worker; static pthread_cond_t thread_parent, thread_worker;
static struct stats requeuetime_stats, requeued_stats; static struct stats requeuetime_stats, requeued_stats;
static unsigned int ncpus, threads_starting, nthreads = 0; static unsigned int ncpus, threads_starting, nthreads = 0;
static int futex_flag = 0;
static const struct option options[] = { static const struct option options[] = {
OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"), OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"),
OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", &fshared, "Use shared futexes instead of private ones"),
OPT_END() OPT_END()
}; };
...@@ -70,7 +72,7 @@ static void *workerfn(void *arg __maybe_unused) ...@@ -70,7 +72,7 @@ static void *workerfn(void *arg __maybe_unused)
pthread_cond_wait(&thread_worker, &thread_lock); pthread_cond_wait(&thread_worker, &thread_lock);
pthread_mutex_unlock(&thread_lock); pthread_mutex_unlock(&thread_lock);
futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG); futex_wait(&futex1, 0, NULL, futex_flag);
return NULL; return NULL;
} }
...@@ -127,9 +129,12 @@ int bench_futex_requeue(int argc, const char **argv, ...@@ -127,9 +129,12 @@ int bench_futex_requeue(int argc, const char **argv,
if (!worker) if (!worker)
err(EXIT_FAILURE, "calloc"); err(EXIT_FAILURE, "calloc");
printf("Run summary [PID %d]: Requeuing %d threads (from %p to %p), " if (!fshared)
"%d at a time.\n\n", futex_flag = FUTEX_PRIVATE_FLAG;
getpid(), nthreads, &futex1, &futex2, nrequeue);
printf("Run summary [PID %d]: Requeuing %d threads (from [%s] %p to %p), "
"%d at a time.\n\n", getpid(), nthreads,
fshared ? "shared":"private", &futex1, &futex2, nrequeue);
init_stats(&requeued_stats); init_stats(&requeued_stats);
init_stats(&requeuetime_stats); init_stats(&requeuetime_stats);
...@@ -156,16 +161,20 @@ int bench_futex_requeue(int argc, const char **argv, ...@@ -156,16 +161,20 @@ int bench_futex_requeue(int argc, const char **argv,
/* Ok, all threads are patiently blocked, start requeueing */ /* Ok, all threads are patiently blocked, start requeueing */
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (nrequeued = 0; nrequeued < nthreads; nrequeued += nrequeue) for (nrequeued = 0; nrequeued < nthreads; nrequeued += nrequeue) {
/* /*
* Do not wakeup any tasks blocked on futex1, allowing * Do not wakeup any tasks blocked on futex1, allowing
* us to really measure futex_wait functionality. * us to really measure futex_wait functionality.
*/ */
futex_cmp_requeue(&futex1, 0, &futex2, 0, nrequeue, futex_cmp_requeue(&futex1, 0, &futex2, 0,
FUTEX_PRIVATE_FLAG); nrequeue, futex_flag);
}
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
timersub(&end, &start, &runtime); timersub(&end, &start, &runtime);
if (nrequeued > nthreads)
nrequeued = nthreads;
update_stats(&requeued_stats, nrequeued); update_stats(&requeued_stats, nrequeued);
update_stats(&requeuetime_stats, runtime.tv_usec); update_stats(&requeuetime_stats, runtime.tv_usec);
...@@ -175,7 +184,7 @@ int bench_futex_requeue(int argc, const char **argv, ...@@ -175,7 +184,7 @@ int bench_futex_requeue(int argc, const char **argv,
} }
/* everybody should be blocked on futex2, wake'em up */ /* everybody should be blocked on futex2, wake'em up */
nrequeued = futex_wake(&futex2, nthreads, FUTEX_PRIVATE_FLAG); nrequeued = futex_wake(&futex2, nthreads, futex_flag);
if (nthreads != nrequeued) if (nthreads != nrequeued)
warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads); warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads);
...@@ -184,7 +193,6 @@ int bench_futex_requeue(int argc, const char **argv, ...@@ -184,7 +193,6 @@ int bench_futex_requeue(int argc, const char **argv,
if (ret) if (ret)
err(EXIT_FAILURE, "pthread_join"); err(EXIT_FAILURE, "pthread_join");
} }
} }
/* cleanup & report results */ /* cleanup & report results */
......
...@@ -31,16 +31,18 @@ static u_int32_t futex1 = 0; ...@@ -31,16 +31,18 @@ static u_int32_t futex1 = 0;
static unsigned int nwakes = 1; static unsigned int nwakes = 1;
pthread_t *worker; pthread_t *worker;
static bool done = false, silent = false; static bool done = false, silent = false, fshared = false;
static pthread_mutex_t thread_lock; static pthread_mutex_t thread_lock;
static pthread_cond_t thread_parent, thread_worker; static pthread_cond_t thread_parent, thread_worker;
static struct stats waketime_stats, wakeup_stats; static struct stats waketime_stats, wakeup_stats;
static unsigned int ncpus, threads_starting, nthreads = 0; static unsigned int ncpus, threads_starting, nthreads = 0;
static int futex_flag = 0;
static const struct option options[] = { static const struct option options[] = {
OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
OPT_UINTEGER('w', "nwakes", &nwakes, "Specify amount of threads to wake at once"), OPT_UINTEGER('w', "nwakes", &nwakes, "Specify amount of threads to wake at once"),
OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", &fshared, "Use shared futexes instead of private ones"),
OPT_END() OPT_END()
}; };
...@@ -58,7 +60,7 @@ static void *workerfn(void *arg __maybe_unused) ...@@ -58,7 +60,7 @@ static void *workerfn(void *arg __maybe_unused)
pthread_cond_wait(&thread_worker, &thread_lock); pthread_cond_wait(&thread_worker, &thread_lock);
pthread_mutex_unlock(&thread_lock); pthread_mutex_unlock(&thread_lock);
futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG); futex_wait(&futex1, 0, NULL, futex_flag);
return NULL; return NULL;
} }
...@@ -130,9 +132,12 @@ int bench_futex_wake(int argc, const char **argv, ...@@ -130,9 +132,12 @@ int bench_futex_wake(int argc, const char **argv,
if (!worker) if (!worker)
err(EXIT_FAILURE, "calloc"); err(EXIT_FAILURE, "calloc");
printf("Run summary [PID %d]: blocking on %d threads (at futex %p), " if (!fshared)
futex_flag = FUTEX_PRIVATE_FLAG;
printf("Run summary [PID %d]: blocking on %d threads (at [%s] futex %p), "
"waking up %d at a time.\n\n", "waking up %d at a time.\n\n",
getpid(), nthreads, &futex1, nwakes); getpid(), nthreads, fshared ? "shared":"private", &futex1, nwakes);
init_stats(&wakeup_stats); init_stats(&wakeup_stats);
init_stats(&waketime_stats); init_stats(&waketime_stats);
...@@ -160,7 +165,7 @@ int bench_futex_wake(int argc, const char **argv, ...@@ -160,7 +165,7 @@ int bench_futex_wake(int argc, const char **argv,
/* Ok, all threads are patiently blocked, start waking folks up */ /* Ok, all threads are patiently blocked, start waking folks up */
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
while (nwoken != nthreads) while (nwoken != nthreads)
nwoken += futex_wake(&futex1, nwakes, FUTEX_PRIVATE_FLAG); nwoken += futex_wake(&futex1, nwakes, futex_flag);
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
timersub(&end, &start, &runtime); timersub(&end, &start, &runtime);
......
...@@ -1695,7 +1695,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, ...@@ -1695,7 +1695,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
union perf_event *event __maybe_unused, union perf_event *event __maybe_unused,
struct perf_sample *sample) struct perf_sample *sample)
{ {
int ret; long ret;
u64 duration = 0; u64 duration = 0;
struct thread *thread; struct thread *thread;
int id = perf_evsel__sc_tp_uint(evsel, id, sample); int id = perf_evsel__sc_tp_uint(evsel, id, sample);
...@@ -1748,7 +1748,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, ...@@ -1748,7 +1748,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
if (sc->fmt == NULL) { if (sc->fmt == NULL) {
signed_print: signed_print:
fprintf(trace->output, ") = %d", ret); fprintf(trace->output, ") = %ld", ret);
} else if (ret < 0 && sc->fmt->errmsg) { } else if (ret < 0 && sc->fmt->errmsg) {
char bf[STRERR_BUFSIZE]; char bf[STRERR_BUFSIZE];
const char *emsg = strerror_r(-ret, bf, sizeof(bf)), const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
...@@ -1758,7 +1758,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, ...@@ -1758,7 +1758,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
} else if (ret == 0 && sc->fmt->timeout) } else if (ret == 0 && sc->fmt->timeout)
fprintf(trace->output, ") = 0 Timeout"); fprintf(trace->output, ") = 0 Timeout");
else if (sc->fmt->hexret) else if (sc->fmt->hexret)
fprintf(trace->output, ") = %#x", ret); fprintf(trace->output, ") = %#lx", ret);
else else
goto signed_print; goto signed_print;
......
...@@ -653,6 +653,65 @@ struct dso *dso__kernel_findnew(struct machine *machine, const char *name, ...@@ -653,6 +653,65 @@ struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
return dso; return dso;
} }
/*
* Find a matching entry and/or link current entry to RB tree.
* Either one of the dso or name parameter must be non-NULL or the
* function will not work.
*/
static struct dso *dso__findlink_by_longname(struct rb_root *root,
struct dso *dso, const char *name)
{
struct rb_node **p = &root->rb_node;
struct rb_node *parent = NULL;
if (!name)
name = dso->long_name;
/*
* Find node with the matching name
*/
while (*p) {
struct dso *this = rb_entry(*p, struct dso, rb_node);
int rc = strcmp(name, this->long_name);
parent = *p;
if (rc == 0) {
/*
* In case the new DSO is a duplicate of an existing
* one, print an one-time warning & put the new entry
* at the end of the list of duplicates.
*/
if (!dso || (dso == this))
return this; /* Find matching dso */
/*
* The core kernel DSOs may have duplicated long name.
* In this case, the short name should be different.
* Comparing the short names to differentiate the DSOs.
*/
rc = strcmp(dso->short_name, this->short_name);
if (rc == 0) {
pr_err("Duplicated dso name: %s\n", name);
return NULL;
}
}
if (rc < 0)
p = &parent->rb_left;
else
p = &parent->rb_right;
}
if (dso) {
/* Add new node and rebalance tree */
rb_link_node(&dso->rb_node, parent, p);
rb_insert_color(&dso->rb_node, root);
}
return NULL;
}
static inline struct dso *
dso__find_by_longname(const struct rb_root *root, const char *name)
{
return dso__findlink_by_longname((struct rb_root *)root, NULL, name);
}
void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated) void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
{ {
if (name == NULL) if (name == NULL)
...@@ -755,6 +814,7 @@ struct dso *dso__new(const char *name) ...@@ -755,6 +814,7 @@ struct dso *dso__new(const char *name)
dso->a2l_fails = 1; dso->a2l_fails = 1;
dso->kernel = DSO_TYPE_USER; dso->kernel = DSO_TYPE_USER;
dso->needs_swap = DSO_SWAP__UNSET; dso->needs_swap = DSO_SWAP__UNSET;
RB_CLEAR_NODE(&dso->rb_node);
INIT_LIST_HEAD(&dso->node); INIT_LIST_HEAD(&dso->node);
INIT_LIST_HEAD(&dso->data.open_entry); INIT_LIST_HEAD(&dso->data.open_entry);
} }
...@@ -765,6 +825,10 @@ struct dso *dso__new(const char *name) ...@@ -765,6 +825,10 @@ struct dso *dso__new(const char *name)
void dso__delete(struct dso *dso) void dso__delete(struct dso *dso)
{ {
int i; int i;
if (!RB_EMPTY_NODE(&dso->rb_node))
pr_err("DSO %s is still in rbtree when being deleted!\n",
dso->long_name);
for (i = 0; i < MAP__NR_TYPES; ++i) for (i = 0; i < MAP__NR_TYPES; ++i)
symbols__delete(&dso->symbols[i]); symbols__delete(&dso->symbols[i]);
...@@ -851,35 +915,34 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits) ...@@ -851,35 +915,34 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
return have_build_id; return have_build_id;
} }
void dsos__add(struct list_head *head, struct dso *dso) void dsos__add(struct dsos *dsos, struct dso *dso)
{ {
list_add_tail(&dso->node, head); list_add_tail(&dso->node, &dsos->head);
dso__findlink_by_longname(&dsos->root, dso, NULL);
} }
struct dso *dsos__find(const struct list_head *head, const char *name, bool cmp_short) struct dso *dsos__find(const struct dsos *dsos, const char *name,
bool cmp_short)
{ {
struct dso *pos; struct dso *pos;
if (cmp_short) { if (cmp_short) {
list_for_each_entry(pos, head, node) list_for_each_entry(pos, &dsos->head, node)
if (strcmp(pos->short_name, name) == 0) if (strcmp(pos->short_name, name) == 0)
return pos; return pos;
return NULL; return NULL;
} }
list_for_each_entry(pos, head, node) return dso__find_by_longname(&dsos->root, name);
if (strcmp(pos->long_name, name) == 0)
return pos;
return NULL;
} }
struct dso *__dsos__findnew(struct list_head *head, const char *name) struct dso *__dsos__findnew(struct dsos *dsos, const char *name)
{ {
struct dso *dso = dsos__find(head, name, false); struct dso *dso = dsos__find(dsos, name, false);
if (!dso) { if (!dso) {
dso = dso__new(name); dso = dso__new(name);
if (dso != NULL) { if (dso != NULL) {
dsos__add(head, dso); dsos__add(dsos, dso);
dso__set_basename(dso); dso__set_basename(dso);
} }
} }
......
...@@ -90,8 +90,18 @@ struct dso_cache { ...@@ -90,8 +90,18 @@ struct dso_cache {
char data[0]; char data[0];
}; };
/*
* DSOs are put into both a list for fast iteration and rbtree for fast
* long name lookup.
*/
struct dsos {
struct list_head head;
struct rb_root root; /* rbtree root sorted by long name */
};
struct dso { struct dso {
struct list_head node; struct list_head node;
struct rb_node rb_node; /* rbtree node sorted by long name */
struct rb_root symbols[MAP__NR_TYPES]; struct rb_root symbols[MAP__NR_TYPES];
struct rb_root symbol_names[MAP__NR_TYPES]; struct rb_root symbol_names[MAP__NR_TYPES];
void *a2l; void *a2l;
...@@ -224,10 +234,10 @@ struct map *dso__new_map(const char *name); ...@@ -224,10 +234,10 @@ struct map *dso__new_map(const char *name);
struct dso *dso__kernel_findnew(struct machine *machine, const char *name, struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
const char *short_name, int dso_type); const char *short_name, int dso_type);
void dsos__add(struct list_head *head, struct dso *dso); void dsos__add(struct dsos *dsos, struct dso *dso);
struct dso *dsos__find(const struct list_head *head, const char *name, struct dso *dsos__find(const struct dsos *dsos, const char *name,
bool cmp_short); bool cmp_short);
struct dso *__dsos__findnew(struct list_head *head, const char *name); struct dso *__dsos__findnew(struct dsos *dsos, const char *name);
bool __dsos__read_build_ids(struct list_head *head, bool with_hits); bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
......
...@@ -214,11 +214,11 @@ static int machine__hit_all_dsos(struct machine *machine) ...@@ -214,11 +214,11 @@ static int machine__hit_all_dsos(struct machine *machine)
{ {
int err; int err;
err = __dsos__hit_all(&machine->kernel_dsos); err = __dsos__hit_all(&machine->kernel_dsos.head);
if (err) if (err)
return err; return err;
return __dsos__hit_all(&machine->user_dsos); return __dsos__hit_all(&machine->user_dsos.head);
} }
int dsos__hit_all(struct perf_session *session) int dsos__hit_all(struct perf_session *session)
...@@ -288,11 +288,12 @@ static int machine__write_buildid_table(struct machine *machine, int fd) ...@@ -288,11 +288,12 @@ static int machine__write_buildid_table(struct machine *machine, int fd)
umisc = PERF_RECORD_MISC_GUEST_USER; umisc = PERF_RECORD_MISC_GUEST_USER;
} }
err = __dsos__write_buildid_table(&machine->kernel_dsos, machine, err = __dsos__write_buildid_table(&machine->kernel_dsos.head, machine,
machine->pid, kmisc, fd); machine->pid, kmisc, fd);
if (err == 0) if (err == 0)
err = __dsos__write_buildid_table(&machine->user_dsos, machine, err = __dsos__write_buildid_table(&machine->user_dsos.head,
machine->pid, umisc, fd); machine, machine->pid, umisc,
fd);
return err; return err;
} }
...@@ -455,9 +456,10 @@ static int __dsos__cache_build_ids(struct list_head *head, ...@@ -455,9 +456,10 @@ static int __dsos__cache_build_ids(struct list_head *head,
static int machine__cache_build_ids(struct machine *machine, const char *debugdir) static int machine__cache_build_ids(struct machine *machine, const char *debugdir)
{ {
int ret = __dsos__cache_build_ids(&machine->kernel_dsos, machine, int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine,
debugdir); debugdir);
ret |= __dsos__cache_build_ids(&machine->user_dsos, machine, debugdir); ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine,
debugdir);
return ret; return ret;
} }
...@@ -483,8 +485,10 @@ static int perf_session__cache_build_ids(struct perf_session *session) ...@@ -483,8 +485,10 @@ static int perf_session__cache_build_ids(struct perf_session *session)
static bool machine__read_build_ids(struct machine *machine, bool with_hits) static bool machine__read_build_ids(struct machine *machine, bool with_hits)
{ {
bool ret = __dsos__read_build_ids(&machine->kernel_dsos, with_hits); bool ret;
ret |= __dsos__read_build_ids(&machine->user_dsos, with_hits);
ret = __dsos__read_build_ids(&machine->kernel_dsos.head, with_hits);
ret |= __dsos__read_build_ids(&machine->user_dsos.head, with_hits);
return ret; return ret;
} }
...@@ -1548,7 +1552,7 @@ static int __event_process_build_id(struct build_id_event *bev, ...@@ -1548,7 +1552,7 @@ static int __event_process_build_id(struct build_id_event *bev,
struct perf_session *session) struct perf_session *session)
{ {
int err = -1; int err = -1;
struct list_head *head; struct dsos *dsos;
struct machine *machine; struct machine *machine;
u16 misc; u16 misc;
struct dso *dso; struct dso *dso;
...@@ -1563,22 +1567,22 @@ static int __event_process_build_id(struct build_id_event *bev, ...@@ -1563,22 +1567,22 @@ static int __event_process_build_id(struct build_id_event *bev,
switch (misc) { switch (misc) {
case PERF_RECORD_MISC_KERNEL: case PERF_RECORD_MISC_KERNEL:
dso_type = DSO_TYPE_KERNEL; dso_type = DSO_TYPE_KERNEL;
head = &machine->kernel_dsos; dsos = &machine->kernel_dsos;
break; break;
case PERF_RECORD_MISC_GUEST_KERNEL: case PERF_RECORD_MISC_GUEST_KERNEL:
dso_type = DSO_TYPE_GUEST_KERNEL; dso_type = DSO_TYPE_GUEST_KERNEL;
head = &machine->kernel_dsos; dsos = &machine->kernel_dsos;
break; break;
case PERF_RECORD_MISC_USER: case PERF_RECORD_MISC_USER:
case PERF_RECORD_MISC_GUEST_USER: case PERF_RECORD_MISC_GUEST_USER:
dso_type = DSO_TYPE_USER; dso_type = DSO_TYPE_USER;
head = &machine->user_dsos; dsos = &machine->user_dsos;
break; break;
default: default:
goto out; goto out;
} }
dso = __dsos__findnew(head, filename); dso = __dsos__findnew(dsos, filename);
if (dso != NULL) { if (dso != NULL) {
char sbuild_id[BUILD_ID_SIZE * 2 + 1]; char sbuild_id[BUILD_ID_SIZE * 2 + 1];
......
...@@ -17,8 +17,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) ...@@ -17,8 +17,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
{ {
map_groups__init(&machine->kmaps); map_groups__init(&machine->kmaps);
RB_CLEAR_NODE(&machine->rb_node); RB_CLEAR_NODE(&machine->rb_node);
INIT_LIST_HEAD(&machine->user_dsos); INIT_LIST_HEAD(&machine->user_dsos.head);
INIT_LIST_HEAD(&machine->kernel_dsos); INIT_LIST_HEAD(&machine->kernel_dsos.head);
machine->threads = RB_ROOT; machine->threads = RB_ROOT;
INIT_LIST_HEAD(&machine->dead_threads); INIT_LIST_HEAD(&machine->dead_threads);
...@@ -72,11 +72,12 @@ struct machine *machine__new_host(void) ...@@ -72,11 +72,12 @@ struct machine *machine__new_host(void)
return NULL; return NULL;
} }
static void dsos__delete(struct list_head *dsos) static void dsos__delete(struct dsos *dsos)
{ {
struct dso *pos, *n; struct dso *pos, *n;
list_for_each_entry_safe(pos, n, dsos, node) { list_for_each_entry_safe(pos, n, &dsos->head, node) {
RB_CLEAR_NODE(&pos->rb_node);
list_del(&pos->node); list_del(&pos->node);
dso__delete(pos); dso__delete(pos);
} }
...@@ -477,23 +478,23 @@ struct map *machine__new_module(struct machine *machine, u64 start, ...@@ -477,23 +478,23 @@ struct map *machine__new_module(struct machine *machine, u64 start,
size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
{ {
struct rb_node *nd; struct rb_node *nd;
size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) + size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) +
__dsos__fprintf(&machines->host.user_dsos, fp); __dsos__fprintf(&machines->host.user_dsos.head, fp);
for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) { for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
struct machine *pos = rb_entry(nd, struct machine, rb_node); struct machine *pos = rb_entry(nd, struct machine, rb_node);
ret += __dsos__fprintf(&pos->kernel_dsos, fp); ret += __dsos__fprintf(&pos->kernel_dsos.head, fp);
ret += __dsos__fprintf(&pos->user_dsos, fp); ret += __dsos__fprintf(&pos->user_dsos.head, fp);
} }
return ret; return ret;
} }
size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp,
bool (skip)(struct dso *dso, int parm), int parm) bool (skip)(struct dso *dso, int parm), int parm)
{ {
return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) + return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) +
__dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm); __dsos__fprintf_buildid(&m->user_dsos.head, fp, skip, parm);
} }
size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
...@@ -994,7 +995,7 @@ static bool machine__uses_kcore(struct machine *machine) ...@@ -994,7 +995,7 @@ static bool machine__uses_kcore(struct machine *machine)
{ {
struct dso *dso; struct dso *dso;
list_for_each_entry(dso, &machine->kernel_dsos, node) { list_for_each_entry(dso, &machine->kernel_dsos.head, node) {
if (dso__is_kcore(dso)) if (dso__is_kcore(dso))
return true; return true;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include "map.h" #include "map.h"
#include "dso.h"
#include "event.h" #include "event.h"
struct addr_location; struct addr_location;
...@@ -32,8 +33,8 @@ struct machine { ...@@ -32,8 +33,8 @@ struct machine {
struct list_head dead_threads; struct list_head dead_threads;
struct thread *last_match; struct thread *last_match;
struct vdso_info *vdso_info; struct vdso_info *vdso_info;
struct list_head user_dsos; struct dsos user_dsos;
struct list_head kernel_dsos; struct dsos kernel_dsos;
struct map_groups kmaps; struct map_groups kmaps;
struct map *vmlinux_maps[MAP__NR_TYPES]; struct map *vmlinux_maps[MAP__NR_TYPES];
u64 kernel_start; u64 kernel_start;
......
...@@ -634,10 +634,9 @@ int parse_events_add_pmu(struct list_head *list, int *idx, ...@@ -634,10 +634,9 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
char *name, struct list_head *head_config) char *name, struct list_head *head_config)
{ {
struct perf_event_attr attr; struct perf_event_attr attr;
struct perf_pmu_info info;
struct perf_pmu *pmu; struct perf_pmu *pmu;
struct perf_evsel *evsel; struct perf_evsel *evsel;
const char *unit;
double scale;
pmu = perf_pmu__find(name); pmu = perf_pmu__find(name);
if (!pmu) if (!pmu)
...@@ -656,7 +655,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx, ...@@ -656,7 +655,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
return evsel ? 0 : -ENOMEM; return evsel ? 0 : -ENOMEM;
} }
if (perf_pmu__check_alias(pmu, head_config, &unit, &scale)) if (perf_pmu__check_alias(pmu, head_config, &info))
return -EINVAL; return -EINVAL;
/* /*
...@@ -671,8 +670,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx, ...@@ -671,8 +670,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
evsel = __add_event(list, idx, &attr, pmu_event_name(head_config), evsel = __add_event(list, idx, &attr, pmu_event_name(head_config),
pmu->cpus); pmu->cpus);
if (evsel) { if (evsel) {
evsel->unit = unit; evsel->unit = info.unit;
evsel->scale = scale; evsel->scale = info.scale;
} }
return evsel ? 0 : -ENOMEM; return evsel ? 0 : -ENOMEM;
...@@ -985,7 +984,7 @@ int parse_filter(const struct option *opt, const char *str, ...@@ -985,7 +984,7 @@ int parse_filter(const struct option *opt, const char *str,
if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) { if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
fprintf(stderr, fprintf(stderr,
"-F option should follow a -e tracepoint option\n"); "--filter option should follow a -e tracepoint option\n");
return -1; return -1;
} }
......
...@@ -210,6 +210,19 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI ...@@ -210,6 +210,19 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
return 0; return 0;
} }
static inline bool pmu_alias_info_file(char *name)
{
size_t len;
len = strlen(name);
if (len > 5 && !strcmp(name + len - 5, ".unit"))
return true;
if (len > 6 && !strcmp(name + len - 6, ".scale"))
return true;
return false;
}
/* /*
* Process all the sysfs attributes located under the directory * Process all the sysfs attributes located under the directory
* specified in 'dir' parameter. * specified in 'dir' parameter.
...@@ -218,7 +231,6 @@ static int pmu_aliases_parse(char *dir, struct list_head *head) ...@@ -218,7 +231,6 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
{ {
struct dirent *evt_ent; struct dirent *evt_ent;
DIR *event_dir; DIR *event_dir;
size_t len;
int ret = 0; int ret = 0;
event_dir = opendir(dir); event_dir = opendir(dir);
...@@ -234,13 +246,9 @@ static int pmu_aliases_parse(char *dir, struct list_head *head) ...@@ -234,13 +246,9 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
continue; continue;
/* /*
* skip .unit and .scale info files * skip info files parsed in perf_pmu__new_alias()
* parsed in perf_pmu__new_alias()
*/ */
len = strlen(name); if (pmu_alias_info_file(name))
if (len > 5 && !strcmp(name + len - 5, ".unit"))
continue;
if (len > 6 && !strcmp(name + len - 6, ".scale"))
continue; continue;
snprintf(path, PATH_MAX, "%s/%s", dir, name); snprintf(path, PATH_MAX, "%s/%s", dir, name);
...@@ -645,7 +653,7 @@ static int check_unit_scale(struct perf_pmu_alias *alias, ...@@ -645,7 +653,7 @@ static int check_unit_scale(struct perf_pmu_alias *alias,
* defined for the alias * defined for the alias
*/ */
int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
const char **unit, double *scale) struct perf_pmu_info *info)
{ {
struct parse_events_term *term, *h; struct parse_events_term *term, *h;
struct perf_pmu_alias *alias; struct perf_pmu_alias *alias;
...@@ -655,8 +663,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, ...@@ -655,8 +663,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
* Mark unit and scale as not set * Mark unit and scale as not set
* (different from default values, see below) * (different from default values, see below)
*/ */
*unit = NULL; info->unit = NULL;
*scale = 0.0; info->scale = 0.0;
list_for_each_entry_safe(term, h, head_terms, list) { list_for_each_entry_safe(term, h, head_terms, list) {
alias = pmu_find_alias(pmu, term); alias = pmu_find_alias(pmu, term);
...@@ -666,7 +674,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, ...@@ -666,7 +674,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
if (ret) if (ret)
return ret; return ret;
ret = check_unit_scale(alias, unit, scale); ret = check_unit_scale(alias, &info->unit, &info->scale);
if (ret) if (ret)
return ret; return ret;
...@@ -679,11 +687,11 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, ...@@ -679,11 +687,11 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
* set defaults as for evsel * set defaults as for evsel
* unit cannot left to NULL * unit cannot left to NULL
*/ */
if (*unit == NULL) if (info->unit == NULL)
*unit = ""; info->unit = "";
if (*scale == 0.0) if (info->scale == 0.0)
*scale = 1.0; info->scale = 1.0;
return 0; return 0;
} }
......
...@@ -25,6 +25,11 @@ struct perf_pmu { ...@@ -25,6 +25,11 @@ struct perf_pmu {
struct list_head list; /* ELEM */ struct list_head list; /* ELEM */
}; };
struct perf_pmu_info {
const char *unit;
double scale;
};
struct perf_pmu *perf_pmu__find(const char *name); struct perf_pmu *perf_pmu__find(const char *name);
int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
struct list_head *head_terms); struct list_head *head_terms);
...@@ -33,7 +38,7 @@ int perf_pmu__config_terms(struct list_head *formats, ...@@ -33,7 +38,7 @@ int perf_pmu__config_terms(struct list_head *formats,
struct list_head *head_terms, struct list_head *head_terms,
bool zero); bool zero);
int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
const char **unit, double *scale); struct perf_pmu_info *info);
struct list_head *perf_pmu__alias(struct perf_pmu *pmu, struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
struct list_head *head_terms); struct list_head *head_terms);
int perf_pmu_wrap(void); int perf_pmu_wrap(void);
......
...@@ -184,7 +184,8 @@ static struct dso *kernel_get_module_dso(const char *module) ...@@ -184,7 +184,8 @@ static struct dso *kernel_get_module_dso(const char *module)
const char *vmlinux_name; const char *vmlinux_name;
if (module) { if (module) {
list_for_each_entry(dso, &host_machine->kernel_dsos, node) { list_for_each_entry(dso, &host_machine->kernel_dsos.head,
node) {
if (strncmp(dso->short_name + 1, module, if (strncmp(dso->short_name + 1, module,
dso->short_name_len - 2) == 0) dso->short_name_len - 2) == 0)
goto found; goto found;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "symbol.h" #include "symbol.h"
#include "machine.h"
#include "vdso.h" #include "vdso.h"
#include <symbol/kallsyms.h> #include <symbol/kallsyms.h>
#include "debug.h" #include "debug.h"
...@@ -929,7 +930,11 @@ int dso__load_sym(struct dso *dso, struct map *map, ...@@ -929,7 +930,11 @@ int dso__load_sym(struct dso *dso, struct map *map,
} }
curr_dso->symtab_type = dso->symtab_type; curr_dso->symtab_type = dso->symtab_type;
map_groups__insert(kmap->kmaps, curr_map); map_groups__insert(kmap->kmaps, curr_map);
dsos__add(&dso->node, curr_dso); /*
* The new DSO should go to the kernel DSOS
*/
dsos__add(&map->groups->machine->kernel_dsos,
curr_dso);
dso__set_loaded(curr_dso, map->type); dso__set_loaded(curr_dso, map->type);
} else } else
curr_dso = curr_map->dso; curr_dso = curr_map->dso;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册