我想用a
BPF_MAP_TYPE_PERCPU_ARRAY
统计在
SK_SKB
钩子。我用以下方式检查了地图值
bpftool map dump
在创建映射后,似乎对于某些CPU,值没有初始化为零。
以下是地图定义:
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, __u64);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} request_count_map SEC(".maps");
以下是输出
bpftool地图转储
:
$ sudo bpftool map dump id 287
[{
"key": 0,
"values": [{
"cpu": 0,
"value": 0
},{
"cpu": 1,
"value": 94322157119214
},{
"cpu": 2,
"value": 140730068914171
},{
"cpu": 3,
"value": 94322160575280
},{
"cpu": 4,
"value": 94322160592312
},{
"cpu": 5,
"value": 94322160592512
},{
"cpu": 6,
"value": 80
},{
"cpu": 7,
"value": 0
},{
"cpu": 8,
"value": 0
},{
"cpu": 9,
"value": 140730068932048
},{
"cpu": 10,
"value": 0
},{
"cpu": 11,
"value": 0
},{
"cpu": 12,
"value": 0
},{
"cpu": 13,
"value": 0
},{
"cpu": 14,
"value": 0
},{
"cpu": 15,
"value": 0
},{
"cpu": 16,
"value": 80
},{
"cpu": 17,
"value": 0
},{
"cpu": 18,
"value": 0
},{
"cpu": 19,
"value": 140730068932048
}
]
}
]
从文档中(
here
和
here
),似乎预期的行为是将值初始化为零?
编辑:
加载地图时,我意识到我正在更新地图,如下所示:
int index = 0;
__u64 value = 0;
// Get the svc_identifier_map fd.
reqcnt_map_fd = bpf_obj_get(reqcnt_map_filename);
// Add the svc identifier to the svc_identifier_map.
err = bpf_map_update_elem(respcnt_map_fd, &index, &value, BPF_ANY);
if (err) {
goto fail;
}
然而,这些值仍然应该是零吗?