From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D7E01A00C5; Sun, 5 Jul 2020 22:41:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 598531DA45; Sun, 5 Jul 2020 22:41:55 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by dpdk.org (Postfix) with ESMTP id 37B6E1DA27 for ; Sun, 5 Jul 2020 22:41:53 +0200 (CEST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C49EB5C009D; Sun, 5 Jul 2020 16:41:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sun, 05 Jul 2020 16:41:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=fm1; bh= U4Y/XcdunMnRxCMFQRBoKeYUTurD9HA3idElu7SLOg8=; b=Kb39VEsxUAHRRuW1 YWVl5ZVnGLhyRLtaYs2R9nzfSVoHphKv3HkRFPK4/5uDZFx11UQmixDhhquy+b8k kJxmilbX69hqyAiaCIN5qOeLpbK1e1adP9ChHKEkuEMF+HFcn1O+aa7yRatlIawC WfP/X/G63BwItaPzOa+iHhhea5IvL8K9AFrEPoQJajpgdBQvQcLNAcQfwZ4EyxWf HiOKVrZEjsD06M16mXw3zKuiMrQ7JIeK+E8d/HhQGl9K1Vt1V7R7G0f1ruAmFoYj 98SvDXD8rnAXE2B/ijxCU/zzEZjC+Rt9NrlhBOS+FDZCvZf/SdBGOHK52OVI6dPo 2NDteA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=U4Y/XcdunMnRxCMFQRBoKeYUTurD9HA3idElu7SLO g8=; b=TT0oG6b81T1qZH8MzfIarih6TT7dt4nfht5x7OV6g1VWzq4wihC/FUA6k hCkf+f8RxPlwEkYNy+982PzNGEP4jfhu7jT/F04pEhhj0bB6Qw498FYUw1TcZ0ns TzxLO7EJ4oILKH6hb5oP1G7zqNH4/gvSsfZ1w+KhXWmpGrIzqHt6ysnqIQVfb0eQ Vh1v5XEStJfqIm4uN4N09bVlYtdDizpZkVE+YUHvPUTF2DvBHjzoRjgXHMpOo4D3 cgdSMlWDDFcqWQo99zTSVa1aO3VoRoJdFsnGbofzZlZLRbdawK8Fh1xxHTauvHix yS4rO3UPwXVeiyLT5aymvTa9EOlJA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddugdduheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfgjfhgggfgtsehtufertddttddvnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepudeggfdvfeduffdtfeeglefghfeukefgfffhueejtdetuedtjeeu ieeivdffgeehnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl ohhnrdhnvght X-ME-Proxy: Received: from xps.localnet (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id C1F08306AAA6; Sun, 5 Jul 2020 16:41:51 -0400 (EDT) From: Thomas Monjalon To: cristian.dumitrescu@intel.com, jasvinder.singh@intel.com Cc: dev@dpdk.org, Alan Dewar , alangordondewar@gmail.com Date: Sun, 05 Jul 2020 22:41:50 +0200 Message-ID: <1765563.QPqcEuCtyy@thomas> In-Reply-To: <20200625095930.18429-1-alan.dewar@att.com> References: <20200416084821.12591-1-alan.dewar@att.com> <20200625095930.18429-1-alan.dewar@att.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [dpdk-dev] [PATCH v2] sched: fix port time rounding error X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Cristian, Jasvinder, please review. 25/06/2020 11:59, alangordondewar@gmail.com: > From: Alan Dewar > > The QoS scheduler works off port time that is computed from the number > of CPU cycles that have elapsed since the last time the port was > polled. It divides the number of elapsed cycles to calculate how > many bytes can be sent, however this division can generate rounding > errors, where some fraction of a byte sent may be lost. > > Lose enough of these fractional bytes and the QoS scheduler > underperforms. The problem is worse with low bandwidths. > > To compensate for this rounding error this fix doesn't advance the > port's time_cpu_cycles by the number of cycles that have elapsed, > but by multiplying the computed number of bytes that can be sent > (which has been rounded down) by number of cycles per byte. > This will mean that port's time_cpu_cycles will lag behind the CPU > cycles momentarily. At the next poll, the lag will be taken into > account. > > v2: > If the cycles value wraps (100 year+) reset the port's cpu cycle back > to zero. > > Fixes: de3cfa2c98 ("sched: initial import") > > Signed-off-by: Alan Dewar > --- > lib/librte_sched/rte_sched.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c > index c0983ddda..7c022cd61 100644 > --- a/lib/librte_sched/rte_sched.c > +++ b/lib/librte_sched/rte_sched.c > @@ -222,6 +222,7 @@ struct rte_sched_port { > uint64_t time_cpu_bytes; /* Current CPU time measured in bytes */ > uint64_t time; /* Current NIC TX time measured in bytes */ > struct rte_reciprocal inv_cycles_per_byte; /* CPU cycles per byte */ > + uint64_t cycles_per_byte; > > /* Grinders */ > struct rte_mbuf **pkts_out; > @@ -852,6 +853,7 @@ rte_sched_port_config(struct rte_sched_port_params *params) > cycles_per_byte = (rte_get_tsc_hz() << RTE_SCHED_TIME_SHIFT) > / params->rate; > port->inv_cycles_per_byte = rte_reciprocal_value(cycles_per_byte); > + port->cycles_per_byte = cycles_per_byte; > > /* Grinders */ > port->pkts_out = NULL; > @@ -2673,16 +2675,21 @@ static inline void > rte_sched_port_time_resync(struct rte_sched_port *port) > { > uint64_t cycles = rte_get_tsc_cycles(); > - uint64_t cycles_diff = cycles - port->time_cpu_cycles; > + uint64_t cycles_diff; > uint64_t bytes_diff; > uint32_t i; > > + if (cycles < port->time_cpu_cycles) > + port->time_cpu_cycles = 0; > + > + cycles_diff = cycles - port->time_cpu_cycles; > /* Compute elapsed time in bytes */ > bytes_diff = rte_reciprocal_divide(cycles_diff << RTE_SCHED_TIME_SHIFT, > port->inv_cycles_per_byte); > > /* Advance port time */ > - port->time_cpu_cycles = cycles; > + port->time_cpu_cycles += > + (bytes_diff * port->cycles_per_byte) >> RTE_SCHED_TIME_SHIFT; > port->time_cpu_bytes += bytes_diff; > if (port->time < port->time_cpu_bytes) > port->time = port->time_cpu_bytes; >