Skip to content

Commit e435f03

Browse files
taoyuhonglijinxia
authored andcommitted
tools: acrnd: handle timer request from UOS
DM can send ACRND_TIMER to Acrnd, then acrnd will setup a timer for it. When this time is expired, acrnd will try to make this UOS run again. Reviewed-by: Yan Like <like.yan@intel.com> Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
1 parent ee9ec9d commit e435f03

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tools/acrn-manager/acrnd.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,37 @@ static void try_do_works(void)
102102
}
103103
}
104104

105+
static void acrnd_run_vm(char *name);
106+
107+
/* Time to run/resume VM */
108+
void acrnd_vm_timer_func(struct work_arg *arg)
109+
{
110+
struct vmmngr_struct *vm;
111+
112+
if (!arg) {
113+
pdebug();
114+
return;
115+
}
116+
117+
vmmngr_update();
118+
vm = vmmngr_find(arg->name);
119+
if (!vm) {
120+
pdebug();
121+
return;
122+
}
123+
124+
switch (vm->state) {
125+
case VM_CREATED:
126+
acrnd_run_vm(arg->name);
127+
break;
128+
case VM_PAUSED:
129+
resume_vm(arg->name);
130+
break;
131+
default:
132+
pdebug();
133+
}
134+
}
135+
105136
#define TIMER_LIST_FILE "/opt/acrn/conf/timer_list"
106137

107138
/* load/store_timer_list to file to keep timers if SOS poweroff */
@@ -192,6 +223,34 @@ unsigned get_sos_wakeup_reason(void)
192223

193224
static void handle_timer_req(struct mngr_msg *msg, int client_fd, void *param)
194225
{
226+
struct req_acrnd_timer *req = (void *)msg;
227+
struct ack_acrnd_timer ack;
228+
struct vmmngr_struct *vm;
229+
struct work_arg arg = {};
230+
231+
ack.msg.msgid = req->msg.msgid;
232+
ack.msg.len = sizeof(ack);
233+
ack.msg.timestamp = req->msg.timestamp;
234+
ack.err = -1;
235+
236+
vmmngr_update();
237+
vm = vmmngr_find(req->name);
238+
if (!vm) {
239+
pdebug();
240+
goto reply_ack;
241+
}
242+
243+
strncpy(arg.name, req->name, sizeof(arg.name) - 1);
244+
245+
if (acrnd_add_work(acrnd_vm_timer_func, &arg, req->t)) {
246+
pdebug();
247+
goto reply_ack;
248+
}
249+
250+
ack.err = 0;
251+
reply_ack:
252+
if (client_fd > 0)
253+
mngr_send_msg(client_fd, (void *)&ack, NULL, 0, 0);
195254
}
196255

197256
static int store_timer_list(void)

0 commit comments

Comments
 (0)