All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Emilio G. Cota" <cota@braap.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	qemu-ppc@nongnu.org
Subject: [Qemu-devel] [PATCH v7 18/73] ppc: convert to cpu_halted
Date: Mon,  4 Mar 2019 13:17:18 -0500	[thread overview]
Message-ID: <20190304181813.8075-19-cota@braap.org> (raw)
In-Reply-To: <20190304181813.8075-1-cota@braap.org>

In ppce500_spin.c, acquire the lock just once to update
both cpu->halted and cpu->stopped.

In hw/ppc/spapr_hcall.c, acquire the lock just once to
update cpu->halted and call cpu_has_work, since later
in the series we'll acquire the BQL (if not already held)
from cpu_has_work.

Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-ppc@nongnu.org
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 target/ppc/helper_regs.h        |  2 +-
 hw/ppc/e500.c                   |  4 ++--
 hw/ppc/ppc.c                    | 10 +++++-----
 hw/ppc/ppce500_spin.c           |  6 ++++--
 hw/ppc/spapr_cpu_core.c         |  4 ++--
 hw/ppc/spapr_hcall.c            |  4 +++-
 hw/ppc/spapr_rtas.c             |  6 +++---
 target/ppc/excp_helper.c        |  4 ++--
 target/ppc/kvm.c                |  4 ++--
 target/ppc/translate_init.inc.c |  6 +++---
 10 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/target/ppc/helper_regs.h b/target/ppc/helper_regs.h
index a2205e1044..5afce54318 100644
--- a/target/ppc/helper_regs.h
+++ b/target/ppc/helper_regs.h
@@ -161,7 +161,7 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
 #if !defined(CONFIG_USER_ONLY)
     if (unlikely(msr_pow == 1)) {
         if (!env->pending_interrupts && (*env->check_pow)(env)) {
-            cs->halted = 1;
+            cpu_halted_set(cs, 1);
             excp = EXCP_HALTED;
         }
     }
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 7553f674c9..4e82906ef2 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -657,7 +657,7 @@ static void ppce500_cpu_reset_sec(void *opaque)
 
     /* Secondary CPU starts in halted state for now. Needs to change when
        implementing non-kernel boot. */
-    cs->halted = 1;
+    cpu_halted_set(cs, 1);
     cs->exception_index = EXCP_HLT;
 }
 
@@ -671,7 +671,7 @@ static void ppce500_cpu_reset(void *opaque)
     cpu_reset(cs);
 
     /* Set initial guest state. */
-    cs->halted = 0;
+    cpu_halted_set(cs, 0);
     env->gpr[1] = (16 * MiB) - 8;
     env->gpr[3] = bi->dt_base;
     env->gpr[4] = 0;
diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index d1e3d4cd20..45e212390a 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -149,7 +149,7 @@ static void ppc6xx_set_irq(void *opaque, int pin, int level)
             /* XXX: Note that the only way to restart the CPU is to reset it */
             if (level) {
                 LOG_IRQ("%s: stop the CPU\n", __func__);
-                cs->halted = 1;
+                cpu_halted_set(cs, 1);
             }
             break;
         case PPC6xx_INPUT_HRESET:
@@ -228,10 +228,10 @@ static void ppc970_set_irq(void *opaque, int pin, int level)
             /* XXX: TODO: relay the signal to CKSTP_OUT pin */
             if (level) {
                 LOG_IRQ("%s: stop the CPU\n", __func__);
-                cs->halted = 1;
+                cpu_halted_set(cs, 1);
             } else {
                 LOG_IRQ("%s: restart the CPU\n", __func__);
-                cs->halted = 0;
+                cpu_halted_set(cs, 0);
                 qemu_cpu_kick(cs);
             }
             break;
@@ -457,10 +457,10 @@ static void ppc40x_set_irq(void *opaque, int pin, int level)
             /* Level sensitive - active low */
             if (level) {
                 LOG_IRQ("%s: stop the CPU\n", __func__);
-                cs->halted = 1;
+                cpu_halted_set(cs, 1);
             } else {
                 LOG_IRQ("%s: restart the CPU\n", __func__);
-                cs->halted = 0;
+                cpu_halted_set(cs, 0);
                 qemu_cpu_kick(cs);
             }
             break;
diff --git a/hw/ppc/ppce500_spin.c b/hw/ppc/ppce500_spin.c
index c45fc858de..4b3532730f 100644
--- a/hw/ppc/ppce500_spin.c
+++ b/hw/ppc/ppce500_spin.c
@@ -107,9 +107,11 @@ static void spin_kick(CPUState *cs, run_on_cpu_data data)
     map_start = ldq_p(&curspin->addr) & ~(map_size - 1);
     mmubooke_create_initial_mapping(env, 0, map_start, map_size);
 
-    cs->halted = 0;
-    cs->exception_index = -1;
+    cpu_mutex_lock(cs);
+    cpu_halted_set(cs, 0);
     cs->stopped = false;
+    cpu_mutex_unlock(cs);
+    cs->exception_index = -1;
     qemu_cpu_kick(cs);
 }
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index ef6cbb9c29..cbb8474cad 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -36,7 +36,7 @@ static void spapr_cpu_reset(void *opaque)
     /* All CPUs start halted.  CPU0 is unhalted from the machine level
      * reset code and the rest are explicitly started up by the guest
      * using an RTAS call */
-    cs->halted = 1;
+    cpu_halted_set(cs, 1);
 
     /* Set compatibility mode to match the boot CPU, which was either set
      * by the machine reset code or by CAS. This should never fail.
@@ -90,7 +90,7 @@ void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip, target_ulong r
     env->nip = nip;
     env->gpr[3] = r3;
     kvmppc_set_reg_ppc_online(cpu, 1);
-    CPU(cpu)->halted = 0;
+    cpu_halted_set(CPU(cpu), 0);
     /* Enable Power-saving mode Exit Cause exceptions */
     ppc_store_lpcr(cpu, env->spr[SPR_LPCR] | pcc->lpcr_pm);
 }
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 476bad6271..2ff49ece8e 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1057,11 +1057,13 @@ static target_ulong h_cede(PowerPCCPU *cpu, sPAPRMachineState *spapr,
 
     env->msr |= (1ULL << MSR_EE);
     hreg_compute_hflags(env);
+    cpu_mutex_lock(cs);
     if (!cpu_has_work(cs)) {
-        cs->halted = 1;
+        cpu_halted_set(cs, 1);
         cs->exception_index = EXCP_HLT;
         cs->exit_request = 1;
     }
+    cpu_mutex_unlock(cs);
     return H_SUCCESS;
 }
 
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 7a2cb786a3..60b7fd8a79 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -109,7 +109,7 @@ static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_,
     id = rtas_ld(args, 0);
     cpu = spapr_find_cpu(id);
     if (cpu != NULL) {
-        if (CPU(cpu)->halted) {
+        if (cpu_halted(CPU(cpu))) {
             rtas_st(rets, 1, 0);
         } else {
             rtas_st(rets, 1, 2);
@@ -153,7 +153,7 @@ static void rtas_start_cpu(PowerPCCPU *callcpu, sPAPRMachineState *spapr,
     env = &newcpu->env;
     pcc = POWERPC_CPU_GET_CLASS(newcpu);
 
-    if (!CPU(newcpu)->halted) {
+    if (!cpu_halted(CPU(newcpu))) {
         rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
         return;
     }
@@ -207,7 +207,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,
      * This could deliver an interrupt on a dying CPU and crash the
      * guest */
     ppc_store_lpcr(cpu, env->spr[SPR_LPCR] & ~pcc->lpcr_pm);
-    cs->halted = 1;
+    cpu_halted_set(cs, 1);
     kvmppc_set_reg_ppc_online(cpu, 0);
     qemu_cpu_kick(cs);
 }
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 39bedbb11d..d0092cc13d 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -220,7 +220,7 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
                 qemu_log("Machine check while not allowed. "
                         "Entering checkstop state\n");
             }
-            cs->halted = 1;
+            cpu_halted_set(cs, 1);
             cpu_interrupt_exittb(cs);
         }
         if (env->msr_mask & MSR_HVB) {
@@ -1005,7 +1005,7 @@ void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn)
     CPUState *cs;
 
     cs = CPU(ppc_env_get_cpu(env));
-    cs->halted = 1;
+    cpu_halted_set(cs, 1);
 
     /* The architecture specifies that HDEC interrupts are
      * discarded in PM states
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index d01852fe31..faa757c417 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -1373,7 +1373,7 @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run)
 
 int kvm_arch_process_async_events(CPUState *cs)
 {
-    return cs->halted;
+    return cpu_halted(cs);
 }
 
 static int kvmppc_handle_halt(PowerPCCPU *cpu)
@@ -1382,7 +1382,7 @@ static int kvmppc_handle_halt(PowerPCCPU *cpu)
     CPUPPCState *env = &cpu->env;
 
     if (!(cs->interrupt_request & CPU_INTERRUPT_HARD) && (msr_ee)) {
-        cs->halted = 1;
+        cpu_halted_set(cs, 1);
         cs->exception_index = EXCP_HLT;
     }
 
diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
index 58542c0fe0..b2cad43e2a 100644
--- a/target/ppc/translate_init.inc.c
+++ b/target/ppc/translate_init.inc.c
@@ -8468,7 +8468,7 @@ static bool cpu_has_work_POWER7(CPUState *cs)
     PowerPCCPU *cpu = POWERPC_CPU(cs);
     CPUPPCState *env = &cpu->env;
 
-    if (cs->halted) {
+    if (cpu_halted(cs)) {
         if (!(cs->interrupt_request & CPU_INTERRUPT_HARD)) {
             return false;
         }
@@ -8622,7 +8622,7 @@ static bool cpu_has_work_POWER8(CPUState *cs)
     PowerPCCPU *cpu = POWERPC_CPU(cs);
     CPUPPCState *env = &cpu->env;
 
-    if (cs->halted) {
+    if (cpu_halted(cs)) {
         if (!(cs->interrupt_request & CPU_INTERRUPT_HARD)) {
             return false;
         }
@@ -8814,7 +8814,7 @@ static bool cpu_has_work_POWER9(CPUState *cs)
     PowerPCCPU *cpu = POWERPC_CPU(cs);
     CPUPPCState *env = &cpu->env;
 
-    if (cs->halted) {
+    if (cpu_halted(cs)) {
         uint64_t psscr = env->spr[SPR_PSSCR];
 
         if (!(cs->interrupt_request & CPU_INTERRUPT_HARD)) {
-- 
2.17.1

  parent reply	other threads:[~2019-03-04 18:18 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-04 18:17 [Qemu-devel] [PATCH v7 00/73] per-CPU locks Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 01/73] cpu: convert queued work to a QSIMPLEQ Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 02/73] cpu: rename cpu->work_mutex to cpu->lock Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 03/73] cpu: introduce cpu_mutex_lock/unlock Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 04/73] cpu: make qemu_work_cond per-cpu Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 05/73] cpu: move run_on_cpu to cpus-common Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 06/73] cpu: introduce process_queued_cpu_work_locked Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 07/73] cpu: make per-CPU locks an alias of the BQL in TCG rr mode Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 08/73] tcg-runtime: define helper_cpu_halted_set Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 09/73] ppc: convert to helper_cpu_halted_set Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 10/73] cris: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 11/73] hppa: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 12/73] m68k: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 13/73] alpha: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 14/73] microblaze: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 15/73] cpu: define cpu_halted helpers Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 16/73] tcg-runtime: convert to cpu_halted_set Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 17/73] arm: convert to cpu_halted Emilio G. Cota
2019-03-04 18:17 ` Emilio G. Cota [this message]
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 19/73] sh4: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 20/73] i386: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 21/73] lm32: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 22/73] m68k: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 23/73] mips: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 24/73] riscv: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 25/73] s390x: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 26/73] sparc: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 27/73] xtensa: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 28/73] gdbstub: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 29/73] openrisc: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 30/73] cpu-exec: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 31/73] cpu: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 32/73] cpu: define cpu_interrupt_request helpers Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 33/73] ppc: use cpu_reset_interrupt Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 34/73] exec: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 35/73] i386: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 36/73] s390x: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 37/73] openrisc: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 38/73] arm: convert to cpu_interrupt_request Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 39/73] i386: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 40/73] i386/kvm: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 41/73] i386/hax-all: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 42/73] i386/whpx-all: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 43/73] i386/hvf: convert to cpu_request_interrupt Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 44/73] ppc: convert to cpu_interrupt_request Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 45/73] sh4: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 46/73] cris: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 47/73] hppa: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 48/73] lm32: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 49/73] m68k: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 50/73] mips: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 51/73] nios: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 52/73] s390x: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 53/73] alpha: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 54/73] moxie: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 55/73] sparc: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 56/73] openrisc: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 57/73] unicore32: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 58/73] microblaze: " Emilio G. Cota
2019-03-04 18:17 ` [Qemu-devel] [PATCH v7 59/73] accel/tcg: " Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 60/73] cpu: convert to interrupt_request Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 61/73] cpu: call .cpu_has_work with the CPU lock held Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 62/73] cpu: introduce cpu_has_work_with_iothread_lock Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 63/73] ppc: convert to cpu_has_work_with_iothread_lock Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 64/73] mips: " Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 65/73] s390x: " Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 66/73] riscv: " Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 67/73] sparc: " Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 68/73] xtensa: " Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 69/73] cpu: rename all_cpu_threads_idle to qemu_tcg_rr_all_cpu_threads_idle Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 70/73] cpu: protect CPU state with cpu->lock instead of the BQL Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 71/73] cpus-common: release BQL earlier in run_on_cpu Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 72/73] cpu: add async_run_on_cpu_no_bql Emilio G. Cota
2019-03-04 18:18 ` [Qemu-devel] [PATCH v7 73/73] cputlb: queue async flush jobs without the BQL Emilio G. Cota
2019-03-05  9:16 ` [Qemu-devel] [PATCH v7 00/73] per-CPU locks Alex Bennée
2019-03-06 19:40 ` Richard Henderson
2019-03-06 19:57   ` Peter Maydell
2019-03-06 23:49   ` Emilio G. Cota

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190304181813.8075-19-cota@braap.org \
    --to=cota@braap.org \
    --cc=alex.bennee@linaro.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.