From patchwork Tue Jun 4 13:41:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Holler X-Patchwork-Id: 248591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-we0-x23f.google.com (mail-we0-x23f.google.com [IPv6:2a00:1450:400c:c03::23f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9DDB22C0099 for ; Tue, 4 Jun 2013 23:41:30 +1000 (EST) Received: by mail-we0-f191.google.com with SMTP id q58sf46634wes.8 for ; Tue, 04 Jun 2013 06:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-beenthere:x-spam-checker-version:x-spam-level:x-spam-status :message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=tFx57JmleJCylCGtt+l0ft6PNwhL1BgOw61hw/rMe0w=; b=dKskP4dLE5YsSPMfqZMnYuS+GkyfaMDac+08Pvtjcq36BajrsEdpNML20RZ+77VUOE B+bOIHO7FoZ31H5tVWnHO6k+L+Lc5X/FdbWawh74N934rOByli54ouknE6+YC7IvPf56 q9ryKmuV/uHEoQ6uM0Pc03ClxxED/4yvchF2R7Cmjyb40uWN+qLMOrx/0QvrkNUpvdgu pqWwPyDqv6ZqpDGp8JnYrTUDwnJrLClJ/vtfTR//7aMNcy8uevg3Y8PWgLAlJFM0SQ3j dd+14PvPng9bdhEgl22uDJ5OBe8sHKBpWB0YMM21j+/+1TrwDTNPImM5JbSGr0HqLAX7 XAvQ== X-Received: by 10.180.187.51 with SMTP id fp19mr101159wic.1.1370353285194; Tue, 04 Jun 2013 06:41:25 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.107.10 with SMTP id gy10ls158908wib.9.gmail; Tue, 04 Jun 2013 06:41:23 -0700 (PDT) X-Received: by 10.14.95.6 with SMTP id o6mr34825164eef.2.1370353283336; Tue, 04 Jun 2013 06:41:23 -0700 (PDT) Received: from mail.ahsoftware.de (h1446028.stratoserver.net. [85.214.92.142]) by gmr-mx.google.com with ESMTP id o5si14825860eew.0.2013.06.04.06.41.23 for ; Tue, 04 Jun 2013 06:41:23 -0700 (PDT) Received-SPF: neutral (google.com: 85.214.92.142 is neither permitted nor denied by best guess record for domain of holler@ahsoftware.de) client-ip=85.214.92.142; Received: by mail.ahsoftware.de (Postfix, from userid 65534) id E1A72888BAD; Tue, 4 Jun 2013 15:41:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.ahsoftware.de X-Spam-Level: X-Spam-Status: No, score=-101.0 required=5.0 tests=ALL_TRUSTED, USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from eiche.ahsoftware (p57B23C08.dip0.t-ipconnect.de [87.178.60.8]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ahsoftware.de (Postfix) with ESMTPSA id 137DB888BAD for ; Tue, 4 Jun 2013 15:41:22 +0200 (CEST) Received: by eiche.ahsoftware (Postfix, from userid 65534) id 8771A7FD69; Tue, 4 Jun 2013 15:41:20 +0200 (CEST) Received: from [192.168.211.6] (unknown [192.168.211.6]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by eiche.ahsoftware (Postfix) with ESMTPS id B27757F9CC; Tue, 4 Jun 2013 13:41:12 +0000 (UTC) Message-ID: <51ADEE76.7090504@ahsoftware.de> Date: Tue, 04 Jun 2013 15:41:10 +0200 From: Alexander Holler User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130421 Thunderbird/17.0.5 MIME-Version: 1.0 To: John Stultz CC: linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com, Andrew Morton , Alessandro Zummo , Lars-Peter Clausen , Jonathan Cameron , Jiri Kosina Subject: [rtc-linux] Re: [PATCH 3/4] rtc: rtc-hid-sensor-time: add option hctosys to set time at boot References: <51765FB9.2050009@ahsoftware.de> <1367752887-2927-1-git-send-email-holler@ahsoftware.de> <1367752887-2927-4-git-send-email-holler@ahsoftware.de> <519BEF13.2040500@linaro.org> <519C0004.9000706@ahsoftware.de> <51A50774.6060400@linaro.org> <51A58726.9090206@ahsoftware.de> In-Reply-To: <51A58726.9090206@ahsoftware.de> X-Original-Sender: holler@ahsoftware.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.214.92.142 is neither permitted nor denied by best guess record for domain of holler@ahsoftware.de) smtp.mail=holler@ahsoftware.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Am 29.05.2013 06:42, schrieb Alexander Holler: > Am 28.05.2013 21:37, schrieb John Stultz: >> On 05/21/2013 04:15 PM, Alexander Holler wrote: >>> Implementation could be as easy as a bool "time_set_at_least_once" in >>> the timer subsystem itself (e.g. in do_settimeofday() and whatever >>> similiar is available). >> >> If it were to be done this way, it would be good to have the RTC layer >> check when RTC devices are registered and call the internal hctosys >> functionality then (rather then just at late_init). Do you want to try >> to rework the patch in this way? > > That sounds like what Andrew Morton wanted to trick me to do. ;) Just in case that was misunderstood. Of course, I would rework the patch if we reach a consensus about how I can do that. I would also volunteer and would remove hctosys and replace it by a better approach (imho) which sets the system time when a rtc registers. That doesn't look like much work. I've just did a small test and I think the mentioned flag could be implemented by the patch below (pasted => wrong format). I don't think stuff like atomic_*, a spinlock, mutex or similiar is necessary to make sure that the system time will only be set by one rtc, because I think it is extremly unlikely that more than one rtc will register at the same time to make such necessary. That means I think it's ok to just use "if (!systime_was_set) do_settimeofday()" in the rtc subsystem afterwards. I would also implement a kernel parameter like systime_from which could not be set (== use the first clock which offers a valid time) or could be set to "persistent" or the name of a RTC module in which case either the persistent clock or the named RTC would be used to set the time, if and only if the system time wasn't be set by something else (most likely userspace). Regards, Alexander Holler now.tv_sec = 0; now.tv_nsec = 0; - } else if (now.tv_sec || now.tv_nsec) + } else if (now.tv_sec || now.tv_nsec) { persistent_clock_exist = true; + systime_was_set = true; + } read_boot_clock(&boot); if (!timespec_valid_strict(&boot)) { diff --git a/include/linux/time.h b/include/linux/time.h index afcdc4b..9c488f3 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -129,6 +129,12 @@ extern int update_persistent_clock(struct timespec now); void timekeeping_init(void); extern int timekeeping_suspended; +/* + * Will be true if the system time was set at least once by + * a persistent clock, RTC or userspace. + */ +extern bool systime_was_set; + unsigned long get_seconds(void); struct timespec current_kernel_time(void); struct timespec __current_kernel_time(void); /* does not take xtime_lock */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 9a0bc98..442e03c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -32,6 +32,9 @@ int __read_mostly timekeeping_suspended; /* Flag for if there is a persistent clock on this platform */ bool __read_mostly persistent_clock_exist = false; +/* Flag for if the system time was set at least once */ +bool __read_mostly systime_was_set = false; + static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) { @@ -448,6 +451,10 @@ int do_settimeofday(const struct timespec *tv) if (!timespec_valid_strict(tv)) return -EINVAL; + systime_was_set = true; + write_seqlock_irqsave(&tk->lock, flags); timekeeping_forward_now(tk); @@ -682,8 +689,11 @@ void __init timekeeping_init(void) " Check your CMOS/BIOS settings.\n");