UEFIStarter
a simple UEFI framework
Functions | Variables
timestamp.c File Reference

Timing functions. More...

#include <Library/UefiBootServicesTableLib.h>
#include <UEFIStarter/core/timestamp.h>
#include <UEFIStarter/core/logger.h>
#include <UEFIStarter/core/string.h>

Functions

int init_timestamps ()
 Initializes the timestamp features. More...
 
UINT64 get_timestamp ()
 Fetches and returns the current timestamp. More...
 
double timestamp_diff_seconds (UINT64 start, UINT64 end)
 Calculates the number of seconds between two timestamps. More...
 
UINT64 get_timestamp_ticks_per_second ()
 Returns the number of timestamp ticks per second. More...
 

Variables

UINT64 _rdtsc_ticks_per_second =0
 internal storage for the number of timestamp ticks per second
 

Detailed Description

Timing functions.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter

Function Documentation

◆ init_timestamps()

int init_timestamps ( )

Initializes the timestamp features.

This will take ~2 seconds at current settings. This function takes the naive approach and simply measures how many ticks pass in 2 seconds. This tick frequency will be used later when converting ticks to seconds.

Make sure to call this function before you attempt to determine elapsed wallclock time.

Returns
0 on success, an error code otherwise.

◆ get_timestamp()

UINT64 get_timestamp ( )

Fetches and returns the current timestamp.

Returns
the current timestamp
Todo:
this could be made inline for improved timing accuracy

◆ timestamp_diff_seconds()

double timestamp_diff_seconds ( UINT64  start,
UINT64  end 
)

Calculates the number of seconds between two timestamps.

This will only work if init_timestamps() has been called first.

Parameters
startthe start of the timestamp interval
endthe end of the timestamp interval
Returns
the difference in seconds
Todo:
this doesn't check for division by 0 errors on purpose, maybe check performance hit and add it if insignificant

◆ get_timestamp_ticks_per_second()

UINT64 get_timestamp_ticks_per_second ( )

Returns the number of timestamp ticks per second.

Returns
timestamp ticks per second