5.2.11 GetNextMonotonicCount()

5.2.11 GetNextMonotonicCount()

This service provides a 64-bit monotonically increasing counter that is guaranteed to provide a higher value each time GetNextMonotonicCount() is called. This 64-bit counter is not related to any time source, so this service should never be used for delays, polling, or for any type of time measurement.

GetNextHighMonotonicCount() is related to this same 64-bit monotonic counter, but that service is only intended to be used by operating systems after ExitBootServices() is called to manage the non-volatile upper 32-bits of the 64-bit monotonic counter. A UEFI Driver should only use the UEFI Boot Service GetNextMonotonicCount() because it manages all 64-bits of the monotonic counter before ExitBootServices() is called.

The code fragment below show how GetNextMonotonicCount() can be used to retrieve the next 64-bit value for the monotonic counter.

#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS Status;
UINT64 MonotonicCount;
Status = gBS->GetNextMonotonicCount (&MonotonicCount);
if (EFI_ERROR (Status)) {
return Status;
}