Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp701368pxf; Thu, 25 Mar 2021 12:00:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtJV0mf2QgevYxE8nNyCeIbditMQ1pTFOLZ4clD9kT1vg7KrshCIBEYBwjQz6G65kCnyF2 X-Received: by 2002:a17:906:f8d5:: with SMTP id lh21mr11065654ejb.64.1616698823569; Thu, 25 Mar 2021 12:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616698823; cv=none; d=google.com; s=arc-20160816; b=PHgbCVpgGfE+QVMp8HdR2X5RXRyfc4XfoCUcUyElsfBXhhbd1678ewGfGAFtV0K8rf 4dC5FLWwuG8a6Adl++pS/x/bt/lLI+nMzbjs+7M5DB1Fo5ZoR4mmbADOZkZcDsOQ49nc kY4jMeH6Gttjau4lIY2/GKAyulB5/zIhZ0RQ3jg+WOrdbx2wXB+KuV5E4W78sXf3nd/i +0rIHvX3QKId8jNDZ/5exAjnjOgAVfUHtrdfsogkT/dkydguix4Ty2/INUCfoYYG2djh oIE2PJB0TLOeoHLT27SHjoAGHgovu/RZGBDecO6cCEN6mfzUqOtPbbV8zcVBSF84t9Sh 5iXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ovOrgJ5qKxIbtMAZ2GunCrEU8R908OLvPlSO6BPSU44=; b=FS3HUNkvPVk0Qt0sGpeunDUEfJ1FP5hfDlod39+52tXR00DmIYDrH8DYj4tIQ/t9zB G0XsLtHgHmv2AZqL+O5FBNvP/nUFQ8gkX8a607b7bkJ1Ml0U5AOXQC9y3zyvQUth/95P gg9vqz/BsXEJ2+8o69lb2N6865MAcXwDRnfo75VlEGboXj8arJuV6fn1rpDLKwVmOoaQ 5j/eP4UFBRJ3octxK2Axef7SCRY1fBDbuop9pKU38GPGOP2N6P9szE4I/IjjfmWZKIkg WbqmrpCrvrJalUIO5MXFgVg757Xz9Y726luShjQGpZ/b1JEqnCeBrfk+0TI4q6+52fs7 6yjQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b17si4887238eds.443.2021.03.25.12.00.00; Thu, 25 Mar 2021 12:00:23 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbhCYS4m (ORCPT + 99 others); Thu, 25 Mar 2021 14:56:42 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:47470 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbhCYS4P (ORCPT ); Thu, 25 Mar 2021 14:56:15 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 2.0.3) id ecdf7dd5ee01525c; Thu, 25 Mar 2021 19:56:13 +0100 Received: from kreacher.localnet (89-64-80-106.dynamic.chello.pl [89.64.80.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 282A4669104; Thu, 25 Mar 2021 19:56:12 +0100 (CET) From: "Rafael J. Wysocki" To: Frederic Weisbecker Cc: "Zhou Ti (x2019cwm)" , linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Thomas Gleixner , LKML , Yunfeng Ye , "Paul E . McKenney" , Marcelo Tosatti , Ingo Molnar , "rafael@kernel.org" , Linux PM Subject: Re: =?UTF-8?B?5Zue5aSNOg==?= [PATCH 01/10] tick/nohz: Prevent tick_nohz_get_sleep_length() from returning negative value Date: Thu, 25 Mar 2021 19:56:11 +0100 Message-ID: <5712356.lOV4Wx5bFT@kreacher> In-Reply-To: <20210325131400.GA938586@lothringen> References: <20210311123708.23501-1-frederic@kernel.org> <20210325131400.GA938586@lothringen> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrudehtddguddvudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdejlefghfeiudektdelkeekvddugfeghffggeejgfeukeejleevgffgvdeluddtnecukfhppeekledrieegrdektddruddtieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrieegrdektddruddtiedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehfrhgvuggvrhhitgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepgidvtddulegtfihmsehsthhfgidrtggrpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhgrfhgrvghlrdhjrdifhihsohgtkhhisehinhhtvghlrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghp thhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhrtghpthhtohephigvhihunhhfvghngheshhhurgifvghirdgtohhmpdhrtghpthhtohepphgruhhlmhgtkheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhtohhsrghtthhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=13 Fuz1=13 Fuz2=13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday, March 25, 2021 2:14:00 PM CET Frederic Weisbecker wrote: > On Tue, Mar 16, 2021 at 04:08:08PM +0000, Zhou Ti (x2019cwm) wrote: > > But I don't think it's a good idea to handle this in callers, because logically the function shouldn't return negative values. Returning 0 directly would allow idle governors to get another chance to select again. > > Hmm, I'm going to leave the last word to Rafael since cpuidle are the only > callers of this. In any case we need to fix it. Yes, we do. So I said that I preferred to address this in the callers and the reason why is because, for example, for the teo governor it would be a matter of using a different data type to store the tick_nohz_get_sleep_length() return value, like in the (untested) patch below. So at least in this case there is no need to add any new branches anywhere. I'm still not sure about menu, because it is more complicated, but even if that one needs an extra branch, that is a win already. --- drivers/cpuidle/governors/teo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) Index: linux-pm/drivers/cpuidle/governors/teo.c =================================================================== --- linux-pm.orig/drivers/cpuidle/governors/teo.c +++ linux-pm/drivers/cpuidle/governors/teo.c @@ -100,8 +100,8 @@ struct teo_idle_state { * @intervals: Saved idle duration values. */ struct teo_cpu { - u64 time_span_ns; - u64 sleep_length_ns; + s64 time_span_ns; + s64 sleep_length_ns; struct teo_idle_state states[CPUIDLE_STATE_MAX]; int interval_idx; u64 intervals[INTERVALS]; @@ -216,7 +216,7 @@ static bool teo_time_ok(u64 interval_ns) */ static int teo_find_shallower_state(struct cpuidle_driver *drv, struct cpuidle_device *dev, int state_idx, - u64 duration_ns) + s64 duration_ns) { int i; @@ -242,7 +242,7 @@ static int teo_select(struct cpuidle_dri { struct teo_cpu *cpu_data = per_cpu_ptr(&teo_cpus, dev->cpu); s64 latency_req = cpuidle_governor_latency_req(dev->cpu); - u64 duration_ns; + s64 duration_ns; unsigned int hits, misses, early_hits; int max_early_idx, prev_max_early_idx, constraint_idx, idx, i; ktime_t delta_tick;