-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpf: add cpu time counter kfuncs #8693
Conversation
Upstream branch: f3f8649 |
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=944865 expired. Closing PR. |
Upstream branch: a259804 |
a06dc5b
to
1206db5
Compare
50dba77
to
ce294a5
Compare
Upstream branch: 79db658 |
1206db5
to
1a4889f
Compare
ce294a5
to
e34fe93
Compare
BPF JIT is moving towards optimizing kfuncs and it was long overdue to switch the dependency. Let's do it now to simplify other patches in the series. Signed-off-by: Vadim Fedorenko <[email protected]>
New kfunc to return ARCH-specific timecounter. The main reason to implement this kfunc is to avoid extra overhead of benchmark measurements, which are usually done by a pair of bpf_ktime_get_ns() at the beginnig and at the end of the code block under benchmark. When fully JITed this function doesn't implement conversion to the monotonic clock and saves some CPU cycles by receiving timecounter values in single-digit amount of instructions. The delta values can be translated into nanoseconds using kfunc introduced in the next patch. For x86_64 BPF JIT converts this kfunc into rdtsc ordered call. Other architectures will get JIT implementation too if supported. The fallback is to get CLOCK_MONOTONIC_RAW value in ns. JIT version of the function uses "LFENCE; RDTSC" variant because it doesn't care about cookie value returned by "RDTSCP" and it doesn't want to trash RCX value. LFENCE option provides the same ordering guarantee as RDTSCP variant. The simplest use-case is added in 5th patch, where we calculate the time spent by bpf_get_ns_current_pid_tgid() kfunc. More complex example is to use session cookie to store timecounter value at kprobe/uprobe using kprobe.session/uprobe.session, and calculate the difference at kretprobe/uretprobe. Acked-by: Eduard Zingerman <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Signed-off-by: Vadim Fedorenko <[email protected]>
The new helper should be used to convert deltas of values received by bpf_get_cpu_time_counter() into nanoseconds. It is not designed to do full conversion of time counter values to CLOCK_MONOTONIC_RAW nanoseconds and cannot guarantee monotonicity of 2 independent values, but rather to convert the difference of 2 close enough values of CPU timestamp counter into nanoseconds. This function is JITted into just several instructions and adds as low overhead as possible and perfectly suits benchmark use-cases. When the kfunc is not JITted it returns the value provided as argument because the kfunc in previous patch will return values in nanoseconds and can be optimized by verifier. Reviewed-by: Eduard Zingerman <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Vadim Fedorenko <[email protected]>
bpf_get_cpu_time_counter() is replaced with rdtsc instruction on x86_64. Add tests to check that JIT works as expected. When JIT is not supported, bpf_cpu_time_counter_to_ns() can be inlined by verifier. Acked-by: Eduard Zingerman <[email protected]> Signed-off-by: Vadim Fedorenko <[email protected]>
The selftest provides an example of how to measure the latency of bpf kfunc/helper call using time stamp counter and how to convert measured value into nanoseconds. Signed-off-by: Vadim Fedorenko <[email protected]>
Upstream branch: e16e64f |
1a4889f
to
69f7146
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=945657 expired. Closing PR. |
Pull request for series with
subject: bpf: add cpu time counter kfuncs
version: 11
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=944865