perf lock: Introduce struct lock_contention
The lock_contention struct is to carry related fields together and to minimize the change when we add new config options. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Blake Jones <blakejones@google.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20220802191004.347740-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Родитель
4ee3c4da8b
Коммит
447ec4e5fa
|
@ -1595,7 +1595,10 @@ static int __cmd_contention(int argc, const char **argv)
|
|||
.mode = PERF_DATA_MODE_READ,
|
||||
.force = force,
|
||||
};
|
||||
struct evlist *evlist = NULL;
|
||||
struct lock_contention con = {
|
||||
.target = &target,
|
||||
.result = &lockhash_table[0],
|
||||
};
|
||||
|
||||
session = perf_session__new(use_bpf ? NULL : &data, &eops);
|
||||
if (IS_ERR(session)) {
|
||||
|
@ -1621,24 +1624,26 @@ static int __cmd_contention(int argc, const char **argv)
|
|||
signal(SIGCHLD, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
evlist = evlist__new();
|
||||
if (evlist == NULL) {
|
||||
con.machine = &session->machines.host;
|
||||
|
||||
con.evlist = evlist__new();
|
||||
if (con.evlist == NULL) {
|
||||
err = -ENOMEM;
|
||||
goto out_delete;
|
||||
}
|
||||
|
||||
err = evlist__create_maps(evlist, &target);
|
||||
err = evlist__create_maps(con.evlist, &target);
|
||||
if (err < 0)
|
||||
goto out_delete;
|
||||
|
||||
if (argc) {
|
||||
err = evlist__prepare_workload(evlist, &target,
|
||||
err = evlist__prepare_workload(con.evlist, &target,
|
||||
argv, false, NULL);
|
||||
if (err < 0)
|
||||
goto out_delete;
|
||||
}
|
||||
|
||||
if (lock_contention_prepare(evlist, &target) < 0) {
|
||||
if (lock_contention_prepare(&con) < 0) {
|
||||
pr_err("lock contention BPF setup failed\n");
|
||||
goto out_delete;
|
||||
}
|
||||
|
@ -1673,13 +1678,13 @@ static int __cmd_contention(int argc, const char **argv)
|
|||
if (use_bpf) {
|
||||
lock_contention_start();
|
||||
if (argc)
|
||||
evlist__start_workload(evlist);
|
||||
evlist__start_workload(con.evlist);
|
||||
|
||||
/* wait for signal */
|
||||
pause();
|
||||
|
||||
lock_contention_stop();
|
||||
lock_contention_read(&session->machines.host, &lockhash_table[0]);
|
||||
lock_contention_read(&con);
|
||||
} else {
|
||||
err = perf_session__process_events(session);
|
||||
if (err)
|
||||
|
@ -1692,7 +1697,7 @@ static int __cmd_contention(int argc, const char **argv)
|
|||
print_contention_result();
|
||||
|
||||
out_delete:
|
||||
evlist__delete(evlist);
|
||||
evlist__delete(con.evlist);
|
||||
lock_contention_finish();
|
||||
perf_session__delete(session);
|
||||
return err;
|
||||
|
|
|
@ -27,10 +27,12 @@ struct lock_contention_data {
|
|||
u32 flags;
|
||||
};
|
||||
|
||||
int lock_contention_prepare(struct evlist *evlist, struct target *target)
|
||||
int lock_contention_prepare(struct lock_contention *con)
|
||||
{
|
||||
int i, fd;
|
||||
int ncpus = 1, ntasks = 1;
|
||||
struct evlist *evlist = con->evlist;
|
||||
struct target *target = con->target;
|
||||
|
||||
skel = lock_contention_bpf__open();
|
||||
if (!skel) {
|
||||
|
@ -102,12 +104,13 @@ int lock_contention_stop(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int lock_contention_read(struct machine *machine, struct hlist_head *head)
|
||||
int lock_contention_read(struct lock_contention *con)
|
||||
{
|
||||
int fd, stack;
|
||||
u32 prev_key, key;
|
||||
struct lock_contention_data data;
|
||||
struct lock_stat *st;
|
||||
struct machine *machine = con->machine;
|
||||
u64 stack_trace[CONTENTION_STACK_DEPTH];
|
||||
|
||||
fd = bpf_map__fd(skel->maps.lock_stat);
|
||||
|
@ -163,7 +166,7 @@ int lock_contention_read(struct machine *machine, struct hlist_head *head)
|
|||
return -1;
|
||||
}
|
||||
|
||||
hlist_add_head(&st->hash_entry, head);
|
||||
hlist_add_head(&st->hash_entry, con->result);
|
||||
prev_key = key;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,18 +107,24 @@ struct evlist;
|
|||
struct machine;
|
||||
struct target;
|
||||
|
||||
struct lock_contention {
|
||||
struct evlist *evlist;
|
||||
struct target *target;
|
||||
struct machine *machine;
|
||||
struct hlist_head *result;
|
||||
};
|
||||
|
||||
#ifdef HAVE_BPF_SKEL
|
||||
|
||||
int lock_contention_prepare(struct evlist *evlist, struct target *target);
|
||||
int lock_contention_prepare(struct lock_contention *con);
|
||||
int lock_contention_start(void);
|
||||
int lock_contention_stop(void);
|
||||
int lock_contention_read(struct machine *machine, struct hlist_head *head);
|
||||
int lock_contention_read(struct lock_contention *con);
|
||||
int lock_contention_finish(void);
|
||||
|
||||
#else /* !HAVE_BPF_SKEL */
|
||||
|
||||
static inline int lock_contention_prepare(struct evlist *evlist __maybe_unused,
|
||||
struct target *target __maybe_unused)
|
||||
static inline int lock_contention_prepare(struct lock_contention *con __maybe_unused)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -127,8 +133,7 @@ static inline int lock_contention_start(void) { return 0; }
|
|||
static inline int lock_contention_stop(void) { return 0; }
|
||||
static inline int lock_contention_finish(void) { return 0; }
|
||||
|
||||
static inline int lock_contention_read(struct machine *machine __maybe_unused,
|
||||
struct hlist_head *head __maybe_unused)
|
||||
static inline int lock_contention_read(struct lock_contention *con __maybe_unused)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче