Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/sysctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include <asm/system.h> |
| 26 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/cputable.h> |
| 28 | #include <asm/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/systemcfg.h> |
Michael Ellerman | fd899c0 | 2005-07-07 17:56:28 -0700 | [diff] [blame] | 30 | #include <asm/machdep.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame^] | 31 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | extern void power4_idle(void); |
| 34 | |
Paul Mackerras | 143a1de | 2005-10-19 23:11:21 +1000 | [diff] [blame] | 35 | void default_idle(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
| 37 | long oldval; |
| 38 | unsigned int cpu = smp_processor_id(); |
| 39 | |
| 40 | while (1) { |
| 41 | oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED); |
| 42 | |
| 43 | if (!oldval) { |
| 44 | set_thread_flag(TIF_POLLING_NRFLAG); |
| 45 | |
| 46 | while (!need_resched() && !cpu_is_offline(cpu)) { |
Anton Blanchard | 45e75df | 2005-07-07 17:56:33 -0700 | [diff] [blame] | 47 | ppc64_runlatch_off(); |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | /* |
| 50 | * Go into low thread priority and possibly |
| 51 | * low power mode. |
| 52 | */ |
| 53 | HMT_low(); |
| 54 | HMT_very_low(); |
| 55 | } |
| 56 | |
| 57 | HMT_medium(); |
| 58 | clear_thread_flag(TIF_POLLING_NRFLAG); |
| 59 | } else { |
| 60 | set_need_resched(); |
| 61 | } |
| 62 | |
Anton Blanchard | 45e75df | 2005-07-07 17:56:33 -0700 | [diff] [blame] | 63 | ppc64_runlatch_on(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | schedule(); |
| 65 | if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING) |
| 66 | cpu_die(); |
| 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Paul Mackerras | 143a1de | 2005-10-19 23:11:21 +1000 | [diff] [blame] | 70 | void native_idle(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Anton Blanchard | 45e75df | 2005-07-07 17:56:33 -0700 | [diff] [blame] | 72 | while (1) { |
| 73 | ppc64_runlatch_off(); |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (!need_resched()) |
| 76 | power4_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Anton Blanchard | 45e75df | 2005-07-07 17:56:33 -0700 | [diff] [blame] | 78 | if (need_resched()) { |
| 79 | ppc64_runlatch_on(); |
| 80 | schedule(); |
| 81 | } |
| 82 | |
| 83 | if (cpu_is_offline(smp_processor_id()) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | system_state == SYSTEM_RUNNING) |
| 85 | cpu_die(); |
| 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | void cpu_idle(void) |
| 90 | { |
Michael Ellerman | fd899c0 | 2005-07-07 17:56:28 -0700 | [diff] [blame] | 91 | BUG_ON(NULL == ppc_md.idle_loop); |
| 92 | ppc_md.idle_loop(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | int powersave_nap; |
| 96 | |
| 97 | #ifdef CONFIG_SYSCTL |
| 98 | /* |
| 99 | * Register the sysctl to set/clear powersave_nap. |
| 100 | */ |
| 101 | static ctl_table powersave_nap_ctl_table[]={ |
| 102 | { |
| 103 | .ctl_name = KERN_PPC_POWERSAVE_NAP, |
| 104 | .procname = "powersave-nap", |
| 105 | .data = &powersave_nap, |
| 106 | .maxlen = sizeof(int), |
| 107 | .mode = 0644, |
| 108 | .proc_handler = &proc_dointvec, |
| 109 | }, |
| 110 | { 0, }, |
| 111 | }; |
| 112 | static ctl_table powersave_nap_sysctl_root[] = { |
| 113 | { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, }, |
| 114 | { 0,}, |
| 115 | }; |
| 116 | |
| 117 | static int __init |
| 118 | register_powersave_nap_sysctl(void) |
| 119 | { |
| 120 | register_sysctl_table(powersave_nap_sysctl_root, 0); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | __initcall(register_powersave_nap_sysctl); |
| 125 | #endif |