From patchwork Wed Apr 24 19:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Moreno?= X-Patchwork-Id: 1927351 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=JnLt1qbK; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VPqSb6Lcxz1yP2 for ; Thu, 25 Apr 2024 05:54:23 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 3B78082309; Wed, 24 Apr 2024 19:54:22 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id DJPTh3iQekEW; Wed, 24 Apr 2024 19:54:19 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 0061D8237E Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JnLt1qbK Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 0061D8237E; Wed, 24 Apr 2024 19:54:12 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B7096C0077; Wed, 24 Apr 2024 19:54:12 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 111DBC008E for ; Wed, 24 Apr 2024 19:54:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0A0FB414BC for ; Wed, 24 Apr 2024 19:54:03 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id JnrIIAL22Ii6 for ; Wed, 24 Apr 2024 19:54:02 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org DADDD4149D Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DADDD4149D Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JnLt1qbK Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id DADDD4149D for ; Wed, 24 Apr 2024 19:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713988440; 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=PAy40QyL61RzIsvIeuTdECdoNPX66WnypXSh4wZWNVg=; b=JnLt1qbKCH9v/j7tuo8gy++jpZt+KrOLguu2g/8zXIcrwz3ZtUK4R3rCGCSBhKoLgQFk7W YRheYKxvtfT2r/ljOTHmEGppJyS8wbvUWq9xWsQt6+wejD33nNvoo4WDQVeBtGOsHGGek5 FckdHwKsLT+SRsIzHZcb54Os1AzTlUY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-DbdJeSblMTGZvI1aCYZXzw-1; Wed, 24 Apr 2024 15:53:59 -0400 X-MC-Unique: DbdJeSblMTGZvI1aCYZXzw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC1C51049C97; Wed, 24 Apr 2024 19:53:58 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.193.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81A15200AE7F; Wed, 24 Apr 2024 19:53:57 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Wed, 24 Apr 2024 21:53:35 +0200 Message-ID: <20240424195337.3596657-10-amorenoz@redhat.com> In-Reply-To: <20240424195337.3596657-1-amorenoz@redhat.com> References: <20240424195337.3596657-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com, i.maximets@ovn.org, horms@kernel.org Subject: [ovs-dev] [RFC 09/11] ofproto-dpif-xlate-cache: Add psample to xcache. 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" Add a cache entry type for psample objects. Store both the dpif_psample reference and the collector_set_id so we can quickly find the particular exporter. Using that mechanism, account for packet and byte statistics. Signed-off-by: Adrian Moreno --- ofproto/ofproto-dpif-psample.c | 20 ++++++++++++++++++++ ofproto/ofproto-dpif-psample.h | 4 ++++ ofproto/ofproto-dpif-xlate-cache.c | 11 ++++++++++- ofproto/ofproto-dpif-xlate-cache.h | 6 ++++++ ofproto/ofproto-dpif-xlate.c | 9 +++++++++ ofproto/ofproto-dpif.c | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ofproto/ofproto-dpif-psample.c b/ofproto/ofproto-dpif-psample.c index 1e4f4bf48..ea4926eb2 100644 --- a/ofproto/ofproto-dpif-psample.c +++ b/ofproto/ofproto-dpif-psample.c @@ -17,6 +17,7 @@ #include #include "ofproto-dpif-psample.h" +#include "dpif.h" #include "hash.h" #include "ofproto.h" #include "openvswitch/hmap.h" @@ -30,6 +31,8 @@ static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; struct psample_exporter { uint32_t group_id; uint32_t collector_set_id; + uint64_t n_packets; + uint64_t n_bytes; }; struct psample_exporter_map_node { @@ -145,6 +148,23 @@ dpif_psample_get_group_id(struct dpif_psample *ps, uint32_t collector_set_id, return found; } +void +dpif_psample_credit_stats(struct dpif_psample *ps, uint32_t collector_set_id, + const struct dpif_flow_stats *stats) +OVS_EXCLUDED(mutex) +{ + struct psample_exporter_map_node *node; + + ovs_mutex_lock(&mutex); + node = dpif_psample_find_exporter_node(ps, collector_set_id); + if (node) { + node->exporter.n_packets += stats->n_packets; + node->exporter.n_bytes += stats->n_bytes; + } + ovs_mutex_unlock(&mutex); +} + + /* Creation and destruction. */ struct dpif_psample * dpif_psample_create(void) diff --git a/ofproto/ofproto-dpif-psample.h b/ofproto/ofproto-dpif-psample.h index b9f2584af..763fbd30b 100644 --- a/ofproto/ofproto-dpif-psample.h +++ b/ofproto/ofproto-dpif-psample.h @@ -20,6 +20,7 @@ #include #include +struct dpif_flow_stats; struct dpif_psample; struct ovs_list; @@ -31,4 +32,7 @@ bool dpif_psample_set_options(struct dpif_psample *, const struct ovs_list *); bool dpif_psample_get_group_id(struct dpif_psample *, uint32_t, uint32_t *); +void dpif_psample_credit_stats(struct dpif_psample *, uint32_t, + const struct dpif_flow_stats *); + #endif // OFPROTO_DPIF_PSAMPLE_H diff --git a/ofproto/ofproto-dpif-xlate-cache.c b/ofproto/ofproto-dpif-xlate-cache.c index 2e1fcb3a6..0fe76e5fa 100644 --- a/ofproto/ofproto-dpif-xlate-cache.c +++ b/ofproto/ofproto-dpif-xlate-cache.c @@ -35,9 +35,10 @@ #include "learn.h" #include "mac-learning.h" #include "netdev-vport.h" +#include "ofproto/ofproto-dpif.h" #include "ofproto/ofproto-dpif-mirror.h" +#include "ofproto/ofproto-dpif-psample.h" #include "ofproto/ofproto-dpif-xlate.h" -#include "ofproto/ofproto-dpif.h" #include "ofproto/ofproto-provider.h" #include "openvswitch/dynamic-string.h" #include "openvswitch/vlog.h" @@ -162,6 +163,11 @@ xlate_push_stats_entry(struct xc_entry *entry, } break; + case XC_PSAMPLE: + dpif_psample_credit_stats(entry->psample.psample, + entry->psample.collector_set_id, + stats); + break; default: OVS_NOT_REACHED(); } @@ -245,6 +251,9 @@ xlate_cache_clear_entry(struct xc_entry *entry) break; case XC_TUNNEL_HEADER: break; + case XC_PSAMPLE: + dpif_psample_unref(entry->psample.psample); + break; default: OVS_NOT_REACHED(); } diff --git a/ofproto/ofproto-dpif-xlate-cache.h b/ofproto/ofproto-dpif-xlate-cache.h index 0fc6d2ea6..fa707889d 100644 --- a/ofproto/ofproto-dpif-xlate-cache.h +++ b/ofproto/ofproto-dpif-xlate-cache.h @@ -29,6 +29,7 @@ struct bfd; struct bond; struct dpif_flow_stats; +struct dpif_psample; struct flow; struct group_dpif; struct mbridge; @@ -53,6 +54,7 @@ enum xc_type { XC_GROUP, XC_TNL_NEIGH, XC_TUNNEL_HEADER, + XC_PSAMPLE, }; /* xlate_cache entries hold enough information to perform the side effects of @@ -126,6 +128,10 @@ struct xc_entry { } operation; uint16_t hdr_size; } tunnel_hdr; + struct { + struct dpif_psample *psample; + uint32_t collector_set_id; + } psample; }; }; diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 1dcf86856..a9856e358 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -5989,6 +5989,15 @@ xlate_sample_action(struct xlate_ctx *ctx, sizeof(os->obs_domain_id)); ofpbuf_put(&psample_args->cookie, &os->obs_point_id, sizeof(os->obs_point_id)); + + if (ctx->xin->xcache) { + struct xc_entry *entry; + + entry = xlate_cache_add_entry(ctx->xin->xcache, XC_PSAMPLE); + entry->psample.psample = dpif_psample_ref(psample); + entry->psample.collector_set_id = os->collector_set_id; + } + } } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 64c06322e..f1efdd482 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -5167,6 +5167,7 @@ ofproto_dpif_xcache_execute(struct ofproto_dpif *ofproto, case XC_GROUP: case XC_TNL_NEIGH: case XC_TUNNEL_HEADER: + case XC_PSAMPLE: xlate_push_stats_entry(entry, stats, false); break; default: