From patchwork Mon Sep 6 08:53:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 1524857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MneEbmNI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H32J32Lrwz9sRN for ; Mon, 6 Sep 2021 18:53:55 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C28B481A47; Mon, 6 Sep 2021 08:53:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YHUEUqAqypZC; Mon, 6 Sep 2021 08:53:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id E00D181776; Mon, 6 Sep 2021 08:53:50 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B71CBC001C; Mon, 6 Sep 2021 08:53:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2D7DEC001B for ; Mon, 6 Sep 2021 08:53:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 724EA81776 for ; Mon, 6 Sep 2021 08:53:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1Fbp5st48IBI for ; Mon, 6 Sep 2021 08:53:48 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id B8C6B81024 for ; Mon, 6 Sep 2021 08:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630918427; 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=G2imxAPX+KgtM9EUae1D2tLHBMMrkvYzUTOznjssh/c=; b=MneEbmNITsC8xABSupvpaV/nBHHOYc2Ks+UtB298hJqZpCR4wFOK1FG5LryiKyN1vX0Lxx gk8inUwtYOBdUm3SwGF0Bc64RfehvPur7nx1Uu0I8Q+hzUlDWYpwBCcU0fr6gSIK94aoTy W4CdjAgMZX0Ov48zUltCQkIVmStn0qM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-412-sLwALNrUOSGSFZu3By6Mvw-1; Mon, 06 Sep 2021 04:53:46 -0400 X-MC-Unique: sLwALNrUOSGSFZu3By6Mvw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C376B84A5EA; Mon, 6 Sep 2021 08:53:45 +0000 (UTC) Received: from ebuild.redhat.com (unknown [10.39.194.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09D075D9CA; Mon, 6 Sep 2021 08:53:44 +0000 (UTC) From: Eelco Chaudron To: dev@openvswitch.org Date: Mon, 6 Sep 2021 10:53:42 +0200 Message-Id: <163091841785.96839.4880012333775292574.stgit@ebuild> In-Reply-To: <163091839517.96839.8006181203263313854.stgit@ebuild> References: <163091839517.96839.8006181203263313854.stgit@ebuild> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=echaudro@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: fbl@sysclose.org Subject: [ovs-dev] [PATCH v6 1/2] dpctl: dpif: add kernel datapath cache hit output X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This patch adds cache usage statistics to the output: $ ovs-dpctl show system@ovs-system: lookups: hit:24 missed:71 lost:0 flows: 0 masks: hit:334 total:0 hit/pkt:3.52 cache: hit:4 hit rate:4.21% port 0: ovs-system (internal) port 1: genev_sys_6081 (geneve: packet_type=ptap) port 2: br-int (internal) port 3: br-ex (internal) port 4: eth2 port 5: sw1p1 (internal) port 6: sw0p4 (internal) Signed-off-by: Eelco Chaudron Acked-by: Flavio Leitner Acked-by: Paolo Valerio v2: - Changed cache naming to use a hyphen instead of spaces - Some error message grammar changes - Update dpctl man page - Add self tests to for the new set/get commands v3: - Rebase on the latest master branch v4: - Fixed commit message and tab/spaces in datapath include v5: - No updates v6: - Add ACKs --- datapath/linux/compat/include/linux/openvswitch.h | 2 +- lib/dpctl.c | 9 +++++++++ lib/dpif-netdev.c | 1 + lib/dpif-netlink.c | 9 +++++++++ lib/dpif.h | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h index f0595eeba..a3f5fb919 100644 --- a/datapath/linux/compat/include/linux/openvswitch.h +++ b/datapath/linux/compat/include/linux/openvswitch.h @@ -126,8 +126,8 @@ struct ovs_dp_megaflow_stats { __u64 n_mask_hit; /* Number of masks used for flow lookups. */ __u32 n_masks; /* Number of masks for the datapath. */ __u32 pad0; /* Pad for future expension. */ + __u64 n_cache_hit; /* Number of cache matches for flow lookups. */ __u64 pad1; /* Pad for future expension. */ - __u64 pad2; /* Pad for future expension. */ }; struct ovs_vport_stats { diff --git a/lib/dpctl.c b/lib/dpctl.c index ef8ae7402..acc677974 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -611,6 +611,15 @@ show_dpif(struct dpif *dpif, struct dpctl_params *dpctl_p) dpctl_print(dpctl_p, " masks: hit:%"PRIu64" total:%"PRIu32 " hit/pkt:%.2f\n", stats.n_mask_hit, stats.n_masks, avg); + + if (stats.n_cache_hit != UINT64_MAX) { + double avg_hits = n_pkts ? + (double) stats.n_cache_hit / n_pkts * 100 : 0.0; + + dpctl_print(dpctl_p, + " cache: hit:%"PRIu64" hit rate:%.2f%%\n", + stats.n_cache_hit, avg_hits); + } } } diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index b3e57bb95..0d0623013 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1963,6 +1963,7 @@ dpif_netdev_get_stats(const struct dpif *dpif, struct dpif_dp_stats *stats) } stats->n_masks = UINT32_MAX; stats->n_mask_hit = UINT64_MAX; + stats->n_cache_hit = UINT64_MAX; return 0; } diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 34fc04237..70751e634 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -749,9 +749,18 @@ dpif_netlink_get_stats(const struct dpif *dpif_, struct dpif_dp_stats *stats) stats->n_masks = dp.megaflow_stats->n_masks; stats->n_mask_hit = get_32aligned_u64( &dp.megaflow_stats->n_mask_hit); + stats->n_cache_hit = get_32aligned_u64( + &dp.megaflow_stats->n_cache_hit); + + if (!stats->n_cache_hit) { + /* Old kernels don't use this field and always + * report zero instead. Disable this stat. */ + stats->n_cache_hit = UINT64_MAX; + } } else { stats->n_masks = UINT32_MAX; stats->n_mask_hit = UINT64_MAX; + stats->n_cache_hit = UINT64_MAX; } ofpbuf_delete(buf); } diff --git a/lib/dpif.h b/lib/dpif.h index 7c322d20e..b32ae5fc7 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -429,6 +429,8 @@ struct dpif_dp_stats { uint64_t n_missed; /* Number of flow table misses. */ uint64_t n_lost; /* Number of misses not sent to userspace. */ uint64_t n_flows; /* Number of flows present. */ + uint64_t n_cache_hit; /* Number of mega flow mask cache hits for + flow table matches. */ uint64_t n_mask_hit; /* Number of mega flow masks visited for flow table matches. */ uint32_t n_masks; /* Number of mega flow masks. */