diff --git a/profiles-tuned-ebpf-Add-AND-logic-of-cpu-mask-in-eBPF-program.patch b/profiles-tuned-ebpf-Add-AND-logic-of-cpu-mask-in-eBPF-program.patch new file mode 100644 index 0000000000000000000000000000000000000000..837be51877f6bb8d9a555eb74e85bfa356b0042a --- /dev/null +++ b/profiles-tuned-ebpf-Add-AND-logic-of-cpu-mask-in-eBPF-program.patch @@ -0,0 +1,47 @@ +From f3006a83e1728100c6c96d6b843962154f9d32d0 Mon Sep 17 00:00:00 2001 +From: tianmuyang +Date: Mon, 15 Sep 2025 20:27:10 +0800 +Subject: [PATCH] tuned-ebpf: Add "AND" logic of cpu mask in eBPF programmable + schedule + +Signed-off-by: tianmuyang +--- + tuned/ebpf/programmable_sched_kern.c | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/tuned/ebpf/programmable_sched_kern.c b/tuned/ebpf/programmable_sched_kern.c +index 4e96801..afc0783 100644 +--- a/tuned/ebpf/programmable_sched_kern.c ++++ b/tuned/ebpf/programmable_sched_kern.c +@@ -99,6 +99,20 @@ static __always_inline int libbpf_sched_set_task_prefer_cpumask(struct task_stru + return bpf_sched_set_task_prefer_cpumask(tsk, mask, len); + } + ++static __always_inline long libbpf_cpumask_and(struct cpumask *dst, ++ struct cpumask *src1, ++ struct cpumask *src2) ++{ ++ struct cpumask_op_args op; ++ ++ op.op_type = CPUMASK_AND; ++ op.arg1 = dst; ++ op.arg2 = src1; ++ op.arg3 = src2; ++ op.arg4 = INVALID_PTR; ++ return bpf_cpumask_op(&op, sizeof(op)); ++} ++ + static __always_inline int str_prefix(char *str, char *prefix) + { + int i = 0; +@@ -199,6 +213,7 @@ void BPF_PROG(programmable_sched, struct task_struct *p) + + libbpf_node_set(cur_index, &mask_info->node_mask); + libbpf_nodemask_to_cpumask(&mask_info->node_mask, &mask_info->cpu_mask); ++ libbpf_cpumask_and(&mask_info->cpu_mask, &mask_info->cpu_mask, (struct cpumask *)p->cpus_ptr); + + __sync_fetch_and_add(&numa_info->numa_index, 1); + mask_info->pid = p->pid; +-- +2.33.0 + diff --git a/profiles-tuned-ebpf-Add-pid-cache-to-avoid-binding-one-proces.patch b/profiles-tuned-ebpf-Add-pid-cache-to-avoid-binding-one-proces.patch new file mode 100644 index 0000000000000000000000000000000000000000..12d15761f12e9ebf27626394648186fbaf6a3502 --- /dev/null +++ b/profiles-tuned-ebpf-Add-pid-cache-to-avoid-binding-one-proces.patch @@ -0,0 +1,83 @@ +From 3c78b117306b8cb6398654b670881ae27036dc7f Mon Sep 17 00:00:00 2001 +From: tianmuyang +Date: Tue, 16 Sep 2025 20:21:32 +0800 +Subject: [PATCH] tuned-ebpf: Add pid cache to avoid binding one process for + multiple times + +Signed-off-by: tianmuyang +--- + tuned/ebpf/programmable_sched_kern.c | 29 +++++++++++++++++++++++++--- + 1 file changed, 26 insertions(+), 3 deletions(-) + +diff --git a/tuned/ebpf/programmable_sched_kern.c b/tuned/ebpf/programmable_sched_kern.c +index afc0783..3e8ea5d 100644 +--- a/tuned/ebpf/programmable_sched_kern.c ++++ b/tuned/ebpf/programmable_sched_kern.c +@@ -72,6 +72,13 @@ struct { + __uint(max_entries, 1); + } numa_info_map SEC(".maps"); + ++struct { ++ __uint(type, BPF_MAP_TYPE_LRU_HASH); ++ __type(key, u32); ++ __type(value, u32); ++ __uint(max_entries, 4096); ++} alloced_pid_map SEC(".maps"); ++ + static __always_inline void libbpf_node_set(int nid, nodemask_t *nodes) + { + struct nodemask_op_args op = {0}; +@@ -175,6 +182,14 @@ static __always_inline int args_match(struct task_struct *p, char *arg_prefix) + SEC("sched/cfs_exec_init") + void BPF_PROG(programmable_sched, struct task_struct *p) + { ++ // if has been allocated recently, skip ++ __u32 pid = p->pid; ++ u32 *exist = bpf_map_lookup_elem(&alloced_pid_map, &pid); ++ if (exist) { ++ bpf_printk("pid: %u has been allocated recently, skip"); ++ return; ++ } ++ + int ret = 0; + char comm[MAX_STR_LEN + 1]; + if (bpf_probe_read_kernel(comm, sizeof(comm), &p->comm)) { +@@ -191,14 +206,17 @@ void BPF_PROG(programmable_sched, struct task_struct *p) + + if (str_prefix(comm, numa_info->proc_prefix) != 0) + return; ++ bpf_printk("matched comm: %s", comm); + + if (numa_info->arg_prefix[0] != '\0') { + ret = args_match(p, numa_info->arg_prefix); +- if (ret) ++ if (ret) { ++ bpf_printk("comm matched, but cmd arg not matched, return"); + return; ++ } ++ bpf_printk("matched cmd arg prefix: %s", numa_info->arg_prefix); + } + +- bpf_printk("matched comm: %s", comm); + struct sched_mask_info *mask_info = bpf_map_lookup_elem(&mask_map, &key); + if (!mask_info) { + bpf_printk("ERROR: lookup from mask_map failed"); +@@ -217,9 +235,14 @@ void BPF_PROG(programmable_sched, struct task_struct *p) + + __sync_fetch_and_add(&numa_info->numa_index, 1); + mask_info->pid = p->pid; +- ++ bpf_printk("bind to numa: %d", cur_index); + libbpf_sched_set_task_prefer_cpumask(p, &mask_info->cpu_mask, sizeof(struct cpumask)); + ++ // add to alloced_pid_map ++ u32 one = 1; ++ if(bpf_map_update_elem(&alloced_pid_map, &pid, &one, BPF_ANY)) ++ bpf_printk("ERROR: update alloced_pid_map failed"); ++ + return; + } + +-- +2.33.0 + diff --git a/tuned.spec b/tuned.spec index 313d0e1440c9fd142a67a83349261add8dd12238..a60c9e4361669972f03991c267a2e0bac4d20b0b 100644 --- a/tuned.spec +++ b/tuned.spec @@ -1,7 +1,7 @@ Summary: A system tuning service for Linux Name: tuned Version: 2.24.1 -Release: 4 +Release: 5 License: GPLv2+ Source0: https://github.com/redhat-performance/%{name}/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz URL: http://www.tuned-project.org/ @@ -43,6 +43,8 @@ Patch8: profiles-add-spark.patch Patch9: profiles-Add-programmable-scheduling-based-on-eBPF.patch Patch10: profiles-Add-vmlinux-to-support-eBPF-program-compila.patch Patch11: support-optional-param-filter-arg_prefix.patch +Patch12: profiles-tuned-ebpf-Add-AND-logic-of-cpu-mask-in-eBPF-program.patch +Patch13: profiles-tuned-ebpf-Add-pid-cache-to-avoid-binding-one-proces.patch Provides: tuned-gtk = %{version}-%{release} Provides: tuned-utils = %{version}-%{release} @@ -306,6 +308,10 @@ fi %{_mandir}/man7/tuned-profiles-spectrumscale-ece.7* %changelog +* Tue Sep 16 2025 tianmuyang - 2.24.1-5 +- tuned-ebpf: Add pid cache to avoid binding one process for multiple times +- tuned-ebpf: Add "AND" logic of cpu mask in eBPF programmable schedule + * Sun Sep 14 2025 wuchangye - 2.24.1-4 - tuned-ebpf: support optional param filter: arg_prefix