AHCI cleanup
v3 cover AHCI cleanup
This series fixes some runtime overhead when handling interrupts in AHCIState. It then extracts the SysBus implementation into a dedicated file for separation of concerns.
v3:
* Remove extra PCI include in ahci-internal.h
* Extract SysBus implementation into dedicated file
Supersedes: [email protected]
Bernhard Beschow (2):
hw/ide/ahci: Decouple from PCI
hw/ide/ahci: Extract TYPE_SYSBUS_AHCI into dedicated file
hw/ide/ahci-internal.h | 1 - include/hw/ide/ahci.h | 2 - hw/ide/ahci-sysbus.c | 91 +++++++++++++++++++++++++++++++++++ hw/ide/ahci.c | 106 ++--------------------------------------- hw/ide/ich.c | 17 ++++++- hw/arm/Kconfig | 10 ++-- hw/ide/Kconfig | 4 ++ hw/ide/meson.build | 1 + 8 files changed, 121 insertions(+), 111 deletions(-) create mode 100644 hw/ide/ahci-sysbus.c
Signature · 1 line
2.47.1
PATCH v3 1/2 hw/ide/ahci: Decouple from PCI
In some adhoc profiling booting Linux VMs, it's observed that ahci_irq_lower() can be a hot path (10000+ triggers until login prompt appears). Even though the parent device never changes, this method re-determines whether the parent device is a PCI device or not using the rather expensive object_dynamic_cast() function. Avoid this overhead by pushing the interrupt handling to the parent device, essentially turning AHCIState into an "IP block".
Note that this change also frees AHCIState from the PCI dependency which wasn't reflected in Kconfig.
--
Supersedes: [email protected]
--- hw/ide/ahci-internal.h | 1 - include/hw/ide/ahci.h | 2 -- hw/ide/ahci.c | 39 ++++----------------------------------- hw/ide/ich.c | 17 ++++++++++++++++- 4 files changed, 20 insertions(+), 39 deletions(-)
hw/ide/ahci-internal.h +0 -1
@@ -25,7 +25,6 @@#define HW_IDE_AHCI_INTERNAL_H #include "hw/ide/ahci.h" -#include "hw/pci/pci_device.h" #include "ide-internal.h" #define AHCI_MEM_BAR_SIZE 0x1000
include/hw/ide/ahci.h +0 -2
@@ -37,8 +37,6 @@ typedef struct AHCIControlRegs { } AHCIControlRegs; typedef struct AHCIState { - DeviceState *container; - AHCIDevice *dev; AHCIControlRegs control_regs; MemoryRegion mem;
hw/ide/ahci.c +4 -35
@@ -23,8 +23,6 @@#include "qemu/osdep.h" #include "hw/irq.h" -#include "hw/pci/msi.h" -#include "hw/pci/pci.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h"
@@ -34,8 +32,6 @@#include "qemu/module.h" #include "sysemu/block-backend.h" #include "sysemu/dma.h" -#include "hw/ide/pci.h" -#include "hw/ide/ahci-pci.h" #include "hw/ide/ahci-sysbus.h" #include "ahci-internal.h" #include "ide-internal.h"
@@ -179,34 +175,6 @@ static uint32_t ahci_port_read(AHCIState *s, int port, int offset)return val; } -static void ahci_irq_raise (AHCIState *s) -{ -DeviceState *dev_state = s->container; -PCIDevice *pci_dev = (PCIDevice *)object_dynamic_cast (OBJECT (dev_state), -TYPE_PCI_DEVICE ); - -trace_ahci_irq_raise (s); - -if (pci_dev &&msi_enabled (pci_dev)) { -msi_notify (pci_dev,0 ); - }else { -qemu_irq_raise (s->irq); - } -} - -static void ahci_irq_lower (AHCIState *s) -{ -DeviceState *dev_state = s->container; -PCIDevice *pci_dev = (PCIDevice *)object_dynamic_cast (OBJECT (dev_state), -TYPE_PCI_DEVICE ); - -trace_ahci_irq_lower (s); - -if (!pci_dev || !msi_enabled (pci_dev)) { -qemu_irq_lower (s->irq); - } -} -static void ahci_check_irq (AHCIState *s) {int i;
@@ -222,9 +190,11 @@ static void ahci_check_irq(AHCIState *s)trace_ahci_check_irq (s, old_irq, s->control_regs.irqstatus);if (s->control_regs.irqstatus && (s->control_regs.ghc &HOST_CTL_IRQ_EN )) { -ahci_irq_raise (s); +trace_ahci_irq_raise (s); +qemu_irq_raise (s->irq); }else { -ahci_irq_lower (s); +trace_ahci_irq_lower (s); +qemu_irq_lower (s->irq); } }
@@ -1608,7 +1578,6 @@ static const IDEDMAOps ahci_dma_ops = {void ahci_init (AHCIState *s,DeviceState *qdev) { - s->container = qdev;/* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */ memory_region_init_io (&s->mem,OBJECT (qdev), &ahci_mem_ops, s,"ahci" ,AHCI_MEM_BAR_SIZE );
hw/ide/ich.c +16 -1
@@ -91,6 +91,21 @@ static const VMStateDescription vmstate_ich9_ahci = { }, }; +static void pci_ich9_ahci_update_irq (void *opaque,int irq_num,int level) +{ +PCIDevice *pci_dev = opaque; + +assert (irq_num ==0 ); + +if (msi_enabled (pci_dev)) { +if (level) { +msi_notify (pci_dev,0 ); + } + }else { +pci_set_irq (pci_dev, level); + } +} +static void pci_ich9_reset (DeviceState *dev) {AHCIPCIState *d =ICH9_AHCI (dev);
@@ -125,7 +140,7 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)/* XXX Software should program this register */ dev->config[0x90 ] =1 <<6 ;/* Address Map Register - AHCI mode */ - d->ahci.irq =pci_allocate_irq (dev); + d->ahci.irq =qemu_allocate_irq (pci_ich9_ahci_update_irq, d,0 );pci_register_bar (dev,ICH9_IDP_BAR ,PCI_BASE_ADDRESS_SPACE_IO , &d->ahci.idp);
Signature · 1 line
2.47.1
PATCH v3 2/2 hw/ide/ahci: Extract TYPE_SYSBUS_AHCI into dedicated file
In reply to Bernhard BeschowImplement in dedicated file, just like TYPE_ICH9_AHCI.
--- hw/ide/ahci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ hw/ide/ahci.c | 67 -------------------------------- hw/arm/Kconfig | 10 ++--- hw/ide/Kconfig | 4 ++ hw/ide/meson.build | 1 + 5 files changed, 101 insertions(+), 72 deletions(-) create mode 100644 hw/ide/ahci-sysbus.c
hw/ide/ahci-sysbus.c new file +91 -0
@@ -0,0 +1,91 @@ +/* +* QEMU AHCI Emulation (MMIO-mapped devices) +* +* Copyright (c) 2010 [email protected] +* Copyright (c) 2010 Roland Elek <[email protected]> +* Copyright (c) 2010 Sebastian Herbszt <[email protected]> +* Copyright (c) 2010 Alexander Graf <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#include "qemu/osdep.h" +#include "exec/address-spaces.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" + +#include "hw/ide/ahci-sysbus.h" +#include "ahci-internal.h" + +static const VMStateDescription vmstate_sysbus_ahci = { + .name ="sysbus-ahci" , + .fields = (const VMStateField []) { +VMSTATE_AHCI (ahci, SysbusAHCIState), +VMSTATE_END_OF_LIST () + }, +}; + +static void sysbus_ahci_reset (DeviceState *dev) +{ +SysbusAHCIState *s =SYSBUS_AHCI (dev); + +ahci_reset (&s->ahci); +} + +static void sysbus_ahci_init (Object *obj) +{ +SysbusAHCIState *s =SYSBUS_AHCI (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + +ahci_init (&s->ahci,DEVICE (obj)); + +sysbus_init_mmio (sbd, &s->ahci.mem); +sysbus_init_irq (sbd, &s->ahci.irq); +} + +static void sysbus_ahci_realize (DeviceState *dev,Error **errp) +{ +SysbusAHCIState *s =SYSBUS_AHCI (dev); + +ahci_realize (&s->ahci, dev, &address_space_memory); +} + +static Property sysbus_ahci_properties[] = { +DEFINE_PROP_UINT32 ("num-ports" , SysbusAHCIState, ahci.ports,1 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void sysbus_ahci_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = sysbus_ahci_realize; + dc->vmsd = &vmstate_sysbus_ahci; +device_class_set_props (dc, sysbus_ahci_properties); +device_class_set_legacy_reset (dc, sysbus_ahci_reset); +set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); +} + +static const TypeInfo sysbus_ahci_types[] = { + { + .name =TYPE_SYSBUS_AHCI , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SysbusAHCIState), + .instance_init = sysbus_ahci_init, + .class_init = sysbus_ahci_class_init, + }, +}; + +DEFINE_TYPES (sysbus_ahci_types)
hw/ide/ahci.c +0 -67
86 lines not on this page · raw message
hw/arm/Kconfig +5 -5
@@ -71,7 +71,7 @@ config HIGHBANK depends on TCG && ARM select A9MPCORE select A15MPCORE - select AHCI + select AHCI_SYSBUS select ARM_TIMER # sp804 select ARM_V7M select PL011 if !HAVE_RUST # UART
@@ -192,7 +192,7 @@ config SBSA_REF depends on TCG && AARCH64 imply PCI_DEVICES select DEVICE_TREE - select AHCI + select AHCI_SYSBUS select ARM_SMMUV3 select GPIO_KEY select PCI_EXPRESS
@@ -319,7 +319,7 @@ config ARM_V7M config ALLWINNER_A10 bool - select AHCI + select AHCI_SYSBUS select ALLWINNER_A10_PIT select ALLWINNER_A10_PIC select ALLWINNER_A10_CCM
@@ -352,7 +352,7 @@ config ALLWINNER_H3 config ALLWINNER_R40 bool default y if TCG && ARM - select AHCI + select AHCI_SYSBUS select ALLWINNER_SRAMC select ALLWINNER_A10_PIT select ALLWINNER_WDT
@@ -422,7 +422,7 @@ config XLNX_ZYNQMP_ARM bool default y if PIXMAN depends on TCG && AARCH64 - select AHCI + select AHCI_SYSBUS select ARM_GIC select CADENCE select CPU_CLUSTER
hw/ide/Kconfig +4 -0
@@ -54,6 +54,10 @@ config AHCI_ICH9 depends on PCI select AHCI +config AHCI_SYSBUS + bool + select AHCI + config IDE_SII3112 bool select IDE_PCI
hw/ide/meson.build +1 -0
@@ -1,5 +1,6 @@ system_ss.add(when: 'CONFIG_AHCI', if_true: files('ahci.c')) system_ss.add(when: 'CONFIG_AHCI_ICH9', if_true: files('ich.c')) +system_ss.add(when: 'CONFIG_AHCI_SYSBUS', if_true: files('ahci-sysbus.c')) system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('ahci-allwinner.c')) system_ss.add(when: 'CONFIG_IDE_BUS', if_true: files('ide-bus.c')) system_ss.add(when: 'CONFIG_IDE_CF', if_true: files('cf.c'))
Signature · 1 line
2.47.1
Re: [PATCH v3 2/2] hw/ide/ahci: Extract TYPE_SYSBUS_AHCI into dedicated file
Quoted 18 lines · Bernhard Beschow
Implement in dedicated file, just like
TYPE_ICH9_AHCI.Signed-off-by Bernhard Beschow <[email protected]>--- hw/ide/ahci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ hw/ide/ahci.c | 67 -------------------------------- hw/arm/Kconfig | 10 ++--- hw/ide/Kconfig | 4 ++ hw/ide/meson.build | 1 + 5 files changed, 101 insertions(+), 72 deletions(-)create mode 100644
hw/ide/ahci-sysbus.chw/ide/ahci-sysbus.c new file +0
-0
hw/ide/ahci-sysbus.c line 9
Quoted 9 lines
hw/ide/ahci-sysbus.c new file +9
-0@@ -0,0 +1,91 @@ +/* +* QEMU AHCI Emulation (MMIO-mapped devices) +* +* Copyright (c) 2010 [email protected] +* Copyright (c) 2010 Roland Elek <[email protected]> +* Copyright (c) 2010 Sebastian Herbszt <[email protected]> +* Copyright (c) 2010 Alexander Graf <[email protected]> +* +* This library is free software; you can redistribute it and/or
Normally hw/ uses GPL, not LGPL, odd.
Quoted 13 lines
hw/ide/ahci-sysbus.c new file +13
-0+* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +* +*/