diff mbox series

[RFC,bpf-next,4/5] samples/bpf/xdpsock_user.c: Make get_nsecs() generic

Message ID 20210803171006.13915-5-kishen.maloor@intel.com
State New
Headers show
Series None | expand

Commit Message

Kishen Maloor Aug. 3, 2021, 5:10 p.m. UTC
From: Jithu Joseph <jithu.joseph@intel.com>

The helper function get_nsecs() assumes clock to be CLOCK_MONOTONIC.

TSN features like Launchtime uses CLOCK_TAI. Subsequent patch
extends this sample to show how Launchtime APIs maybe used
in XDP context.

In prepration for this, extend the function to add CLOCKID parameter.

Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
---
 samples/bpf/xdpsock_user.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 33d0bdebbed8..3fd2f6a0d1eb 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -159,11 +159,11 @@  static int num_socks;
 struct xsk_socket_info *xsks[MAX_SOCKS];
 int sock;
 
-static unsigned long get_nsecs(void)
+static unsigned long get_nsecs(int clockid)
 {
 	struct timespec ts;
 
-	clock_gettime(CLOCK_MONOTONIC, &ts);
+	clock_gettime(clockid, &ts);
 	return ts.tv_sec * 1000000000UL + ts.tv_nsec;
 }
 
@@ -354,7 +354,7 @@  static void dump_driver_stats(long dt)
 
 static void dump_stats(void)
 {
-	unsigned long now = get_nsecs();
+	unsigned long now = get_nsecs(CLOCK_MONOTONIC);
 	long dt = now - prev_time;
 	int i;
 
@@ -443,7 +443,7 @@  static void dump_stats(void)
 static bool is_benchmark_done(void)
 {
 	if (opt_duration > 0) {
-		unsigned long dt = (get_nsecs() - start_time);
+		unsigned long dt = (get_nsecs(CLOCK_MONOTONIC) - start_time);
 
 		if (dt >= opt_duration)
 			benchmark_done = true;
@@ -1683,7 +1683,7 @@  int main(int argc, char **argv)
 			exit_with_error(ret);
 	}
 
-	prev_time = get_nsecs();
+	prev_time = get_nsecs(CLOCK_MONOTONIC);
 	start_time = prev_time;
 
 	if (opt_bench == BENCH_RXDROP)