s390x/pci: add common fmb
PATCH 1/1 s390x/pci: add common fmb
Common function measurement block is used to report counters of successfully issued pcilg/stg/stb and rpcit instructions. This patch introduces a new struct ZpciFmb and schedules a timer callback to copy fmb to the guest memory at a interval time which is set to 4s by default. While attemping to update fmb failed, an event error would be generated. After pcilg/stg/stb and rpcit interception handlers issue successfully, increase the related counter. The guest could pass null address to switch off FMB and stop corresponding timer.
--- hw/s390x/s390-pci-bus.c | 3 +- hw/s390x/s390-pci-bus.h | 24 +++++++++++ hw/s390x/s390-pci-inst.c | 105 +++++++++++++++++++++++++++++++++++++++++++++-- hw/s390x/s390-pci-inst.h | 1 + 4 files changed, 129 insertions(+), 4 deletions(-)
hw/s390x/s390-pci-bus.c +2 -1
@@ -967,6 +967,7 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev, bus =pci_get_bus (pci_dev); devfn = pci_dev->devfn;object_unparent (OBJECT (pci_dev)); +fmb_timer_free (pbdev);s390_pci_msix_free (pbdev);s390_pci_iommu_free (s, bus, devfn); pbdev->pdev =NULL ;
@@ -1139,7 +1140,7 @@ static void s390_pci_device_reset(DeviceState *dev)pci_dereg_ioat (pbdev->iommu); } - pbdev->fmb_addr =0 ; +fmb_timer_free (pbdev); } static void s390_pci_get_fid(Object *obj, Visitor *v, const char *name,
hw/s390x/s390-pci-bus.h +24 -0
@@ -286,6 +286,28 @@ typedef struct S390PCIIOMMUTable {S390PCIIOMMU *iommu[PCI_SLOT_MAX ]; } S390PCIIOMMUTable; +/* Function Measurement Block */ +#define DEFAULT_MUI 4000 +#define UPDATE_U_BIT 0x1ULL +#define FMBK_MASK 0xfULL + +typedef struct ZpciFmbFmt0 { +uint64_t dma_rbytes; +uint64_t dma_wbytes; +}ZpciFmbFmt0 ; + +typedef struct ZpciFmb { +uint8_t format; +uint8_t fmt_ind[3 ]; +uint32_t sample; +uint64_t last_update; +uint64_t ld_ops; +uint64_t st_ops; +uint64_t stb_ops; +uint64_t rpcit_ops; +ZpciFmbFmt0 fmt0; +} QEMU_PACKED __attribute((__aligned__(8))) ZpciFmb; +struct S390PCIBusDevice {DeviceState qdev;PCIDevice *pdev;
@@ -297,6 +319,8 @@ struct S390PCIBusDevice {uint32_t fid;bool fid_defined;uint64_t fmb_addr; +ZpciFmb fmb; +QEMUTimer *fmb_timer;uint8_t isc;uint16_t noi;uint16_t maxstbl;
hw/s390x/s390-pci-inst.c +102 -3
154 lines not on this page · raw message
hw/s390x/s390-pci-inst.h +1 -0
@@ -303,6 +303,7 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar, uintptr_t ra);int stpcifc_service_call (S390CPU *cpu,uint8_t r1,uint64_t fiba,uint8_t ar,uintptr_t ra); +void fmb_timer_free (S390PCIBusDevice *pbdev);#define ZPCI_IO_BAR_MIN 0#define ZPCI_IO_BAR_MAX 5
Signature · 1 line
Yi Min
Quoted 3 lines · Yi Min Zhao
Quoted 1 line · Thomas Huth
On 2018-09-19 09:08, Yi Min Zhao wrote:
[...]
Quoted 31 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
hw/s390x/s390-pci-bus.h +0
-0@@ -286,6 +286,28 @@ typedef struct S390PCIIOMMUTable { S390PCIIOMMU *iommu[PCI_SLOT_MAX]; } S390PCIIOMMUTable;+/* Function Measurement Block */
hw/s390x/s390-pci-bus.h +15
-0+#define DEFAULT_MUI 4000 +#define UPDATE_U_BIT 0x1ULL +#define FMBK_MASK 0xfULL + +typedef struct ZpciFmbFmt0 { + uint64_t dma_rbytes; + uint64_t dma_wbytes; +}ZpciFmbFmt0 ; + +typedef struct ZpciFmb { + uint8_t format; + uint8_t fmt_ind[3]; + uint32_t sample; + uint64_t last_update; + uint64_t ld_ops;Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
+
uint64_tst_ops;
+uint64_tstb_ops;
+uint64_trpcit_ops;
+ ZpciFmbFmt0 fmt0;
+}QEMU_PACKED__attribute((__aligned__(8))) ZpciFmb;All the fields in this struct are naturally aligned already, so I'd maybe rather drop the
QEMU_PACKEDand add aQEMU_BUILD_BUG_MSG(sizeof(ZpciFmb) != xx, ...)statement afterwards.
Quoted 5 lines
Currently we only implement FMT0. There're other FMTs to be implemented in future.
So here there would be a union and we can't give a specific size toQEMU_BUILD_BUG_MSG.
Can we use the max size for checking?
I think you could use this to check the beginning of the struct:
QEMU_BUILD_BUG_MSG(offsetof(ZpciFmb, fmt0) != 48, "padding in ZpciFmb");
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
hw/s390x/s390-pci-bus.h struct S390PCIBusDevice { · line 322
Quoted 8 lines
struct S390PCIBusDevice {
DeviceState qdev;
PCIDevice *pdev;hw/s390x/s390-pci-bus.h +1
-0@@ -297,6 +319,8 @@ struct S390PCIBusDevice { uint32_t fid; bool fid_defined; uint64_t fmb_addr; + ZpciFmb fmb;... since you embed it here in another struct which does not have any alignment requirements. This is likely going to cause an error with GCC 8.1, we've had this problem in the past already:
Quoted 3 lines
Ah...I didn't test the code with gcc 8+. GCC I used is 7.2. It should get the same warining.
Nobody reported the warning in the s390-ccw bios until GCC 8 had been released, so I assume this is a new warning in GCC 8.
Quoted 8 lines
Quoted 5 lines
Is the
__align__(8)required at all? As far as I understand the code, the struct is not living inside the guest memory, is it? So you could simply drop the__align__(8).
But if you need it, I think you have to allocate the memory for ZpciFmb separately (and use a "ZpciFmb *fmb" here instead).I want to copy the entire structure to the guest memory during updating FMB.
It's not a good idea to do copy for all members multiple times.
Sure, but you're doing the updates through address_space_write(), so as far as I can see there is currently no need for the attribute((__aligned__(8))) here (or did I miss something?). Thus I'd like to suggest to simply remove that attribute here.
Thomas
Quoted 35 lines · Thomas Huth
Quoted 2 lines · Yi Min Zhao
Quoted 1 line · Thomas Huth
On 2018-09-19 09:08, Yi Min Zhao wrote:
[...]
Quoted 31 lines
Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
hw/s390x/s390-pci-bus.h +12
-0@@ -286,6 +286,28 @@ typedef struct S390PCIIOMMUTable { S390PCIIOMMU *iommu[PCI_SLOT_MAX]; } S390PCIIOMMUTable; +/* Function Measurement Block */ +#define DEFAULT_MUI 4000 +#define UPDATE_U_BIT 0x1ULL +#define FMBK_MASK 0xfULL + +typedef struct ZpciFmbFmt0 { + uint64_t dma_rbytes; + uint64_t dma_wbytes; +}ZpciFmbFmt0 ; + +typedef struct ZpciFmb { + uint8_t format; + uint8_t fmt_ind[3];Quoted 8 lines
hw/s390x/s390-pci-bus.h typedef struct S390PCIIOMMUTable { · line 309
Quoted 8 lines
hw/s390x/s390-pci-bus.h +8
-0+ uint32_t sample; + uint64_t last_update; + uint64_t ld_ops; + uint64_t st_ops; + uint64_t stb_ops; + uint64_t rpcit_ops; + ZpciFmbFmt0 fmt0; +}QEMU_PACKED __attribute((__aligned__ (8 ))) ZpciFmb;All the fields in this struct are naturally aligned already, so I'd maybe rather drop the
QEMU_PACKEDand add aQEMU_BUILD_BUG_MSG(sizeof(ZpciFmb) != xx, ...)statement afterwards.
Quoted 6 lines
Quoted 5 lines
Currently we only implement FMT0. There're other FMTs to be implemented in future.
So here there would be a union and we can't give a specific size toQEMU_BUILD_BUG_MSG.
Can we use the max size for checking?I think you could use this to check the beginning of the struct:
At the beginning of the struct? not after it?
Quoted 2 lines
QEMU_BUILD_BUG_MSG(offsetof(ZpciFmb, fmt0) != 48, "padding in ZpciFmb");
I think this could satisfy our requirement.
Quoted 27 lines
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines
hw/s390x/s390-pci-bus.h struct S390PCIBusDevice { · line 322
Quoted 9 lines
hw/s390x/s390-pci-bus.h +1
-0struct S390PCIBusDevice { DeviceState qdev; PCIDevice *pdev;@@ -297,6 +319,8 @@ struct S390PCIBusDevice { uint32_t fid; bool fid_defined; uint64_t fmb_addr; + ZpciFmb fmb;... since you embed it here in another struct which does not have any alignment requirements. This is likely going to cause an error with GCC 8.1, we've had this problem in the past already:
Quoted 3 lines
Ah...I didn't test the code with gcc 8+. GCC I used is 7.2. It should get the same warining.
Nobody reported the warning in the s390-ccw bios until GCC 8 had been released, so I assume this is a new warning in GCC 8.
Quoted 8 lines
Quoted 5 lines
Is the
__align__(8)required at all? As far as I understand the code, the struct is not living inside the guest memory, is it? So you could simply drop the__align__(8).
But if you need it, I think you have to allocate the memory for ZpciFmb separately (and use a "ZpciFmb *fmb" here instead).I want to copy the entire structure to the guest memory during updating FMB.
It's not a good idea to do copy for all members multiple times.
Quoted 8 lines
Sure, but you're doing the updates through
address_space_write(), so as far as I can see there is currently no need for the attribute((__aligned__(8))) here (or did I miss something?). Thus I'd like to suggest to simply remove that attribute here.Thomas
Agree to remove it.
Signature · 1 line
Yi Min