accel/tcg: Move CPUNegativeOffsetState into CPUState

Retain the separate structure to emphasize its importance.
Enforce CPUArchState always follows CPUState without padding.

Reviewed-by: Anton Johansson <anjo@rev.ng>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2023-09-12 17:47:56 -07:00
parent 5d30bdcb1b
commit 3b3d7df545
25 changed files with 38 additions and 46 deletions

View file

@ -344,8 +344,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
tcg_ctx->page_bits = TARGET_PAGE_BITS; tcg_ctx->page_bits = TARGET_PAGE_BITS;
tcg_ctx->page_mask = TARGET_PAGE_MASK; tcg_ctx->page_mask = TARGET_PAGE_MASK;
tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS; tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;
tcg_ctx->tlb_fast_offset = tcg_ctx->tlb_fast_offset = (int)offsetof(ArchCPU, parent_obj.neg.tlb.f)
(int)offsetof(ArchCPU, neg.tlb.f) - (int)offsetof(ArchCPU, env); - (int)offsetof(ArchCPU, env);
#endif #endif
tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS; tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
#ifdef TCG_GUEST_DEFAULT_MO #ifdef TCG_GUEST_DEFAULT_MO

View file

@ -48,8 +48,8 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
if ((cflags & CF_USE_ICOUNT) || !(cflags & CF_NOIRQ)) { if ((cflags & CF_USE_ICOUNT) || !(cflags & CF_NOIRQ)) {
count = tcg_temp_new_i32(); count = tcg_temp_new_i32();
tcg_gen_ld_i32(count, cpu_env, tcg_gen_ld_i32(count, cpu_env,
offsetof(ArchCPU, neg.icount_decr.u32) - offsetof(ArchCPU, parent_obj.neg.icount_decr.u32)
offsetof(ArchCPU, env)); - offsetof(ArchCPU, env));
} }
if (cflags & CF_USE_ICOUNT) { if (cflags & CF_USE_ICOUNT) {
@ -78,8 +78,8 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
if (cflags & CF_USE_ICOUNT) { if (cflags & CF_USE_ICOUNT) {
tcg_gen_st16_i32(count, cpu_env, tcg_gen_st16_i32(count, cpu_env,
offsetof(ArchCPU, neg.icount_decr.u16.low) - offsetof(ArchCPU, parent_obj.neg.icount_decr.u16.low)
offsetof(ArchCPU, env)); - offsetof(ArchCPU, env));
} }
/* /*

View file

@ -432,9 +432,13 @@ int cpu_exec(CPUState *cpu);
static inline void cpu_set_cpustate_pointers(ArchCPU *cpu) static inline void cpu_set_cpustate_pointers(ArchCPU *cpu)
{ {
cpu->parent_obj.env_ptr = &cpu->env; cpu->parent_obj.env_ptr = &cpu->env;
cpu->parent_obj.icount_decr_ptr = &cpu->neg.icount_decr; cpu->parent_obj.icount_decr_ptr = &cpu->parent_obj.neg.icount_decr;
} }
/* Validate correct placement of CPUArchState. */
QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
/** /**
* env_archcpu(env) * env_archcpu(env)
* @env: The architecture environment * @env: The architecture environment
@ -443,7 +447,7 @@ static inline void cpu_set_cpustate_pointers(ArchCPU *cpu)
*/ */
static inline ArchCPU *env_archcpu(CPUArchState *env) static inline ArchCPU *env_archcpu(CPUArchState *env)
{ {
return container_of(env, ArchCPU, env); return (void *)env - sizeof(CPUState);
} }
/** /**
@ -454,15 +458,9 @@ static inline ArchCPU *env_archcpu(CPUArchState *env)
*/ */
static inline CPUState *env_cpu(CPUArchState *env) static inline CPUState *env_cpu(CPUArchState *env)
{ {
return &env_archcpu(env)->parent_obj; return (void *)env - sizeof(CPUState);
} }
/*
* Validate placement of CPUNegativeOffsetState.
*/
QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) - offsetof(ArchCPU, neg) >=
sizeof(CPUNegativeOffsetState) + __alignof(CPUArchState));
/** /**
* env_neg(env) * env_neg(env)
* @env: The architecture environment * @env: The architecture environment
@ -471,8 +469,7 @@ QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) - offsetof(ArchCPU, neg) >=
*/ */
static inline CPUNegativeOffsetState *env_neg(CPUArchState *env) static inline CPUNegativeOffsetState *env_neg(CPUArchState *env)
{ {
ArchCPU *arch_cpu = container_of(env, ArchCPU, env); return &env_cpu(env)->neg;
return &arch_cpu->neg;
} }
/** /**
@ -483,8 +480,7 @@ static inline CPUNegativeOffsetState *env_neg(CPUArchState *env)
*/ */
static inline CPUNegativeOffsetState *cpu_neg(CPUState *cpu) static inline CPUNegativeOffsetState *cpu_neg(CPUState *cpu)
{ {
ArchCPU *arch_cpu = container_of(cpu, ArchCPU, parent_obj); return &cpu->neg;
return &arch_cpu->neg;
} }
/** /**

View file

@ -345,8 +345,8 @@ typedef union IcountDecr {
} IcountDecr; } IcountDecr;
/* /*
* This structure must be placed in ArchCPU immediately * Elements of CPUState most efficiently accessed from CPUArchState,
* before CPUArchState, as a field named "neg". * via small negative offsets.
*/ */
typedef struct CPUNegativeOffsetState { typedef struct CPUNegativeOffsetState {
CPUTLB tlb; CPUTLB tlb;
@ -453,6 +453,9 @@ struct qemu_work_item;
* dirty ring structure. * dirty ring structure.
* *
* State of one CPU core or thread. * State of one CPU core or thread.
*
* Align, in order to match possible alignment required by CPUArchState,
* and eliminate a hole between CPUState and CPUArchState within ArchCPU.
*/ */
struct CPUState { struct CPUState {
/*< private >*/ /*< private >*/
@ -571,8 +574,18 @@ struct CPUState {
/* track IOMMUs whose translations we've cached in the TCG TLB */ /* track IOMMUs whose translations we've cached in the TCG TLB */
GArray *iommu_notifiers; GArray *iommu_notifiers;
/*
* MUST BE LAST in order to minimize the displacement to CPUArchState.
*/
char neg_align[-sizeof(CPUNegativeOffsetState) % 16] QEMU_ALIGNED(16);
CPUNegativeOffsetState neg;
}; };
/* Validate placement of CPUNegativeOffsetState. */
QEMU_BUILD_BUG_ON(offsetof(CPUState, neg) !=
sizeof(CPUState) - sizeof(CPUNegativeOffsetState));
typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ; typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
extern CPUTailQ cpus; extern CPUTailQ cpus;

View file

@ -263,7 +263,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUAlphaState env; CPUAlphaState env;
/* This alarm doesn't exist in real hardware; we wish it did. */ /* This alarm doesn't exist in real hardware; we wish it did. */

View file

@ -856,7 +856,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUARMState env; CPUARMState env;
/* Coprocessor information */ /* Coprocessor information */

View file

@ -148,7 +148,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUAVRState env; CPUAVRState env;
}; };

View file

@ -178,7 +178,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUCRISState env; CPUCRISState env;
}; };

View file

@ -141,7 +141,7 @@ struct ArchCPU {
/*< private >*/ /*< private >*/
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUHexagonState env; CPUHexagonState env;
bool lldb_compat; bool lldb_compat;

View file

@ -237,7 +237,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUHPPAState env; CPUHPPAState env;
QEMUTimer *alarm_timer; QEMUTimer *alarm_timer;
}; };

View file

@ -1901,7 +1901,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUX86State env; CPUX86State env;
VMChangeStateEntry *vmsentry; VMChangeStateEntry *vmsentry;

View file

@ -375,7 +375,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPULoongArchState env; CPULoongArchState env;
QEMUTimer timer; QEMUTimer timer;
uint32_t phy_id; uint32_t phy_id;

View file

@ -168,7 +168,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUM68KState env; CPUM68KState env;
}; };

View file

@ -345,15 +345,15 @@ typedef struct {
struct ArchCPU { struct ArchCPU {
/*< private >*/ /*< private >*/
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUMBState env;
bool ns_axi_dp; bool ns_axi_dp;
bool ns_axi_ip; bool ns_axi_ip;
bool ns_axi_dc; bool ns_axi_dc;
bool ns_axi_ic; bool ns_axi_ic;
CPUNegativeOffsetState neg;
CPUMBState env;
MicroBlazeCPUConfig cfg; MicroBlazeCPUConfig cfg;
}; };

View file

@ -1213,10 +1213,10 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUMIPSState env;
Clock *clock; Clock *clock;
Clock *count_div; /* Divider for CP0_Count clock */ Clock *count_div; /* Divider for CP0_Count clock */
CPUNegativeOffsetState neg;
CPUMIPSState env;
}; };

View file

@ -218,7 +218,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUNios2State env; CPUNios2State env;
bool diverr_present; bool diverr_present;

View file

@ -305,7 +305,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUOpenRISCState env; CPUOpenRISCState env;
}; };

View file

@ -1317,7 +1317,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUPPCState env; CPUPPCState env;
int vcpu_id; int vcpu_id;

View file

@ -388,7 +388,7 @@ struct ArchCPU {
/* < private > */ /* < private > */
CPUState parent_obj; CPUState parent_obj;
/* < public > */ /* < public > */
CPUNegativeOffsetState neg;
CPURISCVState env; CPURISCVState env;
char *dyn_csr_xml; char *dyn_csr_xml;

View file

@ -111,7 +111,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPURXState env; CPURXState env;
}; };

View file

@ -170,7 +170,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUS390XState env; CPUS390XState env;
S390CPUModel *model; S390CPUModel *model;
/* needed for live migration */ /* needed for live migration */

View file

@ -208,7 +208,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUSH4State env; CPUSH4State env;
}; };

View file

@ -561,7 +561,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUSPARCState env; CPUSPARCState env;
}; };

View file

@ -67,7 +67,6 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
CPUNegativeOffsetState neg;
CPUTriCoreState env; CPUTriCoreState env;
}; };

View file

@ -560,9 +560,8 @@ struct ArchCPU {
CPUState parent_obj; CPUState parent_obj;
/*< public >*/ /*< public >*/
Clock *clock;
CPUNegativeOffsetState neg;
CPUXtensaState env; CPUXtensaState env;
Clock *clock;
}; };