On 20/9/22 01:17, Bernhard Beschow wrote:
In QEMU, a machine and the main_system_bus always go togehter. Usually
the bus is part of the machine which suggsts to host it there.
"together", "suggests"
Since tere is already a current_machine singleton, all code that
accesses the main_system_bus can be changed (behind the scenes) to go
through current_machine. This resolves a singleton. Futhermore, by
"Furthermore"
reifying it in code, the every-machine-has-exactly-one-main-system-bus
relationship becomes very obvious.
Note that the main_system_bus attribute is a value rather than a
pointer. This trades pointer dereferences for pointer arithmetic. The
idea is to reduce cache misses - a rule of thumb says that
every pointer dereference causes a cache miss while arithmetic is
basically free.
Signed-off-by: Bernhard Beschow <shen...@gmail.com>
---
hw/core/bus.c | 5 ++++-
hw/core/machine.c | 3 +++
hw/core/sysbus.c | 22 +++++-----------------
include/hw/boards.h | 1 +
4 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 311ed17e18..7af940102d 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
Likely missing the BusState declaration:
#include "hw/qdev-core.h"
@@ -346,6 +346,7 @@ struct MachineState {
*/
MemoryRegion *ram;
DeviceMemoryState *device_memory;
+ BusState main_system_bus;
ram_addr_t ram_size;
ram_addr_t maxram_size;