0001
0002 #ifndef _ASM_POWERPC_IDLE_H
0003 #define _ASM_POWERPC_IDLE_H
0004 #include <asm/runlatch.h>
0005 #include <asm/paca.h>
0006
0007 #ifdef CONFIG_PPC_PSERIES
0008 DECLARE_PER_CPU(u64, idle_spurr_cycles);
0009 DECLARE_PER_CPU(u64, idle_entry_purr_snap);
0010 DECLARE_PER_CPU(u64, idle_entry_spurr_snap);
0011
0012 static inline void snapshot_purr_idle_entry(void)
0013 {
0014 *this_cpu_ptr(&idle_entry_purr_snap) = mfspr(SPRN_PURR);
0015 }
0016
0017 static inline void snapshot_spurr_idle_entry(void)
0018 {
0019 *this_cpu_ptr(&idle_entry_spurr_snap) = mfspr(SPRN_SPURR);
0020 }
0021
0022 static inline void update_idle_purr_accounting(void)
0023 {
0024 u64 wait_cycles;
0025 u64 in_purr = *this_cpu_ptr(&idle_entry_purr_snap);
0026
0027 wait_cycles = be64_to_cpu(get_lppaca()->wait_state_cycles);
0028 wait_cycles += mfspr(SPRN_PURR) - in_purr;
0029 get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles);
0030 }
0031
0032 static inline void update_idle_spurr_accounting(void)
0033 {
0034 u64 *idle_spurr_cycles_ptr = this_cpu_ptr(&idle_spurr_cycles);
0035 u64 in_spurr = *this_cpu_ptr(&idle_entry_spurr_snap);
0036
0037 *idle_spurr_cycles_ptr += mfspr(SPRN_SPURR) - in_spurr;
0038 }
0039
0040 static inline void pseries_idle_prolog(void)
0041 {
0042 ppc64_runlatch_off();
0043 snapshot_purr_idle_entry();
0044 snapshot_spurr_idle_entry();
0045
0046
0047
0048
0049 get_lppaca()->idle = 1;
0050 }
0051
0052 static inline void pseries_idle_epilog(void)
0053 {
0054 update_idle_purr_accounting();
0055 update_idle_spurr_accounting();
0056 get_lppaca()->idle = 0;
0057 ppc64_runlatch_on();
0058 }
0059
0060 static inline u64 read_this_idle_purr(void)
0061 {
0062
0063
0064
0065
0066
0067
0068 if (unlikely(get_lppaca()->idle == 1)) {
0069 update_idle_purr_accounting();
0070 snapshot_purr_idle_entry();
0071 }
0072
0073 return be64_to_cpu(get_lppaca()->wait_state_cycles);
0074 }
0075
0076 static inline u64 read_this_idle_spurr(void)
0077 {
0078
0079
0080
0081
0082
0083
0084 if (get_lppaca()->idle == 1) {
0085 update_idle_spurr_accounting();
0086 snapshot_spurr_idle_entry();
0087 }
0088
0089 return *this_cpu_ptr(&idle_spurr_cycles);
0090 }
0091
0092 #endif
0093 #endif