Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2645398imm; Mon, 16 Jul 2018 11:31:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe5/QgsUMx56XaWDCfZTVgiWtOfwRFRz+yTAsPgTcEaqit+j+NQVe8o8DLnuk1DkLG7ACNj X-Received: by 2002:a62:2f84:: with SMTP id v126-v6mr5302447pfv.115.1531765888173; Mon, 16 Jul 2018 11:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531765888; cv=none; d=google.com; s=arc-20160816; b=zyGqecJ/p7KzUyQ4J3FQQMTZ3kPALHTogB9wGJ/Q15rmhGtDIDMrRnr8bfCBMj6Vg7 4XkJqMJzH66ITgAFJaQRWa1nfAeA2FjH1cgUTYPxEk6CH/WESFFrkMPrrDFdwwqEA5SM R+M21oZrYnNfQQ2s0G67sG6OjkCONDGyZKE7N+DJ2IUCAOeM9rOKZJA1k1d4+htgQvOQ +1zbMzcdclcCdRK9TapSdvyHmxg6/Z9kByFJgoXlicNl38pjjMvBMJGFtjLCanHC9Fwa RV0OClMsWNybBwwFeGR5uNCaatLkF+kN+4wPypCThxmHzKUCn6Um3f1XGpJJkM4SOKer wTVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=9oIWl0hJfVp1tjHSb46sXg+MH8GqIBM1igCVaeMyM3k=; b=S/PWCOesGXiT/sJNBLVkoLJZQ1iL/YEYVTRZwv1zlmVVuqjXUtrzHGgpEwUJSCQCma D2eTkVL7lNwsZmRcbcL3fi2RN3yVVf6jZSSYbeDmL78yxSnm2VhWUFnh1Wz6T57sEfyE cnfIake8RLgtOWKE6BRnGOlLVFgGLgAnsIy3j8jG+t67+XjC1DU6p1qC0LJxOlOOfM5E 3qcVzADaUK7n4YZQ8x7l9qUKVimR/8oGf57/lvcTOGsfa02XxlpBeH5jJJiLnk/t75C8 skTtCIScj1d2V9MX8e2lSsgY5qSDS3LXU6c8kL4DDUt98/r+c93uSZvDLIep7XAUybYN 2BiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=TX09J9Pj; dkim=pass header.i=@codeaurora.org header.s=default header.b=Q83q+a4S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k30-v6si30446121pgn.258.2018.07.16.11.31.12; Mon, 16 Jul 2018 11:31:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=TX09J9Pj; dkim=pass header.i=@codeaurora.org header.s=default header.b=Q83q+a4S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728839AbeGPS7L (ORCPT + 99 others); Mon, 16 Jul 2018 14:59:11 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:37002 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727809AbeGPS7L (ORCPT ); Mon, 16 Jul 2018 14:59:11 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 005166074D; Mon, 16 Jul 2018 18:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1531765832; bh=HUBYhO7SIjCK66ZuKfYQPO/pCOzedZiKMNeReQ1oA74=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=TX09J9Pjew+rHoxDxueEezXZO32XgCxov33FWVCceGrqC49I44ChLCnl29OKk0LPZ 2RTHKmhO5Zqh6GQRXNH0orkbLpH7D7dJr1PUiah4te+xxzKrOzl8WC1lSzxynyOBWb eiWuo81TYlX0xYb82SPVpC84n13kea6VHhtH5sRI= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.79.165.144] (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mojha@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E32F56074D; Mon, 16 Jul 2018 18:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1531765831; bh=HUBYhO7SIjCK66ZuKfYQPO/pCOzedZiKMNeReQ1oA74=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Q83q+a4S6Itt17/yo7nZkioWstwqmLdVld/4hS4SvMmy72nOyAkMjR1UMpMD8s5LX KnqJF+2hqgvMHMxyidIWtIzgFjzZTVTHvbc+wW3hNj9cg/XYYW72OlU2T1/34VCuB4 vOE8WdDRtSdZLLyZPDSf+qgCcBm4v/TezLUuD5JI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E32F56074D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=mojha@codeaurora.org Subject: Re: [PATCH v3] time: Fix incorrect sleeptime injection when suspend fails To: John Stultz Cc: Thomas Gleixner , lkml , gkohli@codeaurora.org, cpandya@codeaurora.org, neeraju@codeaurora.org, Baolin Wang References: <1530883047-17452-1-git-send-email-mojha@codeaurora.org> <7e25b63e-cc9b-1f6d-e3d2-087dd484f631@codeaurora.org> <45be9c4f-34fd-200a-df95-9c30b332a96b@codeaurora.org> From: Mukesh Ojha Message-ID: <19b10a21-2636-49a9-2a1a-488f293aeb45@codeaurora.org> Date: Tue, 17 Jul 2018 00:00:26 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/16/2018 10:44 PM, John Stultz wrote: > On Mon, Jul 16, 2018 at 9:30 AM, John Stultz wrote: >> On Mon, Jul 16, 2018 at 9:17 AM, Mukesh Ojha wrote: >>> On 7/13/2018 10:50 PM, John Stultz wrote: >>>> On Fri, Jul 13, 2018 at 12:13 AM, Mukesh Ojha >>>>> On 7/11/2018 1:43 AM, John Stultz wrote: >>>>>> I worry this upside-down logic is too subtle to be easily reasoned >>>>>> about, and will just lead to future mistakes. >>>>>> >>>>>> Can we instead call this "suspend_timing_needed" and only set it to >>>>>> true when we don't inject any sleep time on resume? >>>>> >>>>> I did not get your point "only set it to true when we don't inject any >>>>> sleep >>>>> time on resume? " >>>>> How do we know this ? >>>>> This question itself depends on the "sleeptime_injected" if it is true >>>>> means >>>>> no need to inject else need to inject. >>>>> >>>>> Also, we need to make this variable back and forth true, false; suspends >>>>> path ensures it to make it false. >>>> So yea, I'm not saying logically the code is really any different, >>>> this is more of a naming nit. So instead of having a variable that is >>>> always on that we occasionally turn off, lets invert the naming and >>>> have it be a flag that we occasionally turn on. >>> >>> I understand your concern about the name of the variable will be misleading. >>> But the changing Boolean state would not solve the actual issue. >>> >>> If i understand you correctly you meant below code >>> >>> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c >>> index 32ae9ae..becc5bd 100644 >>> --- a/kernel/time/timekeeping.c >>> +++ b/kernel/time/timekeeping.c >>> @@ -1523,7 +1523,7 @@ void __weak read_boot_clock64(struct timespec64 *ts) >>> * If a suspend fails before reaching timekeeping_resume() then the flag >>> * stays true and prevents erroneous sleeptime injection. >>> */ >>> -static bool sleeptime_injected = true; >>> +static bool suspend_timing_needed; >>> >>> /* Flag for if there is a persistent clock on this platform */ >>> static bool persistent_clock_exists; >>> @@ -1658,7 +1658,7 @@ void timekeeping_inject_sleeptime64(struct timespec64 >>> *delta) >>> raw_spin_lock_irqsave(&timekeeper_lock, flags); >>> write_seqcount_begin(&tk_core.seq); >>> >>> - sleeptime_injected = true; >>> + suspend_timing_needed = false; >>> >>> timekeeping_forward_now(tk); >>> >>> @@ -1714,10 +1714,10 @@ void timekeeping_resume(void) >>> tk->tkr_mono.mask); >>> nsec = mul_u64_u32_shr(cyc_delta, clock->mult, >>> clock->shift); >>> ts_delta = ns_to_timespec64(nsec); >>> - sleeptime_injected = true; >>> + suspend_timing_needed = true; >>> } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > >>> 0) { >>> ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time); >>> - sleeptime_injected = true; >>> + suspend_timing_needed = true; >>> } >> No no... This part is wrong. We only set suspend_timing_needed if we >> *didn't* calculate the suspend time in timekeeping_resume. >> >> You have to invert all the boolean logic for it to be equivalent. >> > ... >>> >> >> So, I think with the logic bug above it will work out properly, but >> let me know if I'm still missing something. Please give it thought to a case where very first suspend fails with your logic. If i am not able to get your thought, please write a patch. -Mukesh > Sorry, I meant "with the logic bug above fixed it will work out". > > thanks > -john