From patchwork Wed May 29 22:54:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140407 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 292E544107; Thu, 30 May 2024 00:58:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B4CC40A84; Thu, 30 May 2024 00:57:46 +0200 (CEST) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mails.dpdk.org (Postfix) with ESMTP id 0C43740A67 for ; Thu, 30 May 2024 00:57:41 +0200 (CEST) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2c199e776ebso194926a91.3 for ; Wed, 29 May 2024 15:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717023460; x=1717628260; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uDckzPMoggt3O0PD6CzLT8GtY/9DAGBqZIMGwEjEdxs=; b=hYLzLEaIlj9Tc1OiecuxKaJkoLgB3lt5W7ZIlF2h9Ig00vI0WA3LqSwepcSWLbQ4x7 otcVNWQJDSeMY42+BUTRd531pLE/bXa9lB0FsDDhPD2URDozgfRGXjxwNUM9ZLHBjWj0 kHhieeqFs5QRijamZm+lLTit+B0ZFcivH80amaib2ZTWbgKdkAk2V+a1ky/Z8flQpkBC NtcYZn3AvWO2GvEcYCWicVdrGIPoDdhvepXihuRqmLrjK6SMkYBhwPfHyCmSw3gREThd 1YQlKfZ/WrNRRsiomJM2rwiqEmWbiTpWy5+rC0qZWZeM9c/bY4IORi45++w/VwZdR3O1 RnMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717023460; x=1717628260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uDckzPMoggt3O0PD6CzLT8GtY/9DAGBqZIMGwEjEdxs=; b=TyiqLXw6GzHUGtNuVM1lsZPO7ym9Mm8cM/fogRnqpZr30gW45Gr/Ai55uxvG1mGbFN MLvTH7KSesySiNbg8mIqGX30KdEOP+BvSyskvuSTo+AOU76XcuL5mZHAEktbT6bf9lkz k8knN0g8NdlHQjW/WjpKVUz9IEg4KgedKLtI2R8Uk8hlkhYVxVL/Nm35h7VrpgKHGlFn cQSMe1TwH77UqCoFLE6B86XeLQIVNs0HLQ2nYx301zoj8qTwQYHqcDIiH4c/UR56YL2p UQyfeDKgwdzUrvVnlgnOKP+wP2auTNSXkOCIiRE4DzoMMhIP78uEk/4GsB75yiWPZBJ6 aviQ== X-Gm-Message-State: AOJu0YzFrWPoL1NBUNFqBmjbMccuYx2YwiO7n1Gu2OJUjM7+UiPOEufk 4sBcJcL87vibqerq35FEvDRtWLVwx+ORkZBnlx6A578zeJwxCexl+vflqYI9Egf9L9m3TDh16FS / X-Google-Smtp-Source: AGHT+IHwbDBtw7hKzXvX4q/PC9dOs1fRZCy/3ahWQnlfkOUA4DMQ7YOqFicJIJu3kuCaFOwIM7ntew== X-Received: by 2002:a17:90b:33d0:b0:2bd:e917:232c with SMTP id 98e67ed59e1d1-2c1abc4a963mr490741a91.48.1717023460208; Wed, 29 May 2024 15:57:40 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c1a77baebcsm351762a91.53.2024.05.29.15.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 15:57:39 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v6 7/8] latencystats: add metric for number of samples Date: Wed, 29 May 2024 15:54:44 -0700 Message-ID: <20240529225732.442539-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529225732.442539-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240529225732.442539-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Keeping track of the number of samples is useful when doing debug and testing to make sure that samples are actually happening. Signed-off-by: Stephen Hemminger --- lib/latencystats/rte_latencystats.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index 8311adb411..e5a84fbd92 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -59,6 +59,7 @@ struct rte_latency_stats { uint64_t avg_latency; /**< Average latency */ uint64_t max_latency; /**< Maximum latency */ uint64_t jitter; /** Latency variation */ + uint64_t samples; /** Number of latency samples */ rte_spinlock_t lock; /** Latency calculation lock */ }; @@ -82,20 +83,26 @@ static const struct latency_stats_nameoff lat_stats_strings[] = { {"avg_latency_ns", offsetof(struct rte_latency_stats, avg_latency), LATENCY_AVG_SCALE}, {"max_latency_ns", offsetof(struct rte_latency_stats, max_latency), 1}, {"jitter_ns", offsetof(struct rte_latency_stats, jitter), LATENCY_JITTER_SCALE}, + {"samples", offsetof(struct rte_latency_stats, samples), 0}, }; -#define NUM_LATENCY_STATS (sizeof(lat_stats_strings) / \ - sizeof(lat_stats_strings[0])) +#define NUM_LATENCY_STATS RTE_DIM(lat_stats_strings) static void latencystats_collect(uint64_t values[]) { - unsigned int i; + unsigned int i, scale; const uint64_t *stats; for (i = 0; i < NUM_LATENCY_STATS; i++) { stats = RTE_PTR_ADD(glob_stats, lat_stats_strings[i].offset); - values[i] = floor(*stats / (cycles_per_ns * lat_stats_strings[i].scale)); + scale = lat_stats_strings[i].scale; + + /* used to mark samples which are not a time interval */ + if (scale == 0) + values[i] = *stats; + else + values[i] = floor(*stats / (cycles_per_ns * scale)); } } @@ -173,7 +180,6 @@ calc_latency(uint16_t pid __rte_unused, unsigned int i; uint64_t now, latency; static uint64_t prev_latency; - static bool first_sample = true; now = rte_rdtsc(); @@ -184,9 +190,7 @@ calc_latency(uint16_t pid __rte_unused, latency = now - *timestamp_dynfield(pkts[i]); - if (unlikely(first_sample)) { - first_sample = false; - + if (glob_stats->samples++ == 0) { glob_stats->min_latency = latency; glob_stats->max_latency = latency; glob_stats->avg_latency = latency * 4;