From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 5/8] flow, tcp: Add flow-centric dispatch for deferred flow handling
Date: Thu, 14 Dec 2023 13:15:38 +1100 [thread overview]
Message-ID: <20231214021541.3925825-6-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20231214021541.3925825-1-david@gibson.dropbear.id.au>
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 <david@gibson.dropbear.id.au>
---
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 c2a5190..4733671 100644
--- a/flow.h
+++ b/flow.h
@@ -56,6 +56,7 @@ static_assert(sizeof(flow_sidx_t) <= sizeof(uint32_t),
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 fc9176f..0e8e9e3 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1304,7 +1304,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;
@@ -1362,26 +1362,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 75def3c..99a3b3b 100644
--- a/tcp_conn.h
+++ b/tcp_conn.h
@@ -160,6 +160,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[]);
--
@@ -160,6 +160,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
next prev parent reply other threads:[~2023-12-14 2:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-14 2:15 [PATCH 0/8] Improve flow table based dispatch of timers and other handlers David Gibson
2023-12-14 2:15 ` [PATCH 1/8] flow: Make flow_table.h #include the protocol specific headers it needs David Gibson
2023-12-14 2:15 ` [PATCH 2/8] treewide: Standardise on 'now' for current timestamp variables David Gibson
2023-12-14 2:15 ` [PATCH 3/8] tcp, tcp_splice: Remove redundant handling from tcp_timer() David Gibson
2023-12-14 2:15 ` [PATCH 4/8] tcp, tcp_splice: Move per-type cleanup logic into per-type helpers David Gibson
2023-12-14 2:15 ` David Gibson [this message]
2023-12-14 2:15 ` [PATCH 6/8] flow, tcp: Add handling for per-flow timers David Gibson
2023-12-14 2:15 ` [PATCH 7/8] epoll: Better handling of number of epoll types David Gibson
2023-12-14 2:15 ` [PATCH 8/8] tcp, tcp_splice: Avoid double layered dispatch for connected TCP sockets David Gibson
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231214021541.3925825-6-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/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://passt.top/passt
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 IMAP folder(s).