History

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

Dmitrii Banshchikov committed 5 years ago

Commit d0551261 parent ea87ae86 files · +39 −0Browse files

Showing the changes to include/uapi/linux (1 of 6 files). Show all

Unified · Split

include/uapi/linux/bpf.h+11−0
@@ -3797,6 +3797,16 @@ union bpf_attr { · 3796 unmodified lines
37973797 * is cleared if the flag is not specified.
37983798 * Return
37993799 * **-EINVAL** if invalid *flags* are passed, zero otherwise.
3800+ *
3801+ * u64 bpf_ktime_get_coarse_ns(void)
3802+ * Description
3803+ * Return a coarse-grained version of the time elapsed since
3804+ * system boot, in nanoseconds. Does not include time the system
3805+ * was suspended.
3806+ *
3807+ * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
3808+ * Return
3809+ * Current *ktime*.
38003810 */
38013811 #define __BPF_FUNC_MAPPER(FN) \
38023812 FN(unspec), \
@@ -3959,6 +3969,7 @@ union bpf_attr { · 156 unmodified lines
39593969 FN(task_storage_delete), \
39603970 FN(get_current_task_btf), \
39613971 FN(bprm_opts_set), \
3972+ FN(ktime_get_coarse_ns), \
39623973 /* */
39633974
39643975 /* integer value in 'imm' field of BPF_CALL instruction selects which helper