summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorDmitrii Banshchikov <me@ubique.spb.ru>2020-11-17 18:45:49 +0000
committerDaniel Borkmann <daniel@iogearbox.net>2020-11-18 23:25:32 +0100
commitd055126180564a57fe533728a4e93d0cb53d49b3 (patch)
treebc4413bce59ff96530fb58525010f22cbb1ff5b3 /tools/include
parentea87ae85c9b31303a2e9d4c769d9f3ee8a3a60d1 (diff)
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
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/uapi/linux/bpf.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index a52299b80b9d..3ca6146f001a 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -3797,6 +3797,16 @@ union bpf_attr {
* is cleared if the flag is not specified.
* Return
* **-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) \
FN(unspec), \
@@ -3959,6 +3969,7 @@ union bpf_attr {
FN(task_storage_delete), \
FN(get_current_task_btf), \
FN(bprm_opts_set), \
+ FN(ktime_get_coarse_ns), \
/* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper