/ src / include / timestamp.h
timestamp.h
 1  /* SPDX-License-Identifier: GPL-2.0-only */
 2  
 3  #ifndef __TIMESTAMP_H__
 4  #define __TIMESTAMP_H__
 5  
 6  #include <commonlib/timestamp_serialized.h> /* IWYU pragma: export */
 7  #include <stdint.h>
 8  
 9  #if CONFIG(COLLECT_TIMESTAMPS)
10  /*
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_BOOTBLOCK / ENV_SEPARATE_ROMSTAGE call must be made before CAR is torn down.
15   */
16  void timestamp_init(uint64_t base);
17  /*
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.
21   */
22  void timestamp_add(enum timestamp_id id, int64_t ts_time);
23  /* Calls timestamp_add with current timestamp. */
24  void timestamp_add_now(enum timestamp_id id);
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  
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  
37  #else
38  #define timestamp_init(base)
39  #define timestamp_add(id, time)
40  #define timestamp_add_now(id)
41  #define timestamp_rescale_table(N, M)
42  #define get_us_since_boot() 0
43  #endif
44  
45  /**
46   * Workaround for guard combination above.
47   */
48  #if CONFIG(COLLECT_TIMESTAMPS)
49  /* Implemented by the architecture code */
50  uint64_t timestamp_get(void);
51  #else
52  #define timestamp_get() 0
53  #endif
54  
55  uint64_t get_initial_timestamp(void);
56  /* Returns timestamp tick frequency in MHz. */
57  int timestamp_tick_freq_mhz(void);
58  
59  #endif