blob: b879d3057ef83d5ba5287321a6d3d5550554b8d3 [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>
Michael Ellermanfd899c02005-07-07 17:56:28 -070029#include <asm/machdep.h>
Paul Mackerras2249ca92005-11-07 13:18:13 +110030#include <asm/smp.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{
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 unsigned int cpu = smp_processor_id();
Nick Piggin64c7c8f2005-11-08 21:39:04 -080037 set_thread_flag(TIF_POLLING_NRFLAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39 while (1) {
Nick Piggin64c7c8f2005-11-08 21:39:04 -080040 if (!need_resched()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 while (!need_resched() && !cpu_is_offline(cpu)) {
Anton Blanchard45e75df2005-07-07 17:56:33 -070042 ppc64_runlatch_off();
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 /*
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();
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 }
54
Anton Blanchard45e75df2005-07-07 17:56:33 -070055 ppc64_runlatch_on();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080056 preempt_enable_no_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080058 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
60 cpu_die();
61 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Paul Mackerras143a1de2005-10-19 23:11:21 +100064void native_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Anton Blanchard45e75df2005-07-07 17:56:33 -070066 while (1) {
67 ppc64_runlatch_off();
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (!need_resched())
70 power4_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Anton Blanchard45e75df2005-07-07 17:56:33 -070072 if (need_resched()) {
73 ppc64_runlatch_on();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080074 preempt_enable_no_resched();
Anton Blanchard45e75df2005-07-07 17:56:33 -070075 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080076 preempt_disable();
Anton Blanchard45e75df2005-07-07 17:56:33 -070077 }
78
79 if (cpu_is_offline(smp_processor_id()) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 system_state == SYSTEM_RUNNING)
81 cpu_die();
82 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085void cpu_idle(void)
86{
Michael Ellermanfd899c02005-07-07 17:56:28 -070087 BUG_ON(NULL == ppc_md.idle_loop);
88 ppc_md.idle_loop();
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91int powersave_nap;
92
93#ifdef CONFIG_SYSCTL
94/*
95 * Register the sysctl to set/clear powersave_nap.
96 */
97static 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};
108static ctl_table powersave_nap_sysctl_root[] = {
109 { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
110 { 0,},
111};
112
113static int __init
114register_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