From nobody Mon Sep 11 19:32:17 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RkxgP2q7bz4sqxx; Mon, 11 Sep 2023 19:32:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RkxgP2PQyz3gPs; Mon, 11 Sep 2023 19:32:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694460737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5ATf95KPhG6fJpKzVEHdeFvg4cfYVDWNIX/pIwRRfZc=; b=gUEURdcNVPHa+PW+lkVJu1OnWrqJUqE5sr13fFVBlI1h03pK97WPRz2oYqy5T/GL2wA+3c 9Ge4PSUQV2K5nX7VlltBeYL+9PPo6OY7h/UV3S2crec4u3BWtFJhvrq8WhKOINZyu5M6lA Jg5wcOPazkE2o9Lftp2XDSBJUdGngHZO9UwLWt5gpm5WppKBJBAWqHe2VqgZ5Q2AsT5yX0 yk5cteF4UkV4RZRbPl/PhF8LWHlbuIyd4sO3Jz7UgTDhcHKaJ3zWuMPTqfm/6CV4keMtAD I+9tDy8PoScuxCIYVLKGR70ko+LM6CNyvJBoHDyMJoQjbqc3/8FhhDGSycxkZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694460737; a=rsa-sha256; cv=none; b=UclTKDMrW96Us7YKn4V3ithhzAC9LLgAkLPzGW+bPb4XPPtQmKW1wOVG/Y4pkvnZ9UA8/j 7ESSXkevIn5BxgMEY/qHt2F/L1kDQggrMBQcroubjFta7KEnq78WVdTWqeSuUXc9uGy6PF 6Y7JMjkgzdkshaggW73ojUKcculmOiwv+XfElI1jNvMFoovft/QtiLNjx4TKZ5eMpYb5kl 9ij3A11C2izTDfqQ2/x2jBlAty2nD3zJIfGLIP2TsnS51y29jTx/4JzDhugtuStoLi47Jv z6yzG4uuopOFm1iOARhm/VjCakMaduFSh9wal8TqkSyD0zyrW8zr1MEYyK41lQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694460737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5ATf95KPhG6fJpKzVEHdeFvg4cfYVDWNIX/pIwRRfZc=; b=PxhTNh9JrhSYZzQmHwg1CZnkKsSbv1lOSPM7kd0skYdjUBhcT5+qctOeGMj8/s/3qT7MP0 vKiuliqNiogZz96Xdw1YOpmNly+bveNOTpwcxCL1anZNpMMpQfqQwKE0E2tKjflD7O75lJ 2eqaX6rY90rIJzuyoLnUg+YEzOHszFVjEgE70k+fEjbJ6VgOynb4U2KurHi/WTMTXIuYYa +r+Gx3QaAp1H2eOyiqNeGYOC3bF3NGiYpjvVA4FrIgBnUc49wahF9lNyR+8l3yQ7BpuZDA V3Bs4LaDHJFn5hjWOpor4mKGzJIXd8MEA3l27htQyEVttA3dWZreImWLAgmt3w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RkxgP1TMKz123b; Mon, 11 Sep 2023 19:32:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38BJWHFB056411; Mon, 11 Sep 2023 19:32:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38BJWHhm056408; Mon, 11 Sep 2023 19:32:17 GMT (envelope-from git) Date: Mon, 11 Sep 2023 19:32:17 GMT Message-Id: <202309111932.38BJWHhm056408@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cheng Cui Subject: git: fafb03ab4254 - main - siftr: flush pkt_nodes to the log file in batch List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cc X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fafb03ab4254ab0d3927bc8ec22e4ba432efdbeb Auto-Submitted: auto-generated The branch main has been updated by cc: URL: https://cgit.FreeBSD.org/src/commit/?id=fafb03ab4254ab0d3927bc8ec22e4ba432efdbeb commit fafb03ab4254ab0d3927bc8ec22e4ba432efdbeb Author: Cheng Cui AuthorDate: 2023-07-25 13:53:55 +0000 Commit: Cheng Cui CommitDate: 2023-09-11 15:23:27 +0000 siftr: flush pkt_nodes to the log file in batch Reviewed by: rscheff, tuexen Differential Revision: https://reviews.freebsd.org/D41175 --- sys/netinet/siftr.c | 73 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/sys/netinet/siftr.c b/sys/netinet/siftr.c index 58603e4aa53c..fbb47fc4a521 100644 --- a/sys/netinet/siftr.c +++ b/sys/netinet/siftr.c @@ -370,12 +370,12 @@ siftr_new_hash_node(struct flow_info info, int dir, } } -static void -siftr_process_pkt(struct pkt_node * pkt_node) +static int +siftr_process_pkt(struct pkt_node * pkt_node, char *buf) { struct flow_hash_node *hash_node; struct listhead *counter_list; - struct ale *log_buf; + int ret_sz; if (pkt_node->flowid == 0) { panic("%s: flowid not available", __func__); @@ -385,7 +385,7 @@ siftr_process_pkt(struct pkt_node * pkt_node) hash_node = siftr_find_flow(counter_list, pkt_node->flowid); if (hash_node == NULL) { - return; + return 0; } else if (siftr_pkts_per_log > 1) { /* * Taking the remainder of the counter divided @@ -401,16 +401,11 @@ siftr_process_pkt(struct pkt_node * pkt_node) * we wrote a log message for this connection, return. */ if (hash_node->counter > 0) - return; + return 0; } - log_buf = alq_getn(siftr_alq, MAX_LOG_MSG_LEN, ALQ_WAITOK); - - if (log_buf == NULL) - return; /* Should only happen if the ALQ is shutting down. */ - /* Construct a log message. */ - log_buf->ae_bytesused = snprintf(log_buf->ae_data, MAX_LOG_MSG_LEN, + ret_sz = snprintf(buf, MAX_LOG_MSG_LEN, "%c,%jd.%06ld,%s,%hu,%s,%hu,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u," "%u,%u,%u,%u,%u,%u,%u,%u\n", direction[pkt_node->direction], @@ -442,7 +437,7 @@ siftr_process_pkt(struct pkt_node * pkt_node) pkt_node->flowid, pkt_node->flowtype); - alq_post_flags(siftr_alq, log_buf, 0); + return ret_sz; } static void @@ -452,6 +447,9 @@ siftr_pkt_manager_thread(void *arg) STAILQ_HEAD_INITIALIZER(tmp_pkt_queue); struct pkt_node *pkt_node, *pkt_node_temp; uint8_t draining; + struct ale *log_buf; + int ret_sz, cnt; + char *bufp; draining = 2; @@ -487,12 +485,51 @@ siftr_pkt_manager_thread(void *arg) */ mtx_unlock(&siftr_pkt_mgr_mtx); - /* Flush all pkt_nodes to the log file. */ - STAILQ_FOREACH_SAFE(pkt_node, &tmp_pkt_queue, nodes, - pkt_node_temp) { - siftr_process_pkt(pkt_node); - STAILQ_REMOVE_HEAD(&tmp_pkt_queue, nodes); - free(pkt_node, M_SIFTR_PKTNODE); +try_again: + pkt_node = STAILQ_FIRST(&tmp_pkt_queue); + if (pkt_node != NULL) { + if (STAILQ_NEXT(pkt_node, nodes) != NULL) { + cnt = 3; + } else { + cnt = 1; + } + + log_buf = alq_getn(siftr_alq, MAX_LOG_MSG_LEN * cnt, + ALQ_WAITOK); + + if (log_buf != NULL) { + log_buf->ae_bytesused = 0; + bufp = log_buf->ae_data; + } else { + /* + * Should only happen if the ALQ is shutting + * down. + */ + bufp = NULL; + } + + /* Flush all pkt_nodes to the log file. */ + STAILQ_FOREACH_SAFE(pkt_node, &tmp_pkt_queue, nodes, + pkt_node_temp) { + if (log_buf != NULL) { + ret_sz = siftr_process_pkt(pkt_node, + bufp); + bufp += ret_sz; + log_buf->ae_bytesused += ret_sz; + cnt--; + } + + STAILQ_REMOVE_HEAD(&tmp_pkt_queue, nodes); + free(pkt_node, M_SIFTR_PKTNODE); + + if (cnt <= 0 && !STAILQ_EMPTY(&tmp_pkt_queue)) { + alq_post_flags(siftr_alq, log_buf, 0); + goto try_again; + } + } + if (log_buf != NULL) { + alq_post_flags(siftr_alq, log_buf, 0); + } } KASSERT(STAILQ_EMPTY(&tmp_pkt_queue),