unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 6/5] t/sigfd: reduce getpid() calls and hash lookups
Date: Tue, 20 Aug 2024 18:40:59 +0000	[thread overview]
Message-ID: <20240820184059.M814830@dcvr> (raw)
In-Reply-To: <20240820103522.3548609-6-e@80x24.org>

getpid() is no longer cached by glibc, syscalls are more
expensive nowadays, so only call it once per test.  The
additional hash table depth is no longer necessary since there's
no longer a difference between signal dispatch methods now that
Sigfd uses the global %SIG.
---
 t/sigfd.t | 55 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/t/sigfd.t b/t/sigfd.t
index eab85ed7..91d11034 100644
--- a/t/sigfd.t
+++ b/t/sigfd.t
@@ -18,15 +18,16 @@ SKIP: {
 	my $old = PublicInbox::DS::block_signals();
 	my $hit = {};
 	my $sig = {};
-	local $SIG{USR2} = sub { $hit->{USR2}->{normal}++ };
-	local $SIG{HUP} = sub { $hit->{HUP}->{normal}++ };
-	local $SIG{TERM} = sub { $hit->{TERM}->{normal}++ };
-	local $SIG{INT} = sub { $hit->{INT}->{normal}++ };
-	local $SIG{WINCH} = sub { $hit->{WINCH}->{normal}++ };
+	local $SIG{USR2} = sub { $hit->{USR2}++ };
+	local $SIG{HUP} = sub { $hit->{HUP}++ };
+	local $SIG{TERM} = sub { $hit->{TERM}++ };
+	local $SIG{INT} = sub { $hit->{INT}++ };
+	local $SIG{WINCH} = sub { $hit->{WINCH}++ };
 	for my $s (qw(USR2 HUP TERM INT WINCH)) {
 		$sig->{$s} = sub { die "SHOULD NOT BE CALLED ($s)" }
 	}
-	kill 'USR2', $$ or die "kill $!";
+	my $PID = $$;
+	kill 'USR2', $PID;
 	ok(!defined($hit->{USR2}), 'no USR2 yet') or diag explain($hit);
 	PublicInbox::DS->Reset;
 	ok($PublicInbox::Syscall::SIGNUM{WINCH}, 'SIGWINCH number defined');
@@ -35,9 +36,9 @@ SKIP: {
 		$linux_sigfd = 1 if $^O eq 'linux';
 		$has_sigfd = 1;
 		ok($sigfd, 'Sigfd->new works');
-		kill('HUP', $$) or die "kill $!";
-		kill('INT', $$) or die "kill $!";
-		kill('WINCH', $$) or die "kill $!";
+		kill 'HUP', $PID;
+		kill 'INT', $PID;
+		kill 'WINCH', $PID;
 		my $fd = fileno($sigfd->{sock});
 		ok($fd >= 0, 'fileno(Sigfd->{sock}) works');
 		my $rvec = '';
@@ -45,12 +46,12 @@ SKIP: {
 		is(select($rvec, undef, undef, undef), 1, 'select() works');
 		ok($sigfd->wait_once, 'wait_once reported success');
 		for my $s (qw(HUP INT)) {
-			is($hit->{$s}->{normal}, 1, "sigfd fired $s");
+			is $hit->{$s}, 1, "sigfd fired $s";
 		}
 		SKIP: {
 			skip 'Linux sigfd-only behavior', 1 if !$linux_sigfd;
-			is($hit->{USR2}->{normal}, 1,
-				'USR2 sent before signalfd created received');
+			is $hit->{USR2}, 1,
+				'USR2 sent before signalfd created received';
 		}
 		PublicInbox::DS->Reset;
 		$sigfd = undef;
@@ -59,38 +60,38 @@ SKIP: {
 		ok($nbsig, 'Sigfd->new SFD_NONBLOCK works');
 		is($nbsig->wait_once, undef, 'nonblocking ->wait_once');
 		ok($! == Errno::EAGAIN, 'got EAGAIN');
-		kill('HUP', $$) or die "kill $!";
+		kill 'HUP', $PID;
 		local @PublicInbox::DS::post_loop_do = (sub {}); # loop once
 		PublicInbox::DS::event_loop();
-		is($hit->{HUP}->{normal}, 2, 'HUP sigfd fired in event loop') or
+		is $hit->{HUP}, 2, 'HUP sigfd fired in event loop' or
 			diag explain($hit); # sometimes fails on FreeBSD 11.x
-		kill('TERM', $$) or die "kill $!";
-		kill('HUP', $$) or die "kill $!";
+		kill 'TERM', $PID;
+		kill 'HUP', $PID;
 		PublicInbox::DS::event_loop();
 		PublicInbox::DS->Reset;
-		is($hit->{TERM}->{normal}, 1, 'TERM sigfd fired in event loop');
-		is($hit->{HUP}->{normal}, 3, 'HUP sigfd fired in event loop');
-		ok($hit->{WINCH}->{normal}, 'WINCH sigfd fired in event loop');
+		is $hit->{TERM}, 1, 'TERM sigfd fired in event loop';
+		is $hit->{HUP}, 3, 'HUP sigfd fired in event loop';
+		ok $hit->{WINCH}, 'WINCH sigfd fired in event loop';
 
 		my $restore = PublicInbox::DS::allow_sigs 'HUP';
-		kill 'HUP', $$;
+		kill 'HUP', $PID;
 		select undef, undef, undef, 0;
-		is $hit->{HUP}->{normal}, 4, 'HUP sigfd fired after allow_sigs';
+		is $hit->{HUP}, 4, 'HUP sigfd fired after allow_sigs';
 
 		undef $restore;
-		kill 'HUP', $$;
+		kill 'HUP', $PID;
 		vec($rvec = '', fileno($nbsig->{sock}), 1) = 1;
 		ok select($rvec, undef, undef, 1),
 			'select reports sigfd readiness';
-		is $hit->{HUP}->{normal}, 4, 'HUP not fired when sigs blocked';
+		is $hit->{HUP}, 4, 'HUP not fired when sigs blocked';
 		$nbsig->event_step;
-		is $hit->{HUP}->{normal}, 5, 'HUP fires only on ->event_step';
+		is $hit->{HUP}, 5, 'HUP fires only on ->event_step';
 
-		kill 'HUP', $$;
-		is $hit->{HUP}->{normal}, 5, 'HUP not fired, yet';
+		kill 'HUP', $PID;
+		is $hit->{HUP}, 5, 'HUP not fired, yet';
 		$restore = PublicInbox::DS::allow_sigs 'HUP';
 		select(undef, undef, undef, 0);
-		is $hit->{HUP}->{normal}, 6, 'HUP fires from allow_sigs';
+		is $hit->{HUP}, 6, 'HUP fires from allow_sigs';
 	} else {
 		skip('signalfd disabled?', 10);
 	}

      reply	other threads:[~2024-08-20 18:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-20 10:35 [PATCH 0/5] signal handling fixes Eric Wong
2024-08-20 10:35 ` [PATCH 1/5] treewide: handle EINTR for non-(signalfd|kevent) Eric Wong
2024-08-20 10:35 ` [PATCH 2/5] lei: simplify forced signal check Eric Wong
2024-08-20 10:35 ` [PATCH 3/5] sigfd: call normal Perl %SIG handlers Eric Wong
2024-08-20 10:35 ` [PATCH 4/5] lei: allow Ctrl-C to interrupt IMAP+NNTP reads Eric Wong
2024-08-20 10:35 ` [PATCH 5/5] lei_xsearch: allow signals during long queries Eric Wong
2024-08-20 18:40   ` Eric Wong [this message]

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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20240820184059.M814830@dcvr \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).