Fix: folded format & lookup_batch error #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
环境
当前存以下几个问题
Makefile 路径不对,导致无法正常编译
当使用 ford 格式的时候,如果 nr_kip = 0; std::size_t 类型会出现异常,出现 j -1 则会发生下溢(underflow);
从而导致死循环
!直到出现错误内核抛堆栈异常。解决方案:
把
std::size_t
这个类型 改成跟其他是一致的int
类型 。当前使用的是 batch_map_ops=true 批量获取的方式,这里存在几个问题:
3.1 使用 bpf_map_lookup_batch 的异常, 参数 keys 和 vals 的参数有些问题
解决方案:
参考:
https://github.com/iovisor/bcc/blob/6fbcf16b4a4222b2ea92ea32ceed2532a28b8080/libbpf-tools/map_helpers.c#L58
改成
3.2 使用 bpf_map_lookup_batch 的异常,没有添加 BPF_F_LOCK,
counts map 导致 value 出现 0 的情况
,但是直接用bpftool
显示正常的,因为 bpftool 使用的是 iter 遍历的方式
(https://github.com/libbpf/bpftool/blob/3e6f814e534421c4fd638c1bffc7e8318da78d16/src/map.c#L823)
使用 GDB attach bpf_map_lookup_batch 调用出来就是会出现 0 的情况
深入内核代码 https://elixir.bootlin.com/linux/v5.15/source/kernel/bpf/hashtab.c#L1585
https://elixir.bootlin.com/linux/v5.15/source/kernel/bpf/hashtab.c#L1722
同时遍历的时候,也是有 添加锁的
https://elixir.bootlin.com/linux/v5.15/source/kernel/bpf/syscall.c#L1262
解决方案:
添加batch_opts 之后测试正常
测试结果
./profile -K -p129677