]> git.feebdaed.xyz Git - 0xmirror/cilium.git/commitdiff
bpf, time: remove jiffies macro and kernel_hz sentinel
authorviktor-kurchenko <viktor.kurchenko@isovalent.com>
Fri, 5 Dec 2025 15:54:28 +0000 (16:54 +0100)
committerTimo Beckers <ti-mo@users.noreply.github.com>
Thu, 18 Dec 2025 11:15:04 +0000 (11:15 +0000)
The `jiffies` macro is used only in a single place in the time header.
Let's remove it and use the `jiffies64` function as is.

Also, `kernel_hz` sentinel value: 1 removed. This should be fine now
because `kernel_hz` property has been migrated to runtime configuration
and `division by zero` error can be caught at compile time.

Signed-off-by: viktor-kurchenko <viktor.kurchenko@isovalent.com>
bpf/include/bpf/helpers.h
bpf/lib/time.h
daemon/cmd/daemon_main.go

index 8f335388dd2cb0473f83e49819f0b48ec368ff08..d5a823a817a82461e4b80869fd71d8ada503a2cf 100644 (file)
@@ -43,7 +43,6 @@ static long BPF_FUNC(for_each_map_elem, void *map, void *callback_fn,
 static __u64 BPF_FUNC(ktime_get_ns);
 static __u64 BPF_FUNC(ktime_get_boot_ns);
 static __u64 BPF_FUNC(jiffies64);
-#define jiffies        jiffies64()
 
 /* We have cookies! ;-) */
 static __sock_cookie BPF_FUNC(get_socket_cookie, void *ctx);
index 033657cfdb0d104f281d9df7beab3bc546d45f98..ba1e9e89bd00de26f5ca3749b67b77e26d6807fa 100644 (file)
@@ -23,14 +23,14 @@ static __always_inline __u64 bpf_ktime_get_sec(void)
 
 static __always_inline __u64 bpf_mono_now(void)
 {
-       if (CONFIG(enable_jiffies) && CONFIG(kernel_hz) != 1)
-               return jiffies >> BPF_MONO_SCALER;
+       if (CONFIG(enable_jiffies))
+               return jiffies64() >> BPF_MONO_SCALER;
        return bpf_ktime_get_sec();
 }
 
 static __always_inline __u32 bpf_sec_to_mono(__u32 s)
 {
-       if (CONFIG(enable_jiffies) && CONFIG(kernel_hz) != 1)
+       if (CONFIG(enable_jiffies))
                return (__u32)(s * CONFIG(kernel_hz)) >> BPF_MONO_SCALER;
        return s;
 }
index 26123e5a1b312a7a3f2e61fea43811450a92ac40..9104468348205307f722669216fe73fd89b4797f 100644 (file)
@@ -1319,7 +1319,6 @@ func daemonLegacyInitialization(params daemonParams) legacy.DaemonInitialization
 
 func initClockSourceOption(logger *slog.Logger) {
        option.Config.ClockSource = option.ClockSourceKtime
-       option.Config.KernelHz = 1 // Known invalid non-zero to avoid div by zero.
        hz, err := probes.KernelHZ()
        if err != nil {
                logger.Info(