summaryrefslogtreecommitdiffstats
path: root/include/hw
diff options
context:
space:
mode:
authorAlex Bennée2022-09-23 10:47:59 +0200
committerRichard Henderson2022-10-04 05:53:30 +0200
commit6fbdff870620705042a5b2d87491659487b3f4e2 (patch)
tree941583f9811b98773d46ceeaa2f56740e602d44c /include/hw
parentMerge tag 'for-upstream' of git://repo.or.cz/qemu/kevin into staging (diff)
downloadqemu-6fbdff870620705042a5b2d87491659487b3f4e2.tar.gz
qemu-6fbdff870620705042a5b2d87491659487b3f4e2.tar.xz
qemu-6fbdff870620705042a5b2d87491659487b3f4e2.zip
cpu: cache CPUClass in CPUState for hot code paths
The class cast checkers are quite expensive and always on (unlike the dynamic case who's checks are gated by CONFIG_QOM_CAST_DEBUG). To avoid the overhead of repeatedly checking something which should never change we cache the CPUClass reference for use in the hot code paths. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220811151413.3350684-3-alex.bennee@linaro.org> Signed-off-by: Cédric Le Goater <clg@kaod.org> Message-Id: <20220923084803.498337-3-clg@kaod.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'include/hw')
-rw-r--r--include/hw/core/cpu.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 500503da13..1a7e1a9380 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -51,6 +51,13 @@ typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
*/
#define CPU(obj) ((CPUState *)(obj))
+/*
+ * The class checkers bring in CPU_GET_CLASS() which is potentially
+ * expensive given the eventual call to
+ * object_class_dynamic_cast_assert(). Because of this the CPUState
+ * has a cached value for the class in cs->cc which is set up in
+ * cpu_exec_realizefn() for use in hot code paths.
+ */
typedef struct CPUClass CPUClass;
DECLARE_CLASS_CHECKERS(CPUClass, CPU,
TYPE_CPU)
@@ -317,6 +324,8 @@ struct qemu_work_item;
struct CPUState {
/*< private >*/
DeviceState parent_obj;
+ /* cache to avoid expensive CPU_GET_CLASS */
+ CPUClass *cc;
/*< public >*/
int nr_cores;