Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3824506pxb; Mon, 1 Feb 2021 05:49:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNfKZIkDYbeTZ+d7DPXIe1zJ3bwmpXUZwuOfXSWNeqWB7tS8Zs+s8+0LETwrGkk5eFEkp3 X-Received: by 2002:aa7:de82:: with SMTP id j2mr1329252edv.313.1612187374553; Mon, 01 Feb 2021 05:49:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612187374; cv=none; d=google.com; s=arc-20160816; b=DysddvKtVg59iLPzFgPYR29bWItl7yTInWtDNJUP8fH3kUEtwQhnMic/T8Cy0rC9C/ dj9DISZhNbmZKbR6W3kFzjHdiOzPHAzqTCbnnW7QOGq80pKqg9pDqKWJj8mh960ptKU/ +u1dilJGTFKsM/y6UjiiLfPGoEKug0rZL3eUiKgQ9l+bZ1RxiZUoHiN4kBTiY5hG7vsQ 2EOiqCAv60agctWjMPQ+1i1aNKbhcOE+8+BoqLZrkUdtOP/kVuZNQBhUOwHW1B/FnOsY UK/t14AnGOz1mvPikyrUZVkj+NygsRq3pisqlRyhA83ln33d7vozhMeyoVnBb3CoxN6M yObw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XeL821DxN9rNwqwqG0Ae8PKqw7rocmgMuMNK+uZnMBs=; b=jk18DVVAfMqwMxn5iUMxv3rcqAPjz2OOOz/1tY+0TaluzMlNuI7K5mL7K44u8GoeVI fr3uaI/HSQ5OnHNSmadH4mJ30HM0l45pc897v9hjP+PPGF58jmg+ebeNmhGfFAz732dH CMB/r4pmeScX1t2LxUWnWD5uwhlEjQy9X8AhyItMg4Meas67j145maGewIErbs84hM++ V0TUf9Vcv+EVUu9yFKyxIupSfolTBZLa/Bgp0tUIJXulorJeCOPTSityWIDBOBPCMfMf xCPkLIxPuN/zy6cbonJ/+HWnWK2HKXqGz0IC8bGvxBg12vzWFKWvZwS16QMVwviPxSj/ W3OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kX4MnFOw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 2si9928195ejv.698.2021.02.01.05.49.09; Mon, 01 Feb 2021 05:49:34 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kX4MnFOw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231314AbhBANsJ (ORCPT + 99 others); Mon, 1 Feb 2021 08:48:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:47906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbhBANsG (ORCPT ); Mon, 1 Feb 2021 08:48:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3889564D99; Mon, 1 Feb 2021 13:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612187245; bh=OblNRRU9kt2opjlL2A1b+cyHiv7FjD00GN257vO0Hyw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kX4MnFOwjVBTO0dX5qcuLJTS2yo8RCXKR6PQ1fuvA77uLu740cUMxT7zzZ+oiUWS5 NZB5sJFOEaW23R7+j0cP/Nn1UZH27I/DOn6DT5xU3sl57uNb1y4yQVCyGqZyHGQFBD gbP651gjDexnAhZANFmg56DKTcoJkfFZdT4eGrqQL96Cv0yUVepoS7PeTHzsXrhRJr ptt0Oigp5jmK8lhy94ylbqEpb0Q72fp8yHOuz1PkWuwHfp9c9OI8Yv1vu0OYQf91F5 lqZ784U7BwnTakLFWmy/tgLPMMlzQp4wp4tC05RpuvbIW+DoKDp3cHgPOKf8YpCsRT Xto/3opHaKO4Q== Date: Mon, 1 Feb 2021 14:47:23 +0100 From: Frederic Weisbecker To: "Zhou Ti (x2019cwm)" Cc: "fweisbec@gmail.com" , "tglx@linutronix.de" , "mingo@kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] fix the issue that the tick_nohz_get_sleep_length() function could return a negative value Message-ID: <20210201134723.GB41955@lothringen> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 11:49:38PM +0000, Zhou Ti (x2019cwm) wrote: > Fix the issue that the tick_nohz_get_sleep_length() function could return a > negative value. > > The variable "dev->next_event" has a small possibility to be smaller than > the variable "now" during running, which would result in a negative value > of "*delta_next". The variable "next_event" also has a small posibility to > be smaller than the variable "now". Both case could lead to a negative > return of function tick_nohz_get_sleep_length(). Makes sense, queued, thanks! > > Signed-off-by: Ti Zhou > --- > --- tip/kernel/time/tick-sched.c.orig 2021-01-20 05:34:25.151325912 -0400 > +++ tip/kernel/time/tick-sched.c 2021-01-20 19:44:28.238538380 -0400 > @@ -1142,6 +1142,9 @@ ktime_t tick_nohz_get_sleep_length(ktime > > *delta_next = ktime_sub(dev->next_event, now); > > + if (unlikely(*delta_next < 0)) > + *delta_next = 0; > + > if (!can_stop_idle_tick(cpu, ts)) > return *delta_next; > > @@ -1156,6 +1159,9 @@ ktime_t tick_nohz_get_sleep_length(ktime > next_event = min_t(u64, next_event, > hrtimer_next_event_without(&ts->sched_timer)); > > + if (unlikely(next_event < now)) > + next_event = now; > + > return ktime_sub(next_event, now); > } >