Skip to content

Commit 3087c61

Browse files
laoartorvalds
authored andcommitted
tools/testing/selftests/bpf: replace open-coded 16 with TASK_COMM_LEN
As the sched:sched_switch tracepoint args are derived from the kernel, we'd better make it same with the kernel. So the macro TASK_COMM_LEN is converted to type enum, then all the BPF programs can get it through BTF. The BPF program which wants to use TASK_COMM_LEN should include the header vmlinux.h. Regarding the test_stacktrace_map and test_tracepoint, as the type defined in linux/bpf.h are also defined in vmlinux.h, so we don't need to include linux/bpf.h again. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yafang Shao <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Michal Miroslaw <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Al Viro <[email protected]> Cc: Kees Cook <[email protected]> Cc: Petr Mladek <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Dennis Dalessandro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4cfb943 commit 3087c61

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

include/linux/sched.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,13 @@ struct task_group;
274274

275275
#define get_current_state() READ_ONCE(current->__state)
276276

277-
/* Task command name length: */
278-
#define TASK_COMM_LEN 16
277+
/*
278+
* Define the task command name length as enum, then it can be visible to
279+
* BPF programs.
280+
*/
281+
enum {
282+
TASK_COMM_LEN = 16,
283+
};
279284

280285
extern void scheduler_tick(void);
281286

tools/testing/selftests/bpf/progs/test_stacktrace_map.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2018 Facebook
33

4-
#include <linux/bpf.h>
4+
#include <vmlinux.h>
55
#include <bpf/bpf_helpers.h>
66

77
#ifndef PERF_MAX_STACK_DEPTH
@@ -41,11 +41,11 @@ struct {
4141
/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
4242
struct sched_switch_args {
4343
unsigned long long pad;
44-
char prev_comm[16];
44+
char prev_comm[TASK_COMM_LEN];
4545
int prev_pid;
4646
int prev_prio;
4747
long long prev_state;
48-
char next_comm[16];
48+
char next_comm[TASK_COMM_LEN];
4949
int next_pid;
5050
int next_prio;
5151
};

tools/testing/selftests/bpf/progs/test_tracepoint.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2017 Facebook
33

4-
#include <linux/bpf.h>
4+
#include <vmlinux.h>
55
#include <bpf/bpf_helpers.h>
66

77
/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
88
struct sched_switch_args {
99
unsigned long long pad;
10-
char prev_comm[16];
10+
char prev_comm[TASK_COMM_LEN];
1111
int prev_pid;
1212
int prev_prio;
1313
long long prev_state;
14-
char next_comm[16];
14+
char next_comm[TASK_COMM_LEN];
1515
int next_pid;
1616
int next_prio;
1717
};

0 commit comments

Comments
 (0)