Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 | 23 | #include <linux/sysctl.h> |
1da177e4 LT |
24 | |
25 | #include <asm/system.h> | |
26 | #include <asm/processor.h> | |
1da177e4 LT |
27 | #include <asm/cputable.h> |
28 | #include <asm/time.h> | |
fd899c0c | 29 | #include <asm/machdep.h> |
2249ca9d | 30 | #include <asm/smp.h> |
1da177e4 LT |
31 | |
32 | extern void power4_idle(void); | |
33 | ||
143a1dec | 34 | void default_idle(void) |
1da177e4 | 35 | { |
1da177e4 | 36 | unsigned int cpu = smp_processor_id(); |
64c7c8f8 | 37 | set_thread_flag(TIF_POLLING_NRFLAG); |
1da177e4 LT |
38 | |
39 | while (1) { | |
64c7c8f8 | 40 | if (!need_resched()) { |
1da177e4 | 41 | while (!need_resched() && !cpu_is_offline(cpu)) { |
45e75dfb AB |
42 | ppc64_runlatch_off(); |
43 | ||
1da177e4 LT |
44 | /* |
45 | * Go into low thread priority and possibly | |
46 | * low power mode. | |
47 | */ | |
48 | HMT_low(); | |
49 | HMT_very_low(); | |
50 | } | |
51 | ||
52 | HMT_medium(); | |
1da177e4 LT |
53 | } |
54 | ||
45e75dfb | 55 | ppc64_runlatch_on(); |
5bfb5d69 | 56 | preempt_enable_no_resched(); |
1da177e4 | 57 | schedule(); |
5bfb5d69 | 58 | preempt_disable(); |
1da177e4 LT |
59 | if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING) |
60 | cpu_die(); | |
61 | } | |
1da177e4 LT |
62 | } |
63 | ||
143a1dec | 64 | void native_idle(void) |
1da177e4 | 65 | { |
45e75dfb AB |
66 | while (1) { |
67 | ppc64_runlatch_off(); | |
68 | ||
1da177e4 LT |
69 | if (!need_resched()) |
70 | power4_idle(); | |
45e75dfb AB |
71 | |
72 | if (need_resched()) { | |
73 | ppc64_runlatch_on(); | |
5bfb5d69 | 74 | preempt_enable_no_resched(); |
1da177e4 | 75 | schedule(); |
5bfb5d69 | 76 | preempt_disable(); |
45e75dfb | 77 | } |
1da177e4 | 78 | |
45e75dfb | 79 | if (cpu_is_offline(smp_processor_id()) && |
1da177e4 LT |
80 | system_state == SYSTEM_RUNNING) |
81 | cpu_die(); | |
82 | } | |
1da177e4 LT |
83 | } |
84 | ||
1da177e4 LT |
85 | void cpu_idle(void) |
86 | { | |
fd899c0c ME |
87 | BUG_ON(NULL == ppc_md.idle_loop); |
88 | ppc_md.idle_loop(); | |
1da177e4 LT |
89 | } |
90 | ||
91 | int powersave_nap; | |
92 | ||
93 | #ifdef CONFIG_SYSCTL | |
94 | /* | |
95 | * Register the sysctl to set/clear powersave_nap. | |
96 | */ | |
97 | static ctl_table powersave_nap_ctl_table[]={ | |
98 | { | |
99 | .ctl_name = KERN_PPC_POWERSAVE_NAP, | |
100 | .procname = "powersave-nap", | |
101 | .data = &powersave_nap, | |
102 | .maxlen = sizeof(int), | |
103 | .mode = 0644, | |
104 | .proc_handler = &proc_dointvec, | |
105 | }, | |
106 | { 0, }, | |
107 | }; | |
108 | static ctl_table powersave_nap_sysctl_root[] = { | |
109 | { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, }, | |
110 | { 0,}, | |
111 | }; | |
112 | ||
113 | static int __init | |
114 | register_powersave_nap_sysctl(void) | |
115 | { | |
116 | register_sysctl_table(powersave_nap_sysctl_root, 0); | |
117 | ||
118 | return 0; | |
119 | } | |
120 | __initcall(register_powersave_nap_sysctl); | |
121 | #endif |