€•uŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ!/translations/zh_CN/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/zh_TW/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/it_IT/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/ja_JP/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/ko_KR/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/pt_BR/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/sp_SP/bpf/map_array”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ%SPDX-License-Identifier: GPL-2.0-only”h]”hŒ%SPDX-License-Identifier: GPL-2.0-only”…””}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³Œ;/var/lib/git/docbuild/linux/Documentation/bpf/map_array.rst”h´Kubh¶)”}”(hŒ Copyright (C) 2022 Red Hat, Inc.”h]”hŒ Copyright (C) 2022 Red Hat, Inc.”…””}”hhÈsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1hµhhh²hh³hÇh´KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒ0BPF_MAP_TYPE_ARRAY and BPF_MAP_TYPE_PERCPU_ARRAY”h]”hŒ0BPF_MAP_TYPE_ARRAY and BPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hhÝh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhhØh²hh³hÇh´KubhŒnote”“”)”}”(hŒ|- ``BPF_MAP_TYPE_ARRAY`` was introduced in kernel version 3.19 - ``BPF_MAP_TYPE_PERCPU_ARRAY`` was introduced in version 4.6”h]”hŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒ<``BPF_MAP_TYPE_ARRAY`` was introduced in kernel version 3.19”h]”hŒ paragraph”“”)”}”(hhúh]”(hŒliteral”“”)”}”(hŒ``BPF_MAP_TYPE_ARRAY``”h]”hŒBPF_MAP_TYPE_ARRAY”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhhþubhŒ& was introduced in kernel version 3.19”…””}”(hhþh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K hhøubah}”(h]”h ]”h"]”h$]”h&]”uh1höhhóubh÷)”}”(hŒ;``BPF_MAP_TYPE_PERCPU_ARRAY`` was introduced in version 4.6”h]”hý)”}”(hj#h]”(j)”}”(hŒ``BPF_MAP_TYPE_PERCPU_ARRAY``”h]”hŒBPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj%ubhŒ was introduced in version 4.6”…””}”(hj%h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K hj!ubah}”(h]”h ]”h"]”h$]”h&]”uh1höhhóubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1hñh³hÇh´K hhíubah}”(h]”h ]”h"]”h$]”h&]”uh1hëhhØh²hh³Nh´Nubhý)”}”(hX``BPF_MAP_TYPE_ARRAY`` and ``BPF_MAP_TYPE_PERCPU_ARRAY`` provide generic array storage. The key type is an unsigned 32-bit integer (4 bytes) and the map is of constant size. The size of the array is defined in ``max_entries`` at creation time. All array elements are pre-allocated and zero initialized when created. ``BPF_MAP_TYPE_PERCPU_ARRAY`` uses a different memory region for each CPU whereas ``BPF_MAP_TYPE_ARRAY`` uses the same memory region. The value stored can be of any size for ``BPF_MAP_TYPE_ARRAY`` and not more than ``PCPU_MIN_UNIT_SIZE`` (32 kB) for ``BPF_MAP_TYPE_PERCPU_ARRAY``. All array elements are aligned to 8 bytes.”h]”(j)”}”(hŒ``BPF_MAP_TYPE_ARRAY``”h]”hŒBPF_MAP_TYPE_ARRAY”…””}”(hjXh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒ and ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_PERCPU_ARRAY``”h]”hŒBPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hjjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒš provide generic array storage. The key type is an unsigned 32-bit integer (4 bytes) and the map is of constant size. The size of the array is defined in ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``max_entries``”h]”hŒ max_entries”…””}”(hj|h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒ[ at creation time. All array elements are pre-allocated and zero initialized when created. ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_PERCPU_ARRAY``”h]”hŒBPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hjŽh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒ5 uses a different memory region for each CPU whereas ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_ARRAY``”h]”hŒBPF_MAP_TYPE_ARRAY”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒF uses the same memory region. The value stored can be of any size for ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_ARRAY``”h]”hŒBPF_MAP_TYPE_ARRAY”…””}”(hj²h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒ and not more than ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``PCPU_MIN_UNIT_SIZE``”h]”hŒPCPU_MIN_UNIT_SIZE”…””}”(hjÄh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒ (32 kB) for ”…””}”(hjTh²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_PERCPU_ARRAY``”h]”hŒBPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hjÖh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjTubhŒ,. All array elements are aligned to 8 bytes.”…””}”(hjTh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K hhØh²hubhý)”}”(hXSince kernel 5.5, memory mapping may be enabled for ``BPF_MAP_TYPE_ARRAY`` by setting the flag ``BPF_F_MMAPABLE``. The map definition is page-aligned and starts on the first page. Sufficient page-sized and page-aligned blocks of memory are allocated to store all array values, starting on the second page, which in some cases will result in over-allocation of memory. The benefit of using this is increased performance and ease of use since userspace programs would not be required to use helper functions to access and mutate data.”h]”(hŒ4Since kernel 5.5, memory mapping may be enabled for ”…””}”(hjîh²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_ARRAY``”h]”hŒBPF_MAP_TYPE_ARRAY”…””}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjîubhŒ by setting the flag ”…””}”(hjîh²hh³Nh´Nubj)”}”(hŒ``BPF_F_MMAPABLE``”h]”hŒBPF_F_MMAPABLE”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjîubhX£. The map definition is page-aligned and starts on the first page. Sufficient page-sized and page-aligned blocks of memory are allocated to store all array values, starting on the second page, which in some cases will result in over-allocation of memory. The benefit of using this is increased performance and ease of use since userspace programs would not be required to use helper functions to access and mutate data.”…””}”(hjîh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KhhØh²hubh×)”}”(hhh]”(hÜ)”}”(hŒUsage”h]”hŒUsage”…””}”(hj#h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj h²hh³hÇh´Kubh×)”}”(hhh]”(hÜ)”}”(hŒ Kernel BPF”h]”hŒ Kernel BPF”…””}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj1h²hh³hÇh´K"ubh×)”}”(hhh]”(hÜ)”}”(hŒbpf_map_lookup_elem()”h]”hŒbpf_map_lookup_elem()”…””}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjBh²hh³hÇh´K%ubhŒ literal_block”“”)”}”(hŒ?void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)”h]”hŒ?void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)”…””}”hjUsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆŒforce”‰Œlanguage”Œc”Œhighlight_args”}”uh1jSh³hÇh´K'hjBh²hubhý)”}”(hXArray elements can be retrieved using the ``bpf_map_lookup_elem()`` helper. This helper returns a pointer into the array element, so to avoid data races with userspace reading the value, the user must use primitives like ``__sync_fetch_and_add()`` when updating the value in-place.”h]”(hŒ*Array elements can be retrieved using the ”…””}”(hjhh²hh³Nh´Nubj)”}”(hŒ``bpf_map_lookup_elem()``”h]”hŒbpf_map_lookup_elem()”…””}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjhubhŒš helper. This helper returns a pointer into the array element, so to avoid data races with userspace reading the value, the user must use primitives like ”…””}”(hjhh²hh³Nh´Nubj)”}”(hŒ``__sync_fetch_and_add()``”h]”hŒ__sync_fetch_and_add()”…””}”(hj‚h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjhubhŒ" when updating the value in-place.”…””}”(hjhh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K+hjBh²hubeh}”(h]”Œbpf-map-lookup-elem”ah ]”h"]”Œbpf_map_lookup_elem()”ah$]”h&]”uh1hÖhj1h²hh³hÇh´K%ubh×)”}”(hhh]”(hÜ)”}”(hŒbpf_map_update_elem()”h]”hŒbpf_map_update_elem()”…””}”(hj¥h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj¢h²hh³hÇh´K1ubjT)”}”(hŒ\long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)”h]”hŒ\long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)”…””}”hj³sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´K3hj¢h²hubhý)”}”(hŒIArray elements can be updated using the ``bpf_map_update_elem()`` helper.”h]”(hŒ(Array elements can be updated using the ”…””}”(hjÂh²hh³Nh´Nubj)”}”(hŒ``bpf_map_update_elem()``”h]”hŒbpf_map_update_elem()”…””}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÂubhŒ helper.”…””}”(hjÂh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K7hj¢h²hubhý)”}”(hŒU``bpf_map_update_elem()`` returns 0 on success, or negative error in case of failure.”h]”(j)”}”(hŒ``bpf_map_update_elem()``”h]”hŒbpf_map_update_elem()”…””}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjâubhŒ< returns 0 on success, or negative error in case of failure.”…””}”(hjâh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K9hj¢h²hubhý)”}”(hŒ·Since the array is of constant size, ``bpf_map_delete_elem()`` is not supported. To clear an array element, you may use ``bpf_map_update_elem()`` to insert a zero value to that index.”h]”(hŒ%Since the array is of constant size, ”…””}”(hjþh²hh³Nh´Nubj)”}”(hŒ``bpf_map_delete_elem()``”h]”hŒbpf_map_delete_elem()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþubhŒ: is not supported. To clear an array element, you may use ”…””}”(hjþh²hh³Nh´Nubj)”}”(hŒ``bpf_map_update_elem()``”h]”hŒbpf_map_update_elem()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþubhŒ& to insert a zero value to that index.”…””}”(hjþh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KThis example BPF program shows how to access an array element.”h]”hŒ>This example BPF program shows how to access an array element.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Kwhjçh²hubjT)”}”(hXxint bpf_prog(struct __sk_buff *skb) { struct iphdr ip; int index; long *value; if (bpf_skb_load_bytes(skb, ETH_HLEN, &ip, sizeof(ip)) < 0) return 0; index = ip.protocol; value = bpf_map_lookup_elem(&my_map, &index); if (value) __sync_fetch_and_add(value, skb->len); return 0; }”h]”hXxint bpf_prog(struct __sk_buff *skb) { struct iphdr ip; int index; long *value; if (bpf_skb_load_bytes(skb, ETH_HLEN, &ip, sizeof(ip)) < 0) return 0; index = ip.protocol; value = bpf_map_lookup_elem(&my_map, &index); if (value) __sync_fetch_and_add(value, skb->len); return 0; }”…””}”hj#sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´Kyhjçh²hubeh}”(h]”Œid1”ah ]”h"]”h$]”j>ah&]”uh1hÖhj¶h²hh³hÇh´Kij@Kubh×)”}”(hhh]”(hÜ)”}”(hŒ Userspace”h]”hŒ Userspace”…””}”(hj<h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj9h²hh³hÇh´Kubh×)”}”(hhh]”(hÜ)”}”(hŒBPF_MAP_TYPE_ARRAY”h]”hŒBPF_MAP_TYPE_ARRAY”…””}”(hjMh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjJh²hh³hÇh´Kubhý)”}”(hŒVThis snippet shows how to create an array, using ``bpf_map_create_opts`` to set flags.”h]”(hŒ1This snippet shows how to create an array, using ”…””}”(hj[h²hh³Nh´Nubj)”}”(hŒ``bpf_map_create_opts``”h]”hŒbpf_map_create_opts”…””}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj[ubhŒ to set flags.”…””}”(hj[h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K’hjJh²hubjT)”}”(hX3#include #include int create_array() { int fd; LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_MMAPABLE); fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "example_array", /* name */ sizeof(__u32), /* key size */ sizeof(long), /* value size */ 256, /* max entries */ &opts); /* create opts */ return fd; }”h]”hX3#include #include int create_array() { int fd; LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_MMAPABLE); fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "example_array", /* name */ sizeof(__u32), /* key size */ sizeof(long), /* value size */ 256, /* max entries */ &opts); /* create opts */ return fd; }”…””}”hj{sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´K•hjJh²hubhý)”}”(hŒ>This snippet shows how to initialize the elements of an array.”h]”hŒ>This snippet shows how to initialize the elements of an array.”…””}”(hjŠh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K¨hjJh²hubjT)”}”(hX:int initialize_array(int fd) { __u32 i; long value; int ret; for (i = 0; i < 256; i++) { value = i; ret = bpf_map_update_elem(fd, &i, &value, BPF_ANY); if (ret < 0) return ret; } return ret; }”h]”hX:int initialize_array(int fd) { __u32 i; long value; int ret; for (i = 0; i < 256; i++) { value = i; ret = bpf_map_update_elem(fd, &i, &value, BPF_ANY); if (ret < 0) return ret; } return ret; }”…””}”hj˜sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´KªhjJh²hubhý)”}”(hŒBThis snippet shows how to retrieve an element value from an array.”h]”hŒBThis snippet shows how to retrieve an element value from an array.”…””}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K¼hjJh²hubjT)”}”(hXint lookup(int fd) { __u32 index = 42; long value; int ret; ret = bpf_map_lookup_elem(fd, &index, &value); if (ret < 0) return ret; /* use value here */ assert(value == 42); return ret; }”h]”hXint lookup(int fd) { __u32 index = 42; long value; int ret; ret = bpf_map_lookup_elem(fd, &index, &value); if (ret < 0) return ret; /* use value here */ assert(value == 42); return ret; }”…””}”hjµsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´K¾hjJh²hubeh}”(h]”Œbpf-map-type-array”ah ]”h"]”Œbpf_map_type_array”ah$]”h&]”uh1hÖhj9h²hh³hÇh´Kubh×)”}”(hhh]”(hÜ)”}”(hŒBPF_MAP_TYPE_PERCPU_ARRAY”h]”hŒBPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hjÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjÌh²hh³hÇh´KÑubhý)”}”(hŒEThis snippet shows how to initialize the elements of a per CPU array.”h]”hŒEThis snippet shows how to initialize the elements of a per CPU array.”…””}”(hjÝh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KÓhjÌh²hubjT)”}”(hX¯int initialize_array(int fd) { int ncpus = libbpf_num_possible_cpus(); long values[ncpus]; __u32 i, j; int ret; for (i = 0; i < 256 ; i++) { for (j = 0; j < ncpus; j++) values[j] = i; ret = bpf_map_update_elem(fd, &i, &values, BPF_ANY); if (ret < 0) return ret; } return ret; }”h]”hX¯int initialize_array(int fd) { int ncpus = libbpf_num_possible_cpus(); long values[ncpus]; __u32 i, j; int ret; for (i = 0; i < 256 ; i++) { for (j = 0; j < ncpus; j++) values[j] = i; ret = bpf_map_update_elem(fd, &i, &values, BPF_ANY); if (ret < 0) return ret; } return ret; }”…””}”hjësbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´KÕhjÌh²hubhý)”}”(hŒHThis snippet shows how to access the per CPU elements of an array value.”h]”hŒHThis snippet shows how to access the per CPU elements of an array value.”…””}”(hjúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KéhjÌh²hubjT)”}”(hX–int lookup(int fd) { int ncpus = libbpf_num_possible_cpus(); __u32 index = 42, j; long values[ncpus]; int ret; ret = bpf_map_lookup_elem(fd, &index, &values); if (ret < 0) return ret; for (j = 0; j < ncpus; j++) { /* Use per CPU value here */ assert(values[j] == 42); } return ret; }”h]”hX–int lookup(int fd) { int ncpus = libbpf_num_possible_cpus(); __u32 index = 42, j; long values[ncpus]; int ret; ret = bpf_map_lookup_elem(fd, &index, &values); if (ret < 0) return ret; for (j = 0; j < ncpus; j++) { /* Use per CPU value here */ assert(values[j] == 42); } return ret; }”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjc‰jdjejf}”uh1jSh³hÇh´KëhjÌh²hubeh}”(h]”Œbpf-map-type-percpu-array”ah ]”h"]”Œbpf_map_type_percpu_array”ah$]”h&]”uh1hÖhj9h²hh³hÇh´KÑubeh}”(h]”Œid2”ah ]”h"]”h$]”j¬ah&]”uh1hÖhj¶h²hh³hÇh´Kj@Kubeh}”(h]”Œexamples”ah ]”h"]”Œexamples”ah$]”h&]”uh1hÖhhØh²hh³hÇh´Kcubh×)”}”(hhh]”(hÜ)”}”(hŒ Semantics”h]”hŒ Semantics”…””}”(hj1h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj.h²hh³hÇh´Mubhý)”}”(hŒ‹As shown in the example above, when accessing a ``BPF_MAP_TYPE_PERCPU_ARRAY`` in userspace, each value is an array with ``ncpus`` elements.”h]”(hŒ0As shown in the example above, when accessing a ”…””}”(hj?h²hh³Nh´Nubj)”}”(hŒ``BPF_MAP_TYPE_PERCPU_ARRAY``”h]”hŒBPF_MAP_TYPE_PERCPU_ARRAY”…””}”(hjGh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj?ubhŒ+ in userspace, each value is an array with ”…””}”(hj?h²hh³Nh´Nubj)”}”(hŒ ``ncpus``”h]”hŒncpus”…””}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj?ubhŒ elements.”…””}”(hj?h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Mhj.h²hubhý)”}”(hŒ_When calling ``bpf_map_update_elem()`` the flag ``BPF_NOEXIST`` can not be used for these maps.”h]”(hŒ When calling ”…””}”(hjqh²hh³Nh´Nubj)”}”(hŒ``bpf_map_update_elem()``”h]”hŒbpf_map_update_elem()”…””}”(hjyh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjqubhŒ the flag ”…””}”(hjqh²hh³Nh´Nubj)”}”(hŒ``BPF_NOEXIST``”h]”hŒ BPF_NOEXIST”…””}”(hj‹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjqubhŒ can not be used for these maps.”…””}”(hjqh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Mhj.h²hubeh}”(h]”Œ semantics”ah ]”h"]”Œ semantics”ah$]”h&]”uh1hÖhhØh²hh³hÇh´Mubeh}”(h]”Œ0bpf-map-type-array-and-bpf-map-type-percpu-array”ah ]”h"]”Œ0bpf_map_type_array and bpf_map_type_percpu_array”ah$]”h&]”uh1hÖhhh²hh³hÇh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hÛNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jÖŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(j°j­j³j°Œ kernel bpf”NjŸjœj5j2j9j6j1j.jrjoŒ userspace”Nj+j(jÉjÆjjj¨j¥uŒ nametypes”}”(j°‰j³‰j‰jŸ‰j5‰j9‰j1‰jr‰j‰j+‰jɉj‰j¨‰uh}”(j­hØj°j j:j1jœjBj2j¢j6jAj.jÈjoj<j¨juj(j¶j4jçj!j9jÆjJjjÌj¥j.uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”jäKs…”R”Œparse_messages”]”(hŒsystem_message”“”)”}”(hhh]”hý)”}”(hŒ-Duplicate implicit target name: "kernel bpf".”h]”hŒ1Duplicate implicit target name: “kernel bpfâ€.”…””}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hühj<ubah}”(h]”h ]”h"]”h$]”h&]”j4aŒlevel”KŒtype”ŒINFO”Œsource”hÇŒline”Kiuh1j:hjçh²hh³hÇh´Kiubj;)”}”(hhh]”hý)”}”(hŒ,Duplicate implicit target name: "userspace".”h]”hŒ0Duplicate implicit target name: “userspaceâ€.”…””}”(hj[h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hühjXubah}”(h]”h ]”h"]”h$]”h&]”j!aŒlevel”KŒtype”jUŒsource”hÇŒline”Kuh1j:hj9h²hh³hÇh´KubeŒtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.