From patchwork Wed Jun 5 17:15:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Holler X-Patchwork-Id: 249148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-x237.google.com (mail-wi0-x237.google.com [IPv6:2a00:1450:400c:c05::237]) (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 A2EDE2C029B for ; Thu, 6 Jun 2013 03:16:27 +1000 (EST) Received: by mail-wi0-f183.google.com with SMTP id en1sf233875wid.0 for ; Wed, 05 Jun 2013 10:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:x-beenthere:x-spam-checker-version:x-spam-level :x-spam-status:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references: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=6/ZwtWuYo8EYsFhNy/060UPfxwotWYE8b5Kf2jgUSSM=; b=X7kpJG1YGWBxeSLpBjdVaJBrKPTr8oKCXTxKlQWikkZRpRKB32UJkLnr8PHc6AZRbG 7h3vrtqw/tO1tZ/vPRIiriT+VbkvfjoHrdanBl5dGd73pdYxZ4lQZjtxkWLE4rZTxKYv 25Fvxh1cHHK2mdY1e/G3VW5WEYNgxo9qvNUUvERjjZt/0UdbvdMMRt/K2x7xMQa1FYuL Z1sdwb+1ttTJHq1mHMPV7sKaTRzkKVH5ydjBUxQGu98m8YAt9liT+SAckird80e0cMSZ RIC44gF9KOIVyIj2O9xTDRvWMy08DrnUTNW50GymQg1LxUC87rIdybUMdNaV+KKhdrB4 NhdQ== X-Received: by 10.180.21.141 with SMTP id v13mr869322wie.0.1370452583536; Wed, 05 Jun 2013 10:16:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.77.48 with SMTP id p16ls684270wiw.12.gmail; Wed, 05 Jun 2013 10:16:22 -0700 (PDT) X-Received: by 10.15.101.142 with SMTP id bp14mr22325641eeb.7.1370452582767; Wed, 05 Jun 2013 10:16:22 -0700 (PDT) Received: from mail.ahsoftware.de (h1446028.stratoserver.net. [85.214.92.142]) by gmr-mx.google.com with ESMTP id bj52si529390eeb.1.2013.06.05.10.16.22 for ; Wed, 05 Jun 2013 10:16:22 -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 7DAFB888B4C; Wed, 5 Jun 2013 19:16: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 (p57B201BF.dip0.t-ipconnect.de [87.178.1.191]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ahsoftware.de (Postfix) with ESMTPSA id E111B888B20 for ; Wed, 5 Jun 2013 19:16:21 +0200 (CEST) Received: by eiche.ahsoftware (Postfix, from userid 65534) id 25E1F7F9CC; Wed, 5 Jun 2013 19:16:21 +0200 (CEST) Received: from laptopahbt.ahsoftware (unknown [192.168.211.6]) by eiche.ahsoftware (Postfix) with ESMTP id 179CE7F9F7; Wed, 5 Jun 2013 17:15:51 +0000 (UTC) From: Alexander Holler To: linux-kernel@vger.kernel.org Cc: Andrew Morton , John Stultz , Thomas Gleixner , Alessandro Zummo , rtc-linux@googlegroups.com, Alexander Holler Subject: [rtc-linux] [PATCH 1/3] RFC: timekeeping: introduce flag systime_was_set Date: Wed, 5 Jun 2013 19:15:38 +0200 Message-Id: <1370452540-3319-2-git-send-email-holler@ahsoftware.de> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1370452540-3319-1-git-send-email-holler@ahsoftware.de> References: <51ADEE76.7090504@ahsoftware.de> <1370452540-3319-1-git-send-email-holler@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: , In order to let an RTC set the time at boot without the problem that a second RTC overwrites it, the flag systime_was_set is introduced. systime_was_set will be true, if a persistent clock sets the time at boot, or if do_settimeofday() is called (e.g. by the RTC subsystem or userspace). Signed-off-by: Alexander Holler --- include/linux/time.h | 6 ++++++ kernel/time/timekeeping.c | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/time.h b/include/linux/time.h index d5d229b..888280f 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 98cd470..07f151f 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -37,6 +37,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; + static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) { @@ -498,6 +501,9 @@ int do_settimeofday(const struct timespec *tv) raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&timekeeper_seq); + systime_was_set = true; + + timekeeping_forward_now(tk); xt = tk_xtime(tk); @@ -781,8 +787,10 @@ void __init timekeeping_init(void) " Check your CMOS/BIOS settings.\n"); 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)) {