From 4d3221a7f33e902e790d026169ca387b5c60e2ad Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Tue, 12 May 2020 11:04:44 +0800 Subject: [PATCH] acrn-dm: add some logs for vm state transition add logs for vm state transition to help analyze some problems. Tracked-On: #4098 Signed-off-by: Mingqiang Chi Reviewed-by: Yin Fengwei --- devicemodel/core/main.c | 5 ++++- devicemodel/core/monitor.c | 1 + devicemodel/core/pm.c | 2 ++ devicemodel/core/vmmapi.c | 21 +++++++++++++++++++-- devicemodel/hw/pci/wdt_i6300esb.c | 2 ++ devicemodel/include/vmm.h | 2 +- devicemodel/include/vmmapi.h | 1 + 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 3a172f0af..5b3972c4c 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -615,6 +615,7 @@ vm_system_reset(struct vmctx *ctx) vm_reset_vdevs(ctx); vm_reset(ctx); + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_NONE)); vm_set_suspend_mode(VM_SUSPEND_NONE); /* set the BSP init state */ @@ -711,7 +712,8 @@ num_vcpus_allowed(struct vmctx *ctx) static void sig_handler_term(int signo) { - printf("Receive SIGINT to terminate application...\n"); + pr_info("Received SIGINT to terminate application...\n"); + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_POWEROFF)); vm_set_suspend_mode(VM_SUSPEND_POWEROFF); mevent_notify(); } @@ -1065,6 +1067,7 @@ main(int argc, char *argv[]) vm_destroy(ctx); _ctx = 0; + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_NONE)); vm_set_suspend_mode(VM_SUSPEND_NONE); } diff --git a/devicemodel/core/monitor.c b/devicemodel/core/monitor.c index 5ce505041..ea33ff78c 100644 --- a/devicemodel/core/monitor.c +++ b/devicemodel/core/monitor.c @@ -351,6 +351,7 @@ static void handle_stop(struct mngr_msg *msg, int client_fd, void *param) ack.timestamp = msg->timestamp; if (msg->data.acrnd_stop.force && !is_rtvm) { + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_POWEROFF)); vm_set_suspend_mode(VM_SUSPEND_POWEROFF); ack.data.err = 0; } else { diff --git a/devicemodel/core/pm.c b/devicemodel/core/pm.c index 938bff8ec..40d0d5b25 100644 --- a/devicemodel/core/pm.c +++ b/devicemodel/core/pm.c @@ -7,6 +7,7 @@ #include #include #include "vmmapi.h" +#include "log.h" static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t suspend_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -27,6 +28,7 @@ int vm_resume(struct vmctx *ctx) { pthread_mutex_lock(&suspend_mutex); + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_NONE)); vm_set_suspend_mode(VM_SUSPEND_NONE); pthread_cond_signal(&suspend_cond); pthread_mutex_unlock(&suspend_mutex); diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 35f8cceef..473455634 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -60,6 +60,22 @@ #define SUPPORT_VHM_API_VERSION_MAJOR 1 #define SUPPORT_VHM_API_VERSION_MINOR 0 +#define VM_STATE_STR_LEN 16 +static const char vm_state_str[VM_SUSPEND_LAST][VM_STATE_STR_LEN] = { + [VM_SUSPEND_NONE] = "RUNNING", + [VM_SUSPEND_SYSTEM_RESET] = "SYSTEM_RESET", + [VM_SUSPEND_FULL_RESET] = "FULL_RESET", + [VM_SUSPEND_POWEROFF] = "POWEROFF", + [VM_SUSPEND_SUSPEND] = "SUSPEND", + [VM_SUSPEND_HALT] = "HALT", + [VM_SUSPEND_TRIPLEFAULT] = "TRIPLEFAULT" +}; + +const char *vm_state_to_str(enum vm_suspend_how idx) +{ + return (idx < VM_SUSPEND_LAST) ? vm_state_str[idx] : "UNKNOWN"; +} + static int check_api(int fd) { @@ -494,12 +510,12 @@ vm_clear_ioreq(struct vmctx *ctx) ioctl(ctx->fd, IC_CLEAR_VM_IOREQ, NULL); } -static int suspend_mode = VM_SUSPEND_NONE; +static enum vm_suspend_how suspend_mode = VM_SUSPEND_NONE; void vm_set_suspend_mode(enum vm_suspend_how how) { - pr_notice("vm mode changed from %d to %d\n", suspend_mode, how); + pr_notice("VM state changed from[ %s ] to [ %s ]\n", vm_state_to_str(suspend_mode), vm_state_to_str(how)); suspend_mode = how; } @@ -512,6 +528,7 @@ vm_get_suspend_mode(void) int vm_suspend(struct vmctx *ctx, enum vm_suspend_how how) { + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(how)); vm_set_suspend_mode(how); mevent_notify(); diff --git a/devicemodel/hw/pci/wdt_i6300esb.c b/devicemodel/hw/pci/wdt_i6300esb.c index 123ddaf5f..8e13e382a 100644 --- a/devicemodel/hw/pci/wdt_i6300esb.c +++ b/devicemodel/hw/pci/wdt_i6300esb.c @@ -136,10 +136,12 @@ wdt_expired_handler(void *arg, uint64_t nexp) /* watchdog timer out, set the uos to reboot */ #ifdef DM_DEBUG + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_SYSTEM_RESET)); vm_set_suspend_mode(VM_SUSPEND_SYSTEM_RESET); /* Notify vm thread to handle VM_SUSPEND_SYSTEM_RESET request */ notify_vmloop_thread(); #else + pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_FULL_RESET)); vm_set_suspend_mode(VM_SUSPEND_FULL_RESET); #endif mevent_notify(); diff --git a/devicemodel/include/vmm.h b/devicemodel/include/vmm.h index 20f63e40e..9817475f8 100644 --- a/devicemodel/include/vmm.h +++ b/devicemodel/include/vmm.h @@ -56,7 +56,7 @@ #define IDT_XF 19 /* #XF: SIMD Floating-Point Exception */ enum vm_suspend_how { - VM_SUSPEND_NONE, + VM_SUSPEND_NONE = 0, VM_SUSPEND_SYSTEM_RESET, VM_SUSPEND_FULL_RESET, VM_SUSPEND_POWEROFF, diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index f0ddf0225..f3ba7a047 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -100,6 +100,7 @@ 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); 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); #ifdef DM_DEBUG void notify_vmloop_thread(void);