ppcr: Avoid decrementer related kvm exits
PATCH 1/1 ppcr: Avoid decrementer related kvm exits
In __cpu_ppc_store_decr(), we set up a regular timer used to trigger decrementer interrupts. This is necessary to implement the decrementer properly under TCG, but is unnecessary under KVM (true for both Book3S-PR and Book3S-HV KVM variants), because the kernel handles generating and delivering decrementer exceptions.
Under kvm, in fact, the timer causes expensive and unnecessary exits from kvm to qemu. This patch, therefore, disables setting the timer when kvm is in use.
--- hw/ppc.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)
hw/ppc.c +14 -11
@@ -658,21 +658,24 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp, int is_excp) {ppc_tb_t *tb_env = env->tb_env; -uint64_t now, next;LOG_TB ("%s: %08" PRIx32" => %08" PRIx32"\n" , __func__, decr, value); - now =qemu_get_clock_ns (vm_clock); - next = now +muldiv64 (value,get_ticks_per_sec (), tb_env->decr_freq); -if (is_excp) { - next += *nextp - now; - } -if (next == now) { - next++; +if (!kvm_enabled ()) { +uint64_t now, next; + + now =qemu_get_clock_ns (vm_clock); + next = now +muldiv64 (value,get_ticks_per_sec (), tb_env->decr_freq); +if (is_excp) { + next += *nextp - now; + } +if (next == now) { + next++; + } + *nextp = next; +/* Adjust timer */ +qemu_mod_timer (timer, next); } - *nextp = next; -/* Adjust timer */ -qemu_mod_timer (timer, next);/* If we set a negative value and the decrementer was positive, raise an * exception.
Signature · 1 line
1.7.6.3
hw/ppc.c static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
Quoted 21 lines · David Gibson
In
__cpu_ppc_store_decr(), we set up a regular timer used to trigger decrementer interrupts. This is necessary to implement the decrementer properly under TCG, but is unnecessary under KVM (true for both Book3S-PR and Book3S-HV KVM variants), because the kernel handles generating and delivering decrementer exceptions.Under kvm, in fact, the timer causes expensive and unnecessary exits from kvm to qemu. This patch, therefore, disables setting the timer when kvm is in use.
Signed-off-by Anton Blanchard <[email protected]>Signed-off-by David Gibson <[email protected]>---
hw/ppc.c| 25 ++++++++++++++-----------1 files changed, 14 insertions(+), 11 deletions(-)hw/ppc.c +0
-0@@ -658,21 +658,24 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
Do we ever call store_decr in the kvm case? Isn't that only called from emulated mtdec?
Alex
Quoted 38 lines
hw/ppc.c +14
-11int is_excp) {ppc_tb_t *tb_env = env->tb_env; -uint64_t now, next;LOG_TB ("%s: %08" PRIx32" => %08" PRIx32"\n" , __func__, decr, value); - now =qemu_get_clock_ns (vm_clock); - next = now +muldiv64 (value,get_ticks_per_sec (), tb_env->decr_freq); -if (is_excp) { - next += *nextp - now; - } -if (next == now) { - next++; +if (!kvm_enabled ()) { +uint64_t now, next; + + now =qemu_get_clock_ns (vm_clock); + next = now +muldiv64 (value,get_ticks_per_sec (), tb_env->decr_freq); +if (is_excp) { + next += *nextp - now; + } +if (next == now) { + next++; + } + *nextp = next; +/* Adjust timer */ +qemu_mod_timer (timer, next); } - *nextp = next; -/* Adjust timer */ -qemu_mod_timer (timer, next);/* If we set a negative value and the decrementer was positive, raise an * exception. Signature · 1 line
1.7.6.3
Quoted 19 lines · Alexander Graf
Quoted 16 lines · David Gibson
In
__cpu_ppc_store_decr(), we set up a regular timer used to trigger decrementer interrupts. This is necessary to implement the decrementer properly under TCG, but is unnecessary under KVM (true for both Book3S-PR and Book3S-HV KVM variants), because the kernel handles generating and delivering decrementer exceptions.Under kvm, in fact, the timer causes expensive and unnecessary exits from kvm to qemu. This patch, therefore, disables setting the timer when kvm is in use.
Signed-off-by Anton Blanchard <[email protected]>Signed-off-by David Gibson <[email protected]>---
hw/ppc.c| 25 ++++++++++++++-----------1 files changed, 14 insertions(+), 11 deletions(-)
Quoted 8 lines
hw/ppc.c static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
Quoted 5 lines
hw/ppc.c +0
-0@@ -658,21 +658,24 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,Do we ever call
store_decrin the kvm case? Isn't that only called from emulated mtdec?
Yes, from cpu_ppc_set_tb_clk(). Anton observed the kvm exits in the wild, they're not theoretical.
Agh, which reminds me, I forgot to fixup the git author again. The patch should show authorship by Anton Blanchard <[email protected]>, as in the s-o-b.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 29 lines · David Gibson
Quoted 19 lines · Alexander Graf
Quoted 16 lines · David Gibson
In
__cpu_ppc_store_decr(), we set up a regular timer used to trigger decrementer interrupts. This is necessary to implement the decrementer properly under TCG, but is unnecessary under KVM (true for both Book3S-PR and Book3S-HV KVM variants), because the kernel handles generating and delivering decrementer exceptions.Under kvm, in fact, the timer causes expensive and unnecessary exits from kvm to qemu. This patch, therefore, disables setting the timer when kvm is in use.
Signed-off-by Anton Blanchard <[email protected]>Signed-off-by David Gibson <[email protected]>---
hw/ppc.c| 25 ++++++++++++++-----------1 files changed, 14 insertions(+), 11 deletions(-)Quoted 8 lines
hw/ppc.c static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
Quoted 5 lines
hw/ppc.c +0
-0@@ -658,21 +658,24 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,Do we ever call
store_decrin the kvm case? Isn't that only called from emulated mtdec?
Quoted 6 lines
Yes, from
cpu_ppc_set_tb_clk(). Anton observed the kvm exits in the wild, they're not theoretical.Agh, which reminds me, I forgot to fixup the git author again. The patch should show authorship by Anton Blanchard <[email protected]>, as in the s-o-b.
Wouldn't a simple
if (kvm_enabled()) {
return;
}in the beginning of the function make more sense? There's no code connecting the in-qemu and the in-kvm decrementors atm, so any logic applying to the in-qemu one is moot for kvm.
Alex
Quoted 41 lines · Alexander Graf
Quoted 29 lines · David Gibson
Quoted 19 lines · Alexander Graf
Quoted 16 lines · David Gibson
In
__cpu_ppc_store_decr(), we set up a regular timer used to trigger decrementer interrupts. This is necessary to implement the decrementer properly under TCG, but is unnecessary under KVM (true for both Book3S-PR and Book3S-HV KVM variants), because the kernel handles generating and delivering decrementer exceptions.Under kvm, in fact, the timer causes expensive and unnecessary exits from kvm to qemu. This patch, therefore, disables setting the timer when kvm is in use.
Signed-off-by Anton Blanchard <[email protected]>Signed-off-by David Gibson <[email protected]>---
hw/ppc.c| 25 ++++++++++++++-----------1 files changed, 14 insertions(+), 11 deletions(-)Quoted 8 lines
hw/ppc.c static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
Quoted 5 lines
hw/ppc.c +0
-0@@ -658,21 +658,24 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,Do we ever call
store_decrin the kvm case? Isn't that only called from emulated mtdec?Quoted 6 lines
Yes, from
cpu_ppc_set_tb_clk(). Anton observed the kvm exits in the wild, they're not theoretical.Agh, which reminds me, I forgot to fixup the git author again. The patch should show authorship by Anton Blanchard <[email protected]>, as in the s-o-b.
Wouldn't a simple
Quoted 7 lines
if (kvm_enabled()) { return; }in the beginning of the function make more sense? There's no code connecting the in-qemu and the in-kvm decrementors atm, so any logic applying to the in-qemu one is moot for kvm.
Uh.. I guess so. I wasn't 100% sure the last bit of code in the function wouldn't have some effect on kvm. But I guess it doesn't; I'll revise.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 46 lines · David Gibson
Quoted 45 lines · Alexander Graf
Quoted 29 lines · David Gibson
Quoted 19 lines · Alexander Graf
Quoted 16 lines · David Gibson
In
__cpu_ppc_store_decr(), we set up a regular timer used to trigger decrementer interrupts. This is necessary to implement the decrementer properly under TCG, but is unnecessary under KVM (true for both Book3S-PR and Book3S-HV KVM variants), because the kernel handles generating and delivering decrementer exceptions.Under kvm, in fact, the timer causes expensive and unnecessary exits from kvm to qemu. This patch, therefore, disables setting the timer when kvm is in use.
Signed-off-by Anton Blanchard <[email protected]>Signed-off-by David Gibson <[email protected]>---
hw/ppc.c| 25 ++++++++++++++-----------1 files changed, 14 insertions(+), 11 deletions(-)Quoted 8 lines
hw/ppc.c static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,
Quoted 5 lines
hw/ppc.c +0
-0@@ -658,21 +658,24 @@ static void __cpu_ppc_store_decr (CPUState *env, uint64_t *nextp,Do we ever call
store_decrin the kvm case? Isn't that only called from emulated mtdec?Quoted 6 lines
Yes, from
cpu_ppc_set_tb_clk(). Anton observed the kvm exits in the wild, they're not theoretical.Agh, which reminds me, I forgot to fixup the git author again. The patch should show authorship by Anton Blanchard <[email protected]>, as in the s-o-b.
Wouldn't a simple
if (kvm_enabled()) { return; }
Quoted 7 lines
Quoted 3 lines
in the beginning of the function make more sense? There's no code connecting the in-qemu and the in-kvm decrementors atm, so any logic applying to the in-qemu one is moot for kvm.
Uh.. I guess so. I wasn't 100% sure the last bit of code in the function wouldn't have some effect on kvm. But I guess it doesn't; I'll revise.
Revised patch sent.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 7 lines · Alexander Graf
Wouldn't a simple
if (kvm_enabled()) { return; }in the beginning of the function make more sense? There's no code connecting the in-qemu and the in-kvm decrementors atm, so any logic applying to the in-qemu one is moot for kvm.
On book3e at least, we can use sregs to set the decrementer, and we probably want this to happen on reset.
-Scott
Quoted 11 lines · Scott Wood
Quoted 7 lines · Alexander Graf
Wouldn't a simple
if (kvm_enabled()) { return; }in the beginning of the function make more sense? There's no code connecting the in-qemu and the in-kvm decrementors atm, so any logic applying to the in-qemu one is moot for kvm.
On book3e at least, we can use sregs to set the decrementer, and we probably want this to happen on reset.
Sure.
if (kvm_enabled()) {
kvmppc_set_dec(x);
return;
}Alex