user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] dskqxs: more closely match epoll semantics
@ 2019-06-29 20:19 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-06-29 20:19 UTC (permalink / raw)
  To: meta

EV_DISPATCH is actually a better match for EPOLLONESHOT
semantics than EV_ONESHOT in that it doesn't require EV_ADD
for every mod operation.

Blindly using EV_ADD everywhere forces the FreeBSD kernel to
do extra allocations up front, so it's best avoided.
---
 lib/PublicInbox/DSKQXS.pm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/DSKQXS.pm b/lib/PublicInbox/DSKQXS.pm
index 278d3f88..1c3b970b 100644
--- a/lib/PublicInbox/DSKQXS.pm
+++ b/lib/PublicInbox/DSKQXS.pm
@@ -17,7 +17,7 @@ use parent qw(IO::KQueue);
 use parent qw(Exporter);
 use IO::KQueue;
 use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT EPOLLET
-	EPOLL_CTL_DEL);
+	EPOLL_CTL_ADD EPOLL_CTL_MOD EPOLL_CTL_DEL);
 our @EXPORT_OK = qw(epoll_ctl epoll_wait);
 my $owner_pid = -1; # kqueue is close-on-fork (yes, fork, not exec)
 
@@ -25,11 +25,15 @@ my $owner_pid = -1; # kqueue is close-on-fork (yes, fork, not exec)
 sub kq_flag ($$) {
 	my ($bit, $ev) = @_;
 	if ($ev & $bit) {
-		my $fl = EV_ADD | EV_ENABLE;
+		my $fl = EV_ENABLE;
 		$fl |= EV_CLEAR if $fl & EPOLLET;
-		($ev & EPOLLONESHOT) ? ($fl | EV_ONESHOT) : $fl;
+
+		# EV_DISPATCH matches EPOLLONESHOT semantics more closely
+		# than EV_ONESHOT, in that EV_ADD is not required to
+		# re-enable a disabled watch.
+		($ev & EPOLLONESHOT) ? ($fl | EV_DISPATCH) : $fl;
 	} else {
-		EV_ADD | EV_DISABLE;
+		EV_DISABLE;
 	}
 }
 
@@ -42,9 +46,15 @@ sub new {
 
 sub epoll_ctl {
 	my ($self, $op, $fd, $ev) = @_;
-	if ($op != EPOLL_CTL_DEL) {
+	if ($op == EPOLL_CTL_MOD) {
 		$self->EV_SET($fd, EVFILT_READ, kq_flag(EPOLLIN, $ev));
 		$self->EV_SET($fd, EVFILT_WRITE, kq_flag(EPOLLOUT, $ev));
+	} elsif ($op == EPOLL_CTL_DEL) {
+		$self->EV_SET($fd, EVFILT_READ, EV_DISABLE);
+		$self->EV_SET($fd, EVFILT_WRITE, EV_DISABLE);
+	} else {
+		$self->EV_SET($fd, EVFILT_READ, EV_ADD|kq_flag(EPOLLIN, $ev));
+		$self->EV_SET($fd, EVFILT_WRITE, EV_ADD|kq_flag(EPOLLOUT, $ev));
 	}
 	0;
 }
-- 
EW


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-29 20:19 [PATCH] dskqxs: more closely match epoll semantics Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox