From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Andi Kleen <ak@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [RFC] init.h: mark init functions hot instead of cold
Date: Sat, 9 May 2015 00:45:01 +0200 [thread overview]
Message-ID: <1431125101-16273-1-git-send-email-linux@rasmusvillemoes.dk> (raw)
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@rasmusvillemoes.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
next reply other threads:[~2015-05-08 22:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 22:45 Rasmus Villemoes [this message]
2015-05-09 9:17 ` Andi Kleen
2015-05-09 21:17 ` Josh Triplett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431125101-16273-1-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®