user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] dskqxs: more closely match epoll semantics
Date: Sat, 29 Jun 2019 20:19:29 +0000	[thread overview]
Message-ID: <20190629201929.54447-1-e@80x24.org> (raw)

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


                 reply	other threads:[~2019-06-29 20:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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: http://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=20190629201929.54447-1-e@80x24.org \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).