Skip to content

Commit f4ece41

Browse files
Tao ChenKernel Patches Daemon
authored andcommitted
perf: Use extern perf_callchain_entry for get_perf_callchain
From bpf stack map, we want to use our own buffers to avoid unnecessary copy, so let us pass it directly. BPF will use this in the next patch. Signed-off-by: Tao Chen <[email protected]>
1 parent 2b803ce commit f4ece41

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

include/linux/perf_event.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,8 +1719,8 @@ DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
17191719
extern void perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs);
17201720
extern void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs);
17211721
extern struct perf_callchain_entry *
1722-
get_perf_callchain(struct pt_regs *regs, bool kernel, bool user,
1723-
u32 max_stack, bool crosstask, bool add_mark);
1722+
get_perf_callchain(struct pt_regs *regs, struct perf_callchain_entry *external_entry,
1723+
bool kernel, bool user, u32 max_stack, bool crosstask, bool add_mark);
17241724
extern int get_callchain_buffers(int max_stack);
17251725
extern void put_callchain_buffers(void);
17261726
extern struct perf_callchain_entry *get_callchain_entry(int *rctx);

kernel/bpf/stackmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map,
314314
if (max_depth > sysctl_perf_event_max_stack)
315315
max_depth = sysctl_perf_event_max_stack;
316316

317-
trace = get_perf_callchain(regs, kernel, user, max_depth,
317+
trace = get_perf_callchain(regs, NULL, kernel, user, max_depth,
318318
false, false);
319319

320320
if (unlikely(!trace))
@@ -451,7 +451,7 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
451451
else if (kernel && task)
452452
trace = get_callchain_entry_for_task(task, max_depth);
453453
else
454-
trace = get_perf_callchain(regs, kernel, user, max_depth,
454+
trace = get_perf_callchain(regs, NULL, kernel, user, max_depth,
455455
crosstask, false);
456456

457457
if (unlikely(!trace) || trace->nr < skip) {

kernel/events/callchain.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ static void fixup_uretprobe_trampoline_entries(struct perf_callchain_entry *entr
217217
}
218218

219219
struct perf_callchain_entry *
220-
get_perf_callchain(struct pt_regs *regs, bool kernel, bool user,
221-
u32 max_stack, bool crosstask, bool add_mark)
220+
get_perf_callchain(struct pt_regs *regs, struct perf_callchain_entry *external_entry,
221+
bool kernel, bool user, u32 max_stack, bool crosstask, bool add_mark)
222222
{
223223
struct perf_callchain_entry *entry;
224224
struct perf_callchain_entry_ctx ctx;
@@ -228,7 +228,11 @@ get_perf_callchain(struct pt_regs *regs, bool kernel, bool user,
228228
if (crosstask && user && !kernel)
229229
return NULL;
230230

231-
entry = get_callchain_entry(&rctx);
231+
if (external_entry)
232+
entry = external_entry;
233+
else
234+
entry = get_callchain_entry(&rctx);
235+
232236
if (!entry)
233237
return NULL;
234238

@@ -260,7 +264,8 @@ get_perf_callchain(struct pt_regs *regs, bool kernel, bool user,
260264
}
261265

262266
exit_put:
263-
put_callchain_entry(rctx);
267+
if (!external_entry)
268+
put_callchain_entry(rctx);
264269

265270
return entry;
266271
}

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8217,7 +8217,7 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs)
82178217
if (!kernel && !user)
82188218
return &__empty_callchain;
82198219

8220-
callchain = get_perf_callchain(regs, kernel, user,
8220+
callchain = get_perf_callchain(regs, NULL, kernel, user,
82218221
max_stack, crosstask, true);
82228222
return callchain ?: &__empty_callchain;
82238223
}

0 commit comments

Comments
 (0)