From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D80A2ECAAD8 for ; Wed, 21 Sep 2022 08:27:57 +0000 (UTC) Received: from localhost ([::1]:59502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oav5I-0002GP-CM for qemu-devel@archiver.kernel.org; Wed, 21 Sep 2022 04:27:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oauvU-0006N6-JC; Wed, 21 Sep 2022 04:17:48 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:39496 helo=fanzine2.igalia.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oauvR-000529-0q; Wed, 21 Sep 2022 04:17:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=dAzh8scQptASFOfjVEy1wYUkMCILJ7L+7RP7e5IoN0Y=; b=hy44E21QkxTTNj0rkJn4znQPUf knMW1RAk/ZnF9KOU5HD7pBPQpVQuSokWC/Ff1PIsjF0QTeqamcsMX6lupun38HjULrqoFFZE6WY6U Qhb6Gh0ykuydeQ+lrJKfz++pYcUadxzYHreC5B9wgdDOBKU7wAOrysXZDTqrItlrPrqKQScdxU910 lQ/RnWWqeRHsxPU91fjVVO5wEHw0axlA9YNXGfK2l3JjJcXJRctX5wzjnf/7U/Ago6jfc+OO/vC7W 3bwW0waqt887MxK3AebxWCJmvJbGikWnuHgI/HSiuAVAkif+6x5UN6lrs6uOE1ybef0wL5JD1bi+v 3aK+xfTw==; Received: from maestria.local.igalia.com ([192.168.10.14] helo=mail.igalia.com) by fanzine2.igalia.com with esmtps (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oauvH-00G5nq-8X; Wed, 21 Sep 2022 10:17:34 +0200 Received: from gate.service.igalia.com ([192.168.21.52]) by mail.igalia.com with esmtp (Exim) id 1oauvE-00Gvop-Q2; Wed, 21 Sep 2022 10:17:34 +0200 Received: from berto by gate.service.igalia.com with local (Exim 4.94.2) (envelope-from ) id 1oauvE-000yYa-6v; Wed, 21 Sep 2022 08:17:32 +0000 From: Alberto Garcia To: Wang Liang , qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: pbonzini@redhat.com, stefanha@redhat.com, silbe@linux.vnet.ibm.com, Wang Liang Subject: Re: [PATCH] ratelimit: restrict the delay time to a non-negative value In-Reply-To: References: <20220920123350.205391-1-wangliangzz@126.com> Date: Wed, 21 Sep 2022 08:17:32 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=178.60.130.6; envelope-from=berto@igalia.com; helo=fanzine2.igalia.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Wed 21 Sep 2022 09:47:32 AM +08, Wang Liang wrote: >> > - return limit->slice_end_time - now; >> > + return MAX(limit->slice_end_time - now, 0); >> >> How can this be negative? slice_end_time is guaranteed to be larger >> than >> now: >> >> if (limit->slice_end_time < now) { >> /* Previous, possibly extended, time slice finished; reset >> the >> * accounting. */ >> limit->slice_start_time = now; >> limit->slice_end_time = now + limit->slice_ns; >> limit->dispatched = 0; >> } >> > This is just a guarantee. > > If slice_end_time is assigned later by > limit->slice_end_time = limit->slice_start_time + > (uint64_t)(delay_slices * limit->slice_ns); Ok, on a closer look, if at the start of the function limit->slice_start_time < now, and limit->slice_end_time >= now it seems that in principle what you say can happen. If it's so, it would be good to know under what conditions this happens, because this hasn't changed in years. Berto