From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 3DC9E5A0272 for ; Thu, 10 Aug 2023 21:49:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691696984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hnSMKI/SYO1ubnXLWIByJ4+S6jbjQgFho5ATiFqcDIE=; b=bktYgU0Q8lCty/2cDrmlN47cfUjQKRNELId3IgFn9Sn5eOx8ZdxwnWwZ0yC817otLfSgRu 690xlMlFkJqB8ru5HDWmidFY3rMC5ieGCyAAG0T2D73RhESkql6doDVBBsGsQniD/w0tj6 O8IdyLxp2OJNhTa7AeZ0iZYLuzyLKVU= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-74-BinNCZQaNTuaE99ekl1fhA-1; Thu, 10 Aug 2023 15:49:41 -0400 X-MC-Unique: BinNCZQaNTuaE99ekl1fhA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C08B3C1392D; Thu, 10 Aug 2023 19:49:41 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29326492C3E; Thu, 10 Aug 2023 19:49:39 +0000 (UTC) Date: Thu, 10 Aug 2023 21:49:37 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 07/13] epoll: Fold sock_handler into general switch on epoll event fd Message-ID: <20230810214841.3d148ba0@elisabeth> In-Reply-To: <20230810023315.684784-8-david@gibson.dropbear.id.au> References: <20230810023315.684784-1-david@gibson.dropbear.id.au> <20230810023315.684784-8-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: A25ZFNMN7CZA3DVKXEWFHDTNLREKJZB7 X-Message-ID-Hash: A25ZFNMN7CZA3DVKXEWFHDTNLREKJZB7 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 10 Aug 2023 12:33:09 +1000 David Gibson wrote: > When we process events from epoll_wait(), we check for a number of special > cases before calling sock_handler() which then dispatches based on the > protocol type of the socket in the event. > > Fold these cases together into a single switch on the fd type recorded in > the epoll data field. > > Signed-off-by: David Gibson > --- > passt.c | 54 +++++++++++++++++++++++++++--------------------------- > 1 file changed, 27 insertions(+), 27 deletions(-) > > diff --git a/passt.c b/passt.c > index 45e9fbf..665262b 100644 > --- a/passt.c > +++ b/passt.c > @@ -64,29 +64,6 @@ char *epoll_type_str[EPOLL_TYPE_MAX + 1] = { > [EPOLL_TYPE_TAP] = "tap device", > }; > > -/** > - * sock_handler() - Event handler for L4 sockets > - * @c: Execution context > - * @ref: epoll reference > - * @events: epoll events > - * @now: Current timestamp > - */ > -static void sock_handler(struct ctx *c, union epoll_ref ref, > - uint32_t events, const struct timespec *now) > -{ > - trace("%s: packet from %s %i (events: 0x%08x)", > - c->mode == MODE_PASST ? "passt" : "pasta", > - EPOLL_TYPE_STR(ref.type), ref.fd, events); > - > - if (!c->no_tcp && ref.type == EPOLL_TYPE_TCP) > - tcp_sock_handler(c, ref, events, now); > - else if (!c->no_udp && ref.type == EPOLL_TYPE_UDP) > - udp_sock_handler(c, ref, events, now); > - else if (!c->no_icmp && > - (ref.type == EPOLL_TYPE_ICMP || ref.type == EPOLL_TYPE_ICMPV6)) > - icmp_sock_handler(c, ref, events, now); > -} > - > /** > * post_handler() - Run periodic and deferred tasks for L4 protocol handlers > * @c: Execution context > @@ -330,13 +307,36 @@ loop: > > for (i = 0; i < nfds; i++) { > union epoll_ref ref = *((union epoll_ref *)&events[i].data.u64); > + uint32_t eventmask = events[i].events; > > - if (ref.type == EPOLL_TYPE_TAP) > + trace("%s: epoll event on %s %i (events: 0x%08x)", > + c.mode == MODE_PASST ? "passt" : "pasta", > + EPOLL_TYPE_STR(ref.type), ref.fd, events); Gah, sorry I missed this earlier, but covscan reported it -- you probably wanted to pass 'eventmask' to trace(). Actually, a long time ago, I was pondering about a macro that would print constants' names ("EPOLLIN", etc.) instead, but then I thought that once you remember the values from , hex values might be a bit easier on eyes when you're digging through thousands of them... or maybe not. I don't know actually. -- Stefano