Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 2 | |
| 3 | #ifndef __TIMESTAMP_H__ |
| 4 | #define __TIMESTAMP_H__ |
| 5 | |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 6 | #include <commonlib/timestamp_serialized.h> |
Elyes HAOUAS | 5817c56 | 2020-07-12 09:03:22 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 8 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 9 | #if CONFIG(COLLECT_TIMESTAMPS) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 10 | /* |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 11 | * timestamp_init() needs to be called once in *one* of the ENV_ROMSTAGE_OR_BEFORE |
| 12 | * stages (bootblock, romstage, verstage, etc). It's up to the chipset/arch |
| 13 | * to make the call in the earliest stage, otherwise some timestamps will be lost. |
| 14 | * For x86 ENV_ROMSTAGE call must be made before CAR is torn down. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 15 | */ |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 16 | void timestamp_init(uint64_t base); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 17 | /* |
Kyösti Mälkki | 8b93689 | 2019-09-12 13:45:15 +0300 | [diff] [blame] | 18 | * Add a new timestamp. For ENV_ROMSTAGE_OR_BEFORE, this timestamp will be stored |
| 19 | * inside REGION(timestamp) before cbmem comes online. For later stages, timestamps |
| 20 | * added before cbmem_[recovery|initialize] calls will be lost. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 21 | */ |
Bora Guvendik | bf73c49 | 2021-11-22 16:03:39 -0800 | [diff] [blame] | 22 | void timestamp_add(enum timestamp_id id, int64_t ts_time); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 23 | /* Calls timestamp_add with current timestamp. */ |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 24 | void timestamp_add_now(enum timestamp_id id); |
Kyösti Mälkki | 806ea08b | 2017-07-15 20:42:20 +0300 | [diff] [blame] | 25 | |
| 26 | /* Apply a factor of N/M to all timestamps recorded so far. */ |
| 27 | void timestamp_rescale_table(uint16_t N, uint16_t M); |
| 28 | |
Werner Zeh | 35cceb8 | 2017-09-12 07:42:54 +0200 | [diff] [blame] | 29 | /* |
| 30 | * Get the time since boot scaled in microseconds. Therefore use the base time |
| 31 | * of the timestamps to get the initial value which is subtracted from |
| 32 | * current timestamp at call time. This will provide a more reliable value even |
| 33 | * if the TSC is not reset on soft reset or warm start. |
| 34 | */ |
| 35 | uint32_t get_us_since_boot(void); |
| 36 | |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 37 | #else |
| 38 | #define timestamp_init(base) |
| 39 | #define timestamp_add(id, time) |
| 40 | #define timestamp_add_now(id) |
Kyösti Mälkki | 806ea08b | 2017-07-15 20:42:20 +0300 | [diff] [blame] | 41 | #define timestamp_rescale_table(N, M) |
Werner Zeh | 35cceb8 | 2017-09-12 07:42:54 +0200 | [diff] [blame] | 42 | #define get_us_since_boot() 0 |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 43 | #endif |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 44 | |
Philipp Deppenwiese | 86fd884 | 2017-10-24 15:08:49 +0200 | [diff] [blame] | 45 | /** |
| 46 | * Workaround for guard combination above. |
Philipp Deppenwiese | 86fd884 | 2017-10-24 15:08:49 +0200 | [diff] [blame] | 47 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 48 | #if CONFIG(COLLECT_TIMESTAMPS) |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 49 | /* Implemented by the architecture code */ |
| 50 | uint64_t timestamp_get(void); |
Philipp Deppenwiese | 86fd884 | 2017-10-24 15:08:49 +0200 | [diff] [blame] | 51 | #else |
| 52 | #define timestamp_get() 0 |
| 53 | #endif |
| 54 | |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 55 | uint64_t get_initial_timestamp(void); |
Aaron Durbin | c49014e | 2015-08-30 21:19:55 -0500 | [diff] [blame] | 56 | /* Returns timestamp tick frequency in MHz. */ |
| 57 | int timestamp_tick_freq_mhz(void); |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 58 | |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 59 | #endif |