Re: the size of BPF_MAP_TYPE_PERCPU_ARRAY doesn't match the number of CPU


Forrest Chen
 

map defined:
struct bpf_map_def SEC("maps/protocount") proto_count = {
    .type = BPF_MAP_TYPE_PERCPU_ARRAY,
    .key_size = sizeof(__u32),
    .value_size = sizeof(__u32),
    .max_entries = 1,
};
userspace code:
int32_t * allocArray(size_t ln) { return (int32_t*) malloc(ln * sizeof(int32_t)); }
void sum(int32_t* arr, size_t ln, void* sum) {
    int32_t* s = (int32_t*)sum;
    int i=0;
    for(i=0;i<ln;i++){
        printf("cpu %d: %d\n", i, arr[i]);
        (*s)+=arr[i];
    }
    sum = (void*)s;
}

Hi Yonghong Song,
The code is as above.
When I use 32bit key, the count result is in CPU 0 and 2, when I use 64bit key, the result is in CPU 0 and 1 as expect.

Thanks 
forrest chen

Join iovisor-dev@lists.iovisor.org to automatically receive all group messages.