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-next>] [day] [month] [year] [list]
Message-Id: <1431125101-16273-1-git-send-email-linux@rasmusvillemoes.dk>
Date:	Sat,  9 May 2015 00:45:01 +0200
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	Ingo Molnar <mingo@...nel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Andi Kleen <ak@...ux.intel.com>
Cc:	linux-kernel@...r.kernel.org,
	Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [RFC] init.h: mark init functions hot instead of cold

attribute((cold)) causes gcc to optimize the function for size rather
than speed. But since __init functions will be discarded anyway, I
don't see why memory should be a concern. On the contrary, everybody
wants their box to boot faster. Using the opposite attribute, hot,
causes gcc to optimize the functions more aggressively, possibly at
the expense of larger (.init).text. A completely unscientific test
showed about 2% faster boot time: I booted a kernel in qemu with and
without this patch five times each; the boot times were very stable in
each case, so I think the 2% is ok, but of course only applies to that
specific .config running in a virtual machine on my hardware.

__cold also means any path to a call of such a function is treated as
unlikely, while __hot means the opposite. For intra-__init calls, I
don't think that matters. That leaves calls from __ref functions to
__init functions. While I also think it doesn't matter in that case,
I'm sure someone can tell me why I'm wrong.

Signed-off-by: Rasmus Villemoes <linux@...musvillemoes.dk>
---
 include/linux/compiler-gcc4.h | 6 ++----
 include/linux/compiler.h      | 8 ++++++++
 include/linux/init.h          | 2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
index 769e19864632..b5e5c96d538e 100644
--- a/include/linux/compiler-gcc4.h
+++ b/include/linux/compiler-gcc4.h
@@ -27,11 +27,9 @@
    Early snapshots of gcc 4.3 don't support this and we can't detect this
    in the preprocessor, but we can live with this because they're unreleased.
    Maketime probing would be overkill here.
-
-   gcc also has a __attribute__((__hot__)) to move hot functions into
-   a special section, but I don't see any sense in this right now in
-   the kernel context */
+ */
 #define __cold			__attribute__((__cold__))
+#define __hot			__attribute__((__hot__))
 
 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
 
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 0e41ca0e5927..50dbdc8d570d 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -357,6 +357,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 #define __cold
 #endif
 
+/*
+ * The opposite of __cold: Tell the compiler to optimize the function
+ * more aggressively, and treat paths leading to a call as likely.
+ */
+#ifndef __hot
+#define __hot
+#endif
+
 /* Simple shorthand for a section definition */
 #ifndef __section
 # define __section(S) __attribute__ ((__section__(#S)))
diff --git a/include/linux/init.h b/include/linux/init.h
index 21b6d768edd7..b6153a612ea0 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -39,7 +39,7 @@
 
 /* These are for everybody (although not all archs will actually
    discard it in modules) */
-#define __init		__section(.init.text) __cold notrace
+#define __init		__section(.init.text) __hot notrace
 #define __initdata	__section(.init.data)
 #define __initconst	__constsection(.init.rodata)
 #define __exitdata	__section(.exit.data)
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ