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>] [day] [month] [year] [list]
Message-Id: <20250215172711.1767546-1-visitorckw@gmail.com>
Date: Sun, 16 Feb 2025 01:27:11 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: mingo@...hat.com,
	peterz@...radead.org,
	juri.lelli@...hat.com,
	vincent.guittot@...aro.org
Cc: dietmar.eggemann@....com,
	rostedt@...dmis.org,
	bsegall@...gle.com,
	mgorman@...e.de,
	vschneid@...hat.com,
	yury.norov@...il.com,
	jserv@...s.ncku.edu.tw,
	linux-kernel@...r.kernel.org,
	Kuan-Wei Chiu <visitorckw@...il.com>
Subject: [PATCH v2] sched/topology: Optimize sched_numa_find_nth_cpu() by inlining bsearch()

When CONFIG_MITIGATION_RETPOLINE is enabled, indirect function calls
become costly. Replacing bsearch() with an inline version of the binary
search reduces the overhead of indirect function calls, improving
efficiency. This change also results in a reduction of the code size by
91 bytes on x86-64 systems.

$ ./scripts/bloat-o-meter ./build_utility.o.old ./build_utility.o.new
add/remove: 0/1 grow/shrink: 1/0 up/down: 19/-110 (-91)
Function                                     old     new   delta
sched_numa_find_nth_cpu                      442     461     +19
hop_cmp                                      110       -    -110
Total: Before=46675, After=46584, chg -0.19%

Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
---
Changes in v2:
Use bloat-o-meter to measure code size impact.

v1: https://lore.kernel.org/lkml/20241205162336.1675428-1-visitorckw@gmail.com/

 kernel/sched/topology.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index c49aea8c1025..3ba1476a97de 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2171,7 +2171,8 @@ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node)
 	if (!k.masks)
 		goto unlock;
 
-	hop_masks = bsearch(&k, k.masks, sched_domains_numa_levels, sizeof(k.masks[0]), hop_cmp);
+	hop_masks = __inline_bsearch(&k, k.masks, sched_domains_numa_levels, sizeof(k.masks[0]),
+				     hop_cmp);
 	hop = hop_masks	- k.masks;
 
 	ret = hop ?
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ