mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 08:09:07 +08:00
bpf: Add bpf_ktime_get_coarse_ns helper
The helper uses CLOCK_MONOTONIC_COARSE source of time that is less accurate but more performant. We have a BPF CGROUP_SKB firewall that supports event logging through bpf_perf_event_output(). Each event has a timestamp and currently we use bpf_ktime_get_ns() for it. Use of bpf_ktime_get_coarse_ns() saves ~15-20 ns in time required for event logging. bpf_ktime_get_ns(): EgressLogByRemoteEndpoint 113.82ns 8.79M bpf_ktime_get_coarse_ns(): EgressLogByRemoteEndpoint 95.40ns 10.48M Signed-off-by: Dmitrii Banshchikov <me@ubique.spb.ru> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20201117184549.257280-1-me@ubique.spb.ru
This commit is contained in:
committed by
Andrii Nakryiko
parent
6969a44914
commit
39f5b2e75e
@@ -3797,6 +3797,16 @@ union bpf_attr {
|
|||||||
* is cleared if the flag is not specified.
|
* is cleared if the flag is not specified.
|
||||||
* Return
|
* Return
|
||||||
* **-EINVAL** if invalid *flags* are passed, zero otherwise.
|
* **-EINVAL** if invalid *flags* are passed, zero otherwise.
|
||||||
|
*
|
||||||
|
* u64 bpf_ktime_get_coarse_ns(void)
|
||||||
|
* Description
|
||||||
|
* Return a coarse-grained version of the time elapsed since
|
||||||
|
* system boot, in nanoseconds. Does not include time the system
|
||||||
|
* was suspended.
|
||||||
|
*
|
||||||
|
* See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
|
||||||
|
* Return
|
||||||
|
* Current *ktime*.
|
||||||
*/
|
*/
|
||||||
#define __BPF_FUNC_MAPPER(FN) \
|
#define __BPF_FUNC_MAPPER(FN) \
|
||||||
FN(unspec), \
|
FN(unspec), \
|
||||||
@@ -3959,6 +3969,7 @@ union bpf_attr {
|
|||||||
FN(task_storage_delete), \
|
FN(task_storage_delete), \
|
||||||
FN(get_current_task_btf), \
|
FN(get_current_task_btf), \
|
||||||
FN(bprm_opts_set), \
|
FN(bprm_opts_set), \
|
||||||
|
FN(ktime_get_coarse_ns), \
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
||||||
|
|||||||
Reference in New Issue
Block a user