Re: [PATCH 7/7] (Optional) implement current as a per-cpu var

From: Rusty Russell
Date: Mon Sep 25 2006 - 01:29:26 EST


On Fri, 2006-09-22 at 22:01 +1000, Rusty Russell wrote:
> This implements current as a per-cpu variable.

Again, revised for updated 5/7: we no longer need to avoid using current
early on.

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@xxxxxxxxxxxxxxx>

Index: ak-fresh/arch/i386/kernel/setup.c
===================================================================
--- ak-fresh.orig/arch/i386/kernel/setup.c 2006-09-25 15:02:33.000000000 +1000
+++ ak-fresh/arch/i386/kernel/setup.c 2006-09-25 15:06:31.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-25 15:02:51.000000000 +1000
+++ ak-fresh/arch/i386/kernel/smpboot.c 2006-09-25 15:06:31.000000000 +1000
@@ -972,6 +972,7 @@
if (IS_ERR(idle))
panic("failed fork for CPU %d", cpu);
idle->thread.eip = (unsigned long) start_secondary;
+ per_cpu(current_task, cpu) = idle;

setup_percpu(cpu);
booting_cpu_gdt_desc_ptr = &per_cpu(cpu_gdt_descr, cpu);
Index: ak-fresh/include/asm-i386/current.h
===================================================================
--- ak-fresh.orig/include/asm-i386/current.h 2006-09-25 15:02:33.000000000 +1000
+++ ak-fresh/include/asm-i386/current.h 2006-09-25 15:06:31.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-25 15:02:33.000000000 +1000
+++ ak-fresh/arch/i386/kernel/process.c 2006-09-25 15:06:31.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.

--
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law

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