1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Intel Corporation
4 * Author: Johannes Berg <johannes@sipsolutions.net>
10 #include <kern_util.h>
11 #include <sys/select.h>
13 #include <sys/timerfd.h>
16 static int uml_rtc_irq_fds[2];
18 void uml_rtc_send_timetravel_alarm(void)
20 unsigned long long c = 1;
22 CATCH_EINTR(write(uml_rtc_irq_fds[1], &c, sizeof(c)));
25 int uml_rtc_start(bool timetravel)
30 int err = os_pipe(uml_rtc_irq_fds, 1, 1);
34 uml_rtc_irq_fds[0] = timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC);
35 if (uml_rtc_irq_fds[0] < 0) {
40 /* apparently timerfd won't send SIGIO, use workaround */
41 sigio_broken(uml_rtc_irq_fds[0]);
42 err = add_sigio_fd(uml_rtc_irq_fds[0]);
44 close(uml_rtc_irq_fds[0]);
49 return uml_rtc_irq_fds[0];
51 uml_rtc_stop(timetravel);
55 int uml_rtc_enable_alarm(unsigned long long delta_seconds)
57 struct itimerspec it = {
59 .tv_sec = delta_seconds,
63 if (timerfd_settime(uml_rtc_irq_fds[0], 0, &it, NULL))
68 void uml_rtc_disable_alarm(void)
70 uml_rtc_enable_alarm(0);
73 void uml_rtc_stop(bool timetravel)
76 os_close_file(uml_rtc_irq_fds[1]);
78 ignore_sigio_fd(uml_rtc_irq_fds[0]);
79 os_close_file(uml_rtc_irq_fds[0]);