#ifndef KPERF_TIMER_H
#define KPERF_TIMER_H
#include <kern/timer_call.h>
#include <kern/bits.h>
struct kperf_timer {
struct timer_call tcall;
uint64_t period;
_Atomic uint32_t action_state;
uint32_t actionid;
_Atomic bitmap_t pending_cpus;
#if DEVELOPMENT || DEBUG
uint64_t fire_time;
#endif
};
extern struct kperf_timer *kperf_timerv;
extern unsigned int kperf_timerc;
void kperf_timer_reprogram(void);
void kperf_timer_reprogram_all(void);
void kperf_ipi_handler(void *param);
#define TIMER_REPROGRAM (0)
#define TIMER_STOP (1)
#if defined(__x86_64__)
#define KP_MIN_PERIOD_NS (20 * NSEC_PER_USEC)
#define KP_MIN_PERIOD_BG_NS (1 * NSEC_PER_MSEC)
#define KP_MIN_PERIOD_PET_NS (2 * NSEC_PER_MSEC)
#define KP_MIN_PERIOD_PET_BG_NS (5 * NSEC_PER_MSEC)
#elif defined(__arm64__)
#define KP_MIN_PERIOD_NS (50 * NSEC_PER_USEC)
#define KP_MIN_PERIOD_BG_NS (1 * NSEC_PER_MSEC)
#define KP_MIN_PERIOD_PET_NS (2 * NSEC_PER_MSEC)
#define KP_MIN_PERIOD_PET_BG_NS (10 * NSEC_PER_MSEC)
#elif defined(__arm__)
#define KP_MIN_PERIOD_NS (100 * NSEC_PER_USEC)
#define KP_MIN_PERIOD_BG_NS (10 * NSEC_PER_MSEC)
#define KP_MIN_PERIOD_PET_NS (2 * NSEC_PER_MSEC)
#define KP_MIN_PERIOD_PET_BG_NS (50 * NSEC_PER_MSEC)
#else
#error "unsupported architecture"
#endif
unsigned kperf_timer_get_count(void);
int kperf_timer_set_count(unsigned int count);
int kperf_timer_get_period(unsigned int timer, uint64_t *period);
int kperf_timer_set_period(unsigned int timer, uint64_t period);
int kperf_timer_get_action(unsigned int timer, uint32_t *action);
int kperf_timer_set_action(unsigned int timer, uint32_t action);
void kperf_timer_go(void);
void kperf_timer_stop(void);
void kperf_timer_reset(void);
unsigned int kperf_timer_get_petid(void);
int kperf_timer_set_petid(unsigned int count);
void kperf_timer_pet_rearm(uint64_t elapsed_ticks);
#endif