Skip to content

Commit

Permalink
cpu: Avoid QOM casts for CPU()
Browse files Browse the repository at this point in the history
CPU address spaces touching load and store helpers as well as the
movement of (almost) all fields from CPU_COMMON to CPUState have led to
a noticeable increase of CPU() usage in "hot" paths for both TCG and KVM.

While CPU()'s OBJECT_CHECK() might help detect development errors, i.e.
in form of crashes due to QOM vs. non-QOM mismatches rather than QOM
type mismatches, it is not really needed at runtime since mostly used in
CPU-specific paths, coming from a target-specific CPU subtype. If that
pointer is damaged, other errors are highly likely to occur elsewhere
anyway.

Keep the CPU() macro for a consistent developer experience and for
flexibility to exchange its implementation, but turn it into a pure,
unchecked C cast for now.

Compare commit 6e42be7.

Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
afaerber committed Mar 31, 2014
1 parent c8c14bc commit 0d6d1ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/qom/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ typedef uint64_t vaddr;

#define TYPE_CPU "cpu"

#define CPU(obj) OBJECT_CHECK(CPUState, (obj), TYPE_CPU)
/* Since this macro is used a lot in hot code paths and in conjunction with
* FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
* an unchecked cast.
*/
#define CPU(obj) ((CPUState *)(obj))

#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)

Expand Down

0 comments on commit 0d6d1ab

Please sign in to comment.