Skip to content

Helper function bpf_ktime_get_boot_ns

v5.8

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Return the time elapsed since system boot, in nanoseconds. Does include the time the system was suspended. See: clock_gettime(CLOCK_BOOTTIME)

Returns

Current ktime.

static __u64 (* const bpf_ktime_get_boot_ns)(void) = (void *) 125;

Usage

Returns a 64-bit value representing the current kernel time in nanoseconds since the system boot, including any time the system was suspended. This can be useful for measuring time intervals or generating timestamps in eBPF programs.

Program types

This helper call can be used in the following program types:

Example

__u64 start_time = bpf_ktime_get_boot_ns();
/* some tasks */
__u64 end_time = bpf_ktime_get_boot_ns();
__u64 duration = end_time - start_time;