From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Anton Johansson" <anjo@rev.ng>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v2 13/13] accel/tcg: Move icount fields from CPUState to TCG AccelCPUState
Date: Mon, 29 Apr 2024 23:30:50 +0200 [thread overview]
Message-ID: <20240429213050.55177-14-philmd@linaro.org> (raw)
In-Reply-To: <20240429213050.55177-1-philmd@linaro.org>
Both @icount_budget and @icount_extra fields are specific
to TCG accelerator, move them to its AccelCPUState.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20240428221450.26460-25-philmd@linaro.org>
---
accel/tcg/vcpu-state.h | 4 ++++
include/hw/core/cpu.h | 3 ---
accel/tcg/cpu-exec.c | 14 +++++++-------
accel/tcg/icount-common.c | 7 ++++---
accel/tcg/tcg-accel-ops-icount.c | 14 +++++++-------
accel/tcg/tcg-accel-ops.c | 1 +
hw/core/cpu-common.c | 1 -
7 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/accel/tcg/vcpu-state.h b/accel/tcg/vcpu-state.h
index 6c12bd17df..7fff5413e9 100644
--- a/accel/tcg/vcpu-state.h
+++ b/accel/tcg/vcpu-state.h
@@ -12,6 +12,7 @@
/**
* AccelCPUState: vCPU fields specific to TCG accelerator
* @cflags: Pre-computed cflags for this cpu.
+ * @icount_extra: Instructions until next timer event.
* @plugin_state: per-CPU plugin state
*/
struct AccelCPUState {
@@ -24,6 +25,9 @@ struct AccelCPUState {
#ifdef CONFIG_USER_ONLY
TaskState *ts;
#else
+ int64_t icount_budget;
+ int64_t icount_extra;
+
/* track IOMMUs whose translations we've cached in the TCG TLB */
GArray *iommu_notifiers;
#endif /* !CONFIG_USER_ONLY */
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 14e96aae85..c0c28befd3 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -409,7 +409,6 @@ struct qemu_work_item;
* @unplug: Indicates a pending CPU unplug request.
* @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.
* @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
* AddressSpaces this CPU has)
* @num_ases: number of CPUAddressSpaces in @cpu_ases
@@ -470,8 +469,6 @@ struct CPUState {
/* updates protected by BQL */
uint32_t interrupt_request;
int singlestep_enabled;
- int64_t icount_budget;
- int64_t icount_extra;
uint64_t random_seed;
QemuMutex work_mutex;
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 1f618f6c2e..7c21542e52 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -74,7 +74,7 @@ static void align_clocks(SyncClocks *sc, CPUState *cpu)
return;
}
- cpu_icount = cpu->icount_extra + cpu->neg.icount_decr.u16.low;
+ cpu_icount = cpu->accel->icount_extra + cpu->neg.icount_decr.u16.low;
sc->diff_clk += icount_to_ns(sc->last_cpu_icount - cpu_icount);
sc->last_cpu_icount = cpu_icount;
@@ -125,7 +125,7 @@ static void init_delay_params(SyncClocks *sc, CPUState *cpu)
sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
sc->diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - sc->realtime_clock;
sc->last_cpu_icount
- = cpu->icount_extra + cpu->neg.icount_decr.u16.low;
+ = cpu->accel->icount_extra + cpu->neg.icount_decr.u16.low;
if (sc->diff_clk < max_delay) {
max_delay = sc->diff_clk;
}
@@ -718,7 +718,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
if (cpu->exception_index < 0) {
#ifndef CONFIG_USER_ONLY
if (replay_has_exception()
- && cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0) {
+ && cpu->neg.icount_decr.u16.low + cpu->accel->icount_extra == 0) {
/* Execute just one insn to trigger exception pending in the log */
cpu->accel->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
| CF_NOIRQ | 1;
@@ -789,7 +789,7 @@ static inline bool icount_exit_request(CPUState *cpu)
if (!(cpu->accel->cflags_next_tb == -1 || cpu->accel->cflags_next_tb & CF_USE_ICOUNT)) {
return false;
}
- return cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0;
+ return cpu->neg.icount_decr.u16.low + cpu->accel->icount_extra == 0;
#endif
}
@@ -941,9 +941,9 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
/* Ensure global icount has gone forward */
icount_update(cpu);
/* Refill decrementer and continue execution. */
- int32_t insns_left = MIN(0xffff, cpu->icount_budget);
+ int32_t insns_left = MIN(0xffff, cpu->accel->icount_budget);
cpu->neg.icount_decr.u16.low = insns_left;
- cpu->icount_extra = cpu->icount_budget - insns_left;
+ cpu->accel->icount_extra = cpu->accel->icount_budget - insns_left;
/*
* If the next tb has more instructions than we have left to
@@ -952,7 +952,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
*/
if (insns_left > 0 && insns_left < tb->icount) {
assert(insns_left <= CF_COUNT_MASK);
- assert(cpu->icount_extra == 0);
+ assert(cpu->accel->icount_extra == 0);
cpu->accel->cflags_next_tb = (tb->cflags & ~CF_COUNT_MASK) | insns_left;
}
#endif
diff --git a/accel/tcg/icount-common.c b/accel/tcg/icount-common.c
index 8d3d3a7e9d..ff503f8e96 100644
--- a/accel/tcg/icount-common.c
+++ b/accel/tcg/icount-common.c
@@ -38,6 +38,7 @@
#include "sysemu/cpu-timers.h"
#include "sysemu/cpu-throttle.h"
#include "sysemu/cpu-timers-internal.h"
+#include "accel/tcg/vcpu-state.h"
/*
* ICOUNT: Instruction Counter
@@ -71,8 +72,8 @@ static void icount_enable_adaptive(void)
*/
static int64_t icount_get_executed(CPUState *cpu)
{
- return (cpu->icount_budget -
- (cpu->neg.icount_decr.u16.low + cpu->icount_extra));
+ return (cpu->accel->icount_budget -
+ (cpu->neg.icount_decr.u16.low + cpu->accel->icount_extra));
}
/*
@@ -83,7 +84,7 @@ static int64_t icount_get_executed(CPUState *cpu)
static void icount_update_locked(CPUState *cpu)
{
int64_t executed = icount_get_executed(cpu);
- cpu->icount_budget -= executed;
+ cpu->accel->icount_budget -= executed;
qatomic_set_i64(&timers_state.qemu_icount,
timers_state.qemu_icount + executed);
diff --git a/accel/tcg/tcg-accel-ops-icount.c b/accel/tcg/tcg-accel-ops-icount.c
index 9e1ae66f65..75073ec23f 100644
--- a/accel/tcg/tcg-accel-ops-icount.c
+++ b/accel/tcg/tcg-accel-ops-icount.c
@@ -112,16 +112,16 @@ void icount_prepare_for_run(CPUState *cpu, int64_t cpu_budget)
* asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
*/
g_assert(cpu->neg.icount_decr.u16.low == 0);
- g_assert(cpu->icount_extra == 0);
+ g_assert(cpu->accel->icount_extra == 0);
replay_mutex_lock();
- cpu->icount_budget = MIN(icount_get_limit(), cpu_budget);
- insns_left = MIN(0xffff, cpu->icount_budget);
+ cpu->accel->icount_budget = MIN(icount_get_limit(), cpu_budget);
+ insns_left = MIN(0xffff, cpu->accel->icount_budget);
cpu->neg.icount_decr.u16.low = insns_left;
- cpu->icount_extra = cpu->icount_budget - insns_left;
+ cpu->accel->icount_extra = cpu->accel->icount_budget - insns_left;
- if (cpu->icount_budget == 0) {
+ if (cpu->accel->icount_budget == 0) {
/*
* We're called without the BQL, so must take it while
* we're calling timer handlers.
@@ -139,8 +139,8 @@ void icount_process_data(CPUState *cpu)
/* Reset the counters */
cpu->neg.icount_decr.u16.low = 0;
- cpu->icount_extra = 0;
- cpu->icount_budget = 0;
+ cpu->accel->icount_extra = 0;
+ cpu->accel->icount_budget = 0;
replay_account_executed_instructions();
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index d9132a5835..3b28cab0b5 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -89,6 +89,7 @@ static void tcg_cpu_reset_hold(CPUState *cpu)
qatomic_set(&cpu->neg.icount_decr.u32, 0);
cpu->neg.can_do_io = true;
+ cpu->accel->icount_extra = 0;
cpu->accel->cflags_next_tb = -1;
}
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 073eb75ad0..c8e6f63943 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -121,7 +121,6 @@ static void cpu_common_reset_hold(Object *obj, ResetType type)
cpu->interrupt_request = 0;
cpu->halted = cpu->start_powered_off;
cpu->mem_io_pc = 0;
- cpu->icount_extra = 0;
cpu->exception_index = -1;
cpu->crash_occurred = false;
--
2.41.0
prev parent reply other threads:[~2024-04-29 21:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 21:30 [PATCH v2 00/13] exec: Rework around CPUState user fields (part 2) Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 01/13] accel/tcg: Restrict qemu_plugin_vcpu_exit_hook() to TCG plugins Philippe Mathieu-Daudé
2024-04-29 23:50 ` Richard Henderson
2024-04-29 21:30 ` [PATCH v2 02/13] accel/tcg: Restrict cpu_plugin_mem_cbs_enabled() to TCG Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 03/13] accel/tcg: Move @plugin_mem_cbs from CPUState to CPUNegativeOffsetState Philippe Mathieu-Daudé
2024-04-29 23:53 ` Richard Henderson
2024-04-29 21:30 ` [PATCH v2 04/13] accel/tcg: Move @plugin_state from CPUState to TCG AccelCPUState Philippe Mathieu-Daudé
2024-04-29 23:59 ` Richard Henderson
2024-04-29 21:30 ` [PATCH v2 05/13] accel/tcg: Restrict IcountDecr / can_do_io / CPUTLB to TCG Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 06/13] accel/tcg: Move @jmp_env from CPUState to TCG AccelCPUState Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 07/13] accel/tcg: Move @cflags_next_tb " Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 08/13] accel/tcg: Move @iommu_notifiers " Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 09/13] accel/tcg: Move @tb_jmp_cache " Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 10/13] accel/tcg: Remove NULL check in tcg_flush_jmp_cache() Philippe Mathieu-Daudé
2024-04-30 1:12 ` Ilya Leoshkevich
2024-04-29 21:30 ` [PATCH v2 11/13] accel/tcg: Move @tcg_cflags from CPUState to TCG AccelCPUState Philippe Mathieu-Daudé
2024-04-29 21:30 ` [PATCH v2 12/13] accel/tcg: Restrict icount to system emulation Philippe Mathieu-Daudé
2024-04-29 21:30 ` Philippe Mathieu-Daudé [this message]
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=20240429213050.55177-14-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=anjo@rev.ng \
--cc=qemu-devel@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 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).