From patchwork Thu Jun 6 10:51:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Holler X-Patchwork-Id: 249383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-bk0-x237.google.com (mail-bk0-x237.google.com [IPv6:2a00:1450:4008:c01::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 6DDD52C00A1 for ; Thu, 6 Jun 2013 20:52:45 +1000 (EST) Received: by mail-bk0-f55.google.com with SMTP id je10sf535376bkc.10 for ; Thu, 06 Jun 2013 03:52:41 -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=YCK5fIdS4L4kLeC70t+hsE2q/uSBIMhzd8Aml3uMUdBcaKfZmG0h1+iFAUXFJhkTpS 6JvfTLsUWFunqIaeE67OIPlBZG9/Bf9sC762cl2LxdlHfwwXwn2KijK8iT57h7/vbbbC oVvPSCTeJ1ZbWnvbcvDl7mm8rPi9m14dVxBd+ciCX7YqRZ377CPwLbYWKlFA4puByn9J Zt8PZtWjrSEdoPYhla2s7TBMarC1rUfMl9xYfDhjU2tKJLMnRYqSCO2HPDkLass3H/7Y fLydW7NvqkWZ5aoJgkKlkKmLbvTDBxGIQfOuaVKwwSmIZq2TYGMeBspltH/rXHUDdp2U 0cng== X-Received: by 10.180.77.4 with SMTP id o4mr1155512wiw.21.1370515961760; Thu, 06 Jun 2013 03:52:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.88.196 with SMTP id bi4ls844431wib.47.gmail; Thu, 06 Jun 2013 03:52:40 -0700 (PDT) X-Received: by 10.204.228.202 with SMTP id jf10mr3127100bkb.2.1370515960943; Thu, 06 Jun 2013 03:52:40 -0700 (PDT) Received: from mail.ahsoftware.de (h1446028.stratoserver.net. [85.214.92.142]) by gmr-mx.google.com with ESMTP id cm16si5408614bkb.0.2013.06.06.03.52.40 for ; Thu, 06 Jun 2013 03:52:40 -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 B1A45888C12; Thu, 6 Jun 2013 12:52:40 +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 (p57B205D7.dip0.t-ipconnect.de [87.178.5.215]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ahsoftware.de (Postfix) with ESMTPSA id F2D1C888BD0 for ; Thu, 6 Jun 2013 12:52:39 +0200 (CEST) Received: by eiche.ahsoftware (Postfix, from userid 65534) id 566407F810; Thu, 6 Jun 2013 12:52:39 +0200 (CEST) Received: from laptopahbt.ahsoftware (unknown [192.168.211.6]) by eiche.ahsoftware (Postfix) with ESMTP id ACC8280682; Thu, 6 Jun 2013 10:52:28 +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 RESEND] RFC: timekeeping: introduce flag systime_was_set Date: Thu, 6 Jun 2013 12:51:48 +0200 Message-Id: <1370515910-2883-2-git-send-email-holler@ahsoftware.de> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1370515910-2883-1-git-send-email-holler@ahsoftware.de> References: <1370452540-3319-1-git-send-email-holler@ahsoftware.de> <1370515910-2883-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)) {