1 /* 2 * Copyright (C) 2021 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef COMMON_TICKS_H 8 #define COMMON_TICKS_H 9 10 #include <types.h> 11 12 #define TICKS_PER_MS us_to_ticks(1000U) 13 14 /** 15 * @brief Read current CPU tick count. 16 * 17 * @remark On x86, this is the Time Stamp Counter (TSC) value of the current logical CPU. 18 * 19 * @return CPU ticks 20 */ 21 uint64_t cpu_ticks(void); 22 23 /** 24 * @brief Get CPU tick frequency in KHz. 25 * 26 * @remark On x86, this is the Time Stamp Counter (TSC) frequency of the current logical CPU. 27 * 28 * @return CPU frequency (KHz) 29 */ 30 uint32_t cpu_tickrate(void); 31 32 /** 33 * @brief Convert micro seconds to CPU ticks. 34 * 35 * @param[in] us micro seconds to convert 36 * @return CPU ticks 37 */ 38 uint64_t us_to_ticks(uint32_t us); 39 40 /** 41 * @brief Convert CPU cycles to micro seconds. 42 * 43 * @param[in] ticks CPU ticks to convert 44 * @return microsecond 45 */ 46 uint64_t ticks_to_us(uint64_t ticks); 47 48 /** 49 * @brief Convert CPU cycles to milli seconds. 50 * 51 * @param[in] ticks CPU ticks to convert 52 * @return millisecond 53 */ 54 uint64_t ticks_to_ms(uint64_t ticks); 55 56 #endif /* COMMON_TICKS_H */ 57 58