diff mbox series

[RFC,bpf-next,34/52] samples/bpf: add 'timeout' option to xdp_redirect_cpu

Message ID 20220628194812.1453059-35-alexandr.lobakin@intel.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf, xdp: introduce and use Generic Hints/metadata | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 fail Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/apply fail Patch does not apply to bpf-next

Commit Message

Alexander Lobakin June 28, 2022, 7:47 p.m. UTC
Add ability to specify a deferred flush timeout (in usec, not nsec!)
when setting up a cpumap in xdp_redirect_cpu sample.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 samples/bpf/xdp_redirect_cpu_user.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
index ca457c34eb0f..d184c3fcab53 100644
--- a/samples/bpf/xdp_redirect_cpu_user.c
+++ b/samples/bpf/xdp_redirect_cpu_user.c
@@ -34,6 +34,8 @@  static const char *__doc__ =
 #include "xdp_sample_user.h"
 #include "xdp_redirect_cpu.skel.h"
 
+#define NSEC_PER_USEC		1000UL
+
 static int map_fd;
 static int avail_fd;
 static int count_fd;
@@ -61,6 +63,7 @@  static const struct option long_options[] = {
 	{ "redirect-device", required_argument, NULL, 'r' },
 	{ "redirect-map", required_argument, NULL, 'm' },
 	{ "meta-thresh", optional_argument, NULL, 'M' },
+	{ "timeout", required_argument, NULL, 't'},
 	{}
 };
 
@@ -128,9 +131,10 @@  static int create_cpu_entry(__u32 cpu, struct bpf_cpumap_val *value,
 		}
 	}
 
-	printf("%s CPU: %u as idx: %u qsize: %d cpumap_prog_fd: %d (cpus_count: %u)\n",
+	printf("%s CPU: %u as idx: %u qsize: %d timeout: %llu cpumap_prog_fd: %d (cpus_count: %u)\n",
 	       new ? "Add new" : "Replace", cpu, avail_idx,
-	       value->qsize, value->bpf_prog.fd, curr_cpus_count);
+	       value->qsize, value->timeout, value->bpf_prog.fd,
+	       curr_cpus_count);
 
 	return 0;
 }
@@ -346,6 +350,7 @@  int main(int argc, char **argv)
 	 *   tuned-adm profile network-latency
 	 */
 	qsize = 2048;
+	value.timeout = 0; /* Defaults to 0 to mimic the previous behaviour. */
 
 	skel = xdp_redirect_cpu__open();
 	if (!skel) {
@@ -383,7 +388,7 @@  int main(int argc, char **argv)
 	}
 
 	prog = skel->progs.xdp_prognum5_lb_hash_ip_pairs;
-	while ((opt = getopt_long(argc, argv, "d:si:Sxp:f:e:r:m:c:q:FMvh",
+	while ((opt = getopt_long(argc, argv, "d:si:Sxp:f:e:r:m:c:q:FMt:vh",
 				  long_options, &longindex)) != -1) {
 		switch (opt) {
 		case 'd':
@@ -466,6 +471,10 @@  int main(int argc, char **argv)
 			opts.meta_thresh = optarg ? strtoul(optarg, NULL, 0) :
 					   1;
 			break;
+		case 't':
+			value.timeout = strtoull(optarg, NULL, 0) *
+					NSEC_PER_USEC;
+			break;
 		case 'h':
 			error = false;
 		default: