Skip to content

Commit ceb13bf

Browse files
namhyungacmel
authored andcommitted
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: Namhyung Kim <[email protected]> Cc: Blake Jones <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Waiman Long <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 447ec4e commit ceb13bf

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

tools/perf/Documentation/perf-lock.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ CONTENTION OPTIONS
145145
--tid=::
146146
Record events on existing thread ID (comma separated list).
147147

148+
--map-nr-entries::
149+
Maximum number of BPF map entries (default: 10240).
150+
148151

149152
SEE ALSO
150153
--------

tools/perf/builtin-lock.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static struct rb_root thread_stats;
5656
static bool combine_locks;
5757
static bool show_thread_stats;
5858
static bool use_bpf;
59+
static unsigned long bpf_map_entries = 10240;
5960

6061
static enum {
6162
LOCK_AGGR_ADDR,
@@ -1598,6 +1599,7 @@ static int __cmd_contention(int argc, const char **argv)
15981599
struct lock_contention con = {
15991600
.target = &target,
16001601
.result = &lockhash_table[0],
1602+
.map_nr_entries = bpf_map_entries,
16011603
};
16021604

16031605
session = perf_session__new(use_bpf ? NULL : &data, &eops);
@@ -1787,6 +1789,24 @@ static int __cmd_record(int argc, const char **argv)
17871789
return ret;
17881790
}
17891791

1792+
static int parse_map_entry(const struct option *opt, const char *str,
1793+
int unset __maybe_unused)
1794+
{
1795+
unsigned long *len = (unsigned long *)opt->value;
1796+
unsigned long val;
1797+
char *endptr;
1798+
1799+
errno = 0;
1800+
val = strtoul(str, &endptr, 0);
1801+
if (*endptr != '\0' || errno != 0) {
1802+
pr_err("invalid BPF map length: %s\n", str);
1803+
return -1;
1804+
}
1805+
1806+
*len = val;
1807+
return 0;
1808+
}
1809+
17901810
int cmd_lock(int argc, const char **argv)
17911811
{
17921812
const struct option lock_options[] = {
@@ -1836,9 +1856,10 @@ int cmd_lock(int argc, const char **argv)
18361856
"List of cpus to monitor"),
18371857
OPT_STRING('p', "pid", &target.pid, "pid",
18381858
"Trace on existing process id"),
1839-
/* TODO: Add short option -t after -t/--tracer can be removed. */
18401859
OPT_STRING(0, "tid", &target.tid, "tid",
18411860
"Trace on existing thread id (exclusive to --pid)"),
1861+
OPT_CALLBACK(0, "map-nr-entries", &bpf_map_entries, "num",
1862+
"Max number of BPF map entries", parse_map_entry),
18421863
OPT_PARENT(lock_options)
18431864
};
18441865

tools/perf/util/bpf_lock_contention.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ int lock_contention_prepare(struct lock_contention *con)
4040
return -1;
4141
}
4242

43+
bpf_map__set_max_entries(skel->maps.stacks, con->map_nr_entries);
44+
bpf_map__set_max_entries(skel->maps.lock_stat, con->map_nr_entries);
45+
4346
if (target__has_cpu(target))
4447
ncpus = perf_cpu_map__nr(evlist->core.user_requested_cpus);
4548
if (target__has_task(target))

tools/perf/util/lock-contention.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct lock_contention {
112112
struct target *target;
113113
struct machine *machine;
114114
struct hlist_head *result;
115+
unsigned long map_nr_entries;
115116
};
116117

117118
#ifdef HAVE_BPF_SKEL

0 commit comments

Comments
 (0)