Re: [PATCH bpf 1/4] libbpf: Adjust ring buffer size when probing ring buffer map

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

 



On 11/11, Hou Tao wrote:
From: Hou Tao <houtao1@xxxxxxxxxx>

Adjusting the size of ring buffer when probing ring buffer map, else
the probe may fail on host with 64KB page size (e.g., an ARM64 host).

After the fix, the output of "bpftool feature" on above host will be
correct.

Before :
     eBPF map_type ringbuf is NOT available
     eBPF map_type user_ringbuf is NOT available

After :
     eBPF map_type ringbuf is available
     eBPF map_type user_ringbuf is available

Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx>
---
  tools/lib/bpf/libbpf.c          | 2 +-
  tools/lib/bpf/libbpf_internal.h | 2 ++
  tools/lib/bpf/libbpf_probes.c   | 2 +-
  3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 184ce1684dcd..907f735568ae 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2353,7 +2353,7 @@ int parse_btf_map_def(const char *map_name, struct btf *btf,
  	return 0;
  }

-static size_t adjust_ringbuf_sz(size_t sz)
+size_t adjust_ringbuf_sz(size_t sz)
  {
  	__u32 page_sz = sysconf(_SC_PAGE_SIZE);
  	__u32 mul;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 377642ff51fc..99dc4d6a19be 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -576,4 +576,6 @@ static inline bool is_pow_of_2(size_t x)
  #define PROG_LOAD_ATTEMPTS 5
int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size, int attempts);

+size_t adjust_ringbuf_sz(size_t sz);
+
  #endif /* __LIBBPF_LIBBPF_INTERNAL_H */
diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c
index f3a8e8e74eb8..29a1db2645fd 100644
--- a/tools/lib/bpf/libbpf_probes.c
+++ b/tools/lib/bpf/libbpf_probes.c
@@ -234,7 +234,7 @@ static int probe_map_create(enum bpf_map_type map_type)
  	case BPF_MAP_TYPE_USER_RINGBUF:
  		key_size = 0;
  		value_size = 0;
-		max_entries = 4096;
+		max_entries = adjust_ringbuf_sz(4096);

Why not pass PAGE_SIZE directly here? Something like:

max_entries = sysconf(_SC_PAGE_SIZE);

?

  		break;
  	case BPF_MAP_TYPE_STRUCT_OPS:
  		/* we'll get -ENOTSUPP for invalid BTF type ID for struct_ops */
--
2.29.2




[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