Lines Matching +full:key +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
36 if (map_fd == -1) in create_map()
42 static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key, in bpf_map_lookup_elem_with_ref_bit() argument
48 BPF_LD_IMM64(BPF_REG_3, key), in bpf_map_lookup_elem_with_ref_bit()
50 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8), in bpf_map_lookup_elem_with_ref_bit()
71 return -1; in bpf_map_lookup_elem_with_ref_bit()
78 return -1; in bpf_map_lookup_elem_with_ref_bit()
83 ret = -1; in bpf_map_lookup_elem_with_ref_bit()
103 printf("key:%llu not found from map. %s(%d)\n", in map_subset()
108 printf("key:%llu value0:%llu != value1:%llu\n", in map_subset()
125 int ret = -1; in sched_next_online()
142 * Add key=1 (+1 key)
143 * Add key=2 (+1 key)
144 * Lookup Key=1
145 * Add Key=3
146 * => Key=2 will be removed by LRU
147 * Iterate map. Only found key=1 and key=3
151 unsigned long long key, value[nr_cpus]; in test_lru_sanity0() local
158 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity0()
164 assert(lru_map_fd != -1); in test_lru_sanity0()
167 assert(expected_map_fd != -1); in test_lru_sanity0()
171 /* insert key=1 element */ in test_lru_sanity0()
173 key = 1; in test_lru_sanity0()
174 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity0()
175 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity0()
179 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST) == -EEXIST); in test_lru_sanity0()
180 /* key=1 already exists */ in test_lru_sanity0()
182 assert(bpf_map_update_elem(lru_map_fd, &key, value, -1) == -EINVAL); in test_lru_sanity0()
184 /* insert key=2 element */ in test_lru_sanity0()
186 /* check that key=2 is not found */ in test_lru_sanity0()
187 key = 2; in test_lru_sanity0()
188 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity0()
191 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_EXIST) == -ENOENT); in test_lru_sanity0()
192 /* key=2 is not there */ in test_lru_sanity0()
194 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity0()
196 /* insert key=3 element */ in test_lru_sanity0()
198 /* check that key=3 is not found */ in test_lru_sanity0()
199 key = 3; in test_lru_sanity0()
200 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity0()
202 /* check that key=1 can be found and mark the ref bit to in test_lru_sanity0()
203 * stop LRU from removing key=1 in test_lru_sanity0()
205 key = 1; in test_lru_sanity0()
206 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity0()
209 key = 3; in test_lru_sanity0()
210 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity0()
211 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity0()
214 /* key=2 has been removed from the LRU */ in test_lru_sanity0()
215 key = 2; in test_lru_sanity0()
216 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity0()
218 /* lookup elem key=1 and delete it, then check it doesn't exist */ in test_lru_sanity0()
219 key = 1; in test_lru_sanity0()
220 assert(!bpf_map_lookup_and_delete_elem(lru_map_fd, &key, &value)); in test_lru_sanity0()
224 assert(!bpf_map_delete_elem(expected_map_fd, &key)); in test_lru_sanity0()
242 unsigned long long key, end_key, value[nr_cpus]; in test_lru_sanity1() local
255 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity1()
262 assert(lru_map_fd != -1); in test_lru_sanity1()
265 assert(expected_map_fd != -1); in test_lru_sanity1()
271 for (key = 1; key < end_key; key++) in test_lru_sanity1()
272 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity1()
277 for (key = 1; key < end_key; key++) { in test_lru_sanity1()
278 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity1()
279 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity1()
287 key = 1 + tgt_free; in test_lru_sanity1()
288 end_key = key + tgt_free; in test_lru_sanity1()
289 for (; key < end_key; key++) { in test_lru_sanity1()
290 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity1()
292 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity1()
309 * Re-insert 1 to tgt_free/2 again and do a lookup immeidately
312 * => Key 1+tgt_free to tgt_free*3/2
318 unsigned long long key, value[nr_cpus]; in test_lru_sanity2() local
332 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity2()
339 assert(lru_map_fd != -1); in test_lru_sanity2()
342 assert(expected_map_fd != -1); in test_lru_sanity2()
348 for (key = 1; key < end_key; key++) in test_lru_sanity2()
349 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity2()
360 * Hence, the oldest key 1 to tgt_free/2 in test_lru_sanity2()
363 key = 1; in test_lru_sanity2()
365 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity2()
367 assert(!bpf_map_delete_elem(lru_map_fd, &key)); in test_lru_sanity2()
369 assert(bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity2()
373 /* Re-insert 1 to tgt_free/2 again and do a lookup in test_lru_sanity2()
378 for (key = 1; key < end_key; key++) { in test_lru_sanity2()
379 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity2()
380 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity2()
382 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity2()
384 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity2()
392 for (key = 1 + tgt_free; key < end_key; key++) in test_lru_sanity2()
396 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity2()
400 end_key = key + tgt_free; in test_lru_sanity2()
401 for (; key < end_key; key++) { in test_lru_sanity2()
402 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity2()
404 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity2()
419 * Lookup key 1 to tgt_free*3/2
421 * => key 1+tgt_free*3/2 to 2*tgt_free are removed from LRU
425 unsigned long long key, end_key, value[nr_cpus]; in test_lru_sanity3() local
438 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity3()
445 assert(lru_map_fd != -1); in test_lru_sanity3()
448 assert(expected_map_fd != -1); in test_lru_sanity3()
454 for (key = 1; key < end_key; key++) in test_lru_sanity3()
455 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity3()
458 /* Lookup key 1 to tgt_free*3/2 */ in test_lru_sanity3()
460 for (key = 1; key < end_key; key++) { in test_lru_sanity3()
461 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity3()
462 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity3()
469 key = 2 * tgt_free + 1; in test_lru_sanity3()
470 end_key = key + batch_size; in test_lru_sanity3()
471 for (; key < end_key; key++) { in test_lru_sanity3()
472 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity3()
474 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity3()
490 unsigned long long key, value[nr_cpus]; in test_lru_sanity4() local
497 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity4()
504 assert(lru_map_fd != -1); in test_lru_sanity4()
508 assert(expected_map_fd != -1); in test_lru_sanity4()
512 for (key = 1; key <= 2 * tgt_free; key++) in test_lru_sanity4()
513 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity4()
516 key = 1; in test_lru_sanity4()
517 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity4()
519 for (key = 1; key <= tgt_free; key++) { in test_lru_sanity4()
520 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity4()
521 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity4()
525 for (; key <= 2 * tgt_free; key++) { in test_lru_sanity4()
526 assert(!bpf_map_delete_elem(lru_map_fd, &key)); in test_lru_sanity4()
527 assert(bpf_map_delete_elem(lru_map_fd, &key)); in test_lru_sanity4()
530 end_key = key + 2 * tgt_free; in test_lru_sanity4()
531 for (; key < end_key; key++) { in test_lru_sanity4()
532 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity4()
534 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity4()
548 unsigned long long key, value[nr_cpus]; in do_test_lru_sanity5() local
550 /* Ensure the last key inserted by previous CPU can be found */ in do_test_lru_sanity5()
554 key = last_key + 1; in do_test_lru_sanity5()
555 assert(!bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST)); in do_test_lru_sanity5()
556 assert(!bpf_map_lookup_elem_with_ref_bit(map_fd, key, value)); in do_test_lru_sanity5()
558 /* Cannot find the last key because it was removed by LRU */ in do_test_lru_sanity5()
559 assert(bpf_map_lookup_elem(map_fd, &last_key, value) == -ENOENT); in do_test_lru_sanity5()
565 unsigned long long key, value[nr_cpus]; in test_lru_sanity5() local
576 assert(map_fd != -1); in test_lru_sanity5()
579 key = 0; in test_lru_sanity5()
580 assert(!bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity5()
582 while (sched_next_online(0, &next_cpu) != -1) { in test_lru_sanity5()
587 do_test_lru_sanity5(key, map_fd); in test_lru_sanity5()
589 } else if (pid == -1) { in test_lru_sanity5()
590 printf("couldn't spawn process to test key:%llu\n", in test_lru_sanity5()
591 key); in test_lru_sanity5()
598 key++; in test_lru_sanity5()
603 /* At least one key should be tested */ in test_lru_sanity5()
604 assert(key > 0); in test_lru_sanity5()
613 unsigned long long key, value[nr_cpus]; in test_lru_sanity6() local
623 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity6()
626 assert(expected_map_fd != -1); in test_lru_sanity6()
629 assert(lru_map_fd != -1); in test_lru_sanity6()
633 for (key = 1; key <= tgt_free; key++) { in test_lru_sanity6()
634 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity6()
636 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity6()
640 for (; key <= tgt_free * 2; key++) { in test_lru_sanity6()
643 /* Make ref bit sticky for key: [1, tgt_free] */ in test_lru_sanity6()
649 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity6()
653 for (; key <= tgt_free * 3; key++) { in test_lru_sanity6()
654 assert(!bpf_map_update_elem(lru_map_fd, &key, value, in test_lru_sanity6()
656 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity6()
669 * Add key=1 (+1 key)
670 * Add key=2 (+1 key)
671 * Lookup Key=1 (datapath)
672 * Lookup Key=2 (syscall)
673 * Add Key=3
674 * => Key=2 will be removed by LRU
675 * Iterate map. Only found key=1 and key=3
679 unsigned long long key, value[nr_cpus]; in test_lru_sanity7() local
686 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity7()
692 assert(lru_map_fd != -1); in test_lru_sanity7()
695 assert(expected_map_fd != -1); in test_lru_sanity7()
699 /* insert key=1 element */ in test_lru_sanity7()
701 key = 1; in test_lru_sanity7()
702 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity7()
703 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity7()
707 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST) == -EEXIST); in test_lru_sanity7()
708 /* key=1 already exists */ in test_lru_sanity7()
710 /* insert key=2 element */ in test_lru_sanity7()
712 /* check that key=2 is not found */ in test_lru_sanity7()
713 key = 2; in test_lru_sanity7()
714 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity7()
717 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_EXIST) == -ENOENT); in test_lru_sanity7()
718 /* key=2 is not there */ in test_lru_sanity7()
720 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity7()
722 /* insert key=3 element */ in test_lru_sanity7()
724 /* check that key=3 is not found */ in test_lru_sanity7()
725 key = 3; in test_lru_sanity7()
726 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity7()
728 /* check that key=1 can be found and mark the ref bit to in test_lru_sanity7()
729 * stop LRU from removing key=1 in test_lru_sanity7()
731 key = 1; in test_lru_sanity7()
732 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity7()
735 /* check that key=2 can be found and do _not_ mark ref bit. in test_lru_sanity7()
738 key = 2; in test_lru_sanity7()
739 assert(!bpf_map_lookup_elem(lru_map_fd, &key, value)); in test_lru_sanity7()
742 key = 3; in test_lru_sanity7()
743 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity7()
744 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity7()
747 /* key=2 has been removed from the LRU */ in test_lru_sanity7()
748 key = 2; in test_lru_sanity7()
749 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity7()
760 * Add key=1 (+1 key)
761 * Add key=2 (+1 key)
762 * Lookup Key=1 (syscall)
763 * Lookup Key=2 (datapath)
764 * Add Key=3
765 * => Key=1 will be removed by LRU
766 * Iterate map. Only found key=2 and key=3
770 unsigned long long key, value[nr_cpus]; in test_lru_sanity8() local
777 assert(sched_next_online(0, &next_cpu) != -1); in test_lru_sanity8()
783 assert(lru_map_fd != -1); in test_lru_sanity8()
786 assert(expected_map_fd != -1); in test_lru_sanity8()
790 /* insert key=1 element */ in test_lru_sanity8()
792 key = 1; in test_lru_sanity8()
793 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity8()
796 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST) == -EEXIST); in test_lru_sanity8()
797 /* key=1 already exists */ in test_lru_sanity8()
799 /* insert key=2 element */ in test_lru_sanity8()
801 /* check that key=2 is not found */ in test_lru_sanity8()
802 key = 2; in test_lru_sanity8()
803 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity8()
806 assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_EXIST) == -ENOENT); in test_lru_sanity8()
807 /* key=2 is not there */ in test_lru_sanity8()
809 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity8()
810 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity8()
813 /* insert key=3 element */ in test_lru_sanity8()
815 /* check that key=3 is not found */ in test_lru_sanity8()
816 key = 3; in test_lru_sanity8()
817 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity8()
819 /* check that key=1 can be found and do _not_ mark ref bit. in test_lru_sanity8()
822 key = 1; in test_lru_sanity8()
823 assert(!bpf_map_lookup_elem(lru_map_fd, &key, value)); in test_lru_sanity8()
826 /* check that key=2 can be found and mark the ref bit to in test_lru_sanity8()
827 * stop LRU from removing key=2 in test_lru_sanity8()
829 key = 2; in test_lru_sanity8()
830 assert(!bpf_map_lookup_elem_with_ref_bit(lru_map_fd, key, value)); in test_lru_sanity8()
833 key = 3; in test_lru_sanity8()
834 assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST)); in test_lru_sanity8()
835 assert(!bpf_map_update_elem(expected_map_fd, &key, value, in test_lru_sanity8()
838 /* key=1 has been removed from the LRU */ in test_lru_sanity8()
839 key = 1; in test_lru_sanity8()
840 assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -ENOENT); in test_lru_sanity8()
860 assert(nr_cpus != -1); in main()