Lines Matching +full:key +full:- +full:value

1 // SPDX-License-Identifier: GPL-2.0-only
22 pcpu_map_value_t value[nr_cpus]; in map_populate() local
24 map_key_t key; in map_populate() local
27 bpf_percpu(value, i) = FILL_VALUE; in map_populate()
29 for (key = 1; key <= num; key++) { in map_populate()
30 err = bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST); in map_populate()
32 return -1; in map_populate()
48 err = bpf_map__set_type(skel->maps.hashmap1, map_type); in setup()
52 err = bpf_map__set_max_entries(skel->maps.hashmap1, map_sz); in setup()
60 *map_fd = bpf_map__fd(skel->maps.hashmap1); in setup()
77 /* executes bpf program that updates map with key, value */
78 static int prog_run_insert_elem(struct test_map_init *skel, map_key_t key, in prog_run_insert_elem() argument
79 map_value_t value) in prog_run_insert_elem() argument
83 bss = skel->bss; in prog_run_insert_elem()
85 bss->inKey = key; in prog_run_insert_elem()
86 bss->inValue = value; in prog_run_insert_elem()
87 bss->inPid = getpid(); in prog_run_insert_elem()
90 return -1; in prog_run_insert_elem()
100 static int check_values_one_cpu(pcpu_map_value_t *value, map_value_t expected) in check_values_one_cpu() argument
106 val = bpf_percpu(value, i); in check_values_one_cpu()
108 if (CHECK(val != expected, "map value", in check_values_one_cpu()
110 return -1; in check_values_one_cpu()
115 if (CHECK(nzCnt != 1, "map value", "set for %d CPUs instead of 1!\n", in check_values_one_cpu()
117 return -1; in check_values_one_cpu()
122 /* Add key=1 elem with values set for all CPUs
123 * Delete elem key=1
124 * Run bpf prog that inserts new key=1 elem with value=0x1234
125 * (bpf prog can only set value for current CPU)
126 * Lookup Key=1 and check value is as expected for all CPUs:
127 * value set by bpf prog for one CPU, 0 for all others
131 pcpu_map_value_t value[nr_cpus]; in test_pcpu_map_init() local
134 map_key_t key; in test_pcpu_map_init() local
141 /* delete element so the entry can be re-used*/ in test_pcpu_map_init()
142 key = 1; in test_pcpu_map_init()
143 err = bpf_map_delete_elem(map_fd, &key); in test_pcpu_map_init()
147 /* run bpf prog that inserts new elem, re-using the slot just freed */ in test_pcpu_map_init()
148 err = prog_run_insert_elem(skel, key, TEST_VALUE); in test_pcpu_map_init()
152 /* check that key=1 was re-created by bpf prog */ in test_pcpu_map_init()
153 err = bpf_map_lookup_elem(map_fd, &key, value); in test_pcpu_map_init()
158 check_values_one_cpu(value, TEST_VALUE); in test_pcpu_map_init()
164 /* Add key=1 and key=2 elems with values set for all CPUs
165 * Run bpf prog that inserts new key=3 elem
166 * (only for current cpu; other cpus should have initial value = 0)
167 * Lookup Key=1 and check value is as expected for all CPUs
171 pcpu_map_value_t value[nr_cpus]; in test_pcpu_lru_map_init() local
174 map_key_t key; in test_pcpu_lru_map_init() local
183 /* run bpf prog that inserts new key=3 element, re-using LRU slot */ in test_pcpu_lru_map_init()
184 key = 3; in test_pcpu_lru_map_init()
185 err = prog_run_insert_elem(skel, key, TEST_VALUE); in test_pcpu_lru_map_init()
189 /* check that key=3 replaced one of earlier elements */ in test_pcpu_lru_map_init()
190 err = bpf_map_lookup_elem(map_fd, &key, value); in test_pcpu_lru_map_init()
195 check_values_one_cpu(value, TEST_VALUE); in test_pcpu_lru_map_init()