Commit ceb13bfc authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf lock: Add --map-nr-entries option

The --map-nr-entries option is to control number of max entries in the
perf lock contention BPF maps.
Signed-off-by: default avatarNamhyung 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-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 447ec4e5
...@@ -145,6 +145,9 @@ CONTENTION OPTIONS ...@@ -145,6 +145,9 @@ CONTENTION OPTIONS
--tid=:: --tid=::
Record events on existing thread ID (comma separated list). Record events on existing thread ID (comma separated list).
--map-nr-entries::
Maximum number of BPF map entries (default: 10240).
SEE ALSO SEE ALSO
-------- --------
......
...@@ -56,6 +56,7 @@ static struct rb_root thread_stats; ...@@ -56,6 +56,7 @@ static struct rb_root thread_stats;
static bool combine_locks; static bool combine_locks;
static bool show_thread_stats; static bool show_thread_stats;
static bool use_bpf; static bool use_bpf;
static unsigned long bpf_map_entries = 10240;
static enum { static enum {
LOCK_AGGR_ADDR, LOCK_AGGR_ADDR,
...@@ -1598,6 +1599,7 @@ static int __cmd_contention(int argc, const char **argv) ...@@ -1598,6 +1599,7 @@ static int __cmd_contention(int argc, const char **argv)
struct lock_contention con = { struct lock_contention con = {
.target = &target, .target = &target,
.result = &lockhash_table[0], .result = &lockhash_table[0],
.map_nr_entries = bpf_map_entries,
}; };
session = perf_session__new(use_bpf ? NULL : &data, &eops); session = perf_session__new(use_bpf ? NULL : &data, &eops);
...@@ -1787,6 +1789,24 @@ static int __cmd_record(int argc, const char **argv) ...@@ -1787,6 +1789,24 @@ static int __cmd_record(int argc, const char **argv)
return ret; return ret;
} }
static int parse_map_entry(const struct option *opt, const char *str,
int unset __maybe_unused)
{
unsigned long *len = (unsigned long *)opt->value;
unsigned long val;
char *endptr;
errno = 0;
val = strtoul(str, &endptr, 0);
if (*endptr != '\0' || errno != 0) {
pr_err("invalid BPF map length: %s\n", str);
return -1;
}
*len = val;
return 0;
}
int cmd_lock(int argc, const char **argv) int cmd_lock(int argc, const char **argv)
{ {
const struct option lock_options[] = { const struct option lock_options[] = {
...@@ -1836,9 +1856,10 @@ int cmd_lock(int argc, const char **argv) ...@@ -1836,9 +1856,10 @@ int cmd_lock(int argc, const char **argv)
"List of cpus to monitor"), "List of cpus to monitor"),
OPT_STRING('p', "pid", &target.pid, "pid", OPT_STRING('p', "pid", &target.pid, "pid",
"Trace on existing process id"), "Trace on existing process id"),
/* TODO: Add short option -t after -t/--tracer can be removed. */
OPT_STRING(0, "tid", &target.tid, "tid", OPT_STRING(0, "tid", &target.tid, "tid",
"Trace on existing thread id (exclusive to --pid)"), "Trace on existing thread id (exclusive to --pid)"),
OPT_CALLBACK(0, "map-nr-entries", &bpf_map_entries, "num",
"Max number of BPF map entries", parse_map_entry),
OPT_PARENT(lock_options) OPT_PARENT(lock_options)
}; };
......
...@@ -40,6 +40,9 @@ int lock_contention_prepare(struct lock_contention *con) ...@@ -40,6 +40,9 @@ int lock_contention_prepare(struct lock_contention *con)
return -1; return -1;
} }
bpf_map__set_max_entries(skel->maps.stacks, con->map_nr_entries);
bpf_map__set_max_entries(skel->maps.lock_stat, con->map_nr_entries);
if (target__has_cpu(target)) if (target__has_cpu(target))
ncpus = perf_cpu_map__nr(evlist->core.user_requested_cpus); ncpus = perf_cpu_map__nr(evlist->core.user_requested_cpus);
if (target__has_task(target)) if (target__has_task(target))
......
...@@ -112,6 +112,7 @@ struct lock_contention { ...@@ -112,6 +112,7 @@ struct lock_contention {
struct target *target; struct target *target;
struct machine *machine; struct machine *machine;
struct hlist_head *result; struct hlist_head *result;
unsigned long map_nr_entries;
}; };
#ifdef HAVE_BPF_SKEL #ifdef HAVE_BPF_SKEL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment