From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 7B5C55A0272 for ; Wed, 20 Dec 2023 08:09:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1703056152; bh=mJugLcJ7qOoet2nhArTGSXVF63egibkzWGpn3VrWbEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZriZjbza50+Z8B4zynqL5ZF++gvO9yyZDD4JWxFgyloRgs6a0PimzD1fGUHC0Jp5b ZzclAeZ3uPzhez/SDZkvMhn2908lx5B1SfbGeKGQtDnAJwU3pge1IwOgfW5LWTnp2T rLTu2t0n/0iRogrMfbb1+HbdRgYLX4APLkYsvLDUmQsjbchYAGGapNQiF/GOv9vp6b DFkuUs1qnNnzCAUHvcTtil6q85H9InUuyQq1VS3oWZ9MVYjnhYEet8lKetJizWj/01 fIOlfQ3ae0GDzCzXx2a+nn+lo13ULjYkyrYDji+gP8PGQBRS+ISkrglDPU5K/tCjSF aajuXn8ne02TQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Sw4Rr28SBz4x7q; Wed, 20 Dec 2023 18:09:12 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 05/13] flow, tcp: Add flow-centric dispatch for deferred flow handling Date: Wed, 20 Dec 2023 18:09:00 +1100 Message-ID: <20231220070908.2506277-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220070908.2506277-1-david@gibson.dropbear.id.au> References: <20231220070908.2506277-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UDI6MF4BNAT5ZP6UVHPKBLQ65452OPBH X-Message-ID-Hash: UDI6MF4BNAT5ZP6UVHPKBLQ65452OPBH X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: tcp_defer_handler(), amongst other things, scans the flow table and does some processing for each TCP connection. When we add other protocols to the flow table, they're likely to want some similar scanning. It makes more sense for cache friendliness to perform a single scan of the flow table and dispatch to the protocol specific handlers, rather than having each protocol separately scan the table. To that end, add a new flow_defer_handler() handling all flow-linked deferred operations. Signed-off-by: David Gibson --- flow.c | 23 +++++++++++++++++++++++ flow.h | 1 + passt.c | 1 + tcp.c | 19 ++----------------- tcp_conn.h | 1 + 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/flow.c b/flow.c index a1c0a34..0a0402d 100644 --- a/flow.c +++ b/flow.c @@ -83,3 +83,26 @@ void flow_log_(const struct flow_common *f, int pri, const char *fmt, ...) logmsg(pri, "Flow %u (%s): %s", flow_idx(f), FLOW_TYPE(f), msg); } + +/** + * flow_defer_handler() - Handler for per-flow deferred tasks + * @c: Execution context + */ +void flow_defer_handler(struct ctx *c) +{ + union flow *flow; + + for (flow = flowtab + c->flow_count - 1; flow >= flowtab; flow--) { + switch (flow->f.type) { + case FLOW_TCP: + tcp_flow_defer(c, flow); + break; + case FLOW_TCP_SPLICE: + tcp_splice_flow_defer(c, flow); + break; + default: + /* Assume other flow types don't need any handling */ + ; + } + } +} diff --git a/flow.h b/flow.h index 959b461..6b17fa8 100644 --- a/flow.h +++ b/flow.h @@ -67,6 +67,7 @@ static inline bool flow_sidx_eq(flow_sidx_t a, flow_sidx_t b) union flow; void flow_table_compact(struct ctx *c, union flow *hole); +void flow_defer_handler(struct ctx *c); void flow_log_(const struct flow_common *f, int pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); diff --git a/passt.c b/passt.c index 0246b04..5f72a28 100644 --- a/passt.c +++ b/passt.c @@ -103,6 +103,7 @@ static void post_handler(struct ctx *c, const struct timespec *now) /* NOLINTNEXTLINE(bugprone-branch-clone): intervals can be the same */ CALL_PROTO_HANDLER(c, now, icmp, ICMP); + flow_defer_handler(c); #undef CALL_PROTO_HANDLER } diff --git a/tcp.c b/tcp.c index ad1a70d..9230d80 100644 --- a/tcp.c +++ b/tcp.c @@ -1306,7 +1306,7 @@ static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c, * @c: Execution context * @flow: Flow table entry for this connection */ -static void tcp_flow_defer(struct ctx *c, union flow *flow) +void tcp_flow_defer(struct ctx *c, union flow *flow) { const struct tcp_tap_conn *conn = &flow->tcp; @@ -1364,26 +1364,11 @@ static void tcp_l2_data_buf_flush(const struct ctx *c) * tcp_defer_handler() - Handler for TCP deferred tasks * @c: Execution context */ +/* cppcheck-suppress constParameterPointer */ void tcp_defer_handler(struct ctx *c) { - union flow *flow; - tcp_l2_flags_buf_flush(c); tcp_l2_data_buf_flush(c); - - for (flow = flowtab + c->flow_count - 1; flow >= flowtab; flow--) { - switch (flow->f.type) { - case FLOW_TCP: - tcp_flow_defer(c, flow); - break; - case FLOW_TCP_SPLICE: - tcp_splice_flow_defer(c, flow); - break; - default: - die("Unexpected %s in tcp_defer_handler()", - FLOW_TYPE(&flow->f)); - } - } } /** diff --git a/tcp_conn.h b/tcp_conn.h index 4846565..72b9ecb 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -158,6 +158,7 @@ extern int init_sock_pool6 [TCP_SOCK_POOL_SIZE]; void tcp_tap_conn_update(const struct ctx *c, struct tcp_tap_conn *old, struct tcp_tap_conn *new); void tcp_splice_conn_update(const struct ctx *c, struct tcp_splice_conn *new); +void tcp_flow_defer(struct ctx *c, union flow *flow); void tcp_splice_flow_defer(struct ctx *c, union flow *flow); void tcp_splice_timer(const struct ctx *c, union flow *flow); int tcp_conn_pool_sock(int pool[]); -- 2.43.0