Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global percpu data rfc v1 #8330

Draft
wants to merge 3 commits into
base: bpf-next_base
Choose a base branch
from

Conversation

Asphaltt
Copy link
Contributor

@Asphaltt Asphaltt commented Jan 7, 2025

No description provided.

Kernel Patches Daemon and others added 2 commits January 6, 2025 13:43
Similar to commit 6316f78 ("Merge branch 'support-global-data'"),
this patch introduces global percpu data in order to define global
percpu variable like "DEFINE_PER_CPU()"[0] macro.

Then, in bpf, it is able to define global percpu variable like

\#define PERCPU_BASE_SECTION SEC(".data..percpu")
\#define DEFINE_PERCPU_VAR(typ, name) \
	PERCPU_BASE_SECTION __typeof__(typ) name

DEFINE_PERCPU_VAR(int, percpu_data);

With this patch, retsnoop[1] and bpflbr[2] are able to simplify the bpf
code of lbrs from

static struct perf_branch_entry lbrs[1][MAX_LBR_ENTRIES] SEC(".data.lbrs");

to

static struct perf_branch_entry lbrs[MAX_LBR_ENTRIES] SEC(".data..percpu.lbrs");

and it's unnecessary to get cpu by "bpf_get_smp_processor_id()" helper.

Furthermore, by reusing the maps of global percpu data, data is simpler to
be shared between tail callers&callees and freplace callers&callees than
percpu_array maps.

Links:
[0] https://github.com/torvalds/linux/blob/fbfd64d25c7af3b8695201ebc85efe90be28c5a3/include/linux/percpu-defs.h#L114
[1] https://github.com/anakryiko/retsnoop
[2] https://github.com/Asphaltt/bpflbr

Signed-off-by: Leon Hwang <[email protected]>
@Asphaltt Asphaltt force-pushed the bpf/global-percpu-data-rfc-v1 branch from 9527fdc to c86c10b Compare January 7, 2025 15:22
If the arch does not support percpu insn, skip this case.

cd tools/testing/selftests/bpf; ./test_progs -t global_percpu_data
124     global_percpu_data_init:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Leon Hwang <[email protected]>
@Asphaltt Asphaltt force-pushed the bpf/global-percpu-data-rfc-v1 branch from c86c10b to 66796f8 Compare January 8, 2025 12:19
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 9 times, most recently from 483693f to d01d9d5 Compare January 11, 2025 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant