mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-21 13:08:42 +00:00
HV: refine pci_find_vdev with hash
hv: pci: refine pci_find_vdev with hash 1. Refined pci_find_vdev with BDF-hashing for better performance Tracked-On: #4857 Signed-off-by: Wang Qian <qian1.wang@intel.com> Reviewed-by: Li Fei <Fei1.Li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
8fb8d81935
commit
882c9d5d76
@ -31,6 +31,7 @@
|
|||||||
#include "vpci_priv.h"
|
#include "vpci_priv.h"
|
||||||
#include <ept.h>
|
#include <ept.h>
|
||||||
#include <logmsg.h>
|
#include <logmsg.h>
|
||||||
|
#include <hash.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vdev != NULL
|
* @pre vdev != NULL
|
||||||
@ -78,14 +79,12 @@ void pci_vdev_write_vcfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes,
|
|||||||
*/
|
*/
|
||||||
struct pci_vdev *pci_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf)
|
struct pci_vdev *pci_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf)
|
||||||
{
|
{
|
||||||
struct pci_vdev *vdev, *tmp;
|
struct pci_vdev *vdev = NULL, *tmp;
|
||||||
uint32_t i;
|
struct hlist_node *n;
|
||||||
|
|
||||||
vdev = NULL;
|
hlist_for_each(n, &vpci->vdevs_hlist_heads[hash64(vbdf.value, VDEV_LIST_HASHBITS)]) {
|
||||||
for (i = 0U; i < vpci->pci_vdev_cnt; i++) {
|
tmp = hlist_entry(n, struct pci_vdev, link);
|
||||||
tmp = &(vpci->pci_vdevs[i]);
|
if (bdf_is_equal(vbdf, tmp->bdf)) {
|
||||||
|
|
||||||
if (bdf_is_equal(tmp->bdf, vbdf)) {
|
|
||||||
vdev = tmp;
|
vdev = tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <logmsg.h>
|
#include <logmsg.h>
|
||||||
#include "vpci_priv.h"
|
#include "vpci_priv.h"
|
||||||
#include "pci_dev.h"
|
#include "pci_dev.h"
|
||||||
|
#include <hash.h>
|
||||||
|
|
||||||
static void vpci_init_vdevs(struct acrn_vm *vm);
|
static void vpci_init_vdevs(struct acrn_vm *vm);
|
||||||
static int32_t vpci_read_cfg(struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val);
|
static int32_t vpci_read_cfg(struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
@ -627,6 +628,7 @@ struct pci_vdev *vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pci_dev_c
|
|||||||
vdev->pci_dev_config = dev_config;
|
vdev->pci_dev_config = dev_config;
|
||||||
vdev->phyfun = parent_pf_vdev;
|
vdev->phyfun = parent_pf_vdev;
|
||||||
|
|
||||||
|
hlist_add_head(&vdev->link, &vpci->vdevs_hlist_heads[hash64(dev_config->vbdf.value, VDEV_LIST_HASHBITS)]);
|
||||||
if (dev_config->vdev_ops != NULL) {
|
if (dev_config->vdev_ops != NULL) {
|
||||||
vdev->vdev_ops = dev_config->vdev_ops;
|
vdev->vdev_ops = dev_config->vdev_ops;
|
||||||
} else {
|
} else {
|
||||||
@ -726,6 +728,9 @@ int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pc
|
|||||||
|
|
||||||
vdev->flags |= pcidev->type;
|
vdev->flags |= pcidev->type;
|
||||||
vdev->bdf.value = pcidev->virt_bdf;
|
vdev->bdf.value = pcidev->virt_bdf;
|
||||||
|
/*We should re-add the vdev to hashlist since its vbdf has changed */
|
||||||
|
hlist_del(&vdev->link);
|
||||||
|
hlist_add_head(&vdev->link, &vpci->vdevs_hlist_heads[hash64(vdev->bdf.value, VDEV_LIST_HASHBITS)]);
|
||||||
vdev->parent_user = vdev_in_sos;
|
vdev->parent_user = vdev_in_sos;
|
||||||
spinlock_release(&tgt_vm->vpci.lock);
|
spinlock_release(&tgt_vm->vpci.lock);
|
||||||
vdev_in_sos->user = vdev;
|
vdev_in_sos->user = vdev;
|
||||||
|
@ -32,7 +32,10 @@
|
|||||||
|
|
||||||
#include <spinlock.h>
|
#include <spinlock.h>
|
||||||
#include <pci.h>
|
#include <pci.h>
|
||||||
|
#include <list.h>
|
||||||
|
|
||||||
|
#define VDEV_LIST_HASHBITS 4U
|
||||||
|
#define VDEV_LIST_HASHSIZE (1U << VDEV_LIST_HASHBITS)
|
||||||
|
|
||||||
struct pci_vbar {
|
struct pci_vbar {
|
||||||
enum pci_bar_type type;
|
enum pci_bar_type type;
|
||||||
@ -135,6 +138,7 @@ struct pci_vdev {
|
|||||||
*/
|
*/
|
||||||
struct pci_vdev *parent_user;
|
struct pci_vdev *parent_user;
|
||||||
struct pci_vdev *user;
|
struct pci_vdev *user;
|
||||||
|
struct hlist_node link;
|
||||||
};
|
};
|
||||||
|
|
||||||
union pci_cfg_addr_reg {
|
union pci_cfg_addr_reg {
|
||||||
@ -153,6 +157,7 @@ struct acrn_vpci {
|
|||||||
uint64_t pci_mmcfg_base;
|
uint64_t pci_mmcfg_base;
|
||||||
uint32_t pci_vdev_cnt;
|
uint32_t pci_vdev_cnt;
|
||||||
struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM];
|
struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM];
|
||||||
|
struct hlist_head vdevs_hlist_heads [VDEV_LIST_HASHSIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct acrn_vm;
|
struct acrn_vm;
|
||||||
|
Loading…
Reference in New Issue
Block a user