#ifndef MACHINE_MONOTONIC_H
#define MACHINE_MONOTONIC_H
#if defined(__x86_64__)
#include <x86_64/monotonic.h>
#elif defined(__arm64__)
#include <arm64/monotonic.h>
#elif defined(__arm__)
#include <arm/monotonic.h>
#else
#error unsupported architecture
#endif
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
extern bool mt_core_supported;
struct mt_cpu {
uint64_t mtc_snaps[MT_CORE_NFIXED];
uint64_t mtc_counts[MT_CORE_NFIXED];
uint64_t mtc_counts_last[MT_CORE_NFIXED];
uint64_t mtc_npmis;
bool mtc_active;
};
struct mt_thread {
_Atomic uint64_t mth_gen;
uint64_t mth_counts[MT_CORE_NFIXED];
};
struct mt_task {
uint64_t mtk_counts[MT_CORE_NFIXED];
};
struct mt_cpu *mt_cur_cpu(void);
uint64_t mt_count_pmis(void);
void mt_mtc_update_fixed_counts(struct mt_cpu *mtc, uint64_t *counts,
uint64_t *counts_since);
uint64_t mt_mtc_update_count(struct mt_cpu *mtc, unsigned int ctr);
uint64_t mt_core_snap(unsigned int ctr);
void mt_core_set_snap(unsigned int ctr, uint64_t snap);
void mt_mtc_set_snap(struct mt_cpu *mtc, unsigned int ctr, uint64_t snap);
typedef void (*mt_pmi_fn)(bool user_mode, void *ctx);
extern bool mt_microstackshots;
extern unsigned int mt_microstackshot_ctr;
extern mt_pmi_fn mt_microstackshot_pmi_handler;
extern void *mt_microstackshot_ctx;
extern uint64_t mt_core_reset_values[MT_CORE_NFIXED];
int mt_microstackshot_start_arch(uint64_t period);
#endif