public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 4/5] examples/sendzc: try to print stats on SIGINT
Date: Tue,  5 Dec 2023 15:22:23 +0000	[thread overview]
Message-ID: <08d8d03b0f4e17afb8643996b8d8f55a730d1a4f.1701789563.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

If interrupted in the middle of a long run, instead of silently
crashing, as we currently do, we can try to print intermediate stats.
That's a good use case, and it's always annoying loosing results when
you forget about it.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 examples/send-zerocopy.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index 9725d0b..84d2323 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -39,6 +39,7 @@
 #include <sys/wait.h>
 #include <sys/mman.h>
 #include <linux/mman.h>
+#include <signal.h>
 
 #include "liburing.h"
 
@@ -82,6 +83,16 @@ static char *payload;
 static struct thread_data threads[MAX_THREADS];
 static pthread_barrier_t barrier;
 
+static bool should_stop = false;
+
+static void sigint_handler(int sig)
+{
+	/* kill if should_stop can't unblock threads fast enough */
+	if (should_stop)
+		_exit(-1);
+	should_stop = true;
+}
+
 /*
  * Implementation of error(3), prints an error message and exits.
  */
@@ -421,6 +432,8 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
 			}
 			io_uring_cqe_seen(&ring, cqe);
 		}
+		if (should_stop)
+			break;
 	} while ((++loop % 16 != 0) || gettimeofday_ms() < tstart + cfg_runtime_ms);
 
 	td->dt_ms = gettimeofday_ms() - tstart;
@@ -582,6 +595,9 @@ int main(int argc, char **argv)
 	if (cfg_rx)
 		do_setup_rx(cfg_family, cfg_type, 0);
 
+	if (!cfg_rx)
+		signal(SIGINT, sigint_handler);
+
 	for (i = 0; i < cfg_nr_threads; i++)
 		pthread_create(&threads[i].thread, NULL,
 				!cfg_rx ? do_test : do_rx, &threads[i]);
-- 
2.43.0


  parent reply	other threads:[~2023-12-05 15:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05 15:22 [PATCH liburing 0/5] send-zc test/bench improvements Pavel Begunkov
2023-12-05 15:22 ` [PATCH liburing 1/5] tests: comment on io_uring zc and SO_ZEROCOPY Pavel Begunkov
2023-12-05 15:22 ` [PATCH liburing 2/5] examples/sendzc: remove get time overhead Pavel Begunkov
2023-12-05 15:22 ` [PATCH liburing 3/5] examples/sendzc: use stdout for stats Pavel Begunkov
2023-12-05 15:22 ` Pavel Begunkov [this message]
2023-12-05 15:22 ` [PATCH liburing 5/5] examples/sendzc: improve help message Pavel Begunkov
2023-12-05 16:22 ` [PATCH liburing 0/5] send-zc test/bench improvements Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08d8d03b0f4e17afb8643996b8d8f55a730d1a4f.1701789563.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox