1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Intel Corporation
11 #include <kern_util.h>
12 #include <sys/select.h>
14 #include <sys/timerfd.h>
17 static int uml_rtc_irq_fds[2];
19 void uml_rtc_send_timetravel_alarm(void)
21 unsigned long long c = 1;
23 CATCH_EINTR(write(uml_rtc_irq_fds[1], &c, sizeof(c)));
26 int uml_rtc_start(bool timetravel)
31 int err = os_pipe(uml_rtc_irq_fds, 1, 1);
35 uml_rtc_irq_fds[0] = timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC);
36 if (uml_rtc_irq_fds[0] < 0) {
41 /* apparently timerfd won't send SIGIO, use workaround */
42 sigio_broken(uml_rtc_irq_fds[0]);
43 err = add_sigio_fd(uml_rtc_irq_fds[0]);
45 close(uml_rtc_irq_fds[0]);
50 return uml_rtc_irq_fds[0];
52 uml_rtc_stop(timetravel);
56 int uml_rtc_enable_alarm(unsigned long long delta_seconds)
58 struct itimerspec it = {
60 .tv_sec = delta_seconds,
64 if (timerfd_settime(uml_rtc_irq_fds[0], 0, &it, NULL))
69 void uml_rtc_disable_alarm(void)
71 uml_rtc_enable_alarm(0);
74 void uml_rtc_stop(bool timetravel)
77 os_close_file(uml_rtc_irq_fds[1]);
79 ignore_sigio_fd(uml_rtc_irq_fds[0]);
80 os_close_file(uml_rtc_irq_fds[0]);