From 0f599e8d56b90ff8bb886e264ba0f43537a1cabd Mon Sep 17 00:00:00 2001 From: Conghui Date: Wed, 17 Aug 2022 09:16:52 +0800 Subject: [PATCH] dm: add a new page for asyncio asyncio is a new mechanism in ACRN, which is special for these devices which need high IO performance. ACRN hypervisor would process the IO request from User VM in an async mode. Just like the original IOReq shared page, the devicemodel also create a page for fastio requests. As the asyncio use the ioeventfd, so the reuqests are handled in kernel, devicemodel only need to provide the page. Tracked-On: #8209 Signed-off-by: Conghui Acked-by: Wang, Yu1 --- devicemodel/core/main.c | 24 +++++++++++++++++++++ devicemodel/core/vmmapi.c | 19 ++++++++++++++++ devicemodel/include/public/hsm_ioctl_defs.h | 12 +++++++++++ devicemodel/include/vmmapi.h | 1 + 4 files changed, 56 insertions(+) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index f2acb0b15..135a6435c 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -116,6 +116,7 @@ static cpuset_t cpumask; static void vm_loop(struct vmctx *ctx); static char io_request_page[4096] __aligned(4096); +static char asyncio_page[4096] __aligned(4096); static struct acrn_io_request *ioreq_buf = (struct acrn_io_request *)&io_request_page; @@ -835,6 +836,23 @@ static struct option long_options[] = { static char optstr[] = "AhYvE:k:r:B:s:m:l:U:G:i:"; +int +vm_init_asyncio(struct vmctx *ctx, uint64_t base) +{ + struct shared_buf *sbuf = (struct shared_buf *)base; + + sbuf->magic = SBUF_MAGIC; + sbuf->ele_size = sizeof(uint64_t); + sbuf->ele_num = (4096 - SBUF_HEAD_SIZE) / sbuf->ele_size; + sbuf->size = sbuf->ele_size * sbuf->ele_num; + /* set flag to 0 to make sure not overrun! */ + sbuf->flags = 0; + sbuf->overrun_cnt = 0; + sbuf->head = 0; + sbuf->tail = 0; + return vm_setup_sbuf(ctx, ACRN_ASYNCIO, base); +} + int main(int argc, char *argv[]) { @@ -1093,6 +1111,12 @@ main(int argc, char *argv[]) goto fail; } + pr_notice("vm setup asyncio page\n"); + error = vm_init_asyncio(ctx, (uint64_t)asyncio_page); + if (error) { + pr_warn("ASYNIO capability is not supported by kernel or hyperviosr!\n"); + } + pr_notice("vm_setup_memory: size=0x%lx\n", memsize); error = vm_setup_memory(ctx, memsize); if (error) { diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 336aee01f..43583eafc 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -294,6 +294,25 @@ vm_destroy(struct vmctx *ctx) devfd = -1; } +int +vm_setup_sbuf(struct vmctx *ctx, uint32_t sbuf_id, uint64_t base) +{ + int error; + struct acrn_sbuf sbuf_param; + + bzero(&sbuf_param, sizeof(sbuf_param)); + sbuf_param.sbuf_id = sbuf_id; + sbuf_param.base = base; + + error = ioctl(ctx->fd, ACRN_IOCTL_SETUP_SBUF, &sbuf_param); + + if (error) { + pr_err("ACRN_IOCTL_SBUF_PAGE ioctl() returned an error: %s\n", errormsg(errno)); + } + + return error; +} + int vm_parse_memsize(const char *optarg, size_t *ret_memsize) { diff --git a/devicemodel/include/public/hsm_ioctl_defs.h b/devicemodel/include/public/hsm_ioctl_defs.h index b68a1e5c5..4ff753d14 100644 --- a/devicemodel/include/public/hsm_ioctl_defs.h +++ b/devicemodel/include/public/hsm_ioctl_defs.h @@ -107,6 +107,8 @@ _IOW(ACRN_IOCTL_TYPE, 0x41, struct acrn_vm_memmap) #define ACRN_IOCTL_UNSET_MEMSEG \ _IOW(ACRN_IOCTL_TYPE, 0x42, struct acrn_vm_memmap) +#define ACRN_IOCTL_SETUP_SBUF \ + _IOW(ACRN_IOCTL_TYPE, 0x43, struct acrn_sbuf) /* PCI assignment*/ #define ACRN_IOCTL_SET_PTDEV_INTR \ @@ -246,4 +248,14 @@ struct acrn_irqfd { /** MSI interrupt to be injected */ struct acrn_msi_entry msi; }; + +/** + * @brief data structure to register a share buffer by ioctl + */ +struct acrn_sbuf { + /** Type of the sbuf. */ + uint32_t sbuf_id; + /** Base address of the sbuf. */ + uint64_t base; +}; #endif /* VHM_IOCTL_DEFS_H */ diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index dd848dee9..e9766e5f9 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -107,6 +107,7 @@ int vm_create_ioreq_client(struct vmctx *ctx); int vm_destroy_ioreq_client(struct vmctx *ctx); int vm_attach_ioreq_client(struct vmctx *ctx); int vm_notify_request_done(struct vmctx *ctx, int vcpu); +int vm_setup_sbuf(struct vmctx *ctx, uint32_t sbuf_type, uint64_t base); void vm_clear_ioreq(struct vmctx *ctx); const char *vm_state_to_str(enum vm_suspend_how idx); void vm_set_suspend_mode(enum vm_suspend_how how);