Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2073386imm; Mon, 16 Jul 2018 01:29:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeM0PfffmN9JFWliASCpmjHg8/q2+tZ2/9bLgVe2M10fQOAZuzNv+R1mtxsa/lNi96a7aqf X-Received: by 2002:a63:1403:: with SMTP id u3-v6mr14644715pgl.13.1531729777906; Mon, 16 Jul 2018 01:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531729777; cv=none; d=google.com; s=arc-20160816; b=V66qmiCFvAl7N2mjAK3VMpRe6WUD4TfI3eHBQeqD6KaznRDKoomNrBMIy5aeGrSgFK 4rOQ6c20uoV2LGLrRSEZ4H4PiIDShcWD1htG4fttLMYX9utXh3MKoEbev+IIPhGPHevS VpZeNXc93mtXCll8cQFD8GzC3cqyXZGjC7gQfdXuzQqXbfLlFad7n5P3D/On9i2OOke7 19IPy4nFP34HLx9S+nj8NyH4fTtY7EXU3hn9EZ2azK2Y6v1eTJ2ci/b6T2tzoEZ4uDFL Knp4PP/bVXuYhfeevcFJS4YGC2i24pO/WH/hRv0zED3V/+xZ3g7BTPaU/GS9HD3tarHo LGuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=W4NV1skY5nEaD3ME2JxNBrr9Gy16C3IgizLXX+tkF0Q=; b=tOwndR5TrI45X5eiz2UiTyacYSX0TgT5Ioyn/cNqcrY2OrWTfdNZ/a/reqCTgBspTb E9oL15/n/W5q+wkte1shZHRDnywobjfMtjCP61n+TwwIz9DAtRZJc8AHSoMTEmDHVhJm 18wB6mwhhArWIiqHCg7CuSsc1jSUFQ1Uz6mWH37s7lOJzV5xBH6di3d0ABLXkUXwtVpG xVU7tgtygu2oPwFFaW/+ScOO+LU4FN+XaepnY6CsjdEwpoRMVDumETmbPWQ0shvxi0qP puDqnQkZ5k7hUZHqoEafSTf/8EBKtdXJFLiHLXhlmDwQf40b1rulA9lHz1XMqawH7yEG vDSw== ARC-Authentication-Results: i=1; mx.google.com; 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 9-v6si30447284pla.59.2018.07.16.01.29.22; Mon, 16 Jul 2018 01:29:37 -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; 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 S1729228AbeGPIzD (ORCPT + 99 others); Mon, 16 Jul 2018 04:55:03 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:51209 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727850AbeGPIzD (ORCPT ); Mon, 16 Jul 2018 04:55:03 -0400 Received: from p4fea5a5a.dip0.t-ipconnect.de ([79.234.90.90] helo=nanos.glx-home) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1feys8-0007iT-S7; Mon, 16 Jul 2018 10:28:45 +0200 Date: Mon, 16 Jul 2018 10:28:44 +0200 (CEST) From: Thomas Gleixner To: Baolin Wang cc: john.stultz@linaro.org, sboyd@kernel.org, arnd@arndb.de, broonie@kernel.org, daniel.lezcano@linaro.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/2] time: Introduce one suspend clocksource to compensate the suspend time In-Reply-To: <4aa9a65166f7e10984bfcff59e72d86e37c369a1.1531384486.git.baolin.wang@linaro.org> Message-ID: References: <4aa9a65166f7e10984bfcff59e72d86e37c369a1.1531384486.git.baolin.wang@linaro.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 12 Jul 2018, Baolin Wang wrote: > On some hardware with multiple clocksources, we have course grained > clocksources that support the CLOCK_SOURCE_SUSPEND_NONSTOP flag, but > which are less ideal for timekeeping then other clocksources which > halt in suspend. > > Currently, the timekeeping core only supports timing suspend using > CLOCK_SOURCE_SUSPEND_NONSTOP clocksources if that clocksource is the > current clocksource for timekeeping. > > As a result, some architectures try to implement read_persisitent_clock64() > using those non-stop clocksources, but isn't really ideal. Thus this > patch provides logic to allow a registered SUSPEND_NONSTOP clocksource, Please see Documentation/process/submitting-patches.rst and search for 'This patch...' > +/** > + * clocksource_suspend_select - Select the best clocksource for suspend timing > + * @fallback: if select a fallback clocksource > + */ > +static void clocksource_suspend_select(bool fallback) > +{ > + struct clocksource *cs, *old_suspend; > + > + old_suspend = suspend_clocksource; > + if (fallback) > + suspend_clocksource = NULL; > + > + list_for_each_entry(cs, &clocksource_list, list) { > + /* Skip current if we were requested for a fallback. */ > + if (fallback && cs == old_suspend) > + continue; > + > + __clocksource_suspend_select(cs); > + } > + > + /* If we failed to find a fallback restore the old one. */ > + if (!suspend_clocksource) > + suspend_clocksource = old_suspend; That's for the case where something tries to remove a clocksource, right? The logic here looks odd as the calling code for the fallback case has to check whether the clocksource which is about to be removed is the suspend clocksource. Why not just returning -EBUSY/0 for the fallback case? The other question is whether this should be enforced. We might as well decide to just let the clocksource go and have no suspend clocksource. > +/** > + * clocksource_start_suspend_timing - Start measuring the suspend timing > + * @cs: current clocksource from timekeeping > + * @start_cycles: current cycles from timekeeping > + * > + * This function will save the start cycle values of suspend timer to calculate > + * the suspend time when resuming system. > + * > + * This function is called late in the suspend process from timekeeping_suspend(), > + * that means processes are freezed, non-boot cpus and interrupts are disabled > + * now. It is therefore possible to start the suspend timer without taking the > + * clocksource mutex. > + */ > +void clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles) > +{ > + if (!suspend_clocksource) > + return; > + > + /* > + * If current clocksource is the suspend timer, we should use the > + * tkr_mono.cycle_last value as suspend_start to avoid same reading > + * from suspend timer. > + */ > + if (clocksource_is_suspend(cs)) { > + suspend_start = start_cycles; > + return; > + } > + > + if (suspend_clocksource->enable && > + WARN_ON_ONCE(suspend_clocksource->enable(suspend_clocksource))) { > + pr_warn_once("Failed to enable the non-suspend-able clocksource.\n"); > + return; This is horrible to read and the WARN is really not helpful because the bracktrace is already known. > @@ -779,6 +910,16 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq) > { > unsigned long flags; > > + /* > + * The nonstop clocksource can be selected as the suspend clocksource to > + * calculate the suspend time, so it should not supply suspend/resume > + * interfaces to suspend the nonstop clocksource when system suspends. > + */ > + if ((cs->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) && > + (cs->suspend || cs->resume)) > + pr_warn("Nonstop clocksource %s should not supply suspend/resume interfaces\n", > + cs->name); Lacks braces. See https://lkml.kernel.org/r/alpine.DEB.2.20.1701171956290.3645@nanos Othar that the few nits this looks good. Nice work! Thanks, tglx