blob: 715bc0e71e0f4dbc45327ce08a59a5a1ab58a335 [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>
Paul Mackerras2249ca92005-11-07 13:18:13 +110031#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33extern void power4_idle(void);
34
Paul Mackerras143a1de2005-10-19 23:11:21 +100035void default_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 unsigned int cpu = smp_processor_id();
Nick Piggin64c7c8f2005-11-08 21:39:04 -080038 set_thread_flag(TIF_POLLING_NRFLAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40 while (1) {
Nick Piggin64c7c8f2005-11-08 21:39:04 -080041 if (!need_resched()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 while (!need_resched() && !cpu_is_offline(cpu)) {
Anton Blanchard45e75df2005-07-07 17:56:33 -070043 ppc64_runlatch_off();
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 /*
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();
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 }
55
Anton Blanchard45e75df2005-07-07 17:56:33 -070056 ppc64_runlatch_on();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080057 preempt_enable_no_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080059 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
61 cpu_die();
62 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Paul Mackerras143a1de2005-10-19 23:11:21 +100065void native_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Anton Blanchard45e75df2005-07-07 17:56:33 -070067 while (1) {
68 ppc64_runlatch_off();
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 if (!need_resched())
71 power4_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Anton Blanchard45e75df2005-07-07 17:56:33 -070073 if (need_resched()) {
74 ppc64_runlatch_on();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080075 preempt_enable_no_resched();
Anton Blanchard45e75df2005-07-07 17:56:33 -070076 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080077 preempt_disable();
Anton Blanchard45e75df2005-07-07 17:56:33 -070078 }
79
80 if (cpu_is_offline(smp_processor_id()) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 system_state == SYSTEM_RUNNING)
82 cpu_die();
83 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086void cpu_idle(void)
87{
Michael Ellermanfd899c02005-07-07 17:56:28 -070088 BUG_ON(NULL == ppc_md.idle_loop);
89 ppc_md.idle_loop();
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92int powersave_nap;
93
94#ifdef CONFIG_SYSCTL
95/*
96 * Register the sysctl to set/clear powersave_nap.
97 */
98static 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};
109static ctl_table powersave_nap_sysctl_root[] = {
110 { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
111 { 0,},
112};
113
114static int __init
115register_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