Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4444952pxf; Tue, 16 Mar 2021 13:44:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCdwXKqo9oypBkpvuNaU3t/DsOcbv/BQRv40SqkDeD+tEw27q1DVeIPC9KSdXGH1cPEmOw X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr30646142ejb.264.1615927476411; Tue, 16 Mar 2021 13:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615927476; cv=none; d=google.com; s=arc-20160816; b=IQhtcFC0o3Df01PdSc0O5UoXv4UuHfHaY0TrIv7wFOuNmqYxIwVbstBi4uk0Axhv2Z VYasOcp1kMufKCl2T70wkGV/KavjQJ5Xb+oaon0oqri7OW3zgVkWGMLSn4rkQmVDLv/L zZ8e1UX+9y09gWk2BuwPa4cUVNNgjEk1ufTaqi9lnESjWWoPaWD+kzIEyyz3OkK1h4HR +3rDIEBENzhcv4l9Qvldh9K/rKOxhJLDycaO1W2RSs6u2eyyjLKktlTJz8jstavr8dsB doD3sWkF6qwwbC0/IixkWhukHW1W2Q7u42DMqoL9FC6/E7jnV8aq75taj8KfMX8lH/cE gL6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=TQ8uQB558o9RHZpSa+P3LLxXQkiN5yd0iVWAxJ+UuSw=; b=pj+PDTg1g2m/GsMdbFYEk7G9UIdQJQ1jumns0nCU4SfCigJ9bAyzJ2wVp1ToM17kqU SvFwkGoBNul6qZDB8VccQnXlNlCz9Qynje9QH0gFJXX0ac8TmPTKoYcJprLB6flc7drI ave5pWzAYeVEy6LkJqkPY5D4ckoIjBAcHhM+d5lHty6cL2uvqG29dl5cYT8aWugU+Stx i1gblAlp/7pXFtJKSeqHsx5U6ocVS+8mACou6HELhSoBXCiP9WzustXfok7FuaXZgaQK aeTdrkZmuDmwlGlT1/J5weQ8CjxMJqXW2cmv7bFMlI6/TBWTc6W4lDPsHlZ+GulWV+UA LIEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec10si14324657ejb.386.2021.03.16.13.44.08; Tue, 16 Mar 2021 13:44:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236431AbhCPP0p (ORCPT + 99 others); Tue, 16 Mar 2021 11:26:45 -0400 Received: from mga07.intel.com ([134.134.136.100]:13297 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236553AbhCPP0J (ORCPT ); Tue, 16 Mar 2021 11:26:09 -0400 IronPort-SDR: rUF9XKy77fHPoHUi11zS+RNRZCV5vF1XgR9VBK0JTNqmVggQVBJ1ldkebDN8WZaPGsjauJw/KO jVm/7XumMaQA== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="253294335" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="253294335" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 08:26:08 -0700 IronPort-SDR: T1tvaQwjJrhj/w5sG9FACKGib5o9ePzpPZ5JOsPPqCIzE2c9DiWw/37sGBEZCNvTJ2u4sLpXb4 4a4xa5UDbAjg== X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="405574234" Received: from rjwysock-mobl1.ger.corp.intel.com (HELO [10.249.154.190]) ([10.249.154.190]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 08:26:05 -0700 Subject: Re: [PATCH 01/10] tick/nohz: Prevent tick_nohz_get_sleep_length() from returning negative value To: Frederic Weisbecker , Peter Zijlstra Cc: Thomas Gleixner , LKML , "Zhou Ti (x2019cwm)" , Yunfeng Ye , "Paul E . McKenney" , Marcelo Tosatti , Ingo Molnar , "rafael@kernel.org" References: <20210311123708.23501-1-frederic@kernel.org> <20210311123708.23501-2-frederic@kernel.org> <20210316133703.GC639918@lothringen> <20210316145352.GE639918@lothringen> From: "Rafael J. Wysocki" Organization: Intel Technology Poland Sp. z o. o., KRS 101882, ul. Slowackiego 173, 80-298 Gdansk Message-ID: Date: Tue, 16 Mar 2021 16:26:02 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210316145352.GE639918@lothringen> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/16/2021 3:53 PM, Frederic Weisbecker wrote: > On Tue, Mar 16, 2021 at 03:35:37PM +0100, Peter Zijlstra wrote: >> On Tue, Mar 16, 2021 at 02:37:03PM +0100, Frederic Weisbecker wrote: >>> On Tue, Mar 16, 2021 at 01:21:29PM +0100, Peter Zijlstra wrote: >>>> On Thu, Mar 11, 2021 at 01:36:59PM +0100, Frederic Weisbecker wrote: >>>>> From: "Zhou Ti (x2019cwm)" >>>>> >>>>> If the hardware clock happens to fire its interrupts late, two possible >>>>> issues can happen while calling tick_nohz_get_sleep_length(). Either: >>>>> >>>>> 1) The next clockevent device event is due past the last idle entry time. >>>>> >>>>> or: >>>>> >>>>> 2) The last timekeeping update happened before the last idle entry time >>>>> and the next timer callback expires before the last idle entry time. >>>>> >>>>> Make sure that both cases are handled to avoid returning a negative >>>>> duration to the cpuidle governors. >>>> Why? ... and wouldn't it be cheaper the fix the caller to >>>> check negative once, instead of adding two branches here? >>> There are already two callers and potentially two return values to check >>> for each because the function returns two values. >>> >>> I'd rather make the API more robust instead of fixing each callers and worrying >>> about future ones. >> But what's the actual problem? The Changelog doesn't say why returning a >> negative value is a problem, and in fact the return value is explicitly >> signed. >> >> Anyway, I don't terribly mind the patch, I was just confused by the lack >> of actual justification. > And you're right, the motivation is pure FUD: I don't know exactly > how the cpuidle governors may react to such negative values and so this > is just to prevent from potential accident. > > Rafael, does that look harmless to you? No, this is a problem now.  Both governors using this assign the return value of it to a u64 var and so negative values confuse them. That said I think it's better to deal with the issue in the callers. I can send a patch for that if needed.