lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231231175218.510721-3-qyousef@layalina.io>
Date: Sun, 31 Dec 2023 17:52:18 +0000
From: Qais Yousef <qyousef@...alina.io>
To: Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Vincent Guittot <vincent.guittot@...aro.org>,
	Dietmar Eggemann <dietmar.eggemann@....com>
Cc: linux-kernel@...r.kernel.org,
	"Pierre Gondois" <Pierre.Gondois@....com>,
	Qais Yousef <qyousef@...alina.io>
Subject: [PATCH v3 2/2] sched/topology: Sort asym_cap_list in descending order

So that searches always start from biggest CPU which would help misfit
detection logic to be more efficient.

I see the following when adding trace_printks() during add and del
operations

            init-1       [000] .....     0.058128: asym_cpu_capacity_update_data: Added new capacity 250. Capacity list order:
            init-1       [000] .....     0.058132: asym_cpu_capacity_update_data: -- 250
            init-1       [000] .....     0.058135: asym_cpu_capacity_update_data: Added new capacity 620. Capacity list order:
            init-1       [000] .....     0.058136: asym_cpu_capacity_update_data: -- 620
            init-1       [000] .....     0.058137: asym_cpu_capacity_update_data: -- 250
            init-1       [000] .....     0.058139: asym_cpu_capacity_update_data: Added new capacity 1024. Capacity list order:
            init-1       [000] .....     0.058140: asym_cpu_capacity_update_data: -- 1024
            init-1       [000] .....     0.058141: asym_cpu_capacity_update_data: -- 620
            init-1       [000] .....     0.058142: asym_cpu_capacity_update_data: -- 250
            init-1       [000] .....     0.058143: asym_cpu_capacity_scan: Final capacity list order:
            init-1       [000] .....     0.058145: asym_cpu_capacity_scan: -- 1024
            init-1       [000] .....     0.058145: asym_cpu_capacity_scan: -- 620
            init-1       [000] .....     0.058146: asym_cpu_capacity_scan: -- 250
           <...>-244     [007] .....     1.959174: asym_cpu_capacity_update_data: Added new capacity 160. Capacity list order:
           <...>-244     [007] .....     1.959175: asym_cpu_capacity_update_data: -- 1024
           <...>-244     [007] .....     1.959176: asym_cpu_capacity_update_data: -- 620
           <...>-244     [007] .....     1.959176: asym_cpu_capacity_update_data: -- 250
           <...>-244     [007] .....     1.959176: asym_cpu_capacity_update_data: -- 160
           <...>-244     [007] .....     1.959183: asym_cpu_capacity_update_data: Added new capacity 498. Capacity list order:
           <...>-244     [007] .....     1.959184: asym_cpu_capacity_update_data: -- 1024
           <...>-244     [007] .....     1.959184: asym_cpu_capacity_update_data: -- 620
           <...>-244     [007] .....     1.959185: asym_cpu_capacity_update_data: -- 498
           <...>-244     [007] .....     1.959185: asym_cpu_capacity_update_data: -- 250
           <...>-244     [007] .....     1.959186: asym_cpu_capacity_update_data: -- 160
           <...>-244     [007] .....     1.959204: asym_cpu_capacity_scan: Deleted capacity 620
           <...>-244     [007] .....     1.959208: asym_cpu_capacity_scan: Deleted capacity 250
           <...>-244     [007] .....     1.959209: asym_cpu_capacity_scan: Final capacity list order:
           <...>-244     [007] .....     1.959209: asym_cpu_capacity_scan: -- 1024
           <...>-244     [007] .....     1.959210: asym_cpu_capacity_scan: -- 498
           <...>-244     [007] .....     1.959210: asym_cpu_capacity_scan: -- 160
         rcuop/7-66      [001] b....     1.968114: free_asym_cap_entry: Freeing capacity 620
         rcuop/7-66      [001] b....     1.968118: free_asym_cap_entry: Freeing capacity 250

Suggested-by: Pierre Gondois <pierre.gondois@....com>
Signed-off-by: Qais Yousef (Google) <qyousef@...alina.io>
---
 kernel/sched/topology.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index ba4a0b18ae25..1505677e4247 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1384,18 +1384,30 @@ static void free_asym_cap_entry(struct rcu_head *head)
 static inline void asym_cpu_capacity_update_data(int cpu)
 {
 	unsigned long capacity = arch_scale_cpu_capacity(cpu);
-	struct asym_cap_data *entry = NULL;
+	struct asym_cap_data *insert_entry = NULL;
+	struct asym_cap_data *entry;
 
+	/*
+	 * Search if capacity already exits. If not, track which the entry
+	 * where we should insert to keep the list ordered descendingly.
+	 */
 	list_for_each_entry(entry, &asym_cap_list, link) {
 		if (capacity == entry->capacity)
 			goto done;
+		else if (!insert_entry && capacity > entry->capacity)
+			insert_entry = list_prev_entry(entry, link);
 	}
 
 	entry = kzalloc(sizeof(*entry) + cpumask_size(), GFP_KERNEL);
 	if (WARN_ONCE(!entry, "Failed to allocate memory for asymmetry data\n"))
 		return;
 	entry->capacity = capacity;
-	list_add_rcu(&entry->link, &asym_cap_list);
+
+	/* If NULL then the new capacity is the smallest, add last. */
+	if (!insert_entry)
+		list_add_tail_rcu(&entry->link, &asym_cap_list);
+	else
+		list_add_rcu(&entry->link, &insert_entry->link);
 done:
 	__cpumask_set_cpu(cpu, cpu_capacity_span(entry));
 }
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ