Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf tools: Add helper function for updating bpf maps elements

Add bpf_map_update_elem() helper function which calls the sys_bpf
syscall to update elements in bpf maps. Upcoming patches will use it to
adjust data in map through the perf command line.

Signed-off-by: He Kuang <hekuang@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1448372181-151723-4-git-send-email-wangnan0@huawei.com
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

He Kuang and committed by
Arnaldo Carvalho de Melo
43798bf3 dcdd184b

+16
+14
tools/lib/bpf/bpf.c
··· 83 83 log_buf[0] = 0; 84 84 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 85 85 } 86 + 87 + int bpf_map_update_elem(int fd, void *key, void *value, 88 + u64 flags) 89 + { 90 + union bpf_attr attr; 91 + 92 + bzero(&attr, sizeof(attr)); 93 + attr.map_fd = fd; 94 + attr.key = ptr_to_u64(key); 95 + attr.value = ptr_to_u64(value); 96 + attr.flags = flags; 97 + 98 + return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); 99 + }
+2
tools/lib/bpf/bpf.h
··· 20 20 u32 kern_version, char *log_buf, 21 21 size_t log_buf_sz); 22 22 23 + int bpf_map_update_elem(int fd, void *key, void *value, 24 + u64 flags); 23 25 #endif