Felix Held | 4a8cd72 | 2020-04-18 22:26:39 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 2407932 | 2018-01-23 10:53:05 -0700 | [diff] [blame] | 2 | |
| 3 | #include <cpu/x86/msr.h> |
| 4 | #include <timer.h> |
Aaron Durbin | 51e4c1a | 2018-01-24 17:42:51 -0700 | [diff] [blame] | 5 | #include <timestamp.h> |
Aaron Durbin | 2407932 | 2018-01-23 10:53:05 -0700 | [diff] [blame] | 6 | |
| 7 | #define CU_PTSC_MSR 0xc0010280 |
| 8 | #define PTSC_FREQ_MHZ 100 |
| 9 | |
| 10 | void timer_monotonic_get(struct mono_time *mt) |
| 11 | { |
Aaron Durbin | 51e4c1a | 2018-01-24 17:42:51 -0700 | [diff] [blame] | 12 | mono_time_set_usecs(mt, timestamp_get()); |
| 13 | } |
| 14 | |
Felix Held | c08d804 | 2023-03-24 22:07:48 +0100 | [diff] [blame] | 15 | /* The TSC has a non-constant rate before the microcode update is applied, so it can't be used |
| 16 | in timestamp_get before that. Instead, the Performance Time Stamp Counter is used. */ |
Aaron Durbin | 51e4c1a | 2018-01-24 17:42:51 -0700 | [diff] [blame] | 17 | uint64_t timestamp_get(void) |
| 18 | { |
Aaron Durbin | 2407932 | 2018-01-23 10:53:05 -0700 | [diff] [blame] | 19 | msr_t msr; |
| 20 | |
| 21 | msr = rdmsr(CU_PTSC_MSR); |
| 22 | |
Felix Held | 2c98218 | 2023-03-09 19:28:16 +0100 | [diff] [blame] | 23 | return msr.raw / PTSC_FREQ_MHZ; |
Aaron Durbin | 2407932 | 2018-01-23 10:53:05 -0700 | [diff] [blame] | 24 | } |