From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BE5CA43EDB; Mon, 22 Apr 2024 17:24:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 60D0A40DDD; Mon, 22 Apr 2024 17:24:05 +0200 (CEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id CDDB740A72 for ; Mon, 22 Apr 2024 17:23:52 +0200 (CEST) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6ee0642f718so3868380b3a.0 for ; Mon, 22 Apr 2024 08:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713799432; x=1714404232; 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=pGDKZg/6HkQOz9z73X3Yr7T2TL1zx/51RaJDunErswJNtQGpwDz7MODV0fosSMJXws z2gHeg3hZ0x8W10YzYGt/c6Mzpwj86q3Jx4WU1l2PfYVX6GgToF3L2ktJ2BQGTxwIwL5 LA8WeTreoh2DQVRYONAR29uColzQAXdr/8/HGLAwx4dX3iQlqANvn7I88CDWDbY+At6/ TYzkdtKC7g8xgrGvQlWPmqCrmSeiPaTpyGFoZE0M50QgtxjzCp4EygO085awUSR/+khZ wFkLjmQ0pp/Ppkc0aSJ96kAags5NXMreqIQlWBxKhe5++rn5+Ak6IsfpDJM57UYTJwqf s5lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713799432; x=1714404232; 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=IrtCQ/asHJieltsztflvqQ5CUdxeaszbaJj7qLbiU7GxjQs6pOCBjrc/28zV+N7j1X E2Kfya3ZeCqB7p9DfmCyZFOiSEOKSJ0PicxHKWwTbkMKzPe4Bc2/z4NFg6jjU+8he5ZV IdK3L6MfbNF5tqQlBJH9ApjK0ofoA2f0g5mzJJ8c1ILxD1X9L1rWrBDnn7xihEmdcq7V h8QkLj3kz8q3BgUG/G/PPsrEdi1uFx2VvMdgfAGnrwk5UxUSVVHuj9q0POPuUyVh4PZc NCGezx3DPR2YMz8IGgqD5vCmPgoZDewM7B9OZrgIiLnUF3FbsyFmoQvPqjxYkc6FRxmY OOJw== X-Gm-Message-State: AOJu0YzVQ2k6orQBFT1ykNeQNG7PVIZljSU/P+15AqotKoGle7KHh2rx vQX+FWqkMs59RVOx8u2dJGTK0nQuVj2HNuqUJFiCG+JEAj7sRWi5ftPTEvLqJDv6mVFAArBlKPL 2 X-Google-Smtp-Source: AGHT+IGzKj+IUuFC4n6R1TEB+eAtlHjyEWWGNe9lkWQY9gobcTgR9VkWh2SMqoyLhcJzULpVpgw3oA== X-Received: by 2002:a05:6a21:2723:b0:1ad:4978:adf4 with SMTP id rm35-20020a056a21272300b001ad4978adf4mr828574pzb.1.1713799431992; Mon, 22 Apr 2024 08:23:51 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id cb17-20020a056a02071100b0060063c4be3bsm1402783pgb.14.2024.04.22.08.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 08:23:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v5 7/9] latencystats: add metric for number of samples Date: Mon, 22 Apr 2024 08:21:37 -0700 Message-ID: <20240422152336.147553-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422152336.147553-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240422152336.147553-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; -- 2.43.0