From: Rusty Russell <rusty@rustcorp.com.au>
To: Andi Kleen <ak@muc.de>
Cc: lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>,
virtualization <virtualization@lists.osdl.org>,
Jeremy Fitzhardinge <jeremy@goop.org>
Subject: [PATCH 7/7] (Optional) implement current as a per-cpu var
Date: Fri, 22 Sep 2006 22:01:42 +1000 [thread overview]
Message-ID: <1158926502.26261.20.camel@localhost.localdomain> (raw)
In-Reply-To: <1158926451.26261.18.camel@localhost.localdomain>
This implements current as a per-cpu variable. The generic code
expects it in thread_info still, so I don't remove it from there, but
reducing current from 9 bytes/3 insns to 6 bytes/1 insn is a nice
micro-optimization.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Index: ak-fresh/arch/i386/kernel/setup.c
===================================================================
--- ak-fresh.orig/arch/i386/kernel/setup.c 2006-09-22 17:03:49.000000000 +1000
+++ ak-fresh/arch/i386/kernel/setup.c 2006-09-22 17:04:29.000000000 +1000
@@ -148,6 +148,9 @@
unsigned char __initdata boot_params[PARAM_SIZE];
+DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
+EXPORT_PER_CPU_SYMBOL(current_task);
+
static struct resource data_resource = {
.name = "Kernel data",
.start = 0,
Index: ak-fresh/arch/i386/kernel/smpboot.c
===================================================================
--- ak-fresh.orig/arch/i386/kernel/smpboot.c 2006-09-22 17:04:18.000000000 +1000
+++ ak-fresh/arch/i386/kernel/smpboot.c 2006-09-22 17:04:29.000000000 +1000
@@ -598,12 +598,13 @@
* We don't actually need to load the full TSS,
* basically just the stack pointer and the eip.
*/
-
+ /* Can't use current until setup_percpu_for_this_cpu */
asm volatile(
"movl %0,%%esp\n\t"
"jmp *%1"
:
- :"r" (current->thread.esp),"r" (current->thread.eip));
+ :"r" (current_thread_info()->task->thread.esp),
+ "r" (current_thread_info()->task->thread.eip));
}
extern struct {
@@ -946,6 +947,8 @@
if (IS_ERR(idle))
panic("failed fork for CPU %d", cpu);
idle->thread.eip = (unsigned long) start_secondary;
+ per_cpu(current_task, cpu) = idle;
+
/* start_eip had better be page-aligned! */
start_eip = setup_trampoline();
Index: ak-fresh/include/asm-i386/current.h
===================================================================
--- ak-fresh.orig/include/asm-i386/current.h 2006-09-22 17:02:46.000000000 +1000
+++ ak-fresh/include/asm-i386/current.h 2006-09-22 17:04:29.000000000 +1000
@@ -1,15 +1,10 @@
#ifndef _I386_CURRENT_H
#define _I386_CURRENT_H
+#include <asm/percpu.h>
#include <linux/thread_info.h>
-struct task_struct;
-
-static __always_inline struct task_struct * get_current(void)
-{
- return current_thread_info()->task;
-}
-
-#define current get_current()
+DECLARE_PER_CPU(struct task_struct *, current_task);
+#define current x86_read_percpu(current_task)
#endif /* !(_I386_CURRENT_H) */
Index: ak-fresh/arch/i386/kernel/process.c
===================================================================
--- ak-fresh.orig/arch/i386/kernel/process.c 2006-09-22 17:02:46.000000000 +1000
+++ ak-fresh/arch/i386/kernel/process.c 2006-09-22 17:04:30.000000000 +1000
@@ -669,6 +669,7 @@
if (unlikely(prev->fs | next->fs))
loadsegment(fs, next->fs);
+ x86_write_percpu(current_task, next_p);
/*
* Restore IOPL if needed.
Index: ak-fresh/arch/i386/kernel/cpu/common.c
===================================================================
--- ak-fresh.orig/arch/i386/kernel/cpu/common.c 2006-09-22 17:04:18.000000000 +1000
+++ ak-fresh/arch/i386/kernel/cpu/common.c 2006-09-22 17:05:25.000000000 +1000
@@ -597,9 +597,10 @@
*/
void __cpuinit cpu_init(void)
{
- unsigned int cpu = current->thread_info->cpu;
+ /* Careful: can't use current() or smp_processor_id() yet! */
+ unsigned int cpu = current_thread_info()->cpu;
struct tss_struct * t = &per_cpu(init_tss, cpu);
- struct thread_struct *thread = ¤t->thread;
+ struct thread_struct *thread = &per_cpu(current_task, cpu)->thread;
struct desc_struct *gdt;
__u32 stk16_off = (__u32)&per_cpu(cpu_16bit_stack, cpu);
--
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law
next prev parent reply other threads:[~2006-09-22 12:01 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-22 11:51 [PATCH 0/7] Using %gs for per-cpu areas on x86 Rusty Russell
2006-09-22 11:53 ` [PATCH 1/7] Use per-cpu GDT tables from early in boot Rusty Russell
2006-09-22 11:55 ` [PATCH 2/7] Rusty Russell
2006-09-22 11:56 ` [PATCH 3/7] Update sys_vm86 to cope with changed pt_regs and %gs usage Rusty Russell
2006-09-22 11:58 ` [PATCH 4/7] Fix places where using %gs changes the usermode ABI Rusty Russell
2006-09-22 11:59 ` [PATCH 5/7] Use %gs for per-cpu sections in kernel Rusty Russell
2006-09-22 12:00 ` [PATCH 6/7] (Optional) implement smp_processor_id() as a per-cpu var Rusty Russell
2006-09-22 12:01 ` Rusty Russell [this message]
2006-09-25 5:29 ` [PATCH 7/7] (Optional) implement current " Rusty Russell
2006-09-25 5:27 ` [PATCH 6/7] (Optional) implement smp_processor_id() " Rusty Russell
2006-09-22 12:32 ` [PATCH 5/7] Use %gs for per-cpu sections in kernel Andi Kleen
2006-09-22 22:43 ` Jeremy Fitzhardinge
2006-09-22 23:52 ` Andi Kleen
2006-09-23 4:51 ` Rusty Russell
2006-09-23 8:17 ` Andi Kleen
2006-09-23 8:55 ` Rusty Russell
2006-09-22 22:39 ` Jeremy Fitzhardinge
2006-09-23 4:31 ` Rusty Russell
2006-09-25 1:03 ` Jeremy Fitzhardinge
2006-09-25 1:16 ` Rusty Russell
2006-09-25 1:36 ` Jeremy Fitzhardinge
2006-09-25 2:51 ` Rusty Russell
2006-09-25 5:25 ` Jeremy Fitzhardinge
2006-09-25 6:03 ` Rusty Russell
2006-09-25 6:25 ` Jeremy Fitzhardinge
2006-09-25 23:33 ` Rusty Russell
2006-09-23 8:13 ` Andi Kleen
2006-09-25 1:07 ` Jeremy Fitzhardinge
2006-09-25 1:20 ` Rusty Russell
2006-09-25 5:26 ` Rusty Russell
2006-09-22 22:24 ` [PATCH 2/7] Jeremy Fitzhardinge
2006-09-23 4:36 ` Rusty Russell
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=1158926502.26261.20.camel@localhost.localdomain \
--to=rusty@rustcorp.com.au \
--cc=ak@muc.de \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.osdl.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;
as well as URLs for NNTP newsgroup(s).