in bpf/map_perf_test_user.c [425:504]
int main(int argc, char **argv)
{
int nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
struct bpf_link *links[8];
struct bpf_program *prog;
struct bpf_object *obj;
struct bpf_map *map;
char filename[256];
int i = 0;
if (argc > 1)
test_flags = atoi(argv[1]) ? : test_flags;
if (argc > 2)
nr_cpus = atoi(argv[2]) ? : nr_cpus;
if (argc > 3)
num_map_entries = atoi(argv[3]);
if (argc > 4)
max_cnt = atoi(argv[4]);
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
fprintf(stderr, "ERROR: opening BPF object file failed\n");
return 0;
}
map = bpf_object__find_map_by_name(obj, "inner_lru_hash_map");
if (libbpf_get_error(map)) {
fprintf(stderr, "ERROR: finding a map in obj file failed\n");
goto cleanup;
}
inner_lru_hash_size = bpf_map__max_entries(map);
if (!inner_lru_hash_size) {
fprintf(stderr, "ERROR: failed to get map attribute\n");
goto cleanup;
}
/* resize BPF map prior to loading */
if (num_map_entries > 0)
fixup_map(obj);
/* load BPF program */
if (bpf_object__load(obj)) {
fprintf(stderr, "ERROR: loading BPF object file failed\n");
goto cleanup;
}
map_fd[0] = bpf_object__find_map_fd_by_name(obj, "array_of_lru_hashs");
map_fd[1] = bpf_object__find_map_fd_by_name(obj, "hash_map_alloc");
map_fd[2] = bpf_object__find_map_fd_by_name(obj, "lru_hash_lookup_map");
if (map_fd[0] < 0 || map_fd[1] < 0 || map_fd[2] < 0) {
fprintf(stderr, "ERROR: finding a map in obj file failed\n");
goto cleanup;
}
bpf_object__for_each_program(prog, obj) {
links[i] = bpf_program__attach(prog);
if (libbpf_get_error(links[i])) {
fprintf(stderr, "ERROR: bpf_program__attach failed\n");
links[i] = NULL;
goto cleanup;
}
i++;
}
fill_lpm_trie();
run_perf_test(nr_cpus);
cleanup:
for (i--; i >= 0; i--)
bpf_link__destroy(links[i]);
bpf_object__close(obj);
return 0;
}