Skip to content

Commit e161c6b

Browse files
Jiri Olsarostedt
authored andcommitted
tracing: Iterate trace_[ku]probe objects directly
As suggested by Linus [1] using list_for_each_entry to iterate directly trace_[ku]probe objects so we can skip another call to container_of in these loops. [1] https://lore.kernel.org/r/CAHk-=wjakjw6-rDzDDBsuMoDCqd+9ogifR_EE1F0K-jYek1CdA@mail.gmail.com Link: https://lkml.kernel.org/r/[email protected] Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent ee34c52 commit e161c6b

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,9 @@ static inline int __enable_trace_kprobe(struct trace_kprobe *tk)
327327

328328
static void __disable_trace_kprobe(struct trace_probe *tp)
329329
{
330-
struct trace_probe *pos;
331330
struct trace_kprobe *tk;
332331

333-
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
334-
tk = container_of(pos, struct trace_kprobe, tp);
332+
list_for_each_entry(tk, trace_probe_probe_list(tp), tp.list) {
335333
if (!trace_kprobe_is_registered(tk))
336334
continue;
337335
if (trace_kprobe_is_return(tk))
@@ -348,7 +346,7 @@ static void __disable_trace_kprobe(struct trace_probe *tp)
348346
static int enable_trace_kprobe(struct trace_event_call *call,
349347
struct trace_event_file *file)
350348
{
351-
struct trace_probe *pos, *tp;
349+
struct trace_probe *tp;
352350
struct trace_kprobe *tk;
353351
bool enabled;
354352
int ret = 0;
@@ -369,8 +367,7 @@ static int enable_trace_kprobe(struct trace_event_call *call,
369367
if (enabled)
370368
return 0;
371369

372-
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
373-
tk = container_of(pos, struct trace_kprobe, tp);
370+
list_for_each_entry(tk, trace_probe_probe_list(tp), tp.list) {
374371
if (trace_kprobe_has_gone(tk))
375372
continue;
376373
ret = __enable_trace_kprobe(tk);
@@ -559,11 +556,9 @@ static bool trace_kprobe_has_same_kprobe(struct trace_kprobe *orig,
559556
struct trace_kprobe *comp)
560557
{
561558
struct trace_probe_event *tpe = orig->tp.event;
562-
struct trace_probe *pos;
563559
int i;
564560

565-
list_for_each_entry(pos, &tpe->probes, list) {
566-
orig = container_of(pos, struct trace_kprobe, tp);
561+
list_for_each_entry(orig, &tpe->probes, tp.list) {
567562
if (strcmp(trace_kprobe_symbol(orig),
568563
trace_kprobe_symbol(comp)) ||
569564
trace_kprobe_offset(orig) != trace_kprobe_offset(comp))

kernel/trace/trace_uprobe.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,10 @@ static bool trace_uprobe_has_same_uprobe(struct trace_uprobe *orig,
409409
struct trace_uprobe *comp)
410410
{
411411
struct trace_probe_event *tpe = orig->tp.event;
412-
struct trace_probe *pos;
413412
struct inode *comp_inode = d_real_inode(comp->path.dentry);
414413
int i;
415414

416-
list_for_each_entry(pos, &tpe->probes, list) {
417-
orig = container_of(pos, struct trace_uprobe, tp);
415+
list_for_each_entry(orig, &tpe->probes, tp.list) {
418416
if (comp_inode != d_real_inode(orig->path.dentry) ||
419417
comp->offset != orig->offset)
420418
continue;
@@ -1072,14 +1070,12 @@ static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter)
10721070

10731071
static void __probe_event_disable(struct trace_probe *tp)
10741072
{
1075-
struct trace_probe *pos;
10761073
struct trace_uprobe *tu;
10771074

10781075
tu = container_of(tp, struct trace_uprobe, tp);
10791076
WARN_ON(!uprobe_filter_is_empty(tu->tp.event->filter));
10801077

1081-
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
1082-
tu = container_of(pos, struct trace_uprobe, tp);
1078+
list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
10831079
if (!tu->inode)
10841080
continue;
10851081

@@ -1091,7 +1087,7 @@ static void __probe_event_disable(struct trace_probe *tp)
10911087
static int probe_event_enable(struct trace_event_call *call,
10921088
struct trace_event_file *file, filter_func_t filter)
10931089
{
1094-
struct trace_probe *pos, *tp;
1090+
struct trace_probe *tp;
10951091
struct trace_uprobe *tu;
10961092
bool enabled;
10971093
int ret;
@@ -1126,8 +1122,7 @@ static int probe_event_enable(struct trace_event_call *call,
11261122
if (ret)
11271123
goto err_flags;
11281124

1129-
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
1130-
tu = container_of(pos, struct trace_uprobe, tp);
1125+
list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
11311126
ret = trace_uprobe_enable(tu, filter);
11321127
if (ret) {
11331128
__probe_event_disable(tp);
@@ -1272,7 +1267,7 @@ static bool trace_uprobe_filter_add(struct trace_uprobe_filter *filter,
12721267
static int uprobe_perf_close(struct trace_event_call *call,
12731268
struct perf_event *event)
12741269
{
1275-
struct trace_probe *pos, *tp;
1270+
struct trace_probe *tp;
12761271
struct trace_uprobe *tu;
12771272
int ret = 0;
12781273

@@ -1284,8 +1279,7 @@ static int uprobe_perf_close(struct trace_event_call *call,
12841279
if (trace_uprobe_filter_remove(tu->tp.event->filter, event))
12851280
return 0;
12861281

1287-
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
1288-
tu = container_of(pos, struct trace_uprobe, tp);
1282+
list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
12891283
ret = uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
12901284
if (ret)
12911285
break;
@@ -1297,7 +1291,7 @@ static int uprobe_perf_close(struct trace_event_call *call,
12971291
static int uprobe_perf_open(struct trace_event_call *call,
12981292
struct perf_event *event)
12991293
{
1300-
struct trace_probe *pos, *tp;
1294+
struct trace_probe *tp;
13011295
struct trace_uprobe *tu;
13021296
int err = 0;
13031297

@@ -1309,8 +1303,7 @@ static int uprobe_perf_open(struct trace_event_call *call,
13091303
if (trace_uprobe_filter_add(tu->tp.event->filter, event))
13101304
return 0;
13111305

1312-
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
1313-
tu = container_of(pos, struct trace_uprobe, tp);
1306+
list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
13141307
err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
13151308
if (err) {
13161309
uprobe_perf_close(call, event);

0 commit comments

Comments
 (0)