From patchwork Wed Jun 5 20:23:34 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: 1944156 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=NKoG37dH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4Vvf7m5rN4z20Wh for ; Thu, 6 Jun 2024 06:24:20 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id A04CA41761; Wed, 5 Jun 2024 20:24:18 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Op-7DpvfFt3F; Wed, 5 Jun 2024 20:24:16 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org DCC9D4165E Authentication-Results: smtp2.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=NKoG37dH Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id DCC9D4165E; Wed, 5 Jun 2024 20:24:15 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 75AE6C0DD8; Wed, 5 Jun 2024 20:24:15 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1EA11C0DD6 for ; Wed, 5 Jun 2024 20:24:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 12BE6423D9 for ; Wed, 5 Jun 2024 20:24:09 +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 gbMBctI6QDIG for ; Wed, 5 Jun 2024 20:24:08 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org DAC4F423BE 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 DAC4F423BE 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=NKoG37dH Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id DAC4F423BE for ; Wed, 5 Jun 2024 20:24:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717619046; 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=Z6IWqHqpPLF8+InoAK/z+qX9xGH+up4ml9Ge5jDmy/8=; b=NKoG37dHYZUqjQlNKRoQFJUzHTNM3zZ6qXKVjCOfM/e7UcrWWwAS49BhdkWN0j7SV7PMCU aM2zKAlcmb2RO7Vne8cjSIRA5gMW4RA7ICFcKOWewxtv7V74LfuzYVTyPqOR44Sa0S8yae uOelzU38UmD+pAN7+r5tTkjC0c2uBx0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-KSrJHz_-ObaQ-PIDFXcL-g-1; Wed, 05 Jun 2024 16:24:03 -0400 X-MC-Unique: KSrJHz_-ObaQ-PIDFXcL-g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A56701955BE1; Wed, 5 Jun 2024 20:24:02 +0000 (UTC) Received: from antares.redhat.com (unknown [10.39.193.112]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4DCF01956086; Wed, 5 Jun 2024 20:24:00 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Wed, 5 Jun 2024 22:23:34 +0200 Message-ID: <20240605202337.2904041-7-amorenoz@redhat.com> In-Reply-To: <20240605202337.2904041-1-amorenoz@redhat.com> References: <20240605202337.2904041-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [RFC v2 6/9] ofproto-dpif-xlate-cache: Add lsample 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 local sample objects. Store both the dpif_lsample reference and the collector_set_id so we can quickly find the particular exporter. Using this mechanism, account for packet and byte statistics. Signed-off-by: Adrian Moreno --- ofproto/ofproto-dpif-lsample.c | 18 ++++++++++++++++++ ofproto/ofproto-dpif-lsample.h | 4 ++++ ofproto/ofproto-dpif-xlate-cache.c | 11 ++++++++++- ofproto/ofproto-dpif-xlate-cache.h | 6 ++++++ ofproto/ofproto-dpif-xlate.c | 15 +++++++++++++++ ofproto/ofproto-dpif.c | 1 + 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/ofproto/ofproto-dpif-lsample.c b/ofproto/ofproto-dpif-lsample.c index 2c0b5da89..0c71e354d 100644 --- a/ofproto/ofproto-dpif-lsample.c +++ b/ofproto/ofproto-dpif-lsample.c @@ -18,6 +18,7 @@ #include "ofproto-dpif-lsample.h" #include "cmap.h" +#include "dpif.h" #include "hash.h" #include "ofproto.h" #include "openvswitch/thread.h" @@ -44,6 +45,8 @@ struct dpif_lsample { struct lsample_exporter { struct ofproto_lsample_options options; + atomic_uint64_t n_packets; + atomic_uint64_t n_bytes; }; struct lsample_exporter_node { @@ -156,6 +159,21 @@ dpif_lsample_get_group_id(struct dpif_lsample *ps, uint32_t collector_set_id, return found; } +void +dpif_lsample_credit_stats(struct dpif_lsample *lsample, + uint32_t collector_set_id, + const struct dpif_flow_stats *stats) +{ + struct lsample_exporter_node *node; + uint64_t orig; + + node = dpif_lsample_find_exporter_node(lsample, collector_set_id); + if (node) { + atomic_add_relaxed(&node->exporter.n_packets, stats->n_packets, &orig); + atomic_add_relaxed(&node->exporter.n_bytes, stats->n_bytes, &orig); + } +} + struct dpif_lsample * dpif_lsample_create(void) { diff --git a/ofproto/ofproto-dpif-lsample.h b/ofproto/ofproto-dpif-lsample.h index f13425575..2ce096161 100644 --- a/ofproto/ofproto-dpif-lsample.h +++ b/ofproto/ofproto-dpif-lsample.h @@ -23,6 +23,7 @@ struct dpif_lsample; struct ofproto_lsample_options; +struct dpif_flow_stats; struct dpif_lsample *dpif_lsample_create(void); void dpif_lsample_unref(struct dpif_lsample *); @@ -36,5 +37,8 @@ bool dpif_lsample_get_group_id(struct dpif_lsample *, uint32_t collector_set_id, uint32_t *group_id); +void dpif_lsample_credit_stats(struct dpif_lsample *, + uint32_t collector_set_id, + const struct dpif_flow_stats *); #endif /* OFPROTO_DPIF_LSAMPLE_H */ diff --git a/ofproto/ofproto-dpif-xlate-cache.c b/ofproto/ofproto-dpif-xlate-cache.c index 2e1fcb3a6..508e5fcb2 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-lsample.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_LSAMPLE: + dpif_lsample_credit_stats(entry->lsample.lsample, + entry->lsample.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_LSAMPLE: + dpif_lsample_unref(entry->lsample.lsample); + break; default: OVS_NOT_REACHED(); } diff --git a/ofproto/ofproto-dpif-xlate-cache.h b/ofproto/ofproto-dpif-xlate-cache.h index 0fc6d2ea6..df8115419 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_lsample; struct flow; struct group_dpif; struct mbridge; @@ -53,6 +54,7 @@ enum xc_type { XC_GROUP, XC_TNL_NEIGH, XC_TUNNEL_HEADER, + XC_LSAMPLE, }; /* 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_lsample *lsample; + uint32_t collector_set_id; + } lsample; }; }; diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 5bd215d31..d7648e02c 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -5986,6 +5986,21 @@ xlate_sample_action(struct xlate_ctx *ctx, sizeof(os->obs_domain_id)); ofpbuf_put(&emit_sample_args.cookie, &os->obs_point_id, sizeof(os->obs_point_id)); + + + if (ctx->xin->resubmit_stats) { + dpif_lsample_credit_stats(lsample, + os->collector_set_id, + ctx->xin->resubmit_stats); + } + if (ctx->xin->xcache) { + struct xc_entry *entry; + + entry = xlate_cache_add_entry(ctx->xin->xcache, XC_LSAMPLE); + entry->lsample.lsample = dpif_lsample_ref(lsample); + entry->lsample.collector_set_id = os->collector_set_id; + } + } } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 48167751f..e5a7f0fa5 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -5157,6 +5157,7 @@ ofproto_dpif_xcache_execute(struct ofproto_dpif *ofproto, case XC_GROUP: case XC_TNL_NEIGH: case XC_TUNNEL_HEADER: + case XC_LSAMPLE: xlate_push_stats_entry(entry, stats, false); break; default: