Skip to content

Commit 447ec4e

Browse files
namhyungacmel
authored andcommitted
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 <[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 4ee3c4d commit 447ec4e

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

tools/perf/builtin-lock.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,10 @@ static int __cmd_contention(int argc, const char **argv)
15951595
.mode = PERF_DATA_MODE_READ,
15961596
.force = force,
15971597
};
1598-
struct evlist *evlist = NULL;
1598+
struct lock_contention con = {
1599+
.target = &target,
1600+
.result = &lockhash_table[0],
1601+
};
15991602

16001603
session = perf_session__new(use_bpf ? NULL : &data, &eops);
16011604
if (IS_ERR(session)) {
@@ -1621,24 +1624,26 @@ static int __cmd_contention(int argc, const char **argv)
16211624
signal(SIGCHLD, sighandler);
16221625
signal(SIGTERM, sighandler);
16231626

1624-
evlist = evlist__new();
1625-
if (evlist == NULL) {
1627+
con.machine = &session->machines.host;
1628+
1629+
con.evlist = evlist__new();
1630+
if (con.evlist == NULL) {
16261631
err = -ENOMEM;
16271632
goto out_delete;
16281633
}
16291634

1630-
err = evlist__create_maps(evlist, &target);
1635+
err = evlist__create_maps(con.evlist, &target);
16311636
if (err < 0)
16321637
goto out_delete;
16331638

16341639
if (argc) {
1635-
err = evlist__prepare_workload(evlist, &target,
1640+
err = evlist__prepare_workload(con.evlist, &target,
16361641
argv, false, NULL);
16371642
if (err < 0)
16381643
goto out_delete;
16391644
}
16401645

1641-
if (lock_contention_prepare(evlist, &target) < 0) {
1646+
if (lock_contention_prepare(&con) < 0) {
16421647
pr_err("lock contention BPF setup failed\n");
16431648
goto out_delete;
16441649
}
@@ -1673,13 +1678,13 @@ static int __cmd_contention(int argc, const char **argv)
16731678
if (use_bpf) {
16741679
lock_contention_start();
16751680
if (argc)
1676-
evlist__start_workload(evlist);
1681+
evlist__start_workload(con.evlist);
16771682

16781683
/* wait for signal */
16791684
pause();
16801685

16811686
lock_contention_stop();
1682-
lock_contention_read(&session->machines.host, &lockhash_table[0]);
1687+
lock_contention_read(&con);
16831688
} else {
16841689
err = perf_session__process_events(session);
16851690
if (err)
@@ -1692,7 +1697,7 @@ static int __cmd_contention(int argc, const char **argv)
16921697
print_contention_result();
16931698

16941699
out_delete:
1695-
evlist__delete(evlist);
1700+
evlist__delete(con.evlist);
16961701
lock_contention_finish();
16971702
perf_session__delete(session);
16981703
return err;

tools/perf/util/bpf_lock_contention.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ struct lock_contention_data {
2727
u32 flags;
2828
};
2929

30-
int lock_contention_prepare(struct evlist *evlist, struct target *target)
30+
int lock_contention_prepare(struct lock_contention *con)
3131
{
3232
int i, fd;
3333
int ncpus = 1, ntasks = 1;
34+
struct evlist *evlist = con->evlist;
35+
struct target *target = con->target;
3436

3537
skel = lock_contention_bpf__open();
3638
if (!skel) {
@@ -102,12 +104,13 @@ int lock_contention_stop(void)
102104
return 0;
103105
}
104106

105-
int lock_contention_read(struct machine *machine, struct hlist_head *head)
107+
int lock_contention_read(struct lock_contention *con)
106108
{
107109
int fd, stack;
108110
u32 prev_key, key;
109111
struct lock_contention_data data;
110112
struct lock_stat *st;
113+
struct machine *machine = con->machine;
111114
u64 stack_trace[CONTENTION_STACK_DEPTH];
112115

113116
fd = bpf_map__fd(skel->maps.lock_stat);
@@ -163,7 +166,7 @@ int lock_contention_read(struct machine *machine, struct hlist_head *head)
163166
return -1;
164167
}
165168

166-
hlist_add_head(&st->hash_entry, head);
169+
hlist_add_head(&st->hash_entry, con->result);
167170
prev_key = key;
168171
}
169172

tools/perf/util/lock-contention.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,24 @@ struct evlist;
107107
struct machine;
108108
struct target;
109109

110+
struct lock_contention {
111+
struct evlist *evlist;
112+
struct target *target;
113+
struct machine *machine;
114+
struct hlist_head *result;
115+
};
116+
110117
#ifdef HAVE_BPF_SKEL
111118

112-
int lock_contention_prepare(struct evlist *evlist, struct target *target);
119+
int lock_contention_prepare(struct lock_contention *con);
113120
int lock_contention_start(void);
114121
int lock_contention_stop(void);
115-
int lock_contention_read(struct machine *machine, struct hlist_head *head);
122+
int lock_contention_read(struct lock_contention *con);
116123
int lock_contention_finish(void);
117124

118125
#else /* !HAVE_BPF_SKEL */
119126

120-
static inline int lock_contention_prepare(struct evlist *evlist __maybe_unused,
121-
struct target *target __maybe_unused)
127+
static inline int lock_contention_prepare(struct lock_contention *con __maybe_unused)
122128
{
123129
return 0;
124130
}
@@ -127,8 +133,7 @@ static inline int lock_contention_start(void) { return 0; }
127133
static inline int lock_contention_stop(void) { return 0; }
128134
static inline int lock_contention_finish(void) { return 0; }
129135

130-
static inline int lock_contention_read(struct machine *machine __maybe_unused,
131-
struct hlist_head *head __maybe_unused)
136+
static inline int lock_contention_read(struct lock_contention *con __maybe_unused)
132137
{
133138
return 0;
134139
}

0 commit comments

Comments
 (0)