From: David Howells <dhowells@redhat.com>
To: oleg@redhat.com, linux-arch@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>
Subject: [PATCH 3/3] Make get_current() __attribute__((const))
Date: Tue, 18 May 2010 17:45:47 +0100 [thread overview]
Message-ID: <20100518164547.6194.94193.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20100518164537.6194.73366.stgit@warthog.procyon.org.uk>
get_current() can be made __attribute__((const)) as it's not allowed to change
under you, except in switch_to() (it's fine to violate the constness there
since this switches stacks too, and will almost certainly do this in assembly
code). This allows the compiler more choices about when it can cache this
pointer.
This doesn't break cached copies of current, whether they're cached by gcc in
registers or on the stack. switch_to() will save all registers on the stack
before actually switching, then when it switches current, it will also switch
the stack and then pop back what was stored in the 'unclobbered' registers for
the now active task and stack. Thus the copies of current that were cached
just work.
Note that does not affect all arches under all circumstances. Some arches, at
least some of the time, keep current in a register, and some use thread_info as
the source of current.
This has been the norm on ARM and MN10300 arches (the latter only when not
using E2 to hold current) for a while now. I've also tested this on x86_64.
Signed-off-by: David Howells <dhowells@redhat.com>
---
arch/powerpc/include/asm/current.h | 3 ++-
arch/x86/include/asm/current.h | 3 ++-
include/asm-generic/current.h | 9 ++++++++-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/current.h b/arch/powerpc/include/asm/current.h
index 4ca5126..affcbbe 100644
--- a/arch/powerpc/include/asm/current.h
+++ b/arch/powerpc/include/asm/current.h
@@ -15,7 +15,8 @@ struct task_struct;
#include <linux/stddef.h>
#include <asm/paca.h>
-static inline struct task_struct *get_current(void)
+static inline __attribute_const__
+struct task_struct *get_current(void)
{
struct task_struct *task;
diff --git a/arch/x86/include/asm/current.h b/arch/x86/include/asm/current.h
index 4d447b7..defb13c 100644
--- a/arch/x86/include/asm/current.h
+++ b/arch/x86/include/asm/current.h
@@ -9,7 +9,8 @@ struct task_struct;
DECLARE_PER_CPU(struct task_struct *, current_task);
-static __always_inline struct task_struct *get_current(void)
+static __always_inline __attribute_const__
+struct task_struct *get_current(void)
{
return percpu_read_stable(current_task);
}
diff --git a/include/asm-generic/current.h b/include/asm-generic/current.h
index 5e86f6a..8deb67e 100644
--- a/include/asm-generic/current.h
+++ b/include/asm-generic/current.h
@@ -3,7 +3,14 @@
#include <linux/thread_info.h>
-#define get_current() (current_thread_info()->task)
+struct task_struct;
+
+static inline __attribute_const__
+struct task_struct *get_current(void)
+{
+ return current_thread_info()->task;
+}
+
#define current get_current()
#endif /* __ASM_GENERIC_CURRENT_H */
next prev parent reply other threads:[~2010-05-18 17:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-18 16:45 [PATCH 1/3] Reduce get_current() to the asm-generic implementation where possible David Howells
2010-05-18 16:45 ` [PATCH 2/3] Mark the 'current' pointer register read-only when such a thing exists David Howells
2010-05-18 21:05 ` David Miller
2010-05-18 16:45 ` David Howells [this message]
2010-05-18 21:22 ` schedule() && prev/current (Was: [PATCH 3/3] Make get_current() __attribute__((const))) Oleg Nesterov
2010-05-19 6:21 ` Peter Zijlstra
2010-05-19 10:27 ` Oleg Nesterov
2010-05-19 10:37 ` Peter Zijlstra
2010-05-19 12:57 ` [PATCH] schedule: simplify the reacquire_kernel_lock() logic Oleg Nesterov
2010-05-19 12:57 ` Oleg Nesterov
2010-05-19 13:11 ` Yong Zhang
2010-05-19 13:07 ` schedule() && prev/current (Was: [PATCH 3/3] Make get_current() __attribute__((const))) Yong Zhang
2010-05-19 13:07 ` Yong Zhang
2010-05-18 17:39 ` [PATCH 1/3] Reduce get_current() to the asm-generic implementation where possible Kyle McMartin
2010-05-18 19:47 ` Jamie Lokier
2010-05-19 6:21 ` Nick Piggin
2010-05-19 11:02 ` Oleg Nesterov
2010-05-21 10:13 ` David Howells
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=20100518164547.6194.94193.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linux-arch@vger.kernel.org \
--cc=oleg@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).