2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-04-20 13:02:57 +08:00
|
|
|
/*
|
|
|
|
* PowerNV cpuidle code
|
|
|
|
*
|
|
|
|
* Copyright 2015 IBM Corp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/of.h>
|
2015-04-20 13:02:58 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/cpu.h>
|
2015-04-20 13:02:57 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
#include <asm/asm-prototypes.h>
|
2015-04-20 13:02:57 +08:00
|
|
|
#include <asm/firmware.h>
|
2015-06-15 13:01:32 +08:00
|
|
|
#include <asm/machdep.h>
|
2015-04-20 13:02:57 +08:00
|
|
|
#include <asm/opal.h>
|
|
|
|
#include <asm/cputhreads.h>
|
|
|
|
#include <asm/cpuidle.h>
|
|
|
|
#include <asm/code-patching.h>
|
|
|
|
#include <asm/smp.h>
|
2017-06-13 21:05:45 +08:00
|
|
|
#include <asm/runlatch.h>
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
#include <asm/dbell.h>
|
2015-04-20 13:02:57 +08:00
|
|
|
|
|
|
|
#include "powernv.h"
|
|
|
|
#include "subcore.h"
|
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
/* Power ISA 3.0 allows for stop states 0x0 - 0xF */
|
|
|
|
#define MAX_STOP_STATE 0xF
|
|
|
|
|
2017-05-16 16:49:46 +08:00
|
|
|
#define P9_STOP_SPR_MSR 2000
|
|
|
|
#define P9_STOP_SPR_PSSCR 855
|
|
|
|
|
2015-04-20 13:02:57 +08:00
|
|
|
static u32 supported_cpuidle_states;
|
2018-07-05 19:40:21 +08:00
|
|
|
struct pnv_idle_states_t *pnv_idle_states;
|
|
|
|
int nr_pnv_idle_states;
|
2015-04-20 13:02:57 +08:00
|
|
|
|
2017-05-16 16:49:46 +08:00
|
|
|
/*
|
|
|
|
* The default stop state that will be used by ppc_md.power_save
|
|
|
|
* function on platforms that support stop instruction.
|
|
|
|
*/
|
|
|
|
static u64 pnv_default_stop_val;
|
|
|
|
static u64 pnv_default_stop_mask;
|
|
|
|
static bool default_stop_found;
|
|
|
|
|
|
|
|
/*
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
* First stop state levels when SPR and TB loss can occur.
|
2017-05-16 16:49:46 +08:00
|
|
|
*/
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
static u64 pnv_first_tb_loss_level = MAX_STOP_STATE + 1;
|
|
|
|
static u64 pnv_first_spr_loss_level = MAX_STOP_STATE + 1;
|
2017-05-16 16:49:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* psscr value and mask of the deepest stop idle state.
|
|
|
|
* Used when a cpu is offlined.
|
|
|
|
*/
|
|
|
|
static u64 pnv_deepest_stop_psscr_val;
|
|
|
|
static u64 pnv_deepest_stop_psscr_mask;
|
2017-08-08 16:43:15 +08:00
|
|
|
static u64 pnv_deepest_stop_flag;
|
2017-05-16 16:49:46 +08:00
|
|
|
static bool deepest_stop_found;
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
static unsigned long power7_offline_type;
|
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
static int pnv_save_sprs_for_deep_states(void)
|
2015-04-20 13:02:57 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
2016-02-25 02:51:11 +08:00
|
|
|
* hid0, hid1, hid4, hid5, hmeer and lpcr values are symmetric across
|
2015-04-20 13:02:57 +08:00
|
|
|
* all cpus at boot. Get these reg values of current cpu and use the
|
2016-02-25 02:51:11 +08:00
|
|
|
* same across all cpus.
|
2015-04-20 13:02:57 +08:00
|
|
|
*/
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
uint64_t lpcr_val = mfspr(SPRN_LPCR);
|
|
|
|
uint64_t hid0_val = mfspr(SPRN_HID0);
|
|
|
|
uint64_t hid1_val = mfspr(SPRN_HID1);
|
|
|
|
uint64_t hid4_val = mfspr(SPRN_HID4);
|
|
|
|
uint64_t hid5_val = mfspr(SPRN_HID5);
|
|
|
|
uint64_t hmeer_val = mfspr(SPRN_HMEER);
|
2017-05-16 16:49:46 +08:00
|
|
|
uint64_t msr_val = MSR_IDLE;
|
|
|
|
uint64_t psscr_val = pnv_deepest_stop_psscr_val;
|
2015-04-20 13:02:57 +08:00
|
|
|
|
2018-05-16 20:02:14 +08:00
|
|
|
for_each_present_cpu(cpu) {
|
2015-04-20 13:02:57 +08:00
|
|
|
uint64_t pir = get_hard_smp_processor_id(cpu);
|
2018-02-13 23:08:12 +08:00
|
|
|
uint64_t hsprg0_val = (uint64_t)paca_ptrs[cpu];
|
2015-04-20 13:02:57 +08:00
|
|
|
|
|
|
|
rc = opal_slw_set_reg(pir, SPRN_HSPRG0, hsprg0_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
2017-05-16 16:49:46 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300)) {
|
|
|
|
rc = opal_slw_set_reg(pir, P9_STOP_SPR_MSR, msr_val);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = opal_slw_set_reg(pir,
|
|
|
|
P9_STOP_SPR_PSSCR, psscr_val);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:02:57 +08:00
|
|
|
/* HIDs are per core registers */
|
|
|
|
if (cpu_thread_in_core(cpu) == 0) {
|
|
|
|
|
|
|
|
rc = opal_slw_set_reg(pir, SPRN_HMEER, hmeer_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = opal_slw_set_reg(pir, SPRN_HID0, hid0_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
2017-05-16 16:49:46 +08:00
|
|
|
/* Only p8 needs to set extra HID regiters */
|
|
|
|
if (!cpu_has_feature(CPU_FTR_ARCH_300)) {
|
2015-04-20 13:02:57 +08:00
|
|
|
|
2017-05-16 16:49:46 +08:00
|
|
|
rc = opal_slw_set_reg(pir, SPRN_HID1, hid1_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
2015-04-20 13:02:57 +08:00
|
|
|
|
2017-05-16 16:49:46 +08:00
|
|
|
rc = opal_slw_set_reg(pir, SPRN_HID4, hid4_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = opal_slw_set_reg(pir, SPRN_HID5, hid5_val);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
}
|
2015-04-20 13:02:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 pnv_get_supported_cpuidle_states(void)
|
|
|
|
{
|
|
|
|
return supported_cpuidle_states;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pnv_get_supported_cpuidle_states);
|
|
|
|
|
2015-04-20 13:02:58 +08:00
|
|
|
static void pnv_fastsleep_workaround_apply(void *info)
|
|
|
|
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int *err = info;
|
|
|
|
|
|
|
|
rc = opal_config_cpu_idle_state(OPAL_CONFIG_IDLE_FASTSLEEP,
|
|
|
|
OPAL_CONFIG_IDLE_APPLY);
|
|
|
|
if (rc)
|
|
|
|
*err = 1;
|
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
static bool power7_fastsleep_workaround_entry = true;
|
|
|
|
static bool power7_fastsleep_workaround_exit = true;
|
|
|
|
|
2015-04-20 13:02:58 +08:00
|
|
|
/*
|
|
|
|
* Used to store fastsleep workaround state
|
|
|
|
* 0 - Workaround applied/undone at fastsleep entry/exit path (Default)
|
|
|
|
* 1 - Workaround applied once, never undone.
|
|
|
|
*/
|
|
|
|
static u8 fastsleep_workaround_applyonce;
|
|
|
|
|
|
|
|
static ssize_t show_fastsleep_workaround_applyonce(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", fastsleep_workaround_applyonce);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_fastsleep_workaround_applyonce(struct device *dev,
|
|
|
|
struct device_attribute *attr, const char *buf,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
cpumask_t primary_thread_mask;
|
|
|
|
int err;
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
if (kstrtou8(buf, 0, &val) || val != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (fastsleep_workaround_applyonce == 1)
|
|
|
|
return count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fastsleep_workaround_applyonce = 1 implies
|
|
|
|
* fastsleep workaround needs to be left in 'applied' state on all
|
|
|
|
* the cores. Do this by-
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
* 1. Disable the 'undo' workaround in fastsleep exit path
|
|
|
|
* 2. Sendi IPIs to all the cores which have at least one online thread
|
|
|
|
* 3. Disable the 'apply' workaround in fastsleep entry path
|
|
|
|
*
|
2015-04-20 13:02:58 +08:00
|
|
|
* There is no need to send ipi to cores which have all threads
|
|
|
|
* offlined, as last thread of the core entering fastsleep or deeper
|
|
|
|
* state would have applied workaround.
|
|
|
|
*/
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
power7_fastsleep_workaround_exit = false;
|
2015-04-20 13:02:58 +08:00
|
|
|
|
|
|
|
get_online_cpus();
|
|
|
|
primary_thread_mask = cpu_online_cores_map();
|
|
|
|
on_each_cpu_mask(&primary_thread_mask,
|
|
|
|
pnv_fastsleep_workaround_apply,
|
|
|
|
&err, 1);
|
|
|
|
put_online_cpus();
|
|
|
|
if (err) {
|
|
|
|
pr_err("fastsleep_workaround_applyonce change failed while running pnv_fastsleep_workaround_apply");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
power7_fastsleep_workaround_entry = false;
|
2015-04-20 13:02:58 +08:00
|
|
|
|
|
|
|
fastsleep_workaround_applyonce = 1;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
fail:
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(fastsleep_workaround_applyonce, 0600,
|
|
|
|
show_fastsleep_workaround_applyonce,
|
|
|
|
store_fastsleep_workaround_applyonce);
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
static inline void atomic_start_thread_idle(void)
|
2017-06-13 21:05:45 +08:00
|
|
|
{
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
int thread_nr = cpu_thread_in_core(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
|
|
|
|
clear_bit(thread_nr, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void atomic_stop_thread_idle(void)
|
|
|
|
{
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
int thread_nr = cpu_thread_in_core(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
|
|
|
|
set_bit(thread_nr, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void atomic_lock_thread_idle(void)
|
|
|
|
{
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
|
|
|
|
while (unlikely(test_and_set_bit_lock(NR_PNV_CORE_IDLE_LOCK_BIT, state)))
|
|
|
|
barrier();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void atomic_unlock_and_stop_thread_idle(void)
|
|
|
|
{
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
unsigned long thread = 1UL << cpu_thread_in_core(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
u64 s = READ_ONCE(*state);
|
|
|
|
u64 new, tmp;
|
|
|
|
|
|
|
|
BUG_ON(!(s & PNV_CORE_IDLE_LOCK_BIT));
|
|
|
|
BUG_ON(s & thread);
|
|
|
|
|
|
|
|
again:
|
|
|
|
new = (s | thread) & ~PNV_CORE_IDLE_LOCK_BIT;
|
|
|
|
tmp = cmpxchg(state, s, new);
|
|
|
|
if (unlikely(tmp != s)) {
|
|
|
|
s = tmp;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void atomic_unlock_thread_idle(void)
|
|
|
|
{
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
|
|
|
|
BUG_ON(!test_bit(NR_PNV_CORE_IDLE_LOCK_BIT, state));
|
|
|
|
clear_bit_unlock(NR_PNV_CORE_IDLE_LOCK_BIT, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* P7 and P8 */
|
|
|
|
struct p7_sprs {
|
|
|
|
/* per core */
|
|
|
|
u64 tscr;
|
|
|
|
u64 worc;
|
|
|
|
|
|
|
|
/* per subcore */
|
|
|
|
u64 sdr1;
|
|
|
|
u64 rpr;
|
|
|
|
|
|
|
|
/* per thread */
|
|
|
|
u64 lpcr;
|
|
|
|
u64 hfscr;
|
|
|
|
u64 fscr;
|
|
|
|
u64 purr;
|
|
|
|
u64 spurr;
|
|
|
|
u64 dscr;
|
|
|
|
u64 wort;
|
2019-04-30 12:28:17 +08:00
|
|
|
|
|
|
|
/* per thread SPRs that get lost in shallow states */
|
|
|
|
u64 amr;
|
|
|
|
u64 iamr;
|
|
|
|
u64 amor;
|
|
|
|
u64 uamor;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long power7_idle_insn(unsigned long type)
|
|
|
|
{
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
unsigned long thread = 1UL << cpu_thread_in_core(cpu);
|
|
|
|
unsigned long core_thread_mask = (1UL << threads_per_core) - 1;
|
2017-06-13 21:05:45 +08:00
|
|
|
unsigned long srr1;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
bool full_winkle;
|
|
|
|
struct p7_sprs sprs = {}; /* avoid false use-uninitialised */
|
|
|
|
bool sprs_saved = false;
|
|
|
|
int rc;
|
2017-06-13 21:05:45 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (unlikely(type != PNV_THREAD_NAP)) {
|
|
|
|
atomic_lock_thread_idle();
|
|
|
|
|
|
|
|
BUG_ON(!(*state & thread));
|
|
|
|
*state &= ~thread;
|
|
|
|
|
|
|
|
if (power7_fastsleep_workaround_entry) {
|
|
|
|
if ((*state & core_thread_mask) == 0) {
|
|
|
|
rc = opal_config_cpu_idle_state(
|
|
|
|
OPAL_CONFIG_IDLE_FASTSLEEP,
|
|
|
|
OPAL_CONFIG_IDLE_APPLY);
|
|
|
|
BUG_ON(rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == PNV_THREAD_WINKLE) {
|
|
|
|
sprs.tscr = mfspr(SPRN_TSCR);
|
|
|
|
sprs.worc = mfspr(SPRN_WORC);
|
|
|
|
|
|
|
|
sprs.sdr1 = mfspr(SPRN_SDR1);
|
|
|
|
sprs.rpr = mfspr(SPRN_RPR);
|
|
|
|
|
|
|
|
sprs.lpcr = mfspr(SPRN_LPCR);
|
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
|
|
|
|
sprs.hfscr = mfspr(SPRN_HFSCR);
|
|
|
|
sprs.fscr = mfspr(SPRN_FSCR);
|
|
|
|
}
|
|
|
|
sprs.purr = mfspr(SPRN_PURR);
|
|
|
|
sprs.spurr = mfspr(SPRN_SPURR);
|
|
|
|
sprs.dscr = mfspr(SPRN_DSCR);
|
|
|
|
sprs.wort = mfspr(SPRN_WORT);
|
|
|
|
|
|
|
|
sprs_saved = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Increment winkle counter and set all winkle bits if
|
|
|
|
* all threads are winkling. This allows wakeup side to
|
|
|
|
* distinguish between fast sleep and winkle state
|
|
|
|
* loss. Fast sleep still has to resync the timebase so
|
|
|
|
* this may not be a really big win.
|
|
|
|
*/
|
|
|
|
*state += 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT;
|
|
|
|
if ((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS)
|
|
|
|
>> PNV_CORE_IDLE_WINKLE_COUNT_SHIFT
|
|
|
|
== threads_per_core)
|
|
|
|
*state |= PNV_CORE_IDLE_THREAD_WINKLE_BITS;
|
|
|
|
WARN_ON((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_unlock_thread_idle();
|
|
|
|
}
|
|
|
|
|
2019-04-30 12:28:17 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
|
|
|
|
sprs.amr = mfspr(SPRN_AMR);
|
|
|
|
sprs.iamr = mfspr(SPRN_IAMR);
|
|
|
|
sprs.amor = mfspr(SPRN_AMOR);
|
|
|
|
sprs.uamor = mfspr(SPRN_UAMOR);
|
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
local_paca->thread_idle_state = type;
|
|
|
|
srr1 = isa206_idle_insn_mayloss(type); /* go idle */
|
|
|
|
local_paca->thread_idle_state = PNV_THREAD_RUNNING;
|
|
|
|
|
|
|
|
WARN_ON_ONCE(!srr1);
|
|
|
|
WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));
|
|
|
|
|
2019-04-30 12:28:17 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
|
|
|
|
if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {
|
|
|
|
/*
|
|
|
|
* We don't need an isync after the mtsprs here because
|
|
|
|
* the upcoming mtmsrd is execution synchronizing.
|
|
|
|
*/
|
|
|
|
mtspr(SPRN_AMR, sprs.amr);
|
|
|
|
mtspr(SPRN_IAMR, sprs.iamr);
|
|
|
|
mtspr(SPRN_AMOR, sprs.amor);
|
|
|
|
mtspr(SPRN_UAMOR, sprs.uamor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (unlikely((srr1 & SRR1_WAKEMASK_P8) == SRR1_WAKEHMI))
|
|
|
|
hmi_exception_realmode(NULL);
|
|
|
|
|
|
|
|
if (likely((srr1 & SRR1_WAKESTATE) != SRR1_WS_HVLOSS)) {
|
|
|
|
if (unlikely(type != PNV_THREAD_NAP)) {
|
|
|
|
atomic_lock_thread_idle();
|
|
|
|
if (type == PNV_THREAD_WINKLE) {
|
|
|
|
WARN_ON((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS) == 0);
|
|
|
|
*state -= 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT;
|
|
|
|
*state &= ~(thread << PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT);
|
|
|
|
}
|
|
|
|
atomic_unlock_and_stop_thread_idle();
|
|
|
|
}
|
|
|
|
return srr1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HV state loss */
|
|
|
|
BUG_ON(type == PNV_THREAD_NAP);
|
|
|
|
|
|
|
|
atomic_lock_thread_idle();
|
|
|
|
|
|
|
|
full_winkle = false;
|
|
|
|
if (type == PNV_THREAD_WINKLE) {
|
|
|
|
WARN_ON((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS) == 0);
|
|
|
|
*state -= 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT;
|
|
|
|
if (*state & (thread << PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT)) {
|
|
|
|
*state &= ~(thread << PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT);
|
|
|
|
full_winkle = true;
|
|
|
|
BUG_ON(!sprs_saved);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ON(*state & thread);
|
|
|
|
|
|
|
|
if ((*state & core_thread_mask) != 0)
|
|
|
|
goto core_woken;
|
|
|
|
|
|
|
|
/* Per-core SPRs */
|
|
|
|
if (full_winkle) {
|
|
|
|
mtspr(SPRN_TSCR, sprs.tscr);
|
|
|
|
mtspr(SPRN_WORC, sprs.worc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (power7_fastsleep_workaround_exit) {
|
|
|
|
rc = opal_config_cpu_idle_state(OPAL_CONFIG_IDLE_FASTSLEEP,
|
|
|
|
OPAL_CONFIG_IDLE_UNDO);
|
|
|
|
BUG_ON(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TB */
|
|
|
|
if (opal_resync_timebase() != OPAL_SUCCESS)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
core_woken:
|
|
|
|
if (!full_winkle)
|
|
|
|
goto subcore_woken;
|
|
|
|
|
|
|
|
if ((*state & local_paca->subcore_sibling_mask) != 0)
|
|
|
|
goto subcore_woken;
|
|
|
|
|
|
|
|
/* Per-subcore SPRs */
|
|
|
|
mtspr(SPRN_SDR1, sprs.sdr1);
|
|
|
|
mtspr(SPRN_RPR, sprs.rpr);
|
|
|
|
|
|
|
|
subcore_woken:
|
|
|
|
/*
|
|
|
|
* isync after restoring shared SPRs and before unlocking. Unlock
|
|
|
|
* only contains hwsync which does not necessarily do the right
|
|
|
|
* thing for SPRs.
|
|
|
|
*/
|
|
|
|
isync();
|
|
|
|
atomic_unlock_and_stop_thread_idle();
|
|
|
|
|
|
|
|
/* Fast sleep does not lose SPRs */
|
|
|
|
if (!full_winkle)
|
|
|
|
return srr1;
|
|
|
|
|
|
|
|
/* Per-thread SPRs */
|
|
|
|
mtspr(SPRN_LPCR, sprs.lpcr);
|
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
|
|
|
|
mtspr(SPRN_HFSCR, sprs.hfscr);
|
|
|
|
mtspr(SPRN_FSCR, sprs.fscr);
|
|
|
|
}
|
|
|
|
mtspr(SPRN_PURR, sprs.purr);
|
|
|
|
mtspr(SPRN_SPURR, sprs.spurr);
|
|
|
|
mtspr(SPRN_DSCR, sprs.dscr);
|
|
|
|
mtspr(SPRN_WORT, sprs.wort);
|
|
|
|
|
|
|
|
mtspr(SPRN_SPRG3, local_paca->sprg_vdso);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The SLB has to be restored here, but it sometimes still
|
|
|
|
* contains entries, so the __ variant must be used to prevent
|
|
|
|
* multi hits.
|
|
|
|
*/
|
|
|
|
__slb_restore_bolted_realmode();
|
|
|
|
|
|
|
|
return srr1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern unsigned long idle_kvm_start_guest(unsigned long srr1);
|
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
static unsigned long power7_offline(void)
|
|
|
|
{
|
|
|
|
unsigned long srr1;
|
|
|
|
|
|
|
|
mtmsr(MSR_IDLE);
|
|
|
|
|
|
|
|
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
/* Tell KVM we're entering idle. */
|
|
|
|
/******************************************************/
|
|
|
|
/* N O T E W E L L ! ! ! N O T E W E L L */
|
|
|
|
/* The following store to HSTATE_HWTHREAD_STATE(r13) */
|
|
|
|
/* MUST occur in real mode, i.e. with the MMU off, */
|
|
|
|
/* and the MMU must stay off until we clear this flag */
|
|
|
|
/* and test HSTATE_HWTHREAD_REQ(r13) in */
|
|
|
|
/* pnv_powersave_wakeup in this file. */
|
|
|
|
/* The reason is that another thread can switch the */
|
|
|
|
/* MMU to a guest context whenever this flag is set */
|
|
|
|
/* to KVM_HWTHREAD_IN_IDLE, and if the MMU was on, */
|
|
|
|
/* that would potentially cause this thread to start */
|
|
|
|
/* executing instructions from guest memory in */
|
|
|
|
/* hypervisor mode, leading to a host crash or data */
|
|
|
|
/* corruption, or worse. */
|
|
|
|
/******************************************************/
|
|
|
|
local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_IDLE;
|
|
|
|
#endif
|
2017-06-13 21:05:45 +08:00
|
|
|
|
2017-06-13 21:05:57 +08:00
|
|
|
__ppc64_runlatch_off();
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
srr1 = power7_idle_insn(power7_offline_type);
|
2017-06-13 21:05:57 +08:00
|
|
|
__ppc64_runlatch_on();
|
2017-06-13 21:05:45 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_KERNEL;
|
|
|
|
/* Order setting hwthread_state vs. testing hwthread_req */
|
|
|
|
smp_mb();
|
|
|
|
if (local_paca->kvm_hstate.hwthread_req)
|
|
|
|
srr1 = idle_kvm_start_guest(srr1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mtmsr(MSR_KERNEL);
|
2017-06-13 21:05:45 +08:00
|
|
|
|
|
|
|
return srr1;
|
|
|
|
}
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
#endif
|
2017-06-13 21:05:45 +08:00
|
|
|
|
|
|
|
void power7_idle_type(unsigned long type)
|
|
|
|
{
|
2017-06-13 21:05:47 +08:00
|
|
|
unsigned long srr1;
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (!prep_irq_for_idle_irqsoff())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mtmsr(MSR_IDLE);
|
|
|
|
__ppc64_runlatch_off();
|
|
|
|
srr1 = power7_idle_insn(type);
|
|
|
|
__ppc64_runlatch_on();
|
|
|
|
mtmsr(MSR_KERNEL);
|
|
|
|
|
|
|
|
fini_irq_for_idle_irqsoff();
|
2017-06-13 21:05:47 +08:00
|
|
|
irq_set_pending_from_srr1(srr1);
|
2017-06-13 21:05:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void power7_idle(void)
|
|
|
|
{
|
|
|
|
if (!powersave_nap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
power7_idle_type(PNV_THREAD_NAP);
|
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
struct p9_sprs {
|
|
|
|
/* per core */
|
|
|
|
u64 ptcr;
|
|
|
|
u64 rpr;
|
|
|
|
u64 tscr;
|
|
|
|
u64 ldbar;
|
|
|
|
|
|
|
|
/* per thread */
|
|
|
|
u64 lpcr;
|
|
|
|
u64 hfscr;
|
|
|
|
u64 fscr;
|
|
|
|
u64 pid;
|
|
|
|
u64 purr;
|
|
|
|
u64 spurr;
|
|
|
|
u64 dscr;
|
|
|
|
u64 wort;
|
|
|
|
|
|
|
|
u64 mmcra;
|
|
|
|
u32 mmcr0;
|
|
|
|
u32 mmcr1;
|
|
|
|
u64 mmcr2;
|
2019-04-30 12:28:17 +08:00
|
|
|
|
|
|
|
/* per thread SPRs that get lost in shallow states */
|
|
|
|
u64 amr;
|
|
|
|
u64 iamr;
|
|
|
|
u64 amor;
|
|
|
|
u64 uamor;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
|
2017-06-13 21:05:45 +08:00
|
|
|
{
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
int first = cpu_first_thread_sibling(cpu);
|
|
|
|
unsigned long *state = &paca_ptrs[first]->idle_state;
|
|
|
|
unsigned long core_thread_mask = (1UL << threads_per_core) - 1;
|
2017-06-13 21:05:45 +08:00
|
|
|
unsigned long srr1;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
unsigned long pls;
|
|
|
|
unsigned long mmcr0 = 0;
|
|
|
|
struct p9_sprs sprs = {}; /* avoid false used-uninitialised */
|
|
|
|
bool sprs_saved = false;
|
2017-06-13 21:05:45 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (!(psscr & (PSSCR_EC|PSSCR_ESL))) {
|
|
|
|
/* EC=ESL=0 case */
|
|
|
|
|
|
|
|
BUG_ON(!mmu_on);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wake synchronously. SRESET via xscom may still cause
|
|
|
|
* a 0x100 powersave wakeup with SRR1 reason!
|
|
|
|
*/
|
|
|
|
srr1 = isa300_idle_stop_noloss(psscr); /* go idle */
|
|
|
|
if (likely(!srr1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Registers not saved, can't recover!
|
|
|
|
* This would be a hardware bug
|
|
|
|
*/
|
|
|
|
BUG_ON((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS);
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EC=ESL=1 case */
|
|
|
|
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
if (cpu_has_feature(CPU_FTR_P9_TM_XER_SO_BUG)) {
|
|
|
|
local_paca->requested_psscr = psscr;
|
|
|
|
/* order setting requested_psscr vs testing dont_stop */
|
|
|
|
smp_mb();
|
|
|
|
if (atomic_read(&local_paca->dont_stop)) {
|
|
|
|
local_paca->requested_psscr = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!cpu_has_feature(CPU_FTR_POWER9_DD2_1)) {
|
|
|
|
/*
|
|
|
|
* POWER9 DD2 can incorrectly set PMAO when waking up
|
|
|
|
* after a state-loss idle. Saving and restoring MMCR0
|
|
|
|
* over idle is a workaround.
|
|
|
|
*/
|
|
|
|
mmcr0 = mfspr(SPRN_MMCR0);
|
|
|
|
}
|
|
|
|
if ((psscr & PSSCR_RL_MASK) >= pnv_first_spr_loss_level) {
|
|
|
|
sprs.lpcr = mfspr(SPRN_LPCR);
|
|
|
|
sprs.hfscr = mfspr(SPRN_HFSCR);
|
|
|
|
sprs.fscr = mfspr(SPRN_FSCR);
|
|
|
|
sprs.pid = mfspr(SPRN_PID);
|
|
|
|
sprs.purr = mfspr(SPRN_PURR);
|
|
|
|
sprs.spurr = mfspr(SPRN_SPURR);
|
|
|
|
sprs.dscr = mfspr(SPRN_DSCR);
|
|
|
|
sprs.wort = mfspr(SPRN_WORT);
|
|
|
|
|
|
|
|
sprs.mmcra = mfspr(SPRN_MMCRA);
|
|
|
|
sprs.mmcr0 = mfspr(SPRN_MMCR0);
|
|
|
|
sprs.mmcr1 = mfspr(SPRN_MMCR1);
|
|
|
|
sprs.mmcr2 = mfspr(SPRN_MMCR2);
|
|
|
|
|
|
|
|
sprs.ptcr = mfspr(SPRN_PTCR);
|
|
|
|
sprs.rpr = mfspr(SPRN_RPR);
|
|
|
|
sprs.tscr = mfspr(SPRN_TSCR);
|
|
|
|
sprs.ldbar = mfspr(SPRN_LDBAR);
|
|
|
|
|
|
|
|
sprs_saved = true;
|
|
|
|
|
|
|
|
atomic_start_thread_idle();
|
|
|
|
}
|
|
|
|
|
2019-04-30 12:28:17 +08:00
|
|
|
sprs.amr = mfspr(SPRN_AMR);
|
|
|
|
sprs.iamr = mfspr(SPRN_IAMR);
|
|
|
|
sprs.amor = mfspr(SPRN_AMOR);
|
|
|
|
sprs.uamor = mfspr(SPRN_UAMOR);
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
srr1 = isa300_idle_stop_mayloss(psscr); /* go idle */
|
|
|
|
|
|
|
|
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
local_paca->requested_psscr = 0;
|
|
|
|
#endif
|
2017-06-13 21:05:45 +08:00
|
|
|
|
|
|
|
psscr = mfspr(SPRN_PSSCR);
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
|
|
|
|
WARN_ON_ONCE(!srr1);
|
|
|
|
WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));
|
|
|
|
|
|
|
|
if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {
|
|
|
|
unsigned long mmcra;
|
|
|
|
|
2019-04-30 12:28:17 +08:00
|
|
|
/*
|
|
|
|
* We don't need an isync after the mtsprs here because the
|
|
|
|
* upcoming mtmsrd is execution synchronizing.
|
|
|
|
*/
|
|
|
|
mtspr(SPRN_AMR, sprs.amr);
|
|
|
|
mtspr(SPRN_IAMR, sprs.iamr);
|
|
|
|
mtspr(SPRN_AMOR, sprs.amor);
|
|
|
|
mtspr(SPRN_UAMOR, sprs.uamor);
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
/*
|
|
|
|
* Workaround for POWER9 DD2.0, if we lost resources, the ERAT
|
|
|
|
* might have been corrupted and needs flushing. We also need
|
|
|
|
* to reload MMCR0 (see mmcr0 comment above).
|
|
|
|
*/
|
|
|
|
if (!cpu_has_feature(CPU_FTR_POWER9_DD2_1)) {
|
|
|
|
asm volatile(PPC_INVALIDATE_ERAT);
|
|
|
|
mtspr(SPRN_MMCR0, mmcr0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DD2.2 and earlier need to set then clear bit 60 in MMCRA
|
|
|
|
* to ensure the PMU starts running.
|
|
|
|
*/
|
|
|
|
mmcra = mfspr(SPRN_MMCRA);
|
|
|
|
mmcra |= PPC_BIT(60);
|
|
|
|
mtspr(SPRN_MMCRA, mmcra);
|
|
|
|
mmcra &= ~PPC_BIT(60);
|
|
|
|
mtspr(SPRN_MMCRA, mmcra);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely((srr1 & SRR1_WAKEMASK_P8) == SRR1_WAKEHMI))
|
|
|
|
hmi_exception_realmode(NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On POWER9, SRR1 bits do not match exactly as expected.
|
|
|
|
* SRR1_WS_GPRLOSS (10b) can also result in SPR loss, so
|
|
|
|
* just always test PSSCR for SPR/TB state loss.
|
|
|
|
*/
|
|
|
|
pls = (psscr & PSSCR_PLS) >> PSSCR_PLS_SHIFT;
|
|
|
|
if (likely(pls < pnv_first_spr_loss_level)) {
|
|
|
|
if (sprs_saved)
|
|
|
|
atomic_stop_thread_idle();
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HV state loss */
|
|
|
|
BUG_ON(!sprs_saved);
|
|
|
|
|
|
|
|
atomic_lock_thread_idle();
|
|
|
|
|
|
|
|
if ((*state & core_thread_mask) != 0)
|
|
|
|
goto core_woken;
|
|
|
|
|
|
|
|
/* Per-core SPRs */
|
|
|
|
mtspr(SPRN_PTCR, sprs.ptcr);
|
|
|
|
mtspr(SPRN_RPR, sprs.rpr);
|
|
|
|
mtspr(SPRN_TSCR, sprs.tscr);
|
|
|
|
mtspr(SPRN_LDBAR, sprs.ldbar);
|
|
|
|
|
|
|
|
if (pls >= pnv_first_tb_loss_level) {
|
|
|
|
/* TB loss */
|
|
|
|
if (opal_resync_timebase() != OPAL_SUCCESS)
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* isync after restoring shared SPRs and before unlocking. Unlock
|
|
|
|
* only contains hwsync which does not necessarily do the right
|
|
|
|
* thing for SPRs.
|
|
|
|
*/
|
|
|
|
isync();
|
|
|
|
|
|
|
|
core_woken:
|
|
|
|
atomic_unlock_and_stop_thread_idle();
|
|
|
|
|
|
|
|
/* Per-thread SPRs */
|
|
|
|
mtspr(SPRN_LPCR, sprs.lpcr);
|
|
|
|
mtspr(SPRN_HFSCR, sprs.hfscr);
|
|
|
|
mtspr(SPRN_FSCR, sprs.fscr);
|
|
|
|
mtspr(SPRN_PID, sprs.pid);
|
|
|
|
mtspr(SPRN_PURR, sprs.purr);
|
|
|
|
mtspr(SPRN_SPURR, sprs.spurr);
|
|
|
|
mtspr(SPRN_DSCR, sprs.dscr);
|
|
|
|
mtspr(SPRN_WORT, sprs.wort);
|
|
|
|
|
|
|
|
mtspr(SPRN_MMCRA, sprs.mmcra);
|
|
|
|
mtspr(SPRN_MMCR0, sprs.mmcr0);
|
|
|
|
mtspr(SPRN_MMCR1, sprs.mmcr1);
|
|
|
|
mtspr(SPRN_MMCR2, sprs.mmcr2);
|
|
|
|
|
|
|
|
mtspr(SPRN_SPRG3, local_paca->sprg_vdso);
|
|
|
|
|
|
|
|
if (!radix_enabled())
|
|
|
|
__slb_restore_bolted_realmode();
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (mmu_on)
|
|
|
|
mtmsr(MSR_KERNEL);
|
|
|
|
|
|
|
|
return srr1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
static unsigned long power9_offline_stop(unsigned long psscr)
|
|
|
|
{
|
|
|
|
unsigned long srr1;
|
|
|
|
|
|
|
|
#ifndef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
__ppc64_runlatch_off();
|
|
|
|
srr1 = power9_idle_stop(psscr, true);
|
|
|
|
__ppc64_runlatch_on();
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Tell KVM we're entering idle.
|
|
|
|
* This does not have to be done in real mode because the P9 MMU
|
|
|
|
* is independent per-thread. Some steppings share radix/hash mode
|
|
|
|
* between threads, but in that case KVM has a barrier sync in real
|
|
|
|
* mode before and after switching between radix and hash.
|
|
|
|
*
|
|
|
|
* kvm_start_guest must still be called in real mode though, hence
|
|
|
|
* the false argument.
|
|
|
|
*/
|
|
|
|
local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_IDLE;
|
2017-06-13 21:05:45 +08:00
|
|
|
|
2017-06-13 21:05:57 +08:00
|
|
|
__ppc64_runlatch_off();
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
srr1 = power9_idle_stop(psscr, false);
|
2017-06-13 21:05:57 +08:00
|
|
|
__ppc64_runlatch_on();
|
2017-06-13 21:05:45 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_KERNEL;
|
|
|
|
/* Order setting hwthread_state vs. testing hwthread_req */
|
|
|
|
smp_mb();
|
|
|
|
if (local_paca->kvm_hstate.hwthread_req)
|
|
|
|
srr1 = idle_kvm_start_guest(srr1);
|
|
|
|
mtmsr(MSR_KERNEL);
|
|
|
|
#endif
|
2017-06-13 21:05:45 +08:00
|
|
|
|
|
|
|
return srr1;
|
|
|
|
}
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
#endif
|
2017-06-13 21:05:45 +08:00
|
|
|
|
|
|
|
void power9_idle_type(unsigned long stop_psscr_val,
|
|
|
|
unsigned long stop_psscr_mask)
|
|
|
|
{
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
unsigned long psscr;
|
2017-06-13 21:05:47 +08:00
|
|
|
unsigned long srr1;
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (!prep_irq_for_idle_irqsoff())
|
|
|
|
return;
|
|
|
|
|
|
|
|
psscr = mfspr(SPRN_PSSCR);
|
|
|
|
psscr = (psscr & ~stop_psscr_mask) | stop_psscr_val;
|
|
|
|
|
|
|
|
__ppc64_runlatch_off();
|
|
|
|
srr1 = power9_idle_stop(psscr, true);
|
|
|
|
__ppc64_runlatch_on();
|
|
|
|
|
|
|
|
fini_irq_for_idle_irqsoff();
|
|
|
|
|
2017-06-13 21:05:47 +08:00
|
|
|
irq_set_pending_from_srr1(srr1);
|
2017-06-13 21:05:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
/*
|
|
|
|
* Used for ppc_md.power_save which needs a function with no parameters
|
|
|
|
*/
|
2017-06-13 21:05:45 +08:00
|
|
|
void power9_idle(void)
|
2015-04-20 13:02:57 +08:00
|
|
|
{
|
2017-06-13 21:05:45 +08:00
|
|
|
power9_idle_type(pnv_default_stop_val, pnv_default_stop_mask);
|
2016-07-08 14:20:49 +08:00
|
|
|
}
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
/*
|
|
|
|
* This is used in working around bugs in thread reconfiguration
|
|
|
|
* on POWER9 (at least up to Nimbus DD2.2) relating to transactional
|
|
|
|
* memory and the way that XER[SO] is checkpointed.
|
|
|
|
* This function forces the core into SMT4 in order by asking
|
|
|
|
* all other threads not to stop, and sending a message to any
|
|
|
|
* that are in a stop state.
|
|
|
|
* Must be called with preemption disabled.
|
|
|
|
*/
|
|
|
|
void pnv_power9_force_smt4_catch(void)
|
|
|
|
{
|
|
|
|
int cpu, cpu0, thr;
|
|
|
|
int awake_threads = 1; /* this thread is awake */
|
|
|
|
int poke_threads = 0;
|
|
|
|
int need_awake = threads_per_core;
|
|
|
|
|
|
|
|
cpu = smp_processor_id();
|
|
|
|
cpu0 = cpu & ~(threads_per_core - 1);
|
|
|
|
for (thr = 0; thr < threads_per_core; ++thr) {
|
|
|
|
if (cpu != cpu0 + thr)
|
2018-03-30 21:11:24 +08:00
|
|
|
atomic_inc(&paca_ptrs[cpu0+thr]->dont_stop);
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
}
|
|
|
|
/* order setting dont_stop vs testing requested_psscr */
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
smp_mb();
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
for (thr = 0; thr < threads_per_core; ++thr) {
|
2018-03-30 21:11:24 +08:00
|
|
|
if (!paca_ptrs[cpu0+thr]->requested_psscr)
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
++awake_threads;
|
|
|
|
else
|
|
|
|
poke_threads |= (1 << thr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If at least 3 threads are awake, the core is in SMT4 already */
|
|
|
|
if (awake_threads < need_awake) {
|
|
|
|
/* We have to wake some threads; we'll use msgsnd */
|
|
|
|
for (thr = 0; thr < threads_per_core; ++thr) {
|
|
|
|
if (poke_threads & (1 << thr)) {
|
|
|
|
ppc_msgsnd_sync();
|
|
|
|
ppc_msgsnd(PPC_DBELL_MSGTYPE, 0,
|
2018-03-30 21:11:24 +08:00
|
|
|
paca_ptrs[cpu0+thr]->hw_cpu_id);
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now spin until at least 3 threads are awake */
|
|
|
|
do {
|
|
|
|
for (thr = 0; thr < threads_per_core; ++thr) {
|
|
|
|
if ((poke_threads & (1 << thr)) &&
|
2018-03-30 21:11:24 +08:00
|
|
|
!paca_ptrs[cpu0+thr]->requested_psscr) {
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
++awake_threads;
|
|
|
|
poke_threads &= ~(1 << thr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (awake_threads < need_awake);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pnv_power9_force_smt4_catch);
|
|
|
|
|
|
|
|
void pnv_power9_force_smt4_release(void)
|
|
|
|
{
|
|
|
|
int cpu, cpu0, thr;
|
|
|
|
|
|
|
|
cpu = smp_processor_id();
|
|
|
|
cpu0 = cpu & ~(threads_per_core - 1);
|
|
|
|
|
|
|
|
/* clear all the dont_stop flags */
|
|
|
|
for (thr = 0; thr < threads_per_core; ++thr) {
|
|
|
|
if (cpu != cpu0 + thr)
|
2018-03-30 21:11:24 +08:00
|
|
|
atomic_dec(&paca_ptrs[cpu0+thr]->dont_stop);
|
powerpc/powernv: Provide a way to force a core into SMT4 mode
POWER9 processors up to and including "Nimbus" v2.2 have hardware
bugs relating to transactional memory and thread reconfiguration.
One of these bugs has a workaround which is to get the core into
SMT4 state temporarily. This workaround is only needed when
running bare-metal.
This patch provides a function which gets the core into SMT4 mode
by preventing threads from going to a stop state, and waking up
those which are already in a stop state. Once at least 3 threads
are not in a stop state, the core will be in SMT4 and we can
continue.
To do this, we add a "dont_stop" flag to the paca to tell the
thread not to go into a stop state. If this flag is set,
power9_idle_stop() just returns immediately with a return value
of 0. The pnv_power9_force_smt4_catch() function does the following:
1. Set the dont_stop flag for each thread in the core, except
ourselves (in fact we use an atomic_inc() in case more than
one thread is calling this function concurrently).
2. See how many threads are awake, indicated by their
requested_psscr field in the paca being 0. If this is at
least 3, skip to step 5.
3. Send a doorbell interrupt to each thread that was seen as
being in a stop state in step 2.
4. Until at least 3 threads are awake, scan the threads to which
we sent a doorbell interrupt and check if they are awake now.
This relies on the following properties:
- Once dont_stop is non-zero, requested_psccr can't go from zero to
non-zero, except transiently (and without the thread doing stop).
- requested_psscr being zero guarantees that the thread isn't in
a state-losing stop state where thread reconfiguration could occur.
- Doing stop with a PSSCR value of 0 won't be a state-losing stop
and thus won't allow thread reconfiguration.
- Once threads_per_core/2 + 1 (i.e. 3) threads are awake, the core
must be in SMT4 mode, since SMT modes are powers of 2.
This does add a sync to power9_idle_stop(), which is necessary to
provide the correct ordering between setting requested_psscr and
checking dont_stop. The overhead of the sync should be unnoticeable
compared to the latency of going into and out of a stop state.
Because some objected to incurring this extra latency on systems where
the XER[SO] bug is not relevant, I have put the test in
power9_idle_stop inside a feature section. This means that
pnv_power9_force_smt4_catch() WILL NOT WORK correctly on systems
without the CPU_FTR_P9_TM_XER_SO_BUG feature bit set, and will
probably hang the system.
In order to cater for uses where the caller has an operation that
has to be done while the core is in SMT4, the core continues to be
kept in SMT4 after pnv_power9_force_smt4_catch() function returns,
until the pnv_power9_force_smt4_release() function is called.
It undoes the effect of step 1 above and allows the other threads
to go into a stop state.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 18:32:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pnv_power9_force_smt4_release);
|
|
|
|
#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
|
|
|
|
|
2017-05-11 23:15:20 +08:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2019-02-12 08:58:29 +08:00
|
|
|
|
|
|
|
void pnv_program_cpu_hotplug_lpcr(unsigned int cpu, u64 lpcr_val)
|
2017-07-21 19:01:34 +08:00
|
|
|
{
|
|
|
|
u64 pir = get_hard_smp_processor_id(cpu);
|
|
|
|
|
|
|
|
mtspr(SPRN_LPCR, lpcr_val);
|
2017-08-31 19:47:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Program the LPCR via stop-api only if the deepest stop state
|
|
|
|
* can lose hypervisor context.
|
|
|
|
*/
|
|
|
|
if (supported_cpuidle_states & OPAL_PM_LOSE_FULL_CONTEXT)
|
|
|
|
opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val);
|
2017-07-21 19:01:34 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 23:04:14 +08:00
|
|
|
/*
|
|
|
|
* pnv_cpu_offline: A function that puts the CPU into the deepest
|
|
|
|
* available platform idle state on a CPU-Offline.
|
2017-06-13 21:05:46 +08:00
|
|
|
* interrupts hard disabled and no lazy irq pending.
|
2017-03-22 23:04:14 +08:00
|
|
|
*/
|
|
|
|
unsigned long pnv_cpu_offline(unsigned int cpu)
|
|
|
|
{
|
|
|
|
unsigned long srr1;
|
|
|
|
|
2017-06-13 21:05:57 +08:00
|
|
|
__ppc64_runlatch_off();
|
2017-06-13 21:05:46 +08:00
|
|
|
|
powerpc/powernv/idle: Don't override default/deepest directly in kernel
Currently during idle-init on power9, if we don't find suitable stop
states in the device tree that can be used as the
default_stop/deepest_stop, we set stop0 (ESL=1,EC=1) as the default
stop state psscr to be used by power9_idle and deepest stop state
which is used by CPU-Hotplug.
However, if the platform firmware has not configured or enabled a stop
state, the kernel should not make any assumptions and fallback to a
default choice.
If the kernel uses a stop state that is not configured by the platform
firmware, it may lead to further failures which should be avoided.
In this patch, we modify the init code to ensure that the kernel uses
only the stop states exposed by the firmware through the device
tree. When a suitable default stop state isn't found, we disable
ppc_md.power_save for power9. Similarly, when a suitable
deepest_stop_state is not found in the device tree exported by the
firmware, fall back to the default busy-wait loop in the CPU-Hotplug
code.
[Changelog written with inputs from svaidy@linux.vnet.ibm.com]
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-03-22 23:04:16 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300) && deepest_stop_found) {
|
2017-06-13 21:05:46 +08:00
|
|
|
unsigned long psscr;
|
|
|
|
|
|
|
|
psscr = mfspr(SPRN_PSSCR);
|
|
|
|
psscr = (psscr & ~pnv_deepest_stop_psscr_mask) |
|
|
|
|
pnv_deepest_stop_psscr_val;
|
2017-11-17 22:08:05 +08:00
|
|
|
srr1 = power9_offline_stop(psscr);
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
} else if (cpu_has_feature(CPU_FTR_ARCH_206) && power7_offline_type) {
|
|
|
|
srr1 = power7_offline();
|
2017-03-22 23:04:15 +08:00
|
|
|
} else {
|
|
|
|
/* This is the fallback method. We emulate snooze */
|
|
|
|
while (!generic_check_cpu_restart(cpu)) {
|
|
|
|
HMT_low();
|
|
|
|
HMT_very_low();
|
|
|
|
}
|
|
|
|
srr1 = 0;
|
|
|
|
HMT_medium();
|
2017-03-22 23:04:14 +08:00
|
|
|
}
|
|
|
|
|
2017-06-13 21:05:57 +08:00
|
|
|
__ppc64_runlatch_on();
|
2017-06-13 21:05:46 +08:00
|
|
|
|
2017-03-22 23:04:14 +08:00
|
|
|
return srr1;
|
|
|
|
}
|
2017-05-11 23:15:20 +08:00
|
|
|
#endif
|
2017-03-22 23:04:14 +08:00
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
/*
|
|
|
|
* Power ISA 3.0 idle initialization.
|
|
|
|
*
|
|
|
|
* POWER ISA 3.0 defines a new SPR Processor stop Status and Control
|
|
|
|
* Register (PSSCR) to control idle behavior.
|
|
|
|
*
|
|
|
|
* PSSCR layout:
|
|
|
|
* ----------------------------------------------------------
|
|
|
|
* | PLS | /// | SD | ESL | EC | PSLL | /// | TR | MTL | RL |
|
|
|
|
* ----------------------------------------------------------
|
|
|
|
* 0 4 41 42 43 44 48 54 56 60
|
|
|
|
*
|
|
|
|
* PSSCR key fields:
|
|
|
|
* Bits 0:3 - Power-Saving Level Status (PLS). This field indicates the
|
|
|
|
* lowest power-saving state the thread entered since stop instruction was
|
|
|
|
* last executed.
|
|
|
|
*
|
|
|
|
* Bit 41 - Status Disable(SD)
|
|
|
|
* 0 - Shows PLS entries
|
|
|
|
* 1 - PLS entries are all 0
|
|
|
|
*
|
|
|
|
* Bit 42 - Enable State Loss
|
|
|
|
* 0 - No state is lost irrespective of other fields
|
|
|
|
* 1 - Allows state loss
|
|
|
|
*
|
|
|
|
* Bit 43 - Exit Criterion
|
|
|
|
* 0 - Exit from power-save mode on any interrupt
|
|
|
|
* 1 - Exit from power-save mode controlled by LPCR's PECE bits
|
|
|
|
*
|
|
|
|
* Bits 44:47 - Power-Saving Level Limit
|
|
|
|
* This limits the power-saving level that can be entered into.
|
|
|
|
*
|
|
|
|
* Bits 60:63 - Requested Level
|
|
|
|
* Used to specify which power-saving level must be entered on executing
|
|
|
|
* stop instruction
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
int validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* psscr_mask == 0xf indicates an older firmware.
|
|
|
|
* Set remaining fields of psscr to the default values.
|
|
|
|
* See NOTE above definition of PSSCR_HV_DEFAULT_VAL
|
|
|
|
*/
|
|
|
|
if (*psscr_mask == 0xf) {
|
|
|
|
*psscr_val = *psscr_val | PSSCR_HV_DEFAULT_VAL;
|
|
|
|
*psscr_mask = PSSCR_HV_DEFAULT_MASK;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* New firmware is expected to set the psscr_val bits correctly.
|
|
|
|
* Validate that the following invariants are correctly maintained by
|
|
|
|
* the new firmware.
|
|
|
|
* - ESL bit value matches the EC bit value.
|
|
|
|
* - ESL bit is set for all the deep stop states.
|
|
|
|
*/
|
|
|
|
if (GET_PSSCR_ESL(*psscr_val) != GET_PSSCR_EC(*psscr_val)) {
|
|
|
|
err = ERR_EC_ESL_MISMATCH;
|
|
|
|
} else if ((flags & OPAL_PM_LOSE_FULL_CONTEXT) &&
|
|
|
|
GET_PSSCR_ESL(*psscr_val) == 0) {
|
|
|
|
err = ERR_DEEP_STATE_ESL_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pnv_arch300_idle_init: Initializes the default idle state, first
|
|
|
|
* deep idle state and deepest idle state on
|
|
|
|
* ISA 3.0 CPUs.
|
2016-07-08 14:20:49 +08:00
|
|
|
*
|
|
|
|
* @np: /ibm,opal/power-mgt device node
|
|
|
|
* @flags: cpu-idle-state-flags array
|
|
|
|
* @dt_idle_states: Number of idle state entries
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
static void __init pnv_power9_idle_init(void)
|
2016-07-08 14:20:49 +08:00
|
|
|
{
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
u64 max_residency_ns = 0;
|
2018-07-05 19:40:21 +08:00
|
|
|
int i;
|
2015-04-20 13:02:57 +08:00
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
/*
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
* pnv_deepest_stop_{val,mask} should be set to values corresponding to
|
|
|
|
* the deepest stop state.
|
|
|
|
*
|
|
|
|
* pnv_default_stop_{val,mask} should be set to values corresponding to
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
* the deepest loss-less (OPAL_PM_STOP_INST_FAST) stop state.
|
2016-07-08 14:20:49 +08:00
|
|
|
*/
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
pnv_first_tb_loss_level = MAX_STOP_STATE + 1;
|
|
|
|
pnv_first_spr_loss_level = MAX_STOP_STATE + 1;
|
2018-07-05 19:40:21 +08:00
|
|
|
for (i = 0; i < nr_pnv_idle_states; i++) {
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
int err;
|
2018-07-05 19:40:21 +08:00
|
|
|
struct pnv_idle_states_t *state = &pnv_idle_states[i];
|
|
|
|
u64 psscr_rl = state->psscr_val & PSSCR_RL_MASK;
|
2016-07-08 14:20:49 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if ((state->flags & OPAL_PM_TIMEBASE_STOP) &&
|
|
|
|
(pnv_first_tb_loss_level > psscr_rl))
|
|
|
|
pnv_first_tb_loss_level = psscr_rl;
|
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
if ((state->flags & OPAL_PM_LOSE_FULL_CONTEXT) &&
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
(pnv_first_spr_loss_level > psscr_rl))
|
|
|
|
pnv_first_spr_loss_level = psscr_rl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The idle code does not deal with TB loss occurring
|
|
|
|
* in a shallower state than SPR loss, so force it to
|
|
|
|
* behave like SPRs are lost if TB is lost. POWER9 would
|
|
|
|
* never encouter this, but a POWER8 core would if it
|
|
|
|
* implemented the stop instruction. So this is for forward
|
|
|
|
* compatibility.
|
|
|
|
*/
|
|
|
|
if ((state->flags & OPAL_PM_TIMEBASE_STOP) &&
|
|
|
|
(pnv_first_spr_loss_level > psscr_rl))
|
|
|
|
pnv_first_spr_loss_level = psscr_rl;
|
2016-07-08 14:20:53 +08:00
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
err = validate_psscr_val_mask(&state->psscr_val,
|
|
|
|
&state->psscr_mask,
|
|
|
|
state->flags);
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
if (err) {
|
2018-07-05 19:40:21 +08:00
|
|
|
report_invalid_psscr_val(state->psscr_val, err);
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-02 23:39:51 +08:00
|
|
|
state->valid = true;
|
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
if (max_residency_ns < state->residency_ns) {
|
|
|
|
max_residency_ns = state->residency_ns;
|
|
|
|
pnv_deepest_stop_psscr_val = state->psscr_val;
|
|
|
|
pnv_deepest_stop_psscr_mask = state->psscr_mask;
|
|
|
|
pnv_deepest_stop_flag = state->flags;
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
deepest_stop_found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!default_stop_found &&
|
2018-07-05 19:40:21 +08:00
|
|
|
(state->flags & OPAL_PM_STOP_INST_FAST)) {
|
|
|
|
pnv_default_stop_val = state->psscr_val;
|
|
|
|
pnv_default_stop_mask = state->psscr_mask;
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
default_stop_found = true;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
WARN_ON(state->flags & OPAL_PM_LOSE_FULL_CONTEXT);
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
powerpc/powernv/idle: Don't override default/deepest directly in kernel
Currently during idle-init on power9, if we don't find suitable stop
states in the device tree that can be used as the
default_stop/deepest_stop, we set stop0 (ESL=1,EC=1) as the default
stop state psscr to be used by power9_idle and deepest stop state
which is used by CPU-Hotplug.
However, if the platform firmware has not configured or enabled a stop
state, the kernel should not make any assumptions and fallback to a
default choice.
If the kernel uses a stop state that is not configured by the platform
firmware, it may lead to further failures which should be avoided.
In this patch, we modify the init code to ensure that the kernel uses
only the stop states exposed by the firmware through the device
tree. When a suitable default stop state isn't found, we disable
ppc_md.power_save for power9. Similarly, when a suitable
deepest_stop_state is not found in the device tree exported by the
firmware, fall back to the default busy-wait loop in the CPU-Hotplug
code.
[Changelog written with inputs from svaidy@linux.vnet.ibm.com]
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-03-22 23:04:16 +08:00
|
|
|
if (unlikely(!default_stop_found)) {
|
|
|
|
pr_warn("cpuidle-powernv: No suitable default stop state found. Disabling platform idle.\n");
|
|
|
|
} else {
|
|
|
|
ppc_md.power_save = power9_idle;
|
|
|
|
pr_info("cpuidle-powernv: Default stop: psscr = 0x%016llx,mask=0x%016llx\n",
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
pnv_default_stop_val, pnv_default_stop_mask);
|
|
|
|
}
|
|
|
|
|
powerpc/powernv/idle: Don't override default/deepest directly in kernel
Currently during idle-init on power9, if we don't find suitable stop
states in the device tree that can be used as the
default_stop/deepest_stop, we set stop0 (ESL=1,EC=1) as the default
stop state psscr to be used by power9_idle and deepest stop state
which is used by CPU-Hotplug.
However, if the platform firmware has not configured or enabled a stop
state, the kernel should not make any assumptions and fallback to a
default choice.
If the kernel uses a stop state that is not configured by the platform
firmware, it may lead to further failures which should be avoided.
In this patch, we modify the init code to ensure that the kernel uses
only the stop states exposed by the firmware through the device
tree. When a suitable default stop state isn't found, we disable
ppc_md.power_save for power9. Similarly, when a suitable
deepest_stop_state is not found in the device tree exported by the
firmware, fall back to the default busy-wait loop in the CPU-Hotplug
code.
[Changelog written with inputs from svaidy@linux.vnet.ibm.com]
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-03-22 23:04:16 +08:00
|
|
|
if (unlikely(!deepest_stop_found)) {
|
|
|
|
pr_warn("cpuidle-powernv: No suitable stop state for CPU-Hotplug. Offlined CPUs will busy wait");
|
|
|
|
} else {
|
|
|
|
pr_info("cpuidle-powernv: Deepest stop: psscr = 0x%016llx,mask=0x%016llx\n",
|
powernv: Pass PSSCR value and mask to power9_idle_stop
The power9_idle_stop method currently takes only the requested stop
level as a parameter and picks up the rest of the PSSCR bits from a
hand-coded macro. This is not a very flexible design, especially when
the firmware has the capability to communicate the psscr value and the
mask associated with a particular stop state via device tree.
This patch modifies the power9_idle_stop API to take as parameters the
PSSCR value and the PSSCR mask corresponding to the stop state that
needs to be set. These PSSCR value and mask are respectively obtained
by parsing the "ibm,cpu-idle-state-psscr" and
"ibm,cpu-idle-state-psscr-mask" fields from the device tree.
In addition to this, the patch adds support for handling stop states
for which ESL and EC bits in the PSSCR are zero. As per the
architecture, a wakeup from these stop states resumes execution from
the subsequent instruction as opposed to waking up at the System
Vector.
The older firmware sets only the Requested Level (RL) field in the
psscr and psscr-mask exposed in the device tree. For older firmware
where psscr-mask=0xf, this patch will set the default sane values that
the set for for remaining PSSCR fields (i.e PSLL, MTL, ESL, EC, and
TR). For the new firmware, the patch will validate that the invariants
required by the ISA for the psscr values are maintained by the
firmware.
This skiboot patch that exports fully populated PSSCR values and the
mask for all the stop states can be found here:
https://lists.ozlabs.org/pipermail/skiboot/2016-September/004869.html
[Optimize the number of instructions before entering STOP with
ESL=EC=0, validate the PSSCR values provided by the firimware
maintains the invariants required as per the ISA suggested by Balbir
Singh]
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-01-25 16:36:28 +08:00
|
|
|
pnv_deepest_stop_psscr_val,
|
|
|
|
pnv_deepest_stop_psscr_mask);
|
2016-07-08 14:20:49 +08:00
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
pr_info("cpuidle-powernv: First stop level that may lose SPRs = 0x%lld\n",
|
|
|
|
pnv_first_spr_loss_level);
|
2018-07-05 19:40:21 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
pr_info("cpuidle-powernv: First stop level that may lose timebase = 0x%lld\n",
|
|
|
|
pnv_first_tb_loss_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init pnv_disable_deep_states(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The stop-api is unable to restore hypervisor
|
|
|
|
* resources on wakeup from platform idle states which
|
|
|
|
* lose full context. So disable such states.
|
|
|
|
*/
|
|
|
|
supported_cpuidle_states &= ~OPAL_PM_LOSE_FULL_CONTEXT;
|
|
|
|
pr_warn("cpuidle-powernv: Disabling idle states that lose full context\n");
|
|
|
|
pr_warn("cpuidle-powernv: Idle power-savings, CPU-Hotplug affected\n");
|
|
|
|
|
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300) &&
|
|
|
|
(pnv_deepest_stop_flag & OPAL_PM_LOSE_FULL_CONTEXT)) {
|
|
|
|
/*
|
|
|
|
* Use the default stop state for CPU-Hotplug
|
|
|
|
* if available.
|
|
|
|
*/
|
|
|
|
if (default_stop_found) {
|
|
|
|
pnv_deepest_stop_psscr_val = pnv_default_stop_val;
|
|
|
|
pnv_deepest_stop_psscr_mask = pnv_default_stop_mask;
|
|
|
|
pr_warn("cpuidle-powernv: Offlined CPUs will stop with psscr = 0x%016llx\n",
|
|
|
|
pnv_deepest_stop_psscr_val);
|
|
|
|
} else { /* Fallback to snooze loop for CPU-Hotplug */
|
|
|
|
deepest_stop_found = false;
|
|
|
|
pr_warn("cpuidle-powernv: Offlined CPUs will busy wait\n");
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 14:20:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe device tree for supported idle states
|
|
|
|
*/
|
|
|
|
static void __init pnv_probe_idle_states(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
if (nr_pnv_idle_states < 0) {
|
|
|
|
pr_warn("cpuidle-powernv: no idle states found in the DT\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300))
|
|
|
|
pnv_power9_idle_init();
|
2018-07-05 19:40:21 +08:00
|
|
|
|
|
|
|
for (i = 0; i < nr_pnv_idle_states; i++)
|
|
|
|
supported_cpuidle_states |= pnv_idle_states[i].flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function parses device-tree and populates all the information
|
|
|
|
* into pnv_idle_states structure. It also sets up nr_pnv_idle_states
|
|
|
|
* which is the number of cpuidle states discovered through device-tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int pnv_parse_cpuidle_dt(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
int nr_idle_states, i;
|
|
|
|
int rc = 0;
|
|
|
|
u32 *temp_u32;
|
|
|
|
u64 *temp_u64;
|
|
|
|
const char **temp_string;
|
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
np = of_find_node_by_path("/ibm,opal/power-mgt");
|
|
|
|
if (!np) {
|
2015-04-20 13:02:57 +08:00
|
|
|
pr_warn("opal: PowerMgmt Node not found\n");
|
2018-07-05 19:40:21 +08:00
|
|
|
return -ENODEV;
|
2015-04-20 13:02:57 +08:00
|
|
|
}
|
2018-07-05 19:40:21 +08:00
|
|
|
nr_idle_states = of_property_count_u32_elems(np,
|
|
|
|
"ibm,cpu-idle-state-flags");
|
|
|
|
|
|
|
|
pnv_idle_states = kcalloc(nr_idle_states, sizeof(*pnv_idle_states),
|
|
|
|
GFP_KERNEL);
|
|
|
|
temp_u32 = kcalloc(nr_idle_states, sizeof(u32), GFP_KERNEL);
|
|
|
|
temp_u64 = kcalloc(nr_idle_states, sizeof(u64), GFP_KERNEL);
|
|
|
|
temp_string = kcalloc(nr_idle_states, sizeof(char *), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!(pnv_idle_states && temp_u32 && temp_u64 && temp_string)) {
|
|
|
|
pr_err("Could not allocate memory for dt parsing\n");
|
|
|
|
rc = -ENOMEM;
|
2015-04-20 13:02:57 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
/* Read flags */
|
|
|
|
if (of_property_read_u32_array(np, "ibm,cpu-idle-state-flags",
|
|
|
|
temp_u32, nr_idle_states)) {
|
2015-04-20 13:02:57 +08:00
|
|
|
pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-flags in DT\n");
|
2018-07-05 19:40:21 +08:00
|
|
|
rc = -EINVAL;
|
2016-07-08 14:20:49 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2018-07-05 19:40:21 +08:00
|
|
|
for (i = 0; i < nr_idle_states; i++)
|
|
|
|
pnv_idle_states[i].flags = temp_u32[i];
|
|
|
|
|
|
|
|
/* Read latencies */
|
|
|
|
if (of_property_read_u32_array(np, "ibm,cpu-idle-state-latencies-ns",
|
|
|
|
temp_u32, nr_idle_states)) {
|
|
|
|
pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n");
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nr_idle_states; i++)
|
|
|
|
pnv_idle_states[i].latency_ns = temp_u32[i];
|
|
|
|
|
|
|
|
/* Read residencies */
|
|
|
|
if (of_property_read_u32_array(np, "ibm,cpu-idle-state-residency-ns",
|
|
|
|
temp_u32, nr_idle_states)) {
|
|
|
|
pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n");
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nr_idle_states; i++)
|
|
|
|
pnv_idle_states[i].residency_ns = temp_u32[i];
|
2016-07-08 14:20:49 +08:00
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
/* For power9 */
|
2016-07-08 14:20:49 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300)) {
|
2018-07-05 19:40:21 +08:00
|
|
|
/* Read pm_crtl_val */
|
|
|
|
if (of_property_read_u64_array(np, "ibm,cpu-idle-state-psscr",
|
|
|
|
temp_u64, nr_idle_states)) {
|
|
|
|
pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n");
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nr_idle_states; i++)
|
|
|
|
pnv_idle_states[i].psscr_val = temp_u64[i];
|
|
|
|
|
|
|
|
/* Read pm_crtl_mask */
|
|
|
|
if (of_property_read_u64_array(np, "ibm,cpu-idle-state-psscr-mask",
|
|
|
|
temp_u64, nr_idle_states)) {
|
|
|
|
pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr-mask in DT\n");
|
|
|
|
rc = -EINVAL;
|
2016-07-08 14:20:49 +08:00
|
|
|
goto out;
|
2018-07-05 19:40:21 +08:00
|
|
|
}
|
|
|
|
for (i = 0; i < nr_idle_states; i++)
|
|
|
|
pnv_idle_states[i].psscr_mask = temp_u64[i];
|
2015-04-20 13:02:57 +08:00
|
|
|
}
|
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
/*
|
|
|
|
* power8 specific properties ibm,cpu-idle-state-pmicr-mask and
|
|
|
|
* ibm,cpu-idle-state-pmicr-val were never used and there is no
|
|
|
|
* plan to use it in near future. Hence, not parsing these properties
|
|
|
|
*/
|
2015-04-20 13:02:57 +08:00
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
if (of_property_read_string_array(np, "ibm,cpu-idle-state-names",
|
|
|
|
temp_string, nr_idle_states) < 0) {
|
|
|
|
pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n");
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nr_idle_states; i++)
|
2018-08-09 21:37:20 +08:00
|
|
|
strlcpy(pnv_idle_states[i].name, temp_string[i],
|
2018-07-05 19:40:21 +08:00
|
|
|
PNV_IDLE_NAME_LEN);
|
|
|
|
nr_pnv_idle_states = nr_idle_states;
|
|
|
|
rc = 0;
|
2016-07-08 14:20:49 +08:00
|
|
|
out:
|
2018-07-05 19:40:21 +08:00
|
|
|
kfree(temp_u32);
|
|
|
|
kfree(temp_u64);
|
|
|
|
kfree(temp_string);
|
|
|
|
return rc;
|
2016-07-08 14:20:49 +08:00
|
|
|
}
|
2018-07-05 19:40:21 +08:00
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
static int __init pnv_init_idle_states(void)
|
|
|
|
{
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
int cpu;
|
2018-07-05 19:40:21 +08:00
|
|
|
int rc = 0;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
|
|
|
|
/* Set up PACA fields */
|
|
|
|
for_each_present_cpu(cpu) {
|
|
|
|
struct paca_struct *p = paca_ptrs[cpu];
|
|
|
|
|
|
|
|
p->idle_state = 0;
|
|
|
|
if (cpu == cpu_first_thread_sibling(cpu))
|
|
|
|
p->idle_state = (1 << threads_per_core) - 1;
|
|
|
|
|
|
|
|
if (!cpu_has_feature(CPU_FTR_ARCH_300)) {
|
|
|
|
/* P7/P8 nap */
|
|
|
|
p->thread_idle_state = PNV_THREAD_RUNNING;
|
|
|
|
} else {
|
|
|
|
/* P9 stop */
|
|
|
|
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
|
|
|
|
p->requested_psscr = 0;
|
|
|
|
atomic_set(&p->dont_stop, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 14:20:49 +08:00
|
|
|
|
2018-07-05 19:40:21 +08:00
|
|
|
/* In case we error out nr_pnv_idle_states will be zero */
|
|
|
|
nr_pnv_idle_states = 0;
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
supported_cpuidle_states = 0;
|
|
|
|
|
2016-07-08 14:20:49 +08:00
|
|
|
if (cpuidle_disable != IDLE_NO_OVERRIDE)
|
|
|
|
goto out;
|
2018-07-05 19:40:21 +08:00
|
|
|
rc = pnv_parse_cpuidle_dt();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2016-07-08 14:20:49 +08:00
|
|
|
pnv_probe_idle_states();
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (!cpu_has_feature(CPU_FTR_ARCH_300)) {
|
|
|
|
if (!(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1)) {
|
|
|
|
power7_fastsleep_workaround_entry = false;
|
|
|
|
power7_fastsleep_workaround_exit = false;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* OPAL_PM_SLEEP_ENABLED_ER1 is set. It indicates that
|
|
|
|
* workaround is needed to use fastsleep. Provide sysfs
|
|
|
|
* control to choose how this workaround has to be
|
|
|
|
* applied.
|
|
|
|
*/
|
|
|
|
device_create_file(cpu_subsys.dev_root,
|
2015-04-20 13:02:58 +08:00
|
|
|
&dev_attr_fastsleep_workaround_applyonce);
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
update_subcore_sibling_mask();
|
|
|
|
|
|
|
|
if (supported_cpuidle_states & OPAL_PM_NAP_ENABLED) {
|
|
|
|
ppc_md.power_save = power7_idle;
|
|
|
|
power7_offline_type = PNV_THREAD_NAP;
|
|
|
|
}
|
2015-04-20 13:02:58 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if ((supported_cpuidle_states & OPAL_PM_WINKLE_ENABLED) &&
|
|
|
|
(supported_cpuidle_states & OPAL_PM_LOSE_FULL_CONTEXT))
|
|
|
|
power7_offline_type = PNV_THREAD_WINKLE;
|
|
|
|
else if ((supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED) ||
|
|
|
|
(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1))
|
|
|
|
power7_offline_type = PNV_THREAD_SLEEP;
|
|
|
|
}
|
2016-06-09 00:54:27 +08:00
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 22:30:52 +08:00
|
|
|
if (supported_cpuidle_states & OPAL_PM_LOSE_FULL_CONTEXT) {
|
|
|
|
if (pnv_save_sprs_for_deep_states())
|
|
|
|
pnv_disable_deep_states();
|
|
|
|
}
|
2016-07-08 14:20:49 +08:00
|
|
|
|
2015-04-20 13:02:57 +08:00
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-15 13:01:32 +08:00
|
|
|
machine_subsys_initcall(powernv, pnv_init_idle_states);
|