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

BPF_MAP_TYPE_PERCPU_ARRAY synchronization #3696

Closed
yugeshk opened this issue Nov 11, 2021 · 1 comment
Closed

BPF_MAP_TYPE_PERCPU_ARRAY synchronization #3696

yugeshk opened this issue Nov 11, 2021 · 1 comment

Comments

@yugeshk
Copy link

yugeshk commented Nov 11, 2021

I have the following confusion regarding percpu_array - the bcc documentation here mentions that updates are not synchronized across the copies of CPUs. However, skimming through the kernel code I see that in the update_elem for percpu_array there is a loop over all possible CPUs to update the value - here.

Am I missing something or does the documentation need to be updated?

Thanks!

@davemarchevsky
Copy link
Collaborator

Your second link is pointing to a loop in bpf_percpu_array_copy, but there's a similar loop in bpf_percpu_array_update which seems more relevant to the question you're asking. Guessing you meant to ask about the latter function.

Anyways, the API for updating percpu array from userspace differs a bit from the API BPF programs use, but still preserves the "updates are not synchronized" expectation.

	for_each_possible_cpu(cpu) {
		bpf_long_memcpy(per_cpu_ptr(pptr, cpu), value + off, size);
		off += size;
	}

The passed in value buffer contains a separate value for each cpu, see tools/testing/selftests/bpf/test_maps.c in kernel source for an example use. The helper called from BPF, array_map_update_elem, updates a single cpu's value.

The semantics probably differ to keep the BPF_MAP_UPDATE_ELEM interface simple, since most bpf map types aren't percpu. Most BPF programs use percpu arrays to gather data from the program itself, or as a temporary 'heap' buffer space, and rarely need userspace to populate the percpu array except perhaps with some initial values. If you have a different usecase, though, we'd love to hear about it!

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

No branches or pull requests

2 participants