From: tglx@linutronix.de
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org, rostedt@goodmis.org, johnstul@us.ibm.com,
zippel@linux-m86k.org, mingo@elte.hu
Subject: [patch 03/21] Deinline mktime and set_normalized_timespec
Date: Tue, 06 Dec 2005 01:01:29 +0100 [thread overview]
Message-ID: <20051206000153.102392000@tglx.tec.linutronix.de> (raw)
In-Reply-To: 20051206000126.589223000@tglx.tec.linutronix.de
[-- Attachment #1: deinline-mktime-set-normalized-timespec.patch --]
[-- Type: text/plain, Size: 5237 bytes --]
- mktime() and set_normalized_timespec() are large inline functions used
in many places: deinline them.
From: George Anzinger, off-by-1 bugfix
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/time.h | 52 ++++---------------------------------------
kernel/time.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 47 deletions(-)
Index: linux-2.6.15-rc5/include/linux/time.h
===================================================================
--- linux-2.6.15-rc5.orig/include/linux/time.h
+++ linux-2.6.15-rc5/include/linux/time.h
@@ -38,38 +38,9 @@ static __inline__ int timespec_equal(str
return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
}
-/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
- * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
- * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
- *
- * [For the Julian calendar (which was used in Russia before 1917,
- * Britain & colonies before 1752, anywhere else before 1582,
- * and is still in use by some communities) leave out the
- * -year/100+year/400 terms, and add 10.]
- *
- * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines were long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
- */
-static inline unsigned long
-mktime (unsigned int year, unsigned int mon,
- unsigned int day, unsigned int hour,
- unsigned int min, unsigned int sec)
-{
- if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
- mon += 12; /* Puts Feb last since it has leap day */
- year -= 1;
- }
-
- return (((
- (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
- year*365 - 719499
- )*24 + hour /* now have hours */
- )*60 + min /* now have minutes */
- )*60 + sec; /* finally seconds */
-}
+extern unsigned long mktime (unsigned int year, unsigned int mon,
+ unsigned int day, unsigned int hour,
+ unsigned int min, unsigned int sec);
extern struct timespec xtime;
extern struct timespec wall_to_monotonic;
@@ -80,6 +51,8 @@ static inline unsigned long get_seconds(
return xtime.tv_sec;
}
+extern void set_normalized_timespec (struct timespec *ts, time_t sec, long nsec);
+
struct timespec current_kernel_time(void);
#define CURRENT_TIME (current_kernel_time())
@@ -98,21 +71,6 @@ extern void getnstimeofday (struct times
extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
-static inline void
-set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
-{
- while (nsec >= NSEC_PER_SEC) {
- nsec -= NSEC_PER_SEC;
- ++sec;
- }
- while (nsec < 0) {
- nsec += NSEC_PER_SEC;
- --sec;
- }
- ts->tv_sec = sec;
- ts->tv_nsec = nsec;
-}
-
#endif /* __KERNEL__ */
#define NFDBITS __NFDBITS
Index: linux-2.6.15-rc5/kernel/time.c
===================================================================
--- linux-2.6.15-rc5.orig/kernel/time.c
+++ linux-2.6.15-rc5/kernel/time.c
@@ -561,6 +561,67 @@ void getnstimeofday(struct timespec *tv)
EXPORT_SYMBOL_GPL(getnstimeofday);
#endif
+/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
+ * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
+ * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
+ *
+ * [For the Julian calendar (which was used in Russia before 1917,
+ * Britain & colonies before 1752, anywhere else before 1582,
+ * and is still in use by some communities) leave out the
+ * -year/100+year/400 terms, and add 10.]
+ *
+ * This algorithm was first published by Gauss (I think).
+ *
+ * WARNING: this function will overflow on 2106-02-07 06:28:16 on
+ * machines were long is 32-bit! (However, as time_t is signed, we
+ * will already get problems at other places on 2038-01-19 03:14:08)
+ */
+unsigned long
+mktime (unsigned int year, unsigned int mon,
+ unsigned int day, unsigned int hour,
+ unsigned int min, unsigned int sec)
+{
+ if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
+ mon += 12; /* Puts Feb last since it has leap day */
+ year -= 1;
+ }
+
+ return ((((unsigned long)
+ (year/4 - year/100 + year/400 + 367*mon/12 + day) +
+ year*365 - 719499
+ )*24 + hour /* now have hours */
+ )*60 + min /* now have minutes */
+ )*60 + sec; /* finally seconds */
+}
+
+/**
+ * set_normalized_timespec - set timespec sec and nsec parts and normalize
+ *
+ * @ts: pointer to timespec variable to be set
+ * @sec: seconds to set
+ * @nsec: nanoseconds to set
+ *
+ * Set seconds and nanoseconds field of a timespec variable and
+ * normalize to the timespec storage format
+ *
+ * Note: The tv_nsec part is always in the range of
+ * 0 <= tv_nsec < NSEC_PER_SEC
+ * For negative values only the tv_sec field is negative !
+ */
+void set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
+{
+ while (nsec >= NSEC_PER_SEC) {
+ nsec -= NSEC_PER_SEC;
+ ++sec;
+ }
+ while (nsec < 0) {
+ nsec += NSEC_PER_SEC;
+ --sec;
+ }
+ ts->tv_sec = sec;
+ ts->tv_nsec = nsec;
+}
+
#if (BITS_PER_LONG < 64)
u64 get_jiffies_64(void)
{
--
next prev parent reply other threads:[~2005-12-06 0:34 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-06 0:01 [patch 00/21] hrtimer - High-resolution timer subsystem tglx
2005-12-06 0:01 ` [patch 01/21] Move div_long_long_rem out of jiffies.h tglx
2005-12-06 0:01 ` [patch 02/21] Remove duplicate div_long_long_rem implementation tglx
2005-12-06 0:01 ` tglx [this message]
2005-12-06 0:01 ` [patch 04/21] Clean up mktime and make arguments const tglx
2005-12-06 0:01 ` [patch 05/21] Export deinlined mktime tglx
2005-12-06 0:01 ` [patch 06/21] Remove unused clock constants tglx
2005-12-06 0:01 ` [patch 07/21] Coding style clean up of " tglx
2005-12-06 0:01 ` [patch 08/21] Coding style and white space cleanup tglx
2005-12-06 0:01 ` [patch 09/21] Make clockid_t arguments const tglx
2005-12-06 0:01 ` [patch 10/21] Coding style and white space cleanup tglx
2005-12-06 0:01 ` [patch 11/21] Create and use timespec_valid macro tglx
2005-12-06 0:01 ` [patch 12/21] Validate timespec of do_sys_settimeofday tglx
2005-12-06 0:01 ` [patch 13/21] Introduce nsec_t type and conversion functions tglx
2005-12-06 0:01 ` [patch 14/21] Introduce ktime_t time format tglx
2005-12-06 0:01 ` [patch 15/21] hrtimer core code tglx
2005-12-15 3:43 ` Matt Helsley
2005-12-06 0:01 ` [patch 16/21] hrtimer documentation tglx
2005-12-06 0:01 ` [patch 17/21] Switch itimers to hrtimer tglx
2005-12-06 0:01 ` [patch 18/21] Create hrtimer nanosleep API tglx
2005-12-06 0:01 ` [patch 19/21] Switch sys_nanosleep to hrtimer tglx
2005-12-06 0:01 ` [patch 20/21] Switch clock_nanosleep to hrtimer nanosleep API tglx
2005-12-06 0:01 ` [patch 21/21] Convert posix timers completely tglx
2005-12-06 17:32 ` [patch 00/21] hrtimer - High-resolution timer subsystem Roman Zippel
2005-12-06 19:07 ` Ingo Molnar
2005-12-07 3:05 ` Roman Zippel
2005-12-08 5:18 ` Paul Jackson
2005-12-08 8:12 ` Ingo Molnar
2005-12-08 9:26 ` Ingo Molnar
2005-12-08 13:08 ` Roman Zippel
2005-12-08 15:36 ` Steven Rostedt
2005-12-06 22:10 ` Thomas Gleixner
2005-12-07 3:11 ` Roman Zippel
2005-12-06 22:28 ` Thomas Gleixner
2005-12-07 9:31 ` Andrew Morton
2005-12-07 10:11 ` Ingo Molnar
2005-12-07 10:20 ` Ingo Molnar
2005-12-07 10:23 ` Nick Piggin
2005-12-07 10:49 ` Ingo Molnar
2005-12-07 11:09 ` Nick Piggin
2005-12-07 11:33 ` Ingo Molnar
2005-12-07 11:40 ` Nick Piggin
2005-12-07 13:06 ` Roman Zippel
2005-12-07 12:40 ` Roman Zippel
2005-12-07 23:12 ` Nick Piggin
2005-12-07 12:18 ` Roman Zippel
2005-12-07 16:55 ` Ingo Molnar
2005-12-07 17:17 ` Roman Zippel
2005-12-07 17:57 ` Ingo Molnar
2005-12-07 18:18 ` Roman Zippel
2005-12-07 18:02 ` Paul Baxter
2005-12-09 17:23 ` Thomas Gleixner
2005-12-12 13:39 ` Roman Zippel
2005-12-12 16:42 ` Thomas Gleixner
2005-12-12 18:37 ` Thomas Gleixner
2005-12-13 1:25 ` George Anzinger
2005-12-13 9:18 ` Thomas Gleixner
2005-12-15 1:35 ` Roman Zippel
2005-12-15 2:29 ` George Anzinger
2005-12-19 14:56 ` Roman Zippel
2005-12-19 20:54 ` George Anzinger
2005-12-21 23:03 ` Roman Zippel
2005-12-22 4:30 ` George Anzinger
2005-12-14 20:48 ` Roman Zippel
2005-12-14 22:30 ` Thomas Gleixner
2005-12-15 0:55 ` George Anzinger
2005-12-15 14:18 ` Steven Rostedt
2005-12-19 14:50 ` Roman Zippel
2005-12-19 22:05 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051206000153.102392000@tglx.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=akpm@osdl.org \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=zippel@linux-m86k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).