From: Hui Tang tanghui20@huawei.com
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: Hui Tang tanghui20@huawei.com --- include/uapi/linux/bpf.h | 7 +++++++ kernel/sched/bpf_sched.c | 18 ++++++++++++++++++ tools/include/uapi/linux/bpf.h | 7 +++++++ 3 files changed, 32 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 5f794a297c79..bfd7ddc6bd54 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -3861,6 +3861,12 @@ union bpf_attr { * cpumask operation collections. * Return * 0 on success, or a negative error in case of failure. + * + * 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), \ @@ -4038,6 +4044,7 @@ union bpf_attr { FN(init_cpu_topology), \ FN(get_system_cpus), \ FN(cpumask_op), \ + FN(cpus_share_cache), \ /* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper diff --git a/kernel/sched/bpf_sched.c b/kernel/sched/bpf_sched.c index 00f3186a011b..d4224c80d5cf 100644 --- a/kernel/sched/bpf_sched.c +++ b/kernel/sched/bpf_sched.c @@ -335,6 +335,8 @@ BPF_CALL_3(bpf_sched_cpu_idle_stat_of, int, cpu, ctx->avg_idle = rq->avg_idle; #endif
+ ctx->available_idle = available_idle_cpu(cpu); + return 0; }
@@ -460,6 +462,20 @@ 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) +{ + 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) { @@ -492,6 +508,8 @@ bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_sched_cpu_capacity_of_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); } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 7afd2958934d..a88c9b495824 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -3861,6 +3861,12 @@ union bpf_attr { * cpumask operation collections. * Return * 0 on success, or a negative error in case of failure. + * + * 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), \ @@ -4038,6 +4044,7 @@ union bpf_attr { FN(init_cpu_topology), \ FN(get_system_cpus), \ FN(cpumask_op), \ + FN(cpus_share_cache), \ /* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper