diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 5b3972c4c..81e609a65 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -89,6 +89,7 @@ bool lapic_pt; bool is_rtvm; bool is_winvm; bool skip_pci_mem64bar_workaround = false; +bool is_pmu_pt = false; static int guest_ncpus; static int virtio_msix = 1; @@ -178,7 +179,8 @@ usage(int code) " --pm_notify_channel: define the channel used to notify guest about power event\n" " --pm_by_vuart:pty,/run/acrn/vuart_vmname or tty,/dev/ttySn\n" " --windows: support Oracle virtio-blk, virtio-net and virtio-input devices\n" - " for windows guest with secure boot\n", + " for windows guest with secure boot\n" + " --pmu: passthrough performance monitor unit to VM\n", progname, (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", @@ -737,6 +739,7 @@ enum { CMD_OPT_PM_NOTIFY_CHANNEL, CMD_OPT_PM_BY_VUART, CMD_OPT_WINDOWS, + CMD_OPT_PMU, }; static struct option long_options[] = { @@ -776,6 +779,7 @@ static struct option long_options[] = { {"pm_notify_channel", required_argument, 0, CMD_OPT_PM_NOTIFY_CHANNEL}, {"pm_by_vuart", required_argument, 0, CMD_OPT_PM_BY_VUART}, {"windows", no_argument, 0, CMD_OPT_WINDOWS}, + {"pmu", no_argument, 0, CMD_OPT_PMU}, {0, 0, 0, 0 }, }; @@ -943,6 +947,9 @@ main(int argc, char *argv[]) case CMD_OPT_WINDOWS: is_winvm = true; break; + case CMD_OPT_PMU: + is_pmu_pt = true; + break; case 'h': usage(0); default: diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index f7903207b..6a4b6c791 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -251,6 +251,10 @@ vm_create(const char *name, uint64_t req_buf, int *vcpu_num) create_vm.vm_flag |= GUEST_FLAG_IO_COMPLETION_POLLING; } + if (is_pmu_pt) { + create_vm.vm_flag |= GUEST_FLAG_PMU_PASSTHROUGH; + } + create_vm.req_buf = req_buf; while (retry > 0) { error = ioctl(ctx->fd, IC_CREATE_VM, &create_vm); diff --git a/devicemodel/include/dm.h b/devicemodel/include/dm.h index 575172f02..ad65a25eb 100644 --- a/devicemodel/include/dm.h +++ b/devicemodel/include/dm.h @@ -49,6 +49,7 @@ extern char *mac_seed; extern bool lapic_pt; extern bool is_rtvm; extern bool is_winvm; +extern bool is_pmu_pt; int vmexit_task_switch(struct vmctx *ctx, struct vhm_request *vhm_req, int *vcpu);