Re: [PATCH bpf-next 08/10] selftests/bpf: demonstrate use of custom .rodata/.data sections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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).

---
   .../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;
   }






[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux