lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 27 Apr 2012 10:12:40 +0200
From:	Richard Cochran <richardcochran@...il.com>
To:	<linux-kernel@...r.kernel.org>
Cc:	John Stultz <john.stultz@...aro.org>,
	Thomas Gleixner <tglx@...utronix.de>
Subject: [PATCH RFC V1 1/5] Add functions to convert continuous timescales to UTC.

This patch adds a pair of inline helper functions to convert from
one timescale to the other, around a given leap second threshold.
Also, it adds an academic compile time option to support deleting
leap seconds.

Signed-off-by: Richard Cochran <richardcochran@...il.com>
---
 kernel/time/Kconfig   |   12 ++++++
 kernel/time/utc-tai.h |   99 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+), 0 deletions(-)
 create mode 100644 kernel/time/utc-tai.h

diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig
index a20dc8a..1569aef 100644
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -26,6 +26,18 @@ config HIGH_RES_TIMERS
 	  hardware is not capable then this option only increases
 	  the size of the kernel image.
 
+config DELETE_LEAP_SECONDS
+	bool "Support deletion of leap seconds"
+	default y
+	help
+	  This option enables support for leap second deletion via the
+	  STA_DEL control bit in the NTP adjtimex system call.
+
+	  Historically, leap seconds have only ever been inserted,
+	  never deleted. Saying no here results in a slightly smaller
+	  kernel image. If you believe that Earth's rotational speed
+	  might one day increase, then say yes here.
+
 config GENERIC_CLOCKEVENTS_BUILD
 	bool
 	default y
diff --git a/kernel/time/utc-tai.h b/kernel/time/utc-tai.h
new file mode 100644
index 0000000..ffc3ae9
--- /dev/null
+++ b/kernel/time/utc-tai.h
@@ -0,0 +1,99 @@
+/*
+ * linux/kernel/time/utc-tai.h
+ *
+ * Converts between TAI and UTC by applying the offset correction.
+ *
+ * Copyright (C) 2012 Richard Cochran <richardcochran@...il.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#ifndef __LINUX_KERNEL_TIME_UTC_TAI_H
+#define __LINUX_KERNEL_TIME_UTC_TAI_H
+
+#include <linux/types.h>
+
+static inline time_t __tai_to_utc(time_t tai, time_t next, int offset)
+{
+	time_t utc = tai - offset;
+
+	if (unlikely(tai >= next))
+		utc--;
+
+	return utc;
+}
+
+static inline time_t __utc_to_tai(time_t utc, time_t next, int offset)
+{
+	time_t leapsec = next - offset;
+	time_t result = utc + offset;
+
+	if (unlikely(utc >= leapsec))
+		result++;
+
+	return result;
+}
+
+#ifdef CONFIG_DELETE_LEAP_SECONDS
+
+static inline time_t tai_to_utc(time_t tai, time_t next, int offset, int insert)
+{
+	if (likely(insert))
+		return __tai_to_utc(tai, next, offset);
+
+	if (unlikely(tai > next))
+		return tai - offset + 1;
+
+	return tai - offset;
+}
+
+static inline time_t utc_to_tai(time_t utc, time_t next, int offset, int insert)
+{
+	time_t leapsec, result;
+
+	if (likely(insert))
+		return __utc_to_tai(utc, next, offset);
+
+	leapsec = next - offset + 1;
+
+	if (unlikely(utc > leapsec))
+		result = utc + offset - 1;
+	else if (utc < leapsec)
+		result = utc + offset;
+	else {
+		/*
+		 * Ouch, this time never existed.
+		 */
+		result = next;
+	}
+
+	return result;
+}
+
+#else /*CONFIG_DELETE_LEAP_SECONDS*/
+
+static inline time_t tai_to_utc(time_t tai, time_t next, int offset, int insert)
+{
+	return __tai_to_utc(tai, next, offset);
+}
+
+static inline time_t utc_to_tai(time_t utc, time_t next, int offset, int insert)
+{
+	return __utc_to_tai(utc, next, offset);
+}
+
+#endif /*!CONFIG_DELETE_LEAP_SECONDS*/
+
+#endif
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ