acrn-hypervisor/devicemodel/include/timer.h
Victor Sun 6ffa1aa367 DM: add acrn_timer api for timer emulation
We will use timerfd and epoll mechanism to emulate kinds of timers like
PIT/RTC/WDT/PMTIMER/... in device model under Linux. The api is unified
in this patch.

Compare with sigevent mechanism, timerfd has a advantage that it could
avoid race condition on resource accessing in the async sigev thread.

change log:
	v1 -> v2: add NULL pointer check for function parameter;
	v2 -> v3: rename file name of vtimer.* to timer.*;
		  rename structure name of vtimer to acrn_timer;
		  add read() in timer handler to consume I/O event;
	v3 -> v4: replace bool clock_realtime with int clockid;
		  close acrn_timer->fd properly;

Tracked-On: #1489
Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-17 14:31:09 +08:00

27 lines
580 B
C

/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _TIMER_H_
#define _TIMER_H_
struct acrn_timer {
int32_t fd;
int32_t clockid;
struct mevent *mevp;
void (*callback)(void *);
void *callback_param;
};
int32_t
acrn_timer_init(struct acrn_timer *timer, void (*cb)(void *), void *param);
void
acrn_timer_deinit(struct acrn_timer *timer);
int32_t
acrn_timer_settime(struct acrn_timer *timer, struct itimerspec *new_value);
int32_t
acrn_timer_gettime(struct acrn_timer *timer, struct itimerspec *cur_value);
#endif /* _VTIMER_ */