1 /* 2 * Copyright (C) 2018-2022 Intel Corporation. 3 * SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 #include <stdio.h> 7 #include <stdbool.h> 8 #include <pthread.h> 9 #include "vmmapi.h" 10 #include "log.h" 11 12 static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER; 13 static pthread_mutex_t suspend_mutex = PTHREAD_MUTEX_INITIALIZER; 14 15 int wait_for_resume(struct vmctx * ctx)16wait_for_resume(struct vmctx *ctx) 17 { 18 pthread_mutex_lock(&suspend_mutex); 19 while (vm_get_suspend_mode() == VM_SUSPEND_SUSPEND) { 20 pthread_cond_wait(&suspend_cond, &suspend_mutex); 21 } 22 pthread_mutex_unlock(&suspend_mutex); 23 24 return 0; 25 } 26 27 int vm_resume(struct vmctx * ctx)28vm_resume(struct vmctx *ctx) 29 { 30 pthread_mutex_lock(&suspend_mutex); 31 pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_NONE)); 32 vm_set_suspend_mode(VM_SUSPEND_NONE); 33 pthread_cond_signal(&suspend_cond); 34 pthread_mutex_unlock(&suspend_mutex); 35 36 return 0; 37 } 38 39 int vm_monitor_resume(void * arg)40vm_monitor_resume(void *arg) 41 { 42 struct vmctx *ctx = (struct vmctx *)arg; 43 vm_resume(ctx); 44 45 return 0; 46 } 47 48 int vm_monitor_query(void * arg)49vm_monitor_query(void *arg) 50 { 51 return vm_get_suspend_mode(); 52 } 53