aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2015-03-27 23:21:08 -0400
committerAlexander Graf <agraf@suse.de>2015-04-21 09:21:33 -0400
commitfd6d53b12410b4b73e3996629350dee3f4a7994f (patch)
tree30cfe656f5eda6adf02fa36d9bc65fca7ef4a4d0
parentccc07772c99befeda7a7a4b1d05a6f3b762518c2 (diff)
KVM: PPC: Book3S HV: Use decrementer to wake napping threads
This arranges for threads that are napping due to their vcpu having ceded or due to not having a vcpu to wake up at the end of the guest's timeslice without having to be poked with an IPI. We do that by arranging for the decrementer to contain a value no greater than the number of timebase ticks remaining until the end of the timeslice. In the case of a thread with no vcpu, this number is in the hypervisor decrementer already. In the case of a ceded vcpu, we use the smaller of the HDEC value and the DEC value. Using the DEC like this when ceded means we need to save and restore the guest decrementer value around the nap. Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Alexander Graf <agraf@suse.de>
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S43
1 files changed, 41 insertions, 2 deletions
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 12d7e4c8dc54..16719af88bcc 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -172,6 +172,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
172 172
173kvmppc_primary_no_guest: 173kvmppc_primary_no_guest:
174 /* We handle this much like a ceded vcpu */ 174 /* We handle this much like a ceded vcpu */
175 /* put the HDEC into the DEC, since HDEC interrupts don't wake us */
176 mfspr r3, SPRN_HDEC
177 mtspr SPRN_DEC, r3
175 /* set our bit in napping_threads */ 178 /* set our bit in napping_threads */
176 ld r5, HSTATE_KVM_VCORE(r13) 179 ld r5, HSTATE_KVM_VCORE(r13)
177 lbz r7, HSTATE_PTID(r13) 180 lbz r7, HSTATE_PTID(r13)
@@ -223,6 +226,12 @@ kvm_novcpu_wakeup:
223 cmpdi r3, 0 226 cmpdi r3, 0
224 bge kvm_novcpu_exit 227 bge kvm_novcpu_exit
225 228
229 /* See if our timeslice has expired (HDEC is negative) */
230 mfspr r0, SPRN_HDEC
231 li r12, BOOK3S_INTERRUPT_HV_DECREMENTER
232 cmpwi r0, 0
233 blt kvm_novcpu_exit
234
226 /* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */ 235 /* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */
227 ld r4, HSTATE_KVM_VCPU(r13) 236 ld r4, HSTATE_KVM_VCPU(r13)
228 cmpdi r4, 0 237 cmpdi r4, 0
@@ -1493,10 +1502,10 @@ kvmhv_do_exit: /* r12 = trap, r13 = paca */
1493 cmpwi r3,0x100 /* Are we the first here? */ 1502 cmpwi r3,0x100 /* Are we the first here? */
1494 bge 43f 1503 bge 43f
1495 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER 1504 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
1496 beq 40f 1505 beq 43f
1497 li r0,0 1506 li r0,0
1498 mtspr SPRN_HDEC,r0 1507 mtspr SPRN_HDEC,r0
149940: 1508
1500 /* 1509 /*
1501 * Send an IPI to any napping threads, since an HDEC interrupt 1510 * Send an IPI to any napping threads, since an HDEC interrupt
1502 * doesn't wake CPUs up from nap. 1511 * doesn't wake CPUs up from nap.
@@ -2124,6 +2133,27 @@ _GLOBAL(kvmppc_h_cede) /* r3 = vcpu pointer, r11 = msr, r13 = paca */
2124 /* save FP state */ 2133 /* save FP state */
2125 bl kvmppc_save_fp 2134 bl kvmppc_save_fp
2126 2135
2136 /*
2137 * Set DEC to the smaller of DEC and HDEC, so that we wake
2138 * no later than the end of our timeslice (HDEC interrupts
2139 * don't wake us from nap).
2140 */
2141 mfspr r3, SPRN_DEC
2142 mfspr r4, SPRN_HDEC
2143 mftb r5
2144 cmpw r3, r4
2145 ble 67f
2146 mtspr SPRN_DEC, r4
214767:
2148 /* save expiry time of guest decrementer */
2149 extsw r3, r3
2150 add r3, r3, r5
2151 ld r4, HSTATE_KVM_VCPU(r13)
2152 ld r5, HSTATE_KVM_VCORE(r13)
2153 ld r6, VCORE_TB_OFFSET(r5)
2154 subf r3, r6, r3 /* convert to host TB value */
2155 std r3, VCPU_DEC_EXPIRES(r4)
2156
2127#ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING 2157#ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING
2128 ld r4, HSTATE_KVM_VCPU(r13) 2158 ld r4, HSTATE_KVM_VCPU(r13)
2129 addi r3, r4, VCPU_TB_CEDE 2159 addi r3, r4, VCPU_TB_CEDE
@@ -2181,6 +2211,15 @@ kvm_end_cede:
2181 /* load up FP state */ 2211 /* load up FP state */
2182 bl kvmppc_load_fp 2212 bl kvmppc_load_fp
2183 2213
2214 /* Restore guest decrementer */
2215 ld r3, VCPU_DEC_EXPIRES(r4)
2216 ld r5, HSTATE_KVM_VCORE(r13)
2217 ld r6, VCORE_TB_OFFSET(r5)
2218 add r3, r3, r6 /* convert host TB to guest TB value */
2219 mftb r7
2220 subf r3, r7, r3
2221 mtspr SPRN_DEC, r3
2222
2184 /* Load NV GPRS */ 2223 /* Load NV GPRS */
2185 ld r14, VCPU_GPR(R14)(r4) 2224 ld r14, VCPU_GPR(R14)(r4)
2186 ld r15, VCPU_GPR(R15)(r4) 2225 ld r15, VCPU_GPR(R15)(r4)