Skip to content

Conversation

@kernel-patches-daemon-bpf-rc
Copy link

Pull request for series with
subject: Introduce BPF_F_CPU flag for percpu maps
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=994142

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 78e097f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=994142
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 21aeabb
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=994142
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 0780f54
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=994142
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: d47cc4d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=994142
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 4223bf8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=994142
version: 3

It is to unify map flags checking for lookup, update, lookup_batch and
update_batch.

Therefore, it will be convenient to check BPF_F_CPU flag in this helper
function for them in next patch.

Signed-off-by: Leon Hwang <[email protected]>
Introduce support for the BPF_F_ALL_CPUS flag in percpu_array maps to
allow updating values for all CPUs with a single value.

Introduce support for the BPF_F_CPU flag in percpu_array maps to allow
updating value for specified CPU.

This enhancement enables:

* Efficient update values across all CPUs with a single value when
  BPF_F_ALL_CPUS is set for update_elem and update_batch APIs.
* Targeted update or lookup for a specified CPU when BPF_F_CPU is set.

The BPF_F_CPU flag is passed via:

* map_flags of lookup_elem and update_elem APIs along with embedded cpu
  field.
* elem_flags of lookup_batch and update_batch APIs along with embedded
  cpu field.

Signed-off-by: Leon Hwang <[email protected]>
Introduce BPF_F_ALL_CPUS flag support for percpu_hash and lru_percpu_hash
maps to allow updating values for all CPUs with a single value.

Introduce BPF_F_CPU flag support for percpu_hash and lru_percpu_hash
maps to allow updating value for specified CPU.

This enhancement enables:

* Efficient update values across all CPUs with a single value when
  BPF_F_ALL_CPUS is set for update_elem and update_batch APIs.
* Targeted update or lookup for a specified CPU when BPF_F_CPU is set.

The BPF_F_CPU flag is passed via:

* map_flags of lookup_elem and update_elem APIs along with embedded cpu
  field.
* elem_flags of lookup_batch and update_batch APIs along with embedded
  cpu field.

Signed-off-by: Leon Hwang <[email protected]>
Introduce BPF_F_ALL_CPUS flag support for percpu_cgroup_storage maps to
allow updating values for all CPUs with a single value.

Introduce BPF_F_CPU flag support for percpu_cgroup_storage maps to allow
updating value for specified CPU.

This enhancement enables:

* Efficient update values across all CPUs with a single value when
  BPF_F_ALL_CPUS is set for update_elem API.
* Targeted update or lookup for a specified CPU when BPF_F_CPU is set.

The BPF_F_CPU flag is passed via map_flags of lookup_elem and update_elem
APIs along with embedded cpu field.

Signed-off-by: Leon Hwang <[email protected]>
Add libbpf support for the BPF_F_CPU flag for percpu maps by embedding the
cpu info into the high 32 bits of:

1. **flags**: bpf_map_lookup_elem_flags(), bpf_map__lookup_elem(),
   bpf_map_update_elem() and bpf_map__update_elem()
2. **opts->elem_flags**: bpf_map_lookup_batch() and
   bpf_map_update_batch()

And the flag can be BPF_F_ALL_CPUS, but cannot be
'BPF_F_CPU | BPF_F_ALL_CPUS'.

Behavior:

* If the flag is BPF_F_ALL_CPUS, the update is applied across all CPUs.
* If the flag is BPF_F_CPU, it updates value only to the specified CPU.
* If the flag is BPF_F_CPU, lookup value only from the specified CPU.
* lookup does not support BPF_F_ALL_CPUS.

Signed-off-by: Leon Hwang <[email protected]>
Add test coverage for the new BPF_F_CPU flag support in percpu maps. The
following APIs are exercised:

* bpf_map_update_batch()
* bpf_map_lookup_batch()
* bpf_map_update_elem()
* bpf_map__update_elem()
* bpf_map_lookup_elem_flags()
* bpf_map__lookup_elem()

cd tools/testing/selftests/bpf/
./test_progs -t percpu_alloc
253/13  percpu_alloc/cpu_flag_percpu_array:OK
253/14  percpu_alloc/cpu_flag_percpu_hash:OK
253/15  percpu_alloc/cpu_flag_lru_percpu_hash:OK
253/16  percpu_alloc/cpu_flag_percpu_cgroup_storage:OK
253     percpu_alloc:OK
Summary: 1/16 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Leon Hwang <[email protected]>
@kernel-patches-daemon-bpf-rc
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=994142 expired. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants