On Tue, Oct 12, 2021 at 7:54 AM Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote: > > On 10/12/21 5:47 AM, Andrii Nakryiko wrote: > > On Mon, Oct 11, 2021 at 3:57 PM Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote: > >> On 10/8/21 2:03 AM, andrii.nakryiko@xxxxxxxxx wrote: > >>> From: Andrii Nakryiko <andrii@xxxxxxxxxx> > >>> > >>> Enhance existing selftests to demonstrate the use of custom > >>> .data/.rodata sections. > >>> > >>> Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > >> > >> Just a thought, but wouldn't the actual demo / use case be better to show that we can > >> now have a __read_mostly attribute which implies SEC(".data.read_mostly") section? > >> > >> Would be nice to add a ... > >> > >> #define __read_mostly SEC(".data.read_mostly") > >> > >> ... into tools/lib/bpf/bpf_helpers.h along with the series for use out of BPF programs > >> as I think this should be a rather common use case. Thoughts? > > > > But what's so special about the ".data.read_mostly" ELF section for > > BPF programs? It's just another data section with no extra semantics. > > So unclear why we need to have a dedicated #define for that?.. > > I mean semantics are implicit that only vars would be located there which are > by far more read than written to. Placing into separate .data.read_mostly would > help to reduce cache misses due to false sharing e.g. if they are otherwise placed > near vars which are written more often (silly example would be some counter in > the prog). We've discussed this offline. We concluded that it's a bit premature to add #define __read_mostly into bpf_helpers.h, but I'll use __read_mostly as part of a selftests to demonstrate this concept. > > >>> --- > >>> .../selftests/bpf/prog_tests/skeleton.c | 25 +++++++++++++++++++ > >>> .../selftests/bpf/progs/test_skeleton.c | 10 ++++++++ > >>> 2 files changed, 35 insertions(+) > >> [...] > >>> diff --git a/tools/testing/selftests/bpf/progs/test_skeleton.c b/tools/testing/selftests/bpf/progs/test_skeleton.c > >>> index 441fa1c552c8..47a7e76866c4 100644 > >>> --- a/tools/testing/selftests/bpf/progs/test_skeleton.c > >>> +++ b/tools/testing/selftests/bpf/progs/test_skeleton.c > >>> @@ -40,9 +40,16 @@ int kern_ver = 0; > >>> > >>> struct s out5 = {}; > >>> > >>> +const volatile int in_dynarr_sz SEC(".rodata.dyn"); > >>> +const volatile int in_dynarr[4] SEC(".rodata.dyn") = { -1, -2, -3, -4 }; > >>> + > >>> +int out_dynarr[4] SEC(".data.dyn") = { 1, 2, 3, 4 }; > >>> + > >>> SEC("raw_tp/sys_enter") > >>> int handler(const void *ctx) > >>> { > >>> + int i; > >>> + > >>> out1 = in1; > >>> out2 = in2; > >>> out3 = in3; > >>> @@ -53,6 +60,9 @@ int handler(const void *ctx) > >>> bpf_syscall = CONFIG_BPF_SYSCALL; > >>> kern_ver = LINUX_KERNEL_VERSION; > >>> > >>> + for (i = 0; i < in_dynarr_sz; i++) > >>> + out_dynarr[i] = in_dynarr[i]; > >>> + > >>> return 0; > >>> } > >>> > >>> > >>