All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] aspeed: avocado test boosts
@ 2022-09-23  8:47 Cédric Le Goater
  2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:47 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

Hello,

Alex's patchset [1] showed that by avoiding the class cast checkers in
hot code paths, performance is greatly improved. See results below.

This is a partial resend of [1] plus an extra caching a reference on
the AspeedSMC class, which adds an extra 10% boost.

Thanks ,

C.

[1] http://patchwork.ozlabs.org/project/qemu-devel/list/?series=313458


On a ThinkPad T480 i7-8650U, 

Before :

$ build/tests/venv/bin/avocado --show=app run build/tests/avocado/machine_aspeed.py
    ...
   (1/7) AST1030Machine.test_ast1030_zephyros: PASS (0.21 s)
   (2/7) AST2x00Machine.test_arm_ast2400_palmetto_openbmc_v2_9_0: PASS (23.51 s)
   (3/7) AST2x00Machine.test_arm_ast2500_romulus_openbmc_v2_9_0: PASS (39.59 s)
   (4/7) AST2x00Machine.test_arm_ast2500_evb_buildroot: PASS (23.74 s)
   (5/7) AST2x00Machine.test_arm_ast2600_evb_buildroot: PASS (34.44 s)
   (6/7) AST2x00MachineSDK.test_arm_ast2500_evb_sdk: PASS (91.13 s)
   (7/7) AST2x00MachineSDK.test_arm_ast2600_evb_sdk: PASS (112.27 s)
  RESULTS    : PASS 7 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 325.72 s

After :

  $ build/tests/venv/bin/avocado --show=app run build/tests/avocado/machine_aspeed.py
    ...
   (1/7) AST1030Machine.test_ast1030_zephyros: PASS (0.22 s)
   (2/7) AST2x00Machine.test_arm_ast2400_palmetto_openbmc_v2_9_0: PASS (12.44 s)
   (3/7) AST2x00Machine.test_arm_ast2500_romulus_openbmc_v2_9_0: PASS (13.98 s)
   (4/7) AST2x00Machine.test_arm_ast2500_evb_buildroot: PASS (11.74 s)
   (5/7) AST2x00Machine.test_arm_ast2600_evb_buildroot: PASS (15.90 s)
   (6/7) AST2x00MachineSDK.test_arm_ast2500_evb_sdk: PASS (66.75 s)
   (7/7) AST2x00MachineSDK.test_arm_ast2600_evb_sdk: PASS (82.34 s)
  RESULTS    : PASS 7 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 204.33 s
  
  


Alex Bennée (4):
  cpu: cache CPUClass in CPUState for hot code paths
  hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs
  cputlb: used cached CPUClass in our hot-paths
  ssi: cache SSIPeripheralClass to avoid GET_CLASS()

Cédric Le Goater (2):
  tests/avocado/machine_aspeed.py: Fix typos on buildroot
  aspeed/smc: Cache AspeedSMCClass

 include/hw/core/cpu.h           |  9 +++++++++
 include/hw/ssi/aspeed_smc.h     |  2 ++
 include/hw/ssi/ssi.h            |  3 +++
 accel/tcg/cputlb.c              | 15 ++++++---------
 cpu.c                           |  9 ++++-----
 hw/core/cpu-sysemu.c            |  5 ++---
 hw/ssi/aspeed_smc.c             |  9 ++++-----
 hw/ssi/ssi.c                    | 18 ++++++++----------
 tests/avocado/machine_aspeed.py | 16 ++++++++--------
 9 files changed, 46 insertions(+), 40 deletions(-)

-- 
2.37.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot
  2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
@ 2022-09-23  8:47 ` Cédric Le Goater
  2022-09-23  9:02   ` Thomas Huth
                     ` (2 more replies)
  2022-09-23  8:47 ` [PATCH 2/6] cpu: cache CPUClass in CPUState for hot code paths Cédric Le Goater
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:47 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

Replace 'buidroot' and 'builroot' by 'buildroot'.

Fixes: f7bc7da0724f ("test/avocado/machine_aspeed.py: Add tests using buildroot images")
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 tests/avocado/machine_aspeed.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/avocado/machine_aspeed.py b/tests/avocado/machine_aspeed.py
index 0f64eb636c28..c703be99a6f7 100644
--- a/tests/avocado/machine_aspeed.py
+++ b/tests/avocado/machine_aspeed.py
@@ -92,7 +92,7 @@ def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
 
         self.do_test_arm_aspeed(image_path)
 
-    def do_test_arm_aspeed_buidroot_start(self, image, cpu_id):
+    def do_test_arm_aspeed_buildroot_start(self, image, cpu_id):
         self.vm.set_console()
         self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
                          '-net', 'nic', '-net', 'user')
@@ -109,11 +109,11 @@ def do_test_arm_aspeed_buidroot_start(self, image, cpu_id):
         exec_command(self, 'root')
         time.sleep(0.1)
 
-    def do_test_arm_aspeed_buidroot_poweroff(self):
+    def do_test_arm_aspeed_buildroot_poweroff(self):
         exec_command_and_wait_for_pattern(self, 'poweroff',
                                           'reboot: System halted');
 
-    def test_arm_ast2500_evb_builroot(self):
+    def test_arm_ast2500_evb_buildroot(self):
         """
         :avocado: tags=arch:arm
         :avocado: tags=machine:ast2500-evb
@@ -127,7 +127,7 @@ def test_arm_ast2500_evb_builroot(self):
 
         self.vm.add_args('-device',
                          'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
-        self.do_test_arm_aspeed_buidroot_start(image_path, '0x0')
+        self.do_test_arm_aspeed_buildroot_start(image_path, '0x0')
 
         exec_command_and_wait_for_pattern(self,
              'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
@@ -139,9 +139,9 @@ def test_arm_ast2500_evb_builroot(self):
         exec_command_and_wait_for_pattern(self,
                              'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
 
-        self.do_test_arm_aspeed_buidroot_poweroff()
+        self.do_test_arm_aspeed_buildroot_poweroff()
 
-    def test_arm_ast2600_evb_builroot(self):
+    def test_arm_ast2600_evb_buildroot(self):
         """
         :avocado: tags=arch:arm
         :avocado: tags=machine:ast2600-evb
@@ -157,7 +157,7 @@ def test_arm_ast2600_evb_builroot(self):
                          'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
         self.vm.add_args('-device',
                          'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
-        self.do_test_arm_aspeed_buidroot_start(image_path, '0xf00')
+        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00')
 
         exec_command_and_wait_for_pattern(self,
              'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
@@ -175,7 +175,7 @@ def test_arm_ast2600_evb_builroot(self):
         year = time.strftime("%Y")
         exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
 
-        self.do_test_arm_aspeed_buidroot_poweroff()
+        self.do_test_arm_aspeed_buildroot_poweroff()
 
 
 class AST2x00MachineSDK(QemuSystemTest):
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/6] cpu: cache CPUClass in CPUState for hot code paths
  2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
  2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
@ 2022-09-23  8:47 ` Cédric Le Goater
  2022-09-23  8:48 ` [PATCH 3/6] hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs Cédric Le Goater
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:47 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

From: Alex Bennée <alex.bennee@linaro.org>

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>
---
 include/hw/core/cpu.h | 9 +++++++++
 cpu.c                 | 9 ++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 500503da1316..1a7e1a93804a 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;
diff --git a/cpu.c b/cpu.c
index 584ac78baf96..14365e36f3a1 100644
--- a/cpu.c
+++ b/cpu.c
@@ -131,9 +131,8 @@ const VMStateDescription vmstate_cpu_common = {
 
 void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
-    CPUClass *cc = CPU_GET_CLASS(cpu);
-#endif
+    /* cache the cpu class for the hotpath */
+    cpu->cc = CPU_GET_CLASS(cpu);
 
     cpu_list_add(cpu);
     if (!accel_cpu_realizefn(cpu, errp)) {
@@ -151,8 +150,8 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
     if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
         vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu);
     }
-    if (cc->sysemu_ops->legacy_vmsd != NULL) {
-        vmstate_register(NULL, cpu->cpu_index, cc->sysemu_ops->legacy_vmsd, cpu);
+    if (cpu->cc->sysemu_ops->legacy_vmsd != NULL) {
+        vmstate_register(NULL, cpu->cpu_index, cpu->cc->sysemu_ops->legacy_vmsd, cpu);
     }
 #endif /* CONFIG_USER_ONLY */
 }
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/6] hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs
  2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
  2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
  2022-09-23  8:47 ` [PATCH 2/6] cpu: cache CPUClass in CPUState for hot code paths Cédric Le Goater
@ 2022-09-23  8:48 ` Cédric Le Goater
  2022-09-23  8:48 ` [PATCH 4/6] cputlb: used cached CPUClass in our hot-paths Cédric Le Goater
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:48 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

From: Alex Bennée <alex.bennee@linaro.org>

This is a heavily used function so lets avoid the cost of
CPU_GET_CLASS. On the romulus-bmc run it has a modest effect:

  Before: 36.812 s ±  0.506 s
  After:  35.912 s ±  0.168 s

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220811151413.3350684-4-alex.bennee@linaro.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/core/cpu-sysemu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c
index 00253f89293a..5eaf2e79e66c 100644
--- a/hw/core/cpu-sysemu.c
+++ b/hw/core/cpu-sysemu.c
@@ -69,11 +69,10 @@ hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 
 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
 {
-    CPUClass *cc = CPU_GET_CLASS(cpu);
     int ret = 0;
 
-    if (cc->sysemu_ops->asidx_from_attrs) {
-        ret = cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
+    if (cpu->cc->sysemu_ops->asidx_from_attrs) {
+        ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
         assert(ret < cpu->num_ases && ret >= 0);
     }
     return ret;
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/6] cputlb: used cached CPUClass in our hot-paths
  2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
                   ` (2 preceding siblings ...)
  2022-09-23  8:48 ` [PATCH 3/6] hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs Cédric Le Goater
@ 2022-09-23  8:48 ` Cédric Le Goater
  2022-09-23  8:48 ` [PATCH 5/6] ssi: cache SSIPeripheralClass to avoid GET_CLASS() Cédric Le Goater
  2022-09-23  8:48 ` [PATCH 6/6] aspeed/smc: Cache AspeedSMCClass Cédric Le Goater
  5 siblings, 0 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:48 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

From: Alex Bennée <alex.bennee@linaro.org>

Before: 35.912 s ±  0.168 s
  After: 35.565 s ±  0.087 s

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220811151413.3350684-5-alex.bennee@linaro.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 accel/tcg/cputlb.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index 8fad2d9b83cd..193bfc1cfc14 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -1291,15 +1291,14 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr,
 static void tlb_fill(CPUState *cpu, target_ulong addr, int size,
                      MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
 {
-    CPUClass *cc = CPU_GET_CLASS(cpu);
     bool ok;
 
     /*
      * This is not a probe, so only valid return is success; failure
      * should result in exception + longjmp to the cpu loop.
      */
-    ok = cc->tcg_ops->tlb_fill(cpu, addr, size,
-                               access_type, mmu_idx, false, retaddr);
+    ok = cpu->cc->tcg_ops->tlb_fill(cpu, addr, size,
+                                    access_type, mmu_idx, false, retaddr);
     assert(ok);
 }
 
@@ -1307,9 +1306,8 @@ static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
                                         MMUAccessType access_type,
                                         int mmu_idx, uintptr_t retaddr)
 {
-    CPUClass *cc = CPU_GET_CLASS(cpu);
-
-    cc->tcg_ops->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
+    cpu->cc->tcg_ops->do_unaligned_access(cpu, addr, access_type,
+                                          mmu_idx, retaddr);
 }
 
 static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr,
@@ -1539,10 +1537,9 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,
     if (!tlb_hit_page(tlb_addr, page_addr)) {
         if (!victim_tlb_hit(env, mmu_idx, index, elt_ofs, page_addr)) {
             CPUState *cs = env_cpu(env);
-            CPUClass *cc = CPU_GET_CLASS(cs);
 
-            if (!cc->tcg_ops->tlb_fill(cs, addr, fault_size, access_type,
-                                       mmu_idx, nonfault, retaddr)) {
+            if (!cs->cc->tcg_ops->tlb_fill(cs, addr, fault_size, access_type,
+                                           mmu_idx, nonfault, retaddr)) {
                 /* Non-faulting page table read failed.  */
                 *phost = NULL;
                 return TLB_INVALID_MASK;
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/6] ssi: cache SSIPeripheralClass to avoid GET_CLASS()
  2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
                   ` (3 preceding siblings ...)
  2022-09-23  8:48 ` [PATCH 4/6] cputlb: used cached CPUClass in our hot-paths Cédric Le Goater
@ 2022-09-23  8:48 ` Cédric Le Goater
  2022-09-23  8:48 ` [PATCH 6/6] aspeed/smc: Cache AspeedSMCClass Cédric Le Goater
  5 siblings, 0 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:48 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

From: Alex Bennée <alex.bennee@linaro.org>

Investigating why some BMC models are so slow compared to a plain ARM
virt machines I did some profiling of:

  ./qemu-system-arm -M romulus-bmc -nic user \
    -drive
    file=obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \
    -nographic -serial mon:stdio

And saw that object_class_dynamic_cast_assert was dominating the
profile times. We have a number of cases in this model of the SSI bus.
As the class is static once the object is created we just cache it and
use it instead of the dynamic case macros.

Profiling against:

  ./tests/venv/bin/avocado run \
    tests/avocado/machine_aspeed.py:test_arm_ast2500_romulus_openbmc_v2_9_0

Before: 35.565 s ±  0.087 s
After: 15.713 s ±  0.287 s

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Cédric Le Goater <clg@kaod.org>
Tested-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20220811151413.3350684-6-alex.bennee@linaro.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 include/hw/ssi/ssi.h |  3 +++
 hw/ssi/ssi.c         | 18 ++++++++----------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/hw/ssi/ssi.h b/include/hw/ssi/ssi.h
index f411858ab083..6950f86810d3 100644
--- a/include/hw/ssi/ssi.h
+++ b/include/hw/ssi/ssi.h
@@ -59,6 +59,9 @@ struct SSIPeripheralClass {
 struct SSIPeripheral {
     DeviceState parent_obj;
 
+    /* cache the class */
+    SSIPeripheralClass *spc;
+
     /* Chip select state */
     bool cs;
 };
diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c
index 003931fb509e..d54a109beeb5 100644
--- a/hw/ssi/ssi.c
+++ b/hw/ssi/ssi.c
@@ -38,9 +38,8 @@ static void ssi_cs_default(void *opaque, int n, int level)
     bool cs = !!level;
     assert(n == 0);
     if (s->cs != cs) {
-        SSIPeripheralClass *ssc = SSI_PERIPHERAL_GET_CLASS(s);
-        if (ssc->set_cs) {
-            ssc->set_cs(s, cs);
+        if (s->spc->set_cs) {
+            s->spc->set_cs(s, cs);
         }
     }
     s->cs = cs;
@@ -48,11 +47,11 @@ static void ssi_cs_default(void *opaque, int n, int level)
 
 static uint32_t ssi_transfer_raw_default(SSIPeripheral *dev, uint32_t val)
 {
-    SSIPeripheralClass *ssc = SSI_PERIPHERAL_GET_CLASS(dev);
+    SSIPeripheralClass *ssc = dev->spc;
 
     if ((dev->cs && ssc->cs_polarity == SSI_CS_HIGH) ||
-            (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) ||
-            ssc->cs_polarity == SSI_CS_NONE) {
+        (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) ||
+        ssc->cs_polarity == SSI_CS_NONE) {
         return ssc->transfer(dev, val);
     }
     return 0;
@@ -67,6 +66,7 @@ static void ssi_peripheral_realize(DeviceState *dev, Error **errp)
             ssc->cs_polarity != SSI_CS_NONE) {
         qdev_init_gpio_in_named(dev, ssi_cs_default, SSI_GPIO_CS, 1);
     }
+    s->spc = ssc;
 
     ssc->realize(s, errp);
 }
@@ -115,13 +115,11 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
 {
     BusState *b = BUS(bus);
     BusChild *kid;
-    SSIPeripheralClass *ssc;
     uint32_t r = 0;
 
     QTAILQ_FOREACH(kid, &b->children, sibling) {
-        SSIPeripheral *peripheral = SSI_PERIPHERAL(kid->child);
-        ssc = SSI_PERIPHERAL_GET_CLASS(peripheral);
-        r |= ssc->transfer_raw(peripheral, val);
+        SSIPeripheral *p = SSI_PERIPHERAL(kid->child);
+        r |= p->spc->transfer_raw(p, val);
     }
 
     return r;
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/6] aspeed/smc: Cache AspeedSMCClass
  2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
                   ` (4 preceding siblings ...)
  2022-09-23  8:48 ` [PATCH 5/6] ssi: cache SSIPeripheralClass to avoid GET_CLASS() Cédric Le Goater
@ 2022-09-23  8:48 ` Cédric Le Goater
  5 siblings, 0 replies; 10+ messages in thread
From: Cédric Le Goater @ 2022-09-23  8:48 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée, Cédric Le Goater

Store a reference on the AspeedSMC class under the flash object and
use it when accessing the flash contents. Avoiding the class cast
checkers in these hot paths improves performance by 10% when running
the aspeed avocado tests.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 include/hw/ssi/aspeed_smc.h | 2 ++
 hw/ssi/aspeed_smc.c         | 9 ++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h
index 2d5f8f3d8f68..8e1dda556b91 100644
--- a/include/hw/ssi/aspeed_smc.h
+++ b/include/hw/ssi/aspeed_smc.h
@@ -30,6 +30,7 @@
 #include "qom/object.h"
 
 struct AspeedSMCState;
+struct AspeedSMCClass;
 
 #define TYPE_ASPEED_SMC_FLASH "aspeed.smc.flash"
 OBJECT_DECLARE_SIMPLE_TYPE(AspeedSMCFlash, ASPEED_SMC_FLASH)
@@ -37,6 +38,7 @@ struct AspeedSMCFlash {
     SysBusDevice parent_obj;
 
     struct AspeedSMCState *controller;
+    struct AspeedSMCClass *asc;
     uint8_t cs;
 
     MemoryRegion mmio;
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
index faed7e0cbe17..22df4be528a7 100644
--- a/hw/ssi/aspeed_smc.c
+++ b/hw/ssi/aspeed_smc.c
@@ -388,7 +388,7 @@ static inline int aspeed_smc_flash_cmd(const AspeedSMCFlash *fl)
 static inline int aspeed_smc_flash_addr_width(const AspeedSMCFlash *fl)
 {
     const AspeedSMCState *s = fl->controller;
-    AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
+    AspeedSMCClass *asc = fl->asc;
 
     if (asc->addr_width) {
         return asc->addr_width(s);
@@ -420,7 +420,7 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
                                               uint32_t addr)
 {
     const AspeedSMCState *s = fl->controller;
-    AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
+    AspeedSMCClass *asc = fl->asc;
     AspeedSegments seg;
 
     asc->reg_to_segment(s, s->regs[R_SEG_ADDR0 + fl->cs], &seg);
@@ -1234,7 +1234,6 @@ static const TypeInfo aspeed_smc_info = {
 static void aspeed_smc_flash_realize(DeviceState *dev, Error **errp)
 {
     AspeedSMCFlash *s = ASPEED_SMC_FLASH(dev);
-    AspeedSMCClass *asc;
     g_autofree char *name = g_strdup_printf(TYPE_ASPEED_SMC_FLASH ".%d", s->cs);
 
     if (!s->controller) {
@@ -1242,14 +1241,14 @@ static void aspeed_smc_flash_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    asc = ASPEED_SMC_GET_CLASS(s->controller);
+    s->asc = ASPEED_SMC_GET_CLASS(s->controller);
 
     /*
      * Use the default segment value to size the memory region. This
      * can be changed by FW at runtime.
      */
     memory_region_init_io(&s->mmio, OBJECT(s), &aspeed_smc_flash_ops,
-                          s, name, asc->segments[s->cs].size);
+                          s, name, s->asc->segments[s->cs].size);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
 }
 
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot
  2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
@ 2022-09-23  9:02   ` Thomas Huth
  2022-09-28 16:15   ` Richard Henderson
  2022-09-28 22:48   ` Joel Stanley
  2 siblings, 0 replies; 10+ messages in thread
From: Thomas Huth @ 2022-09-23  9:02 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-arm, qemu-devel
  Cc: Peter Maydell, Richard Henderson, Joel Stanley, Andrew Jeffery,
	Alex Bennée

On 23/09/2022 10.47, Cédric Le Goater wrote:
> Replace 'buidroot' and 'builroot' by 'buildroot'.
> 
> Fixes: f7bc7da0724f ("test/avocado/machine_aspeed.py: Add tests using buildroot images")
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>   tests/avocado/machine_aspeed.py | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot
  2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
  2022-09-23  9:02   ` Thomas Huth
@ 2022-09-28 16:15   ` Richard Henderson
  2022-09-28 22:48   ` Joel Stanley
  2 siblings, 0 replies; 10+ messages in thread
From: Richard Henderson @ 2022-09-28 16:15 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-arm, qemu-devel
  Cc: Peter Maydell, Joel Stanley, Andrew Jeffery, Alex Bennée

On 9/23/22 01:47, Cédric Le Goater wrote:
> Replace 'buidroot' and 'builroot' by 'buildroot'.
> 
> Fixes: f7bc7da0724f ("test/avocado/machine_aspeed.py: Add tests using buildroot images")
> Signed-off-by: Cédric Le Goater <clg@kaod.org>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot
  2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
  2022-09-23  9:02   ` Thomas Huth
  2022-09-28 16:15   ` Richard Henderson
@ 2022-09-28 22:48   ` Joel Stanley
  2 siblings, 0 replies; 10+ messages in thread
From: Joel Stanley @ 2022-09-28 22:48 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-arm, qemu-devel, Peter Maydell, Richard Henderson,
	Andrew Jeffery, Alex Bennée

On Fri, 23 Sept 2022 at 08:48, Cédric Le Goater <clg@kaod.org> wrote:
>
> Replace 'buidroot' and 'builroot' by 'buildroot'.
>
> Fixes: f7bc7da0724f ("test/avocado/machine_aspeed.py: Add tests using buildroot images")
> Signed-off-by: Cédric Le Goater <clg@kaod.org>

Reviewed-by: Joel Stanley <joel@jms.id.au>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-09-28 22:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23  8:47 [PATCH 0/6] aspeed: avocado test boosts Cédric Le Goater
2022-09-23  8:47 ` [PATCH 1/6] tests/avocado/machine_aspeed.py: Fix typos on buildroot Cédric Le Goater
2022-09-23  9:02   ` Thomas Huth
2022-09-28 16:15   ` Richard Henderson
2022-09-28 22:48   ` Joel Stanley
2022-09-23  8:47 ` [PATCH 2/6] cpu: cache CPUClass in CPUState for hot code paths Cédric Le Goater
2022-09-23  8:48 ` [PATCH 3/6] hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs Cédric Le Goater
2022-09-23  8:48 ` [PATCH 4/6] cputlb: used cached CPUClass in our hot-paths Cédric Le Goater
2022-09-23  8:48 ` [PATCH 5/6] ssi: cache SSIPeripheralClass to avoid GET_CLASS() Cédric Le Goater
2022-09-23  8:48 ` [PATCH 6/6] aspeed/smc: Cache AspeedSMCClass Cédric Le Goater

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.