提交 ba18ece2 编写于 作者: H Hui Tang 提交者: Zheng Zengkai

bpf:programmable: Add helper func to check cpu share cache

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5KUFB
CVE: NA

--------------------------------

Add helper function to check two cpu whehter share same LLC cache.
Signed-off-by: NHui Tang <tanghui20@huawei.com>
上级 dc85e050
......@@ -3900,6 +3900,12 @@ union bpf_attr {
* 0 on success, or a negative error in case of failure.
* Return
* View above.
*
* int bpf_cpus_share_cache(int src_cpu, int dst_cpu)
* Description
* check src_cpu whether share cache with dst_cpu.
* Return
* yes 1, no 0.
*/
#define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \
......@@ -4077,6 +4083,7 @@ union bpf_attr {
FN(init_cpu_topology), \
FN(get_cpumask_info), \
FN(cpumask_op), \
FN(cpus_share_cache), \
/* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
......
......@@ -486,6 +486,23 @@ static const struct bpf_func_proto bpf_cpumask_op_proto = {
.arg2_type = ARG_CONST_SIZE,
};
BPF_CALL_2(bpf_cpus_share_cache, int, src_cpu, int, dst_cpu)
{
if ((unsigned int)src_cpu >= nr_cpu_ids ||
(unsigned int)dst_cpu >= nr_cpu_ids)
return 0;
return cpus_share_cache(src_cpu, dst_cpu);
}
static const struct bpf_func_proto bpf_cpus_share_cache_proto = {
.func = bpf_cpus_share_cache,
.gpl_only = false,
.ret_type = RET_INTEGER,
.arg1_type = ARG_ANYTHING,
.arg2_type = ARG_ANYTHING,
};
static const struct bpf_func_proto *
bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
......@@ -518,6 +535,8 @@ bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
return &bpf_get_cpumask_info_proto;
case BPF_FUNC_cpumask_op:
return &bpf_cpumask_op_proto;
case BPF_FUNC_cpus_share_cache:
return &bpf_cpus_share_cache_proto;
default:
return bpf_base_func_proto(func_id);
}
......
......@@ -3900,6 +3900,12 @@ union bpf_attr {
* 0 on success, or a negative error in case of failure.
* Return
* View above.
*
* int bpf_cpus_share_cache(int src_cpu, int dst_cpu)
* Description
* check src_cpu whether share cache with dst_cpu.
* Return
* true yes, false no.
*/
#define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \
......@@ -4077,6 +4083,7 @@ union bpf_attr {
FN(init_cpu_topology), \
FN(get_cpumask_info), \
FN(cpumask_op), \
FN(cpus_share_cache), \
/* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册