From 6b1b4a2416fdf06b366a9b8f8b0246303c2256a8 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 28 Apr 2023 21:04:50 +0100 Subject: [PATCH] kernel: add function to calculate delta between two cycle timestamps --- include/socks/cpu.h | 4 ++++ include/socks/types.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/include/socks/cpu.h b/include/socks/cpu.h index e676a97..419aad5 100644 --- a/include/socks/cpu.h +++ b/include/socks/cpu.h @@ -36,6 +36,10 @@ extern void cpu_set_available(unsigned int cpu_id); extern void cpu_set_online(unsigned int cpu_id); extern cycles_t get_cycles(void); +static inline cycles_t cycles_diff(cycles_t then, cycles_t now) +{ + return now >= then ? now - then : (CYCLES_MAX - then) + now; +} #define irq_enable() ml_int_enable() #define irq_disable() ml_int_disable() diff --git a/include/socks/types.h b/include/socks/types.h index c3ec830..96dcf57 100644 --- a/include/socks/types.h +++ b/include/socks/types.h @@ -3,6 +3,8 @@ #include +#define CYCLES_MAX UINT64_MAX + typedef uintptr_t phys_addr_t; typedef uint64_t cycles_t;