rbpf icon indicating copy to clipboard operation
rbpf copied to clipboard

feat: Replace deprecated time crate with std::time

Open danielmellado opened this issue 3 weeks ago • 5 comments

The v0.2 time crate is deprecated and time::precise_time_ns() has been removed in newer versions. This causes build failures with modern Rust toolchains.

This replaces that function with std::time::Instant, which provides cross-platform monotonic time functionality using only the standard library. The bpf_time_getns() helper now returns elapsed nanoseconds since the first call, and the documentation has been updated to reflect this behavior.

The uptime.rs example has been replaced with a new date.rs example. This new example defines a helper that returns the current Unix timestamp and prints the current date and time.

Signed-off-by: Daniel Mellado [email protected]

danielmellado avatar Dec 04 '25 12:12 danielmellado

Thanks for the PR.

The reason we used this crate is that libc and clock_gettime() caused issues on some platforms, see https://github.com/qmonnet/rbpf/issues/19.

Do you know if there's another alternative? Does the API from the current time crate version offers a way to reproduce the timestamp generated in the helper?

qmonnet avatar Dec 04 '25 12:12 qmonnet

Hey, thanks for the quick response. Tbh I've been really surprised about the windows in appveyor, but it did really pick up the cross-platform issue. I'll update this xD

danielmellado avatar Dec 04 '25 12:12 danielmellado

Hi, @qmonnet, I took a look and saw no direct way to do this in time v0.3. I assume this should also work in cross-platforms. It now uses std::time::Instant to capture a reference time on the first call and returns elapsed nanoseconds from that point. TL;DR time intervals should be the same, which should work the same for eBPF programs since they typically just measure elapsed time between events anyway. Let me know ;)

danielmellado avatar Dec 04 '25 13:12 danielmellado

Hi @qmonnet, yeah, JIT also crashed for me. I kept it as it was later but I'm wondering if it'd make sense to just change it. Thanks!

danielmellado avatar Dec 05 '25 11:12 danielmellado

Thanks for the update. I'll try to take a look in the next few days, sorry for the delay.

qmonnet avatar Dec 09 '25 12:12 qmonnet