[PATCH] sched: resched and cpu_idle rework
[linux-2.6.git] / arch / ppc64 / kernel / idle.c
1 /*
2  * Idle daemon for PowerPC.  Idle daemon will handle any action
3  * that needs to be taken when the system becomes idle.
4  *
5  * Originally Written by Cort Dougan (cort@cs.nmt.edu)
6  *
7  * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com>
8  *
9  * Additional shared processor, SMT, and firmware support
10  *    Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version
15  * 2 of the License, or (at your option) any later version.
16  */
17
18 #include <linux/config.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/smp.h>
22 #include <linux/cpu.h>
23 #include <linux/sysctl.h>
24
25 #include <asm/system.h>
26 #include <asm/processor.h>
27 #include <asm/cputable.h>
28 #include <asm/time.h>
29 #include <asm/systemcfg.h>
30 #include <asm/machdep.h>
31 #include <asm/smp.h>
32
33 extern void power4_idle(void);
34
35 void default_idle(void)
36 {
37         unsigned int cpu = smp_processor_id();
38         set_thread_flag(TIF_POLLING_NRFLAG);
39
40         while (1) {
41                 if (!need_resched()) {
42                         while (!need_resched() && !cpu_is_offline(cpu)) {
43                                 ppc64_runlatch_off();
44
45                                 /*
46                                  * Go into low thread priority and possibly
47                                  * low power mode.
48                                  */
49                                 HMT_low();
50                                 HMT_very_low();
51                         }
52
53                         HMT_medium();
54                 }
55
56                 ppc64_runlatch_on();
57                 preempt_enable_no_resched();
58                 schedule();
59                 preempt_disable();
60                 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
61                         cpu_die();
62         }
63 }
64
65 void native_idle(void)
66 {
67         while (1) {
68                 ppc64_runlatch_off();
69
70                 if (!need_resched())
71                         power4_idle();
72
73                 if (need_resched()) {
74                         ppc64_runlatch_on();
75                         preempt_enable_no_resched();
76                         schedule();
77                         preempt_disable();
78                 }
79
80                 if (cpu_is_offline(smp_processor_id()) &&
81                     system_state == SYSTEM_RUNNING)
82                         cpu_die();
83         }
84 }
85
86 void cpu_idle(void)
87 {
88         BUG_ON(NULL == ppc_md.idle_loop);
89         ppc_md.idle_loop();
90 }
91
92 int powersave_nap;
93
94 #ifdef CONFIG_SYSCTL
95 /*
96  * Register the sysctl to set/clear powersave_nap.
97  */
98 static ctl_table powersave_nap_ctl_table[]={
99         {
100                 .ctl_name       = KERN_PPC_POWERSAVE_NAP,
101                 .procname       = "powersave-nap",
102                 .data           = &powersave_nap,
103                 .maxlen         = sizeof(int),
104                 .mode           = 0644,
105                 .proc_handler   = &proc_dointvec,
106         },
107         { 0, },
108 };
109 static ctl_table powersave_nap_sysctl_root[] = {
110         { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
111         { 0,},
112 };
113
114 static int __init
115 register_powersave_nap_sysctl(void)
116 {
117         register_sysctl_table(powersave_nap_sysctl_root, 0);
118
119         return 0;
120 }
121 __initcall(register_powersave_nap_sysctl);
122 #endif