diff -urNp o1-ref/include/linux/sched.h o1/include/linux/sched.h --- o1-ref/include/linux/sched.h Tue Jul 30 01:46:42 2002 +++ o1/include/linux/sched.h Tue Jul 30 03:13:05 2002 @@ -145,6 +145,7 @@ typedef struct task_struct task_t; extern void sched_init(void); extern void init_idle(task_t *idle, int cpu); +extern int idle_cpu(int cpu); extern void show_state(void); extern void cpu_init (void); extern void trap_init(void); diff -urNp o1-ref/kernel/sched.c o1/kernel/sched.c --- o1-ref/kernel/sched.c Tue Jul 30 01:46:43 2002 +++ o1/kernel/sched.c Tue Jul 30 03:19:53 2002 @@ -473,6 +473,11 @@ unsigned long nr_context_switches(void) return sum; } +inline int idle_cpu(int cpu) +{ + return cpu_curr(cpu) == cpu_rq(cpu)->idle; +} + #if CONFIG_SMP /* * Lock the busiest runqueue as well, this_rq is locked already. @@ -516,6 +521,29 @@ static inline void pull_task(runqueue_t set_need_resched(); } +#ifdef __i386__ +/* + * Find any idle processor package (i.e. both virtual processors are idle) + */ +static inline int find_idle_package(int this_cpu) +{ + int i; + + this_cpu = cpu_number_map(this_cpu); + + for (i = (this_cpu + 1) % smp_num_cpus; + i != this_cpu; + i = (i + 1) % smp_num_cpus) { + int physical = cpu_logical_map(i); + int sibling = cpu_sibling_map[physical]; + + if (idle_cpu(physical) && idle_cpu(sibling)) + return physical; + } + return -1; /* not found */ +} +#endif + /* * Current runqueue is empty, or rebalance tick: if there is an * inbalance (current runqueue is too short) then pull from @@ -533,6 +561,20 @@ static void load_balance(runqueue_t *thi prio_array_t *array; list_t *head, *curr; +#if defined(__i386__) + /* Special hack for hyperthreading */ + if (unlikely(smp_num_siblings > 1) && idle && !idle_cpu(cpu_sibling_map[this_cpu])) { + int found; + runqueue_t *rq_target; + + if ((found = find_idle_package(this_cpu)) >= 0 ) { + rq_target = cpu_rq(found); + resched_task(rq_target->idle); + return; + } + } +#endif + /* * We search all runqueues to find the most busy one. * We do this lockless to reduce cache-bouncing overhead, @@ -1098,11 +1140,6 @@ int task_nice(task_t *p) return TASK_NICE(p); } -int idle_cpu(int cpu) -{ - return cpu_curr(cpu) == cpu_rq(cpu)->idle; -} - static inline task_t *find_process_by_pid(pid_t pid) { return pid ? find_task_by_pid(pid) : current;