qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 16/47] accel/tcg: Move can_do_io to CPUNegativeOffsetState
Date: Tue,  3 Oct 2023 10:30:21 -0700	[thread overview]
Message-ID: <20231003173052.1601813-17-richard.henderson@linaro.org> (raw)
In-Reply-To: <20231003173052.1601813-1-richard.henderson@linaro.org>

Minimize the displacement to can_do_io, since it may
be touched at the start of each TranslationBlock.
It fits into other padding within the substructure.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/hw/core/cpu.h            |  6 ++----
 accel/dummy-cpus.c               |  2 +-
 accel/hvf/hvf-accel-ops.c        |  2 +-
 accel/kvm/kvm-accel-ops.c        |  2 +-
 accel/tcg/cpu-exec-common.c      |  2 +-
 accel/tcg/cpu-exec.c             |  2 +-
 accel/tcg/cputlb.c               |  2 +-
 accel/tcg/tcg-accel-ops-icount.c |  2 +-
 accel/tcg/tcg-accel-ops-mttcg.c  |  2 +-
 accel/tcg/tcg-accel-ops-rr.c     |  4 ++--
 accel/tcg/translator.c           | 10 ++++++----
 hw/core/cpu-common.c             |  2 +-
 softmmu/icount.c                 |  2 +-
 softmmu/watchpoint.c             |  2 +-
 14 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 973ff9d106..293cedd9b5 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -351,6 +351,7 @@ typedef union IcountDecr {
 typedef struct CPUNegativeOffsetState {
     CPUTLB tlb;
     IcountDecr icount_decr;
+    bool can_do_io;
 } CPUNegativeOffsetState;
 
 typedef struct CPUBreakpoint {
@@ -420,9 +421,7 @@ struct qemu_work_item;
  * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
  * @singlestep_enabled: Flags for single-stepping.
  * @icount_extra: Instructions until next timer event.
- * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
- * requires that IO only be performed on the last instruction of a TB
- * so that interrupts take effect immediately.
+ * @neg.can_do_io: True if memory-mapped IO is allowed.
  * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
  *            AddressSpaces this CPU has)
  * @num_ases: number of CPUAddressSpaces in @cpu_ases
@@ -547,7 +546,6 @@ struct CPUState {
     int cluster_index;
     uint32_t tcg_cflags;
     uint32_t halted;
-    uint32_t can_do_io;
     int32_t exception_index;
 
     AccelCPUState *accel;
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index d6a1b8d0a2..b75c919ac3 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -27,7 +27,7 @@ static void *dummy_cpu_thread_fn(void *arg)
     qemu_mutex_lock_iothread();
     qemu_thread_get_self(cpu->thread);
     cpu->thread_id = qemu_get_thread_id();
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     current_cpu = cpu;
 
 #ifndef _WIN32
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 3c94c79747..abe7adf7ee 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -428,7 +428,7 @@ static void *hvf_cpu_thread_fn(void *arg)
     qemu_thread_get_self(cpu->thread);
 
     cpu->thread_id = qemu_get_thread_id();
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     current_cpu = cpu;
 
     hvf_init_vcpu(cpu);
diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
index 457eafa380..6195150a0b 100644
--- a/accel/kvm/kvm-accel-ops.c
+++ b/accel/kvm/kvm-accel-ops.c
@@ -36,7 +36,7 @@ static void *kvm_vcpu_thread_fn(void *arg)
     qemu_mutex_lock_iothread();
     qemu_thread_get_self(cpu->thread);
     cpu->thread_id = qemu_get_thread_id();
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     current_cpu = cpu;
 
     r = kvm_init_vcpu(cpu, &error_fatal);
diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c
index 7e35d7f4b5..82ae837e39 100644
--- a/accel/tcg/cpu-exec-common.c
+++ b/accel/tcg/cpu-exec-common.c
@@ -36,7 +36,7 @@ void cpu_loop_exit_noexc(CPUState *cpu)
 void cpu_loop_exit(CPUState *cpu)
 {
     /* Undo the setting in cpu_tb_exec.  */
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     /* Undo any setting in generated code.  */
     qemu_plugin_disable_mem_helpers(cpu);
     siglongjmp(cpu->jmp_env, 1);
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 60f1986b85..de60fdb612 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -455,7 +455,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
 
     qemu_thread_jit_execute();
     ret = tcg_qemu_tb_exec(env, tb_ptr);
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     qemu_plugin_disable_mem_helpers(cpu);
     /*
      * TODO: Delay swapping back to the read-write region of the TB
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index 3270f65c20..d69e046b80 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -1361,7 +1361,7 @@ io_prepare(hwaddr *out_offset, CPUArchState *env, hwaddr xlat,
     section = iotlb_to_section(cpu, xlat, attrs);
     mr_offset = (xlat & TARGET_PAGE_MASK) + addr;
     cpu->mem_io_pc = retaddr;
-    if (!cpu->can_do_io) {
+    if (!cpu->neg.can_do_io) {
         cpu_io_recompile(cpu, retaddr);
     }
 
diff --git a/accel/tcg/tcg-accel-ops-icount.c b/accel/tcg/tcg-accel-ops-icount.c
index 3d2cfbbc97..0af643b217 100644
--- a/accel/tcg/tcg-accel-ops-icount.c
+++ b/accel/tcg/tcg-accel-ops-icount.c
@@ -153,7 +153,7 @@ void icount_handle_interrupt(CPUState *cpu, int mask)
 
     tcg_handle_interrupt(cpu, mask);
     if (qemu_cpu_is_self(cpu) &&
-        !cpu->can_do_io
+        !cpu->neg.can_do_io
         && (mask & ~old_mask) != 0) {
         cpu_abort(cpu, "Raised interrupt while not in I/O function");
     }
diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c
index 4b0dfb4be7..ae95ba419e 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.c
+++ b/accel/tcg/tcg-accel-ops-mttcg.c
@@ -80,7 +80,7 @@ static void *mttcg_cpu_thread_fn(void *arg)
     qemu_thread_get_self(cpu->thread);
 
     cpu->thread_id = qemu_get_thread_id();
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     current_cpu = cpu;
     cpu_thread_signal_created(cpu);
     qemu_guest_random_seed_thread_part2(cpu->random_seed);
diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index 2d523289a8..671a3c4ca0 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -192,7 +192,7 @@ static void *rr_cpu_thread_fn(void *arg)
     qemu_thread_get_self(cpu->thread);
 
     cpu->thread_id = qemu_get_thread_id();
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     cpu_thread_signal_created(cpu);
     qemu_guest_random_seed_thread_part2(cpu->random_seed);
 
@@ -334,7 +334,7 @@ void rr_start_vcpu_thread(CPUState *cpu)
         cpu->thread = single_tcg_cpu_thread;
         cpu->halt_cond = single_tcg_halt_cond;
         cpu->thread_id = first_cpu->thread_id;
-        cpu->can_do_io = 1;
+        cpu->neg.can_do_io = 1;
         cpu->created = true;
     }
 }
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index b3e12d61e9..460bfc4c74 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -20,9 +20,11 @@ static void set_can_do_io(DisasContextBase *db, bool val)
 {
     if (db->saved_can_do_io != val) {
         db->saved_can_do_io = val;
-        tcg_gen_st_i32(tcg_constant_i32(val), cpu_env,
-                       offsetof(ArchCPU, parent_obj.can_do_io) -
-                       offsetof(ArchCPU, env));
+
+        QEMU_BUILD_BUG_ON(sizeof_field(CPUState, neg.can_do_io) != 1);
+        tcg_gen_st8_i32(tcg_constant_i32(val), cpu_env,
+                        offsetof(ArchCPU, parent_obj.neg.can_do_io) -
+                        offsetof(ArchCPU, env));
     }
 }
 
@@ -83,7 +85,7 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
     }
 
     /*
-     * cpu->can_do_io is set automatically here at the beginning of
+     * cpu->neg.can_do_io is set automatically here at the beginning of
      * each translation block.  The cost is minimal, plus it would be
      * very easy to forget doing it in the translator.
      */
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 08d5bbc873..4d406995ab 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -131,7 +131,7 @@ static void cpu_common_reset_hold(Object *obj)
     cpu->mem_io_pc = 0;
     cpu->icount_extra = 0;
     qatomic_set(&cpu->neg.icount_decr.u32, 0);
-    cpu->can_do_io = 1;
+    cpu->neg.can_do_io = true;
     cpu->exception_index = -1;
     cpu->crash_occurred = false;
     cpu->cflags_next_tb = -1;
diff --git a/softmmu/icount.c b/softmmu/icount.c
index 144e24829c..956d15e343 100644
--- a/softmmu/icount.c
+++ b/softmmu/icount.c
@@ -111,7 +111,7 @@ static int64_t icount_get_raw_locked(void)
     CPUState *cpu = current_cpu;
 
     if (cpu && cpu->running) {
-        if (!cpu->can_do_io) {
+        if (!cpu->neg.can_do_io) {
             error_report("Bad icount read");
             exit(1);
         }
diff --git a/softmmu/watchpoint.c b/softmmu/watchpoint.c
index 5350163385..45d1f12faf 100644
--- a/softmmu/watchpoint.c
+++ b/softmmu/watchpoint.c
@@ -177,7 +177,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
                  * Force recompile to succeed, because icount may
                  * be read only at the end of the block.
                  */
-                if (!cpu->can_do_io) {
+                if (!cpu->neg.can_do_io) {
                     /* Force execution of one insn next time.  */
                     cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
                                           | curr_cflags(cpu);
-- 
2.34.1



  parent reply	other threads:[~2023-10-03 17:43 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 17:30 [PULL 00/47] tcg patch queue Richard Henderson
2023-10-03 17:30 ` [PULL 01/47] accel: Rename accel_cpu_realizefn() -> accel_cpu_realize() Richard Henderson
2023-10-03 17:30 ` [PULL 02/47] accel: Rename AccelCPUClass::cpu_realizefn() -> cpu_target_realize() Richard Henderson
2023-10-03 17:30 ` [PULL 03/47] accel: Rename accel_cpu_realize() -> accel_cpu_common_realize() Richard Henderson
2023-10-03 17:30 ` [PULL 04/47] accel: Introduce accel_cpu_common_unrealize() stub Richard Henderson
2023-10-03 17:30 ` [PULL 05/47] accel: Declare AccelClass::cpu_common_[un]realize() handlers Richard Henderson
2023-10-03 17:30 ` [PULL 06/47] accel/tcg: Have tcg_exec_realizefn() return a boolean Richard Henderson
2023-10-03 17:30 ` [PULL 07/47] accel/tcg: Restrict tcg_exec_[un]realizefn() to TCG Richard Henderson
2023-10-03 17:30 ` [PULL 08/47] target/arm: Replace TARGET_PAGE_ENTRY_EXTRA Richard Henderson
2023-10-03 17:30 ` [PULL 09/47] accel/tcg: Move CPUTLB definitions from cpu-defs.h Richard Henderson
2023-10-03 17:30 ` [PULL 10/47] qom: Propagate alignment through type system Richard Henderson
2023-10-03 17:30 ` [PULL 11/47] target/arm: Remove size and alignment for cpu subclasses Richard Henderson
2023-10-03 17:30 ` [PULL 12/47] target/*: Add instance_align to all cpu base classes Richard Henderson
2023-10-03 17:30 ` [PULL 13/47] accel/tcg: Validate placement of CPUNegativeOffsetState Richard Henderson
2023-10-03 17:30 ` [PULL 14/47] accel/tcg: Move CPUNegativeOffsetState into CPUState Richard Henderson
2023-10-03 17:30 ` [PULL 15/47] accel/tcg: Remove CPUState.icount_decr_ptr Richard Henderson
2023-10-03 17:30 ` Richard Henderson [this message]
2023-10-03 17:30 ` [PULL 17/47] accel/tcg: Remove cpu_neg() Richard Henderson
2023-10-03 17:30 ` [PULL 18/47] tcg: Rename cpu_env to tcg_env Richard Henderson
2023-10-03 17:30 ` [PULL 19/47] accel/tcg: Replace CPUState.env_ptr with cpu_env() Richard Henderson
2023-10-03 17:30 ` [PULL 20/47] accel/tcg: Remove cpu_set_cpustate_pointers Richard Henderson
2023-10-03 17:30 ` [PULL 21/47] accel/tcg: Remove env_neg() Richard Henderson
2023-10-03 17:30 ` [PULL 22/47] tcg: Remove TCGContext.tlb_fast_offset Richard Henderson
2023-10-03 17:30 ` [PULL 23/47] accel/tcg: Modify tlb_*() to use CPUState Richard Henderson
2023-10-03 17:30 ` [PULL 24/47] accel/tcg: Modify probe_access_internal() " Richard Henderson
2023-10-03 17:30 ` [PULL 25/47] accel/tcg: Modify memory access functions " Richard Henderson
2023-10-03 17:30 ` [PULL 26/47] accel/tcg: Modify atomic_mmu_lookup() " Richard Henderson
2023-10-03 17:30 ` [PULL 27/47] accel/tcg: Use CPUState in atomicity helpers Richard Henderson
2023-10-03 17:30 ` [PULL 28/47] accel/tcg: Remove env_tlb() Richard Henderson
2023-10-03 17:30 ` [PULL 29/47] accel/tcg: Unify user and softmmu do_[st|ld]*_mmu() Richard Henderson
2023-10-03 17:30 ` [PULL 30/47] accel/tcg: move ld/st helpers to ldst_common.c.inc Richard Henderson
2023-10-03 17:30 ` [PULL 31/47] exec: Make EXCP_FOO definitions target agnostic Richard Henderson
2023-10-03 17:30 ` [PULL 32/47] exec: Move cpu_loop_foo() target agnostic functions to 'cpu-common.h' Richard Henderson
2023-10-03 17:30 ` [PULL 33/47] accel/tcg: Restrict dump_exec_info() declaration Richard Henderson
2023-10-03 17:30 ` [PULL 34/47] accel: Make accel-blocker.o target agnostic Richard Henderson
2023-10-03 17:30 ` [PULL 35/47] accel: Rename accel-common.c -> accel-target.c Richard Henderson
2023-10-03 17:30 ` [PULL 36/47] exec: Rename cpu.c -> cpu-target.c Richard Henderson
2023-10-03 17:30 ` [PULL 37/47] exec: Rename target specific page-vary.c -> page-vary-target.c Richard Henderson
2023-10-03 17:30 ` [PULL 38/47] accel/tcg: Rename target-specific 'internal.h' -> 'internal-target.h' Richard Henderson
2023-10-03 17:30 ` [PULL 39/47] accel/tcg: Make monitor.c a target-agnostic unit Richard Henderson
2023-10-03 17:30 ` [PULL 40/47] accel/tcg: Make icount.o a target agnostic unit Richard Henderson
2023-10-03 17:30 ` [PULL 41/47] accel/tcg: Make cpu-exec-common.c " Richard Henderson
2023-10-03 17:30 ` [PULL 42/47] tcg: Remove argument to tcg_prologue_init Richard Henderson
2023-10-03 17:30 ` [PULL 43/47] tcg: Split out tcg init functions to tcg/startup.h Richard Henderson
2023-10-03 17:30 ` [PULL 44/47] linux-user/hppa: Fix struct target_sigcontext layout Richard Henderson
2023-10-03 17:30 ` [PULL 45/47] build: Remove --enable-gprof Richard Henderson
2023-10-03 17:30 ` [PULL 46/47] tests/avocado: Re-enable MIPS Malta tests (GitLab issue #1884 fixed) Richard Henderson
2023-10-03 17:30 ` [PULL 47/47] tcg/loongarch64: Fix buid error Richard Henderson
2023-10-04 14:57 ` [PULL 00/47] tcg patch queue Stefan Hajnoczi
2023-10-04 16:28   ` Richard Henderson
2023-10-04 16:46     ` Stefan Hajnoczi
2023-10-04 17:08       ` Richard Henderson

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=20231003173052.1601813-17-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).