]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
time: move the timecounter/cyclecounter code into its own file.
authorRichard Cochran <richardcochran@gmail.com>
Sun, 21 Dec 2014 18:46:56 +0000 (19:46 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 30 Dec 2014 23:29:25 +0000 (18:29 -0500)
The timecounter code has almost nothing to do with the clocksource
code. Let it live in its own file. This will help isolate the
timecounter users from the clocksource users in the source tree.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
16 files changed:
drivers/net/ethernet/amd/xgbe/xgbe.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/intel/e1000e/e1000.h
drivers/net/ethernet/intel/igb/igb.h
drivers/net/ethernet/intel/ixgbe/ixgbe.h
drivers/net/ethernet/ti/cpts.h
include/clocksource/arm_arch_timer.h
include/linux/clocksource.h
include/linux/mlx4/device.h
include/linux/timecounter.h [new file with mode: 0644]
include/linux/types.h
kernel/time/Makefile
kernel/time/clocksource.c
kernel/time/timecounter.c [new file with mode: 0644]
sound/pci/hda/hda_priv.h

index f9ec762ac3f037e780c3f44f70fec2e5bf06577b..2af6affc35a7c7ac322a62fb692d6ec4e49edd03 100644 (file)
 #include <linux/if_vlan.h>
 #include <linux/bitops.h>
 #include <linux/ptp_clock_kernel.h>
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 #include <linux/net_tstamp.h>
 #include <net/dcbnl.h>
 
index c3a6072134f58c0f2df719b9badf102400a92043..792ba72fb5c815cded9d20cc01024e7c7678f380 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <linux/ptp_clock_kernel.h>
 #include <linux/net_tstamp.h>
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 
 /* compilation time flags */
 
index 469691ad4a1ee25dda5ff9dbec0ef8735ae0f6bf..df8bbddaeb37ea5f168d3c19522924dabff2fc6c 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/clocksource.h>
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
+#include <linux/timecounter.h>
 
 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
     defined(CONFIG_M520x) || defined(CONFIG_M532x) || \
index 7785240a0da1a1b409cfbc3d4b18ff63b5f2966a..9416e5a7e0c82262b078ebda3b1374b8ce58934d 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/pci-aspm.h>
 #include <linux/crc32.h>
 #include <linux/if_vlan.h>
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/ptp_classify.h>
index 82d891e183b18f3e2e675dc6778b85bf555e67cc..ee22da391474275c77380e6268c7a7038e04e641 100644 (file)
@@ -29,7 +29,7 @@
 #include "e1000_mac.h"
 #include "e1000_82575.h"
 
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/bitops.h>
index b6137be43920ddd47f27b2684250105a4b575e28..38fc64cf5dca0de5cf4e7e47d1c16b0d51aad202 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/if_vlan.h>
 #include <linux/jiffies.h>
 
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
 
index 1a581ef7eee8fcbd2ed121d64a747e06e84c6113..69a46b92c7d6cdb540299c17847334784fc9fb4d 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/skbuff.h>
+#include <linux/timecounter.h>
 
 struct cpsw_cpts {
        u32 idver;                /* Identification and version */
index 6d26b40cbf5d29c7d80c83a9fe22b4f9e85a0b70..9916d0e4eff505f18cf5e30ad52dbe2e37b3fa3b 100644 (file)
@@ -16,7 +16,7 @@
 #ifndef __CLKSOURCE_ARM_ARCH_TIMER_H
 #define __CLKSOURCE_ARM_ARCH_TIMER_H
 
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 #include <linux/types.h>
 
 #define ARCH_TIMER_CTRL_ENABLE         (1 << 0)
index abcafaa20b868f6b836eb7aa17ce168a41b97fc8..9c78d15d33e4de979b3d70d6a569064aa5529048 100644 (file)
@@ -18,8 +18,6 @@
 #include <asm/div64.h>
 #include <asm/io.h>
 
-/* clocksource cycle base type */
-typedef u64 cycle_t;
 struct clocksource;
 struct module;
 
@@ -27,106 +25,6 @@ struct module;
 #include <asm/clocksource.h>
 #endif
 
-/**
- * struct cyclecounter - hardware abstraction for a free running counter
- *     Provides completely state-free accessors to the underlying hardware.
- *     Depending on which hardware it reads, the cycle counter may wrap
- *     around quickly. Locking rules (if necessary) have to be defined
- *     by the implementor and user of specific instances of this API.
- *
- * @read:              returns the current cycle value
- * @mask:              bitmask for two's complement
- *                     subtraction of non 64 bit counters,
- *                     see CLOCKSOURCE_MASK() helper macro
- * @mult:              cycle to nanosecond multiplier
- * @shift:             cycle to nanosecond divisor (power of two)
- */
-struct cyclecounter {
-       cycle_t (*read)(const struct cyclecounter *cc);
-       cycle_t mask;
-       u32 mult;
-       u32 shift;
-};
-
-/**
- * struct timecounter - layer above a %struct cyclecounter which counts nanoseconds
- *     Contains the state needed by timecounter_read() to detect
- *     cycle counter wrap around. Initialize with
- *     timecounter_init(). Also used to convert cycle counts into the
- *     corresponding nanosecond counts with timecounter_cyc2time(). Users
- *     of this code are responsible for initializing the underlying
- *     cycle counter hardware, locking issues and reading the time
- *     more often than the cycle counter wraps around. The nanosecond
- *     counter will only wrap around after ~585 years.
- *
- * @cc:                        the cycle counter used by this instance
- * @cycle_last:                most recent cycle counter value seen by
- *                     timecounter_read()
- * @nsec:              continuously increasing count
- */
-struct timecounter {
-       const struct cyclecounter *cc;
-       cycle_t cycle_last;
-       u64 nsec;
-};
-
-/**
- * cyclecounter_cyc2ns - converts cycle counter cycles to nanoseconds
- * @cc:                Pointer to cycle counter.
- * @cycles:    Cycles
- *
- * XXX - This could use some mult_lxl_ll() asm optimization. Same code
- * as in cyc2ns, but with unsigned result.
- */
-static inline u64 cyclecounter_cyc2ns(const struct cyclecounter *cc,
-                                     cycle_t cycles)
-{
-       u64 ret = (u64)cycles;
-       ret = (ret * cc->mult) >> cc->shift;
-       return ret;
-}
-
-/**
- * timecounter_init - initialize a time counter
- * @tc:                        Pointer to time counter which is to be initialized/reset
- * @cc:                        A cycle counter, ready to be used.
- * @start_tstamp:      Arbitrary initial time stamp.
- *
- * After this call the current cycle register (roughly) corresponds to
- * the initial time stamp. Every call to timecounter_read() increments
- * the time stamp counter by the number of elapsed nanoseconds.
- */
-extern void timecounter_init(struct timecounter *tc,
-                            const struct cyclecounter *cc,
-                            u64 start_tstamp);
-
-/**
- * timecounter_read - return nanoseconds elapsed since timecounter_init()
- *                    plus the initial time stamp
- * @tc:          Pointer to time counter.
- *
- * In other words, keeps track of time since the same epoch as
- * the function which generated the initial time stamp.
- */
-extern u64 timecounter_read(struct timecounter *tc);
-
-/**
- * timecounter_cyc2time - convert a cycle counter to same
- *                        time base as values returned by
- *                        timecounter_read()
- * @tc:                Pointer to time counter.
- * @cycle_tstamp:      a value returned by tc->cc->read()
- *
- * Cycle counts that are converted correctly as long as they
- * fall into the interval [-1/2 max cycle count, +1/2 max cycle count],
- * with "max cycle count" == cs->mask+1.
- *
- * This allows conversion of cycle counter values which were generated
- * in the past.
- */
-extern u64 timecounter_cyc2time(struct timecounter *tc,
-                               cycle_t cycle_tstamp);
-
 /**
  * struct clocksource - hardware abstraction for a free running counter
  *     Provides mostly state-free accessors to the underlying hardware.
index 25c791e295fd5355650a3db42bc69ddc1adf2cc8..f1e41b33462fc0f261edf58f67005dfa0605bcb1 100644 (file)
@@ -42,7 +42,7 @@
 
 #include <linux/atomic.h>
 
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 
 #define MAX_MSIX_P_PORT                17
 #define MAX_MSIX               64
diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
new file mode 100644 (file)
index 0000000..146f07a
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * linux/include/linux/timecounter.h
+ *
+ * based on code that migrated away from
+ * linux/include/linux/clocksource.h
+ *
+ * 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.
+ */
+#ifndef _LINUX_TIMECOUNTER_H
+#define _LINUX_TIMECOUNTER_H
+
+#include <linux/types.h>
+
+/**
+ * struct cyclecounter - hardware abstraction for a free running counter
+ *     Provides completely state-free accessors to the underlying hardware.
+ *     Depending on which hardware it reads, the cycle counter may wrap
+ *     around quickly. Locking rules (if necessary) have to be defined
+ *     by the implementor and user of specific instances of this API.
+ *
+ * @read:              returns the current cycle value
+ * @mask:              bitmask for two's complement
+ *                     subtraction of non 64 bit counters,
+ *                     see CLOCKSOURCE_MASK() helper macro
+ * @mult:              cycle to nanosecond multiplier
+ * @shift:             cycle to nanosecond divisor (power of two)
+ */
+struct cyclecounter {
+       cycle_t (*read)(const struct cyclecounter *cc);
+       cycle_t mask;
+       u32 mult;
+       u32 shift;
+};
+
+/**
+ * struct timecounter - layer above a %struct cyclecounter which counts nanoseconds
+ *     Contains the state needed by timecounter_read() to detect
+ *     cycle counter wrap around. Initialize with
+ *     timecounter_init(). Also used to convert cycle counts into the
+ *     corresponding nanosecond counts with timecounter_cyc2time(). Users
+ *     of this code are responsible for initializing the underlying
+ *     cycle counter hardware, locking issues and reading the time
+ *     more often than the cycle counter wraps around. The nanosecond
+ *     counter will only wrap around after ~585 years.
+ *
+ * @cc:                        the cycle counter used by this instance
+ * @cycle_last:                most recent cycle counter value seen by
+ *                     timecounter_read()
+ * @nsec:              continuously increasing count
+ */
+struct timecounter {
+       const struct cyclecounter *cc;
+       cycle_t cycle_last;
+       u64 nsec;
+};
+
+/**
+ * cyclecounter_cyc2ns - converts cycle counter cycles to nanoseconds
+ * @cc:                Pointer to cycle counter.
+ * @cycles:    Cycles
+ *
+ * XXX - This could use some mult_lxl_ll() asm optimization. Same code
+ * as in cyc2ns, but with unsigned result.
+ */
+static inline u64 cyclecounter_cyc2ns(const struct cyclecounter *cc,
+                                     cycle_t cycles)
+{
+       u64 ret = (u64)cycles;
+       ret = (ret * cc->mult) >> cc->shift;
+       return ret;
+}
+
+/**
+ * timecounter_init - initialize a time counter
+ * @tc:                        Pointer to time counter which is to be initialized/reset
+ * @cc:                        A cycle counter, ready to be used.
+ * @start_tstamp:      Arbitrary initial time stamp.
+ *
+ * After this call the current cycle register (roughly) corresponds to
+ * the initial time stamp. Every call to timecounter_read() increments
+ * the time stamp counter by the number of elapsed nanoseconds.
+ */
+extern void timecounter_init(struct timecounter *tc,
+                            const struct cyclecounter *cc,
+                            u64 start_tstamp);
+
+/**
+ * timecounter_read - return nanoseconds elapsed since timecounter_init()
+ *                    plus the initial time stamp
+ * @tc:          Pointer to time counter.
+ *
+ * In other words, keeps track of time since the same epoch as
+ * the function which generated the initial time stamp.
+ */
+extern u64 timecounter_read(struct timecounter *tc);
+
+/**
+ * timecounter_cyc2time - convert a cycle counter to same
+ *                        time base as values returned by
+ *                        timecounter_read()
+ * @tc:                Pointer to time counter.
+ * @cycle_tstamp:      a value returned by tc->cc->read()
+ *
+ * Cycle counts that are converted correctly as long as they
+ * fall into the interval [-1/2 max cycle count, +1/2 max cycle count],
+ * with "max cycle count" == cs->mask+1.
+ *
+ * This allows conversion of cycle counter values which were generated
+ * in the past.
+ */
+extern u64 timecounter_cyc2time(struct timecounter *tc,
+                               cycle_t cycle_tstamp);
+
+#endif
index a0bb7048687f565ea959ae21fde70d2cec8282ce..62323825cff943043c5ddf3ec34e84a2b8bc743b 100644 (file)
@@ -213,5 +213,8 @@ struct callback_head {
 };
 #define rcu_head callback_head
 
+/* clocksource cycle base type */
+typedef u64 cycle_t;
+
 #endif /*  __ASSEMBLY__ */
 #endif /* _LINUX_TYPES_H */
index f622cf28628adf6cd116bfdaa2c9acaf0212a392..c09c07817d7a7c854a1b88b12b894f60c547cda9 100644 (file)
@@ -1,6 +1,6 @@
 obj-y += time.o timer.o hrtimer.o itimer.o posix-timers.o posix-cpu-timers.o
 obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
-obj-y += timeconv.o posix-clock.o alarmtimer.o
+obj-y += timeconv.o timecounter.o posix-clock.o alarmtimer.o
 
 obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)                += clockevents.o
 obj-$(CONFIG_GENERIC_CLOCKEVENTS)              += tick-common.o
index b79f39bda7e111436be3b8245f26e77407fdab97..4892352f0e4989c561c5d16ba3b27c063082a8f6 100644 (file)
 #include "tick-internal.h"
 #include "timekeeping_internal.h"
 
-void timecounter_init(struct timecounter *tc,
-                     const struct cyclecounter *cc,
-                     u64 start_tstamp)
-{
-       tc->cc = cc;
-       tc->cycle_last = cc->read(cc);
-       tc->nsec = start_tstamp;
-}
-EXPORT_SYMBOL_GPL(timecounter_init);
-
-/**
- * timecounter_read_delta - get nanoseconds since last call of this function
- * @tc:         Pointer to time counter
- *
- * When the underlying cycle counter runs over, this will be handled
- * correctly as long as it does not run over more than once between
- * calls.
- *
- * The first call to this function for a new time counter initializes
- * the time tracking and returns an undefined result.
- */
-static u64 timecounter_read_delta(struct timecounter *tc)
-{
-       cycle_t cycle_now, cycle_delta;
-       u64 ns_offset;
-
-       /* read cycle counter: */
-       cycle_now = tc->cc->read(tc->cc);
-
-       /* calculate the delta since the last timecounter_read_delta(): */
-       cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask;
-
-       /* convert to nanoseconds: */
-       ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta);
-
-       /* update time stamp of timecounter_read_delta() call: */
-       tc->cycle_last = cycle_now;
-
-       return ns_offset;
-}
-
-u64 timecounter_read(struct timecounter *tc)
-{
-       u64 nsec;
-
-       /* increment time by nanoseconds since last call */
-       nsec = timecounter_read_delta(tc);
-       nsec += tc->nsec;
-       tc->nsec = nsec;
-
-       return nsec;
-}
-EXPORT_SYMBOL_GPL(timecounter_read);
-
-u64 timecounter_cyc2time(struct timecounter *tc,
-                        cycle_t cycle_tstamp)
-{
-       u64 cycle_delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
-       u64 nsec;
-
-       /*
-        * Instead of always treating cycle_tstamp as more recent
-        * than tc->cycle_last, detect when it is too far in the
-        * future and treat it as old time stamp instead.
-        */
-       if (cycle_delta > tc->cc->mask / 2) {
-               cycle_delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
-               nsec = tc->nsec - cyclecounter_cyc2ns(tc->cc, cycle_delta);
-       } else {
-               nsec = cyclecounter_cyc2ns(tc->cc, cycle_delta) + tc->nsec;
-       }
-
-       return nsec;
-}
-EXPORT_SYMBOL_GPL(timecounter_cyc2time);
-
 /**
  * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks
  * @mult:      pointer to mult variable
diff --git a/kernel/time/timecounter.c b/kernel/time/timecounter.c
new file mode 100644 (file)
index 0000000..59a1ec3
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * linux/kernel/time/timecounter.c
+ *
+ * based on code that migrated away from
+ * linux/kernel/time/clocksource.c
+ *
+ * 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.
+ */
+
+#include <linux/export.h>
+#include <linux/timecounter.h>
+
+void timecounter_init(struct timecounter *tc,
+                     const struct cyclecounter *cc,
+                     u64 start_tstamp)
+{
+       tc->cc = cc;
+       tc->cycle_last = cc->read(cc);
+       tc->nsec = start_tstamp;
+}
+EXPORT_SYMBOL_GPL(timecounter_init);
+
+/**
+ * timecounter_read_delta - get nanoseconds since last call of this function
+ * @tc:         Pointer to time counter
+ *
+ * When the underlying cycle counter runs over, this will be handled
+ * correctly as long as it does not run over more than once between
+ * calls.
+ *
+ * The first call to this function for a new time counter initializes
+ * the time tracking and returns an undefined result.
+ */
+static u64 timecounter_read_delta(struct timecounter *tc)
+{
+       cycle_t cycle_now, cycle_delta;
+       u64 ns_offset;
+
+       /* read cycle counter: */
+       cycle_now = tc->cc->read(tc->cc);
+
+       /* calculate the delta since the last timecounter_read_delta(): */
+       cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask;
+
+       /* convert to nanoseconds: */
+       ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta);
+
+       /* update time stamp of timecounter_read_delta() call: */
+       tc->cycle_last = cycle_now;
+
+       return ns_offset;
+}
+
+u64 timecounter_read(struct timecounter *tc)
+{
+       u64 nsec;
+
+       /* increment time by nanoseconds since last call */
+       nsec = timecounter_read_delta(tc);
+       nsec += tc->nsec;
+       tc->nsec = nsec;
+
+       return nsec;
+}
+EXPORT_SYMBOL_GPL(timecounter_read);
+
+u64 timecounter_cyc2time(struct timecounter *tc,
+                        cycle_t cycle_tstamp)
+{
+       u64 cycle_delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+       u64 nsec;
+
+       /*
+        * Instead of always treating cycle_tstamp as more recent
+        * than tc->cycle_last, detect when it is too far in the
+        * future and treat it as old time stamp instead.
+        */
+       if (cycle_delta > tc->cc->mask / 2) {
+               cycle_delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
+               nsec = tc->nsec - cyclecounter_cyc2ns(tc->cc, cycle_delta);
+       } else {
+               nsec = cyclecounter_cyc2ns(tc->cc, cycle_delta) + tc->nsec;
+       }
+
+       return nsec;
+}
+EXPORT_SYMBOL_GPL(timecounter_cyc2time);
index 166e3e84b963875eec1d854e9ef8e2d434df0edb..daf458299753fae6f2ca59571d34508763522d1d 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef __SOUND_HDA_PRIV_H
 #define __SOUND_HDA_PRIV_H
 
-#include <linux/clocksource.h>
+#include <linux/timecounter.h>
 #include <sound/core.h>
 #include <sound/pcm.h>