github.com/cilium/cilium@v1.16.2/bpf/lib/time.h (about)

     1  /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
     2  /* Copyright Authors of Cilium */
     3  
     4  #pragma once
     5  
     6  #include <bpf/ctx/ctx.h>
     7  #include <bpf/api.h>
     8  
     9  #define NSEC_PER_SEC	(1000ULL * 1000ULL * 1000UL)
    10  #define NSEC_PER_MSEC	(1000ULL * 1000ULL)
    11  #define NSEC_PER_USEC	(1000UL)
    12  
    13  /* Monotonic clock, scalar format. */
    14  #define bpf_ktime_get_sec()	\
    15  	({ __u64 __x = ktime_get_ns() / NSEC_PER_SEC; __x; })
    16  #define bpf_ktime_get_msec()	\
    17  	({ __u64 __x = ktime_get_ns() / NSEC_PER_MSEC; __x; })
    18  #define bpf_ktime_get_usec()	\
    19  	({ __u64 __x = ktime_get_ns() / NSEC_PER_USEC; __x; })
    20  #define bpf_ktime_get_nsec()	\
    21  	({ __u64 __x = ktime_get_ns(); __x; })
    22  
    23  /* Jiffies */
    24  #define bpf_jiffies_to_sec(j)	\
    25  	({ __u64 __x = (j) / KERNEL_HZ; __x; })
    26  #define bpf_sec_to_jiffies(s)	\
    27  	({ __u64 __x = (s) * KERNEL_HZ; __x; })