Name: Make current an attribute pure function Author: Rusty Russell Status: Experimental "current" can be considered constant in all cases it is used except in schedule where it actually changes. Can we convince gcc to generate better code? Index: linux-2.6.10-rc2-bk9-Misc/include/asm-i386/current.h =================================================================== --- linux-2.6.10-rc2-bk9-Misc.orig/include/asm-i386/current.h 2003-09-21 17:34:17.000000000 +1000 +++ linux-2.6.10-rc2-bk9-Misc/include/asm-i386/current.h 2004-11-26 14:28:32.990386064 +1100 @@ -5,10 +5,7 @@ struct task_struct; -static inline struct task_struct * get_current(void) -{ - return current_thread_info()->task; -} +struct task_struct *get_current(void) __attribute__((pure)); #define current get_current() Index: linux-2.6.10-rc2-bk9-Misc/kernel/sched.c =================================================================== --- linux-2.6.10-rc2-bk9-Misc.orig/kernel/sched.c 2004-11-26 11:48:28.000000000 +1100 +++ linux-2.6.10-rc2-bk9-Misc/kernel/sched.c 2004-11-26 14:30:16.041719880 +1100 @@ -2292,7 +2292,6 @@ void scheduler_tick(int user_ticks, int sys_ticks) { int cpu = smp_processor_id(); - struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; runqueue_t *rq = this_rq(); task_t *p = current; @@ -2303,28 +2302,28 @@ /* note: this timer irq context must be accounted for as well */ if (hardirq_count() - HARDIRQ_OFFSET) { - cpustat->irq += sys_ticks; + kstat_this_cpu.cpustat.irq += sys_ticks; sys_ticks = 0; } else if (softirq_count()) { - cpustat->softirq += sys_ticks; + kstat_this_cpu.cpustat.softirq += sys_ticks; sys_ticks = 0; } if (p == rq->idle) { if (atomic_read(&rq->nr_iowait) > 0) - cpustat->iowait += sys_ticks; + kstat_this_cpu.cpustat.iowait += sys_ticks; else - cpustat->idle += sys_ticks; + kstat_this_cpu.cpustat.idle += sys_ticks; if (wake_priority_sleeper(rq)) goto out; rebalance_tick(cpu, rq, SCHED_IDLE); return; } if (TASK_NICE(p) > 0) - cpustat->nice += user_ticks; + kstat_this_cpu.cpustat.nice += user_ticks; else - cpustat->user += user_ticks; - cpustat->system += sys_ticks; + kstat_this_cpu.cpustat.user += user_ticks; + kstat_this_cpu.cpustat.system += sys_ticks; /* Task might have expired already, but not scheduled off yet */ if (p->array != rq->active) { Index: linux-2.6.10-rc2-bk9-Misc/arch/i386/kernel/process.c =================================================================== --- linux-2.6.10-rc2-bk9-Misc.orig/arch/i386/kernel/process.c 2004-11-16 15:29:02.000000000 +1100 +++ linux-2.6.10-rc2-bk9-Misc/arch/i386/kernel/process.c 2004-11-26 14:28:32.990386064 +1100 @@ -810,3 +810,7 @@ return 0; } +struct task_struct *get_current(void) +{ + return current_thread_info()->task; +}