From: Jeremy Fitzhardinge <jeremy@goop.org>
To: linux-kernel@vger.kernel.org
Cc: Chuck Ebbert <76306.1226@compuserve.com>,
Zachary Amsden <zach@vmware.com>,
Jan Beulich <jbeulich@novell.com>, Andi Kleen <ak@suse.de>,
Andrew Morton <akpm@osdl.org>
Subject: [PATCH 8/8] Implement "current" with the PDA.
Date: Thu, 31 Aug 2006 23:47:26 -0700 [thread overview]
Message-ID: <20060901064826.569268356@goop.org> (raw)
In-Reply-To: 20060901064718.918494029@goop.org
[-- Attachment #1: i386-pda-current.patch --]
[-- Type: text/plain, Size: 4105 bytes --]
Use the pcurrent field in the PDA to implement the "current" macro.
This ends up compiling down to a single instruction to get the current
task.
This keeps the original definition of "get_current()" with the name
"early_current()", for use before the PDA has been set up. On the
boot CPU, "current" will always work, but on secondary CPUs, it needs
the PDA to be explicitly set up first.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
---
arch/i386/kernel/cpu/common.c | 19 ++++++++++++-------
arch/i386/kernel/smpboot.c | 4 +++-
include/asm-i386/current.h | 10 ++++++++--
3 files changed, 23 insertions(+), 10 deletions(-)
===================================================================
--- a/arch/i386/kernel/cpu/common.c
+++ b/arch/i386/kernel/cpu/common.c
@@ -665,7 +665,7 @@ static __cpuinit void init_gdt(void)
static __cpuinit void init_gdt(void)
{
int cpu = early_smp_processor_id();
- struct task_struct *curr = current;
+ struct task_struct *curr = early_current();
struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, cpu);
__u32 stk16_off = (__u32)&per_cpu(cpu_16bit_stack, cpu);
struct desc_struct *gdt;
@@ -709,15 +709,18 @@ static __cpuinit void init_gdt(void)
pda_init(cpu, curr);
}
-/* Set up a very early PDA for the boot CPU so that smp_processor_id will work */
+/* Set up a very early PDA for the boot CPU so that smp_processor_id()
+ and current will work. */
void __init smp_setup_processor_id(void)
{
- static const __initdata struct i386_pda boot_pda;
+ static __initdata struct i386_pda boot_pda;
pack_descriptor((u32 *)&cpu_gdt_table[GDT_ENTRY_PDA].a,
(u32 *)&cpu_gdt_table[GDT_ENTRY_PDA].b,
(unsigned long)&boot_pda, sizeof(struct i386_pda) - 1,
0x80 | DESCTYPE_S | 0x2, 0); /* present read-write data segment */
+
+ boot_pda.pcurrent = early_current();
/* Set %gs for this CPU's PDA */
set_kernel_gs();
@@ -732,8 +735,10 @@ void __cpuinit cpu_init(void)
void __cpuinit cpu_init(void)
{
int cpu = early_smp_processor_id();
+ struct task_struct *curr = early_current();
+
struct tss_struct * t = &per_cpu(init_tss, cpu);
- struct thread_struct *thread = ¤t->thread;
+ struct thread_struct *thread = &curr->thread;
if (cpu_test_and_set(cpu, cpu_initialized)) {
printk(KERN_WARNING "CPU#%d already initialized!\n", cpu);
@@ -761,10 +766,10 @@ void __cpuinit cpu_init(void)
* Set up and load the per-CPU TSS and LDT
*/
atomic_inc(&init_mm.mm_count);
- current->active_mm = &init_mm;
- if (current->mm)
+ curr->active_mm = &init_mm;
+ if (curr->mm)
BUG();
- enter_lazy_tlb(&init_mm, current);
+ enter_lazy_tlb(&init_mm, curr);
load_esp0(t, thread);
set_tss_desc(cpu,t);
===================================================================
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -590,6 +590,8 @@ static void __devinit start_secondary(vo
*/
void __devinit initialize_secondary(void)
{
+ struct task_struct *curr = early_current();
+
/*
* We don't actually need to load the full TSS,
* basically just the stack pointer and the eip.
@@ -599,7 +601,7 @@ void __devinit initialize_secondary(void
"movl %0,%%esp\n\t"
"jmp *%1"
:
- :"r" (current->thread.esp),"r" (current->thread.eip));
+ :"r" (curr->thread.esp),"r" (curr->thread.eip));
}
extern struct {
===================================================================
--- a/include/asm-i386/current.h
+++ b/include/asm-i386/current.h
@@ -2,14 +2,20 @@
#define _I386_CURRENT_H
#include <linux/thread_info.h>
+#include <asm/pda.h>
struct task_struct;
-static __always_inline struct task_struct * get_current(void)
+static __always_inline struct task_struct *early_current(void)
{
return current_thread_info()->task;
}
-
+
+static __always_inline struct task_struct *get_current(void)
+{
+ return read_pda(pcurrent);
+}
+
#define current get_current()
#endif /* !(_I386_CURRENT_H) */
--
next prev parent reply other threads:[~2006-09-01 6:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-01 6:47 [PATCH 0/8] Implement per-processor data areas for i386 Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 1/8] Use asm-offsets for the offsets of registers into the pt_regs struct, rather than having hard-coded constants Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 2/8] Basic definitions for i386-pda Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 3/8] Initialize the per-CPU data area Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 4/8] Use %gs as the PDA base-segment in the kernel Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 5/8] Fix places where using %gs changes the usermode ABI Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 6/8] Update sys_vm86 to cope with changed pt_regs and %gs usage Jeremy Fitzhardinge
2006-09-01 6:47 ` [PATCH 7/8] Implement smp_processor_id() with the PDA Jeremy Fitzhardinge
2006-09-01 6:47 ` Jeremy Fitzhardinge [this message]
2006-09-01 8:16 ` [PATCH 0/8] Implement per-processor data areas for i386 Andi Kleen
2006-09-01 8:26 ` Jeremy Fitzhardinge
2006-09-01 8:30 ` Andi Kleen
2006-09-01 19:08 ` Jeremy Fitzhardinge
-- strict thread matches above, loose matches on Subject: below --
2006-08-30 23:52 Jeremy Fitzhardinge
2006-08-30 23:52 ` [PATCH 8/8] Implement "current" with the PDA Jeremy Fitzhardinge
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=20060901064826.569268356@goop.org \
--to=jeremy@goop.org \
--cc=76306.1226@compuserve.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=jbeulich@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=zach@vmware.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