blob: 8abd2ad928325e3cc29876859cddae39577d7542 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/sysctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/system.h>
26#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/cputable.h>
28#include <asm/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/systemcfg.h>
Michael Ellermanfd899c02005-07-07 17:56:28 -070030#include <asm/machdep.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32extern void power4_idle(void);
33
Paul Mackerras143a1de2005-10-19 23:11:21 +100034void default_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
36 long oldval;
37 unsigned int cpu = smp_processor_id();
38
39 while (1) {
40 oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
41
42 if (!oldval) {
43 set_thread_flag(TIF_POLLING_NRFLAG);
44
45 while (!need_resched() && !cpu_is_offline(cpu)) {
Anton Blanchard45e75df2005-07-07 17:56:33 -070046 ppc64_runlatch_off();
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 /*
49 * Go into low thread priority and possibly
50 * low power mode.
51 */
52 HMT_low();
53 HMT_very_low();
54 }
55
56 HMT_medium();
57 clear_thread_flag(TIF_POLLING_NRFLAG);
58 } else {
59 set_need_resched();
60 }
61
Anton Blanchard45e75df2005-07-07 17:56:33 -070062 ppc64_runlatch_on();
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 schedule();
64 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
65 cpu_die();
66 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
Paul Mackerras143a1de2005-10-19 23:11:21 +100069void native_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Anton Blanchard45e75df2005-07-07 17:56:33 -070071 while (1) {
72 ppc64_runlatch_off();
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if (!need_resched())
75 power4_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Anton Blanchard45e75df2005-07-07 17:56:33 -070077 if (need_resched()) {
78 ppc64_runlatch_on();
79 schedule();
80 }
81
82 if (cpu_is_offline(smp_processor_id()) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 system_state == SYSTEM_RUNNING)
84 cpu_die();
85 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088void cpu_idle(void)
89{
Michael Ellermanfd899c02005-07-07 17:56:28 -070090 BUG_ON(NULL == ppc_md.idle_loop);
91 ppc_md.idle_loop();
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
94int powersave_nap;
95
96#ifdef CONFIG_SYSCTL
97/*
98 * Register the sysctl to set/clear powersave_nap.
99 */
100static ctl_table powersave_nap_ctl_table[]={
101 {
102 .ctl_name = KERN_PPC_POWERSAVE_NAP,
103 .procname = "powersave-nap",
104 .data = &powersave_nap,
105 .maxlen = sizeof(int),
106 .mode = 0644,
107 .proc_handler = &proc_dointvec,
108 },
109 { 0, },
110};
111static ctl_table powersave_nap_sysctl_root[] = {
112 { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
113 { 0,},
114};
115
116static int __init
117register_powersave_nap_sysctl(void)
118{
119 register_sysctl_table(powersave_nap_sysctl_root, 0);
120
121 return 0;
122}
123__initcall(register_powersave_nap_sysctl);
124#endif