From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Anton Johansson" <anjo@rev.ng>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 24/24] accel/tcg: Move icount fields from CPUState to TCG AccelCPUState
Date: Mon, 29 Apr 2024 00:14:50 +0200 [thread overview]
Message-ID: <20240428221450.26460-25-philmd@linaro.org> (raw)
In-Reply-To: <20240428221450.26460-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>
---
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 1cdca0e0d4..9bb8afac57 100644
--- a/accel/tcg/vcpu-state.h
+++ b/accel/tcg/vcpu-state.h
@@ -12,6 +12,7 @@
/**
* AccelCPUState:
* @cflags: Pre-computed cflags for this cpu.
+ * @icount_extra: Instructions until next timer event.
* @mem_io_pc: Host Program Counter at which the memory was accessed.
*/
struct AccelCPUState {
@@ -24,6 +25,9 @@ struct AccelCPUState {
#ifdef CONFIG_USER_ONLY
TaskState *ts;
#else
+ int64_t icount_budget;
+ int64_t icount_extra;
+
uintptr_t mem_io_pc;
/* track IOMMUs whose translations we've cached in the TCG TLB */
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index f6bafa090a..bdcb09b464 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -411,7 +411,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
@@ -471,8 +470,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 5429e2d219..86bc82b891 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->mem_io_pc = 0;
cpu->accel->cflags_next_tb = -1;
}
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 684422991c..6dc94b1eaf 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -117,7 +117,6 @@ static void cpu_common_reset_hold(Object *obj, ResetType type)
cpu->interrupt_request = 0;
cpu->halted = cpu->start_powered_off;
- cpu->icount_extra = 0;
cpu->exception_index = -1;
cpu->crash_occurred = false;
--
2.41.0
next prev parent reply other threads:[~2024-04-28 22:18 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 22:14 [PATCH 00/24] exec: Rework around CPUState user fields (part 2) Philippe Mathieu-Daudé
2024-04-28 22:14 ` [PATCH 01/24] exec/user: Move 'thunk.h' from 'exec/user' to 'user' Philippe Mathieu-Daudé
2024-04-29 0:49 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 02/24] coverity: Update user emulation regexp Philippe Mathieu-Daudé
2024-04-29 0:52 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 03/24] accel/tcg: Move user definition of cpu_interrupt() to user-exec.c Philippe Mathieu-Daudé
2024-04-29 0:54 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 04/24] accel/tcg: Duplicate cpu_exit() for user / system Philippe Mathieu-Daudé
2024-04-29 0:58 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 05/24] accel/tcg: Extract tcg_cpu_exit() from cpu_exit() Philippe Mathieu-Daudé
2024-04-29 1:02 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 06/24] accel: Introduce AccelOpsClass::exit_vcpu_thread() handler Philippe Mathieu-Daudé
2024-04-29 1:05 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 07/24] accel/tcg: Implement " Philippe Mathieu-Daudé
2024-04-29 1:09 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 08/24] user: Forward declare TaskState type definition Philippe Mathieu-Daudé
2024-04-29 1:13 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 09/24] user: Declare get_task_state() once in 'accel/tcg/vcpu-state.h' Philippe Mathieu-Daudé
2024-04-29 1:19 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 10/24] user: Use get_task_state() helper Philippe Mathieu-Daudé
2024-04-29 1:27 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 11/24] accel/tcg: Allocate per-vCPU accel state in create_vcpu_thread() Philippe Mathieu-Daudé
2024-04-29 14:23 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 12/24] accel/tcg: Move TaskState from CPUState to TCG AccelCPUState Philippe Mathieu-Daudé
2024-04-29 14:31 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 13/24] accel/tcg: Update CPUNegativeOffsetState::can_do_io field documentation Philippe Mathieu-Daudé
2024-04-29 14:33 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 14/24] accel/tcg: Move plugin fields to CPUNegativeOffsetState Philippe Mathieu-Daudé
2024-04-29 14:42 ` Richard Henderson
2024-04-29 20:54 ` Philippe Mathieu-Daudé
2024-04-28 22:14 ` [PATCH 15/24] accel/tcg: Restrict IcountDecr and CPUTLB to TCG Philippe Mathieu-Daudé
2024-04-29 14:03 ` Philippe Mathieu-Daudé
2024-04-29 14:46 ` Richard Henderson
2024-04-29 14:48 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 16/24] accel/tcg: Move @jmp_env from CPUState to TCG AccelCPUState Philippe Mathieu-Daudé
2024-04-29 14:51 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 17/24] accel/tcg: Move @mem_io_pc " Philippe Mathieu-Daudé
2024-04-29 15:02 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 18/24] accel/tcg: Move @cflags_next_tb " Philippe Mathieu-Daudé
2024-04-29 15:22 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 19/24] accel/tcg: Move @iommu_notifiers " Philippe Mathieu-Daudé
2024-04-29 15:25 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 20/24] accel/tcg: Move @tb_jmp_cache " Philippe Mathieu-Daudé
2024-04-29 19:15 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 21/24] accel/tcg: Remove NULL check in tcg_flush_jmp_cache() Philippe Mathieu-Daudé
2024-04-28 22:14 ` [PATCH 22/24] accel/tcg: Move @tcg_cflags from CPUState to TCG AccelCPUState Philippe Mathieu-Daudé
2024-04-29 19:30 ` Richard Henderson
2024-04-28 22:14 ` [PATCH 23/24] accel/tcg: Restrict icount to system emulation Philippe Mathieu-Daudé
2024-04-29 21:07 ` Richard Henderson
2024-04-28 22:14 ` Philippe Mathieu-Daudé [this message]
2024-04-29 21:08 ` [PATCH 24/24] accel/tcg: Move icount fields from CPUState to TCG AccelCPUState Richard Henderson
2024-04-28 22:22 ` [PATCH 00/24] exec: Rework around CPUState user fields (part 2) Philippe Mathieu-Daudé
2024-04-29 21:04 ` Philippe Mathieu-Daudé
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=20240428221450.26460-25-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).