Skip to content

Commit e6d9bfc

Browse files
committed
Merge branch 'powernv-cpuidle' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
Pull powerpc non-virtualized cpuidle from Ben Herrenschmidt: "This is the branch I mentioned in my other pull request which contains our improved cpuidle support for the "powernv" platform (non-virtualized). It adds support for the "fast sleep" feature of the processor which provides higher power savings than our usual "nap" mode but at the cost of losing the timers while asleep, and thus exploits the new timer broadcast framework to work around that limitation. It's based on a tip timer tree that you seem to have already merged" * 'powernv-cpuidle' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc: cpuidle/powernv: Parse device tree to setup idle states cpuidle/powernv: Add "Fast-Sleep" CPU idle state powerpc/powernv: Add OPAL call to resync timebase on wakeup powerpc/powernv: Add context management for Fast Sleep powerpc: Split timer_interrupt() into timer handling and interrupt handling routines powerpc: Implement tick broadcast IPI as a fixed IPI message powerpc: Free up the slot of PPC_MSG_CALL_FUNC_SINGLE IPI message
2 parents 235c7b9 + 0888839 commit e6d9bfc

13 files changed

Lines changed: 253 additions & 77 deletions

File tree

‎arch/powerpc/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ config PPC
130130
select GENERIC_CMOS_UPDATE
131131
select GENERIC_TIME_VSYSCALL_OLD
132132
select GENERIC_CLOCKEVENTS
133+
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
134+
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
133135
select GENERIC_STRNCPY_FROM_USER
134136
select GENERIC_STRNLEN_USER
135137
select HAVE_MOD_ARCH_SPECIFIC

‎arch/powerpc/include/asm/opal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ extern int opal_enter_rtas(struct rtas_args *args,
161161
#define OPAL_FLASH_VALIDATE 76
162162
#define OPAL_FLASH_MANAGE 77
163163
#define OPAL_FLASH_UPDATE 78
164+
#define OPAL_RESYNC_TIMEBASE 79
164165
#define OPAL_DUMP_INIT 81
165166
#define OPAL_DUMP_INFO 82
166167
#define OPAL_DUMP_READ 83
@@ -923,6 +924,7 @@ extern int opal_machine_check(struct pt_regs *regs);
923924
extern bool opal_mce_check_early_recovery(struct pt_regs *regs);
924925

925926
extern void opal_shutdown(void);
927+
extern int opal_resync_timebase(void);
926928

927929
extern void opal_lpc_init(void);
928930

‎arch/powerpc/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
450450

451451
extern int powersave_nap; /* set if nap mode can be used in idle loop */
452452
extern void power7_nap(void);
453+
extern void power7_sleep(void);
453454
extern void flush_instruction_cache(void);
454455
extern void hard_reset_now(void);
455456
extern void poweroff_now(void);

‎arch/powerpc/include/asm/smp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ extern int cpu_to_core_id(int cpu);
120120
* in /proc/interrupts will be wrong!!! --Troy */
121121
#define PPC_MSG_CALL_FUNCTION 0
122122
#define PPC_MSG_RESCHEDULE 1
123-
#define PPC_MSG_CALL_FUNC_SINGLE 2
123+
#define PPC_MSG_TICK_BROADCAST 2
124124
#define PPC_MSG_DEBUGGER_BREAK 3
125125

126126
/* for irq controllers that have dedicated ipis per message (4) */

‎arch/powerpc/include/asm/time.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern struct clock_event_device decrementer_clockevent;
2828
struct rtc_time;
2929
extern void to_tm(int tim, struct rtc_time * tm);
3030
extern void GregorianDay(struct rtc_time *tm);
31+
extern void tick_broadcast_ipi_handler(void);
3132

3233
extern void generic_calibrate_decr(void);
3334

‎arch/powerpc/kernel/exceptions-64s.S‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ BEGIN_FTR_SECTION
121121
cmpwi cr1,r13,2
122122
/* Total loss of HV state is fatal, we could try to use the
123123
* PIR to locate a PACA, then use an emergency stack etc...
124-
* but for now, let's just stay stuck here
124+
* OPAL v3 based powernv platforms have new idle states
125+
* which fall in this catagory.
125126
*/
126-
bgt cr1,.
127+
bgt cr1,8f
127128
GET_PACA(r13)
128129

129130
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
@@ -141,6 +142,11 @@ BEGIN_FTR_SECTION
141142
beq cr1,2f
142143
b .power7_wakeup_noloss
143144
2: b .power7_wakeup_loss
145+
146+
/* Fast Sleep wakeup on PowerNV */
147+
8: GET_PACA(r13)
148+
b .power7_wakeup_tb_loss
149+
144150
9:
145151
END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
146152
#endif /* CONFIG_PPC_P7_NAP */

‎arch/powerpc/kernel/idle_power7.S‎

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,31 @@
1717
#include <asm/ppc-opcode.h>
1818
#include <asm/hw_irq.h>
1919
#include <asm/kvm_book3s_asm.h>
20+
#include <asm/opal.h>
2021

2122
#undef DEBUG
2223

23-
.text
24+
/* Idle state entry routines */
2425

25-
_GLOBAL(power7_idle)
26-
/* Now check if user or arch enabled NAP mode */
27-
LOAD_REG_ADDRBASE(r3,powersave_nap)
28-
lwz r4,ADDROFF(powersave_nap)(r3)
29-
cmpwi 0,r4,0
30-
beqlr
31-
/* fall through */
26+
#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
27+
/* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
28+
std r0,0(r1); \
29+
ptesync; \
30+
ld r0,0(r1); \
31+
1: cmp cr0,r0,r0; \
32+
bne 1b; \
33+
IDLE_INST; \
34+
b .
3235

33-
_GLOBAL(power7_nap)
36+
.text
37+
38+
/*
39+
* Pass requested state in r3:
40+
* 0 - nap
41+
* 1 - sleep
42+
*/
43+
_GLOBAL(power7_powersave_common)
44+
/* Use r3 to pass state nap/sleep/winkle */
3445
/* NAP is a state loss, we create a regs frame on the
3546
* stack, fill it up with the state we care about and
3647
* stick a pointer to it in PACAR1. We really only
@@ -79,8 +90,8 @@ _GLOBAL(power7_nap)
7990
/* Continue saving state */
8091
SAVE_GPR(2, r1)
8192
SAVE_NVGPRS(r1)
82-
mfcr r3
83-
std r3,_CCR(r1)
93+
mfcr r4
94+
std r4,_CCR(r1)
8495
std r9,_MSR(r1)
8596
std r1,PACAR1(r13)
8697

@@ -90,15 +101,56 @@ _GLOBAL(power7_enter_nap_mode)
90101
li r4,KVM_HWTHREAD_IN_NAP
91102
stb r4,HSTATE_HWTHREAD_STATE(r13)
92103
#endif
104+
cmpwi cr0,r3,1
105+
beq 2f
106+
IDLE_STATE_ENTER_SEQ(PPC_NAP)
107+
/* No return */
108+
2: IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
109+
/* No return */
93110

94-
/* Magic NAP mode enter sequence */
95-
std r0,0(r1)
96-
ptesync
97-
ld r0,0(r1)
98-
1: cmp cr0,r0,r0
99-
bne 1b
100-
PPC_NAP
101-
b .
111+
_GLOBAL(power7_idle)
112+
/* Now check if user or arch enabled NAP mode */
113+
LOAD_REG_ADDRBASE(r3,powersave_nap)
114+
lwz r4,ADDROFF(powersave_nap)(r3)
115+
cmpwi 0,r4,0
116+
beqlr
117+
/* fall through */
118+
119+
_GLOBAL(power7_nap)
120+
li r3,0
121+
b power7_powersave_common
122+
/* No return */
123+
124+
_GLOBAL(power7_sleep)
125+
li r3,1
126+
b power7_powersave_common
127+
/* No return */
128+
129+
_GLOBAL(power7_wakeup_tb_loss)
130+
ld r2,PACATOC(r13);
131+
ld r1,PACAR1(r13)
132+
133+
/* Time base re-sync */
134+
li r0,OPAL_RESYNC_TIMEBASE
135+
LOAD_REG_ADDR(r11,opal);
136+
ld r12,8(r11);
137+
ld r2,0(r11);
138+
mtctr r12
139+
bctrl
140+
141+
/* TODO: Check r3 for failure */
142+
143+
REST_NVGPRS(r1)
144+
REST_GPR(2, r1)
145+
ld r3,_CCR(r1)
146+
ld r4,_MSR(r1)
147+
ld r5,_NIP(r1)
148+
addi r1,r1,INT_FRAME_SIZE
149+
mtcr r3
150+
mfspr r3,SPRN_SRR1 /* Return SRR1 */
151+
mtspr SPRN_SRR1,r4
152+
mtspr SPRN_SRR0,r5
153+
rfid
102154

103155
_GLOBAL(power7_wakeup_loss)
104156
ld r1,PACAR1(r13)

‎arch/powerpc/kernel/smp.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <asm/ptrace.h>
3636
#include <linux/atomic.h>
3737
#include <asm/irq.h>
38+
#include <asm/hw_irq.h>
3839
#include <asm/page.h>
3940
#include <asm/pgtable.h>
4041
#include <asm/prom.h>
@@ -145,9 +146,9 @@ static irqreturn_t reschedule_action(int irq, void *data)
145146
return IRQ_HANDLED;
146147
}
147148

148-
static irqreturn_t call_function_single_action(int irq, void *data)
149+
static irqreturn_t tick_broadcast_ipi_action(int irq, void *data)
149150
{
150-
generic_smp_call_function_single_interrupt();
151+
tick_broadcast_ipi_handler();
151152
return IRQ_HANDLED;
152153
}
153154

@@ -168,14 +169,14 @@ static irqreturn_t debug_ipi_action(int irq, void *data)
168169
static irq_handler_t smp_ipi_action[] = {
169170
[PPC_MSG_CALL_FUNCTION] = call_function_action,
170171
[PPC_MSG_RESCHEDULE] = reschedule_action,
171-
[PPC_MSG_CALL_FUNC_SINGLE] = call_function_single_action,
172+
[PPC_MSG_TICK_BROADCAST] = tick_broadcast_ipi_action,
172173
[PPC_MSG_DEBUGGER_BREAK] = debug_ipi_action,
173174
};
174175

175176
const char *smp_ipi_name[] = {
176177
[PPC_MSG_CALL_FUNCTION] = "ipi call function",
177178
[PPC_MSG_RESCHEDULE] = "ipi reschedule",
178-
[PPC_MSG_CALL_FUNC_SINGLE] = "ipi call function single",
179+
[PPC_MSG_TICK_BROADCAST] = "ipi tick-broadcast",
179180
[PPC_MSG_DEBUGGER_BREAK] = "ipi debugger",
180181
};
181182

@@ -251,8 +252,8 @@ irqreturn_t smp_ipi_demux(void)
251252
generic_smp_call_function_interrupt();
252253
if (all & IPI_MESSAGE(PPC_MSG_RESCHEDULE))
253254
scheduler_ipi();
254-
if (all & IPI_MESSAGE(PPC_MSG_CALL_FUNC_SINGLE))
255-
generic_smp_call_function_single_interrupt();
255+
if (all & IPI_MESSAGE(PPC_MSG_TICK_BROADCAST))
256+
tick_broadcast_ipi_handler();
256257
if (all & IPI_MESSAGE(PPC_MSG_DEBUGGER_BREAK))
257258
debug_ipi_action(0, NULL);
258259
} while (info->messages);
@@ -280,7 +281,7 @@ EXPORT_SYMBOL_GPL(smp_send_reschedule);
280281

281282
void arch_send_call_function_single_ipi(int cpu)
282283
{
283-
do_message_pass(cpu, PPC_MSG_CALL_FUNC_SINGLE);
284+
do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
284285
}
285286

286287
void arch_send_call_function_ipi_mask(const struct cpumask *mask)
@@ -291,6 +292,16 @@ void arch_send_call_function_ipi_mask(const struct cpumask *mask)
291292
do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
292293
}
293294

295+
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
296+
void tick_broadcast(const struct cpumask *mask)
297+
{
298+
unsigned int cpu;
299+
300+
for_each_cpu(cpu, mask)
301+
do_message_pass(cpu, PPC_MSG_TICK_BROADCAST);
302+
}
303+
#endif
304+
294305
#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
295306
void smp_send_debugger_break(void)
296307
{

0 commit comments

Comments
 (0)