ptp: IEEE 1588 hardware clock support
Subsystems (15)
Richard Cochran
maintainerv8 cover ptp: IEEE 1588 hardware clock support
* Introduction
The aim of this patch set is to add support for PTP Hardware Clocks (PHCs) into the Linux kernel.
* PTP Patch ChangeLog
** v8
- incorporates Arnd Bergmann's and Thomas Gleixner's comments from v7
- use John Stultz's timekeeping_inject_offset in do_adjtimex()
- adds new syscall clock_adjtime to each arch individually
- cleaned up the CLOCK_DISPATCH mess
- redsigned posix_clock_operations:
. remove compat_ioctl
. flatten clock ops and chardev ops into one structure . drivers use container_of to get private data
- removed unused and useless code from posix-clock.c|h
- moved posix-clock syscall prototypes into private header
- moved extern declaration from c source file into header
- ptp drivers use container_of to get private data
* Previous Discussions
This patch set previously appeared on the netdev list. Since V5 of the character device patch set, the discussion has moved to the lkml.
- IEEE 1588 hardware clock support [V5]
http://lkml.org/lkml/2010/8/16/90
- POSIX clock tuning syscall with static clock ids
http://lkml.org/lkml/2010/8/23/49
- POSIX clock tuning syscall with dynamic clock ids
http://lkml.org/lkml/2010/9/3/119
- IEEE 1588 hardware clock support [V6]
http://lkml.org/lkml/2010/9/23/310
- Dynamic clock devices [RFC]
http://lkml.org/lkml/2010/11/4/290
- IEEE 1588 hardware clock support [V7]
http://lkml.org/lkml/2010/12/16/195
John Stultz (1):
time: Introduce timekeeping_inject_offset
Richard Cochran (12):
ntp: add ADJ_SETOFFSET mode bit
posix clocks: introduce a syscall for clock tuning.
posix_clocks: add clock_adjtime for arm
posix_clocks: add clock_adjtime for blackfin
posix_clocks: add clock_adjtime for powerpc
posix_clocks: add clock_adjtime for x86
posix clocks: cleanup the CLOCK_DISPTACH macro
posix clocks: introduce dynamic clocks
ptp: Added a brand new class driver for ptp clocks.
ptp: Added a clock that uses the eTSEC found on the MPC85xx.
ptp: Added a clock driver for the IXP46x.
ptp: Added a clock driver for the National Semiconductor PHYTER.
Documentation/ABI/testing/sysfs-ptp | 97 +++ Documentation/powerpc/dts-bindings/fsl/tsec.txt | 57 ++ Documentation/ptp/ptp.txt | 93 +++ Documentation/ptp/testptp.c | 352 +++++++++ Documentation/ptp/testptp.mk | 33 + arch/arm/include/asm/unistd.h | 1 + arch/arm/kernel/calls.S | 1 + arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h | 78 ++ arch/blackfin/include/asm/unistd.h | 3 +- arch/blackfin/mach-common/entry.S | 1 + arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 3 +- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 3 +- arch/x86/include/asm/unistd_64.h | 2 + arch/x86/kernel/syscall_table_32.S | 1 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/char/mmtimer.c | 1 + drivers/net/Makefile | 1 + drivers/net/arm/ixp4xx_eth.c | 191 +++++ drivers/net/gianfar_ptp.c | 448 +++++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++ drivers/net/phy/Kconfig | 29 + drivers/net/phy/Makefile | 1 + drivers/net/phy/dp83640.c | 896 +++++++++++++++++++++++ drivers/net/phy/dp83640_reg.h | 261 +++++++ drivers/ptp/Kconfig | 53 ++ drivers/ptp/Makefile | 7 + drivers/ptp/ptp_chardev.c | 146 ++++ drivers/ptp/ptp_clock.c | 318 ++++++++ drivers/ptp/ptp_ixp46x.c | 344 +++++++++ drivers/ptp/ptp_private.h | 86 +++ drivers/ptp/ptp_sysfs.c | 226 ++++++ include/linux/Kbuild | 1 + include/linux/posix-clock.h | 137 ++++ include/linux/posix-timers.h | 23 +- include/linux/ptp_clock.h | 79 ++ include/linux/ptp_clock_kernel.h | 141 ++++ include/linux/syscalls.h | 2 + include/linux/time.h | 3 + include/linux/timex.h | 3 +- kernel/compat.c | 136 +++-- kernel/posix-cpu-timers.c | 6 + kernel/posix-timers.c | 279 ++++++-- kernel/time/Makefile | 3 +- kernel/time/ntp.c | 11 + kernel/time/posix-clock-syscalls.h | 39 + kernel/time/posix-clock.c | 454 ++++++++++++ kernel/time/timekeeping.c | 36 + 54 files changed, 5163 insertions(+), 97 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-ptp create mode 100644 Documentation/ptp/ptp.txt create mode 100644 Documentation/ptp/testptp.c create mode 100644 Documentation/ptp/testptp.mk create mode 100644 arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h create mode 100644 drivers/net/phy/dp83640.c create mode 100644 drivers/net/phy/dp83640_reg.h create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_chardev.c create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_ixp46x.c create mode 100644 drivers/ptp/ptp_private.h create mode 100644 drivers/ptp/ptp_sysfs.c create mode 100644 include/linux/posix-clock.h create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h create mode 100644 kernel/time/posix-clock-syscalls.h create mode 100644 kernel/time/posix-clock.c
John Stultz
maintainerPATCH v8 1/13 time: Introduce timekeeping_inject_offset
This adds a kernel-internal timekeeping interface to add or subtract a fixed amount from CLOCK_REALTIME. This makes it so kernel users or interfaces trying to do so do not have to read the time, then add an offset and then call settimeofday(), which adds some extra error in comparision to just simply adding the offset in the kernel timekeeping core.
--- include/linux/time.h | 1 + kernel/time/timekeeping.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-)
include/linux/time.h +1 -0
@@ -166,6 +166,7 @@ extern int timekeeping_valid_for_hres(void);extern u64 timekeeping_max_deferment (void );extern void update_wall_time (void );extern void timekeeping_leap_insert (int leapsecond); +extern int timekeeping_inject_offset (struct timespec *ts);struct tms ;extern void do_sys_times (struct tms *);
kernel/time/timekeeping.c +36 -0
@@ -340,6 +340,42 @@ int do_settimeofday(struct timespec *tv)EXPORT_SYMBOL (do_settimeofday); + +/** +* timekeeping_inject_offset - Adds or subtracts from the current time. +* @tv: pointer to the timespec variable containing the offset +* +* Adds or subtracts an offset value from the current time. +*/ +int timekeeping_inject_offset (struct timespec *ts) +{ +unsigned long flags; + +if ((unsigned long )ts->tv_nsec >=NSEC_PER_SEC ) +return -EINVAL ; + +write_seqlock_irqsave (&xtime_lock, flags); + +timekeeping_forward_now (); + + xtime =timespec_add (xtime, *ts); + wall_to_monotonic =timespec_sub (wall_to_monotonic, *ts); + + timekeeper.ntp_error =0 ; +ntp_clear (); + +update_vsyscall (&xtime, &wall_to_monotonic, timekeeper.clock, + timekeeper.mult); + +write_sequnlock_irqrestore (&xtime_lock, flags); + +/* signal hrtimers about time change */ +clock_was_set (); + +return 0 ; +} +EXPORT_SYMBOL (timekeeping_inject_offset); +/** * change_clocksource - Swaps clocksources if a new one is available *
Signature · 1 line
1.7.0.4
Arnd Bergmann
maintainerRe: [PATCH V8 01/13] time: Introduce timekeeping_inject_offset
Quoted 1 line · John Stultz
This adds a kernel-internal timekeeping interface to add or subtract
Note that this is not the correct way to submit a patch from someone else.
You should instead use your own name and email address as the sender,
and have "From: John Stultz <johnstul-r/[email protected]>" as the first line in the body of the email. You also need to add your own "Signed-off-by:
Richard Cochran <[email protected]>" line below the S-o-b from John.
Using git-send-email plus git-format-patch will gets this right if the commit was done correctly in your own git tree. If you prefer to use a different set of tools, you need to watch out for these details yourself.
Arnd
Richard Cochran
maintainerPATCH v8 2/13 ntp: add ADJ_SETOFFSET mode bit
In reply to Richard CochranThis patch adds a new mode bit into the timex structure. When set, the bit instructs the kernel to add the given time value to the current time.
--- include/linux/timex.h | 3 ++- kernel/time/ntp.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-)
include/linux/timex.h +2 -1
@@ -73,7 +73,7 @@ struct timex {long tolerance;/* clock frequency tolerance (ppm) * (read only) */ -struct timeval time;/* (read only) */ +struct timeval time;/* (read only, except for ADJ_SETOFFSET) */ long tick;/* (modified) usecs between clock ticks */ long ppsfreq;/* pps frequency (scaled ppm) (ro) */
@@ -101,6 +101,7 @@ struct timex {#define ADJ_ESTERROR 0x0008/* estimated time error */ #define ADJ_STATUS 0x0010/* clock status */ #define ADJ_TIMECONST 0x0020/* pll time constant */ +#define ADJ_SETOFFSET 0x0040/* add 'time' to current time */ #define ADJ_TAI 0x0080/* set TAI offset */ #define ADJ_MICRO 0x1000/* select microsecond resolution */ #define ADJ_NANO 0x2000/* select nanosecond resolution */
kernel/time/ntp.c +11 -0
@@ -482,6 +482,17 @@ int do_adjtimex(struct timex *txc)hrtimer_cancel (&leap_timer); } +if (txc->modes &ADJ_SETOFFSET ) { +struct timespec delta; +if ((unsigned long )txc->time.tv_usec >=NSEC_PER_SEC ) +return -EINVAL ; + delta.tv_sec = txc->time.tv_sec; + delta.tv_nsec = txc->time.tv_usec; +if (!(txc->modes &ADJ_NANO )) + delta.tv_nsec *=1000 ; +timekeeping_inject_offset (&delta); + } +getnstimeofday (&ts);write_seqlock_irq (&xtime_lock);
Signature · 1 line
1.7.0.4
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 1 line · Richard Cochran
+#define
ADJ_SETOFFSET0x0040 /* add 'time' to current time */
As you know, it conflicts with MOD_PPSMAX. And also, it is logically the same as ADJ_OFFSET, unless the kernel PLL is enabled explicitly.
So here's my simple solution:
---
kernel/time/ntp.c +13 -3
@@ -119,14 +119,21 @@return div_s64 (offset64 << (NTP_SCALE_SHIFT -SHIFT_FLL ), secs); } -static void ntp_update_offset (long offset) +static void ntp_update_offset (long offset,struct timespec *ts) {s64 freq_adj;s64 offset64;long secs; -if (!(time_status &STA_PLL )) +if (!(time_status &STA_PLL )) { + offset64 = offset; +if (!(time_status &STA_NANO )) + offset64 *=NSEC_PER_USEC ; + +set_normalized_timespec (ts, ts->tv_sec, offset64 + ts->tv_nsec); +return ; + }if (!(time_status &STA_NANO )) offset *=NSEC_PER_USEC ;
@@ -430,7 +437,7 @@ time_tai = txc->constant;if (txc->modes &ADJ_OFFSET ) -ntp_update_offset (txc->offset); +ntp_update_offset (txc->offset, ts);if (txc->modes &ADJ_TICK ) tick_usec = txc->tick;
@@ -526,6 +533,9 @@write_sequnlock_irq (&xtime_lock); +if ((txc->modes &ADJ_OFFSET ) && !(time_status &STA_PLL )) +do_settimeofday (&ts); + txc->time.tv_sec = ts.tv_sec; txc->time.tv_usec = ts.tv_nsec;if (!(time_status &STA_NANO ))
--
Richard Cochran
maintainerRe: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 2 lines · Kuwahara,T.
As you know, it conflicts with
MOD_PPSMAX. And also, it is logically the same asADJ_OFFSET, unless the kernel PLL is enabled explicitly.
I choose another bit, for the next version of the patch series.
Quoted 3 lines
So here's my simple solution:
I have read the API documentation in the nanokernel source archive. It explains the (very complex looking) timex structure quite clearly and nicely. Now I am more convinced than ever that adding a new mode bit is the best way to go, as opposed to ADJ_OFFSET/!STA_PLL, because:
1. The mode bits update kernel variables. That is what we want.
2. Clearing STA_PLL means disable adjustments.
3. The range of the timex.offset is way too small.
I expand on each point, below. BTW, the API document is also available for online reading here:
http://www.slac.stanford.edu/comp/unix/package/rtems/src/ssrlApps/ntpNanoclock/api.htm
1. Looking at the API, the documentation for the bits of the 'modes' field states:
These bits control which field of the timex structure are used to update the corresponding kernel variable. The bits may be set in any combination. See the description below for which bits control which variable.
With the ADJ_SETOFFSET mode, we are telling the kernel to update the instantaneous value of the 'current time' variable. That usage agrees with the sematics of the other mode bits.
2. The documentation for STA_PLL states:
Master enable switch for the PLL/FLL loop. The algorithm is responsive to time and/or frequency updates if set; otherwise, no change in the current time or frequency will be made other than to complete a pending phase adjustment. This bit does not affect the PPS loop.
So when we clear this bit, the kernel promises that it will make "no change in the current time." The proposed ADJ_OFFSET/!STA_PLL solution would break this pattern.
3. The timex.offset field is of type "long" and represents either nanoseconds or microseconds. On 32 bit architectures, the maximum possible adjustment would be
2^31 * 10^-6 = 2147.5 seconds
which is less than one hour. For the first adjustment of a clock, we want to be able to jump the clock arbitrarily. Not every computer has an RTC, and so some boot up believing that it is still the year 1970.
Richard
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 1 line · Richard Cochran
we want to be able to jump the clock arbitrarily.
Another problem remains: How do you deal with leap seconds? I mean, given that 1 minute is not always 60 seconds, then what time was it
XXXXX seconds ago? Maybe some kind of lookup table is necessary, but
in such case, isn't it a better choice just to use the clock_settime/settimeofday syscall?
Richard Cochran
maintainerRe: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 9 lines · Kuwahara,T.
Quoted 1 line · Richard Cochran
we want to be able to jump the clock arbitrarily.
Another problem remains: How do you deal with leap seconds? I mean, given that 1 minute is not always 60 seconds, then what time was it
XXXXX seconds ago? Maybe some kind of lookup table is necessary, but
in such case, isn't it a better choice just to use the clock_settime/settimeofday syscall?
Well, first of all, the PTP Hardware Clocks for which this whole patch set was created in the first place will keep their time as TAI. Adding seconds to such time values is unambiguous.
Secondly, the question you ask applies equally to the existing interfaces, so it is a mute point with regard to the patch series.
Richard
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 2 lines · Richard Cochran
the PTP Hardware Clocks for which this whole patch set was created in the first place will keep their time as TAI.
Are you sure of that? I don't have the standard handy (it's non-free, right?) but it seems that the Annex B states differently. But that's not the point anyway. My concern is that your patch not only adds the useless (and broken) feature to the existing syscall but also makes a permanent change to the public interface for your own use. That's what I'm against. So if you stop touching the struct timex, I won't complain anymore.
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 5 lines · Kuwahara,T.
Quoted 2 lines · Richard Cochran
the PTP Hardware Clocks for which this whole patch set was created in the first place will keep their time as TAI.
Quoted 7 lines
Are you sure of that? I don't have the standard handy (it's non-free, right?) but it seems that the Annex B states differently. But that's not the point anyway. My concern is that your patch not only adds the useless (and broken) feature to the existing syscall but also makes a permanent change to the public interface for your own use. That's what I'm against. So if you stop touching the struct timex, I won't complain anymore.
You still haven't explained *why* you're so protective of the timex and adjtimex interfaces. While I do want to keep compatible the functionality where possible, I don't see why Linux should be limited by what other OSes do.
Injecting an offset to the system time seems like a reasonable thing for adjtimex to do (rather then adding a new syscall). Further utilizing a new mode bit for this functionality seems reasonable and cleaner then your suggestions for utilizing existing mode bits in combined with other magic bits. If there is a compelling reason why not to do this, do please let us know! We might just agree with you after hearing it. :)
thanks
-john
Richard Cochran
maintainerRe: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
In reply to Kuwahara,T.Quoted 6 lines · Kuwahara,T.
Quoted 2 lines · Richard Cochran
the PTP Hardware Clocks for which this whole patch set was created in the first place will keep their time as TAI.
Are you sure of that?
Yes.
Quoted 2 lines
I don't have the standard handy (it's non-free, right?) but it seems that the Annex B states differently.
IEEE Std 1588-2008, Page 41:
The timescale PTP: In normal operation, the epoch is the PTP epoch and the timescale is continuous; see 7.2.4. The unit of measure of time is the SI second as realized on the rotating geoid.
IEEE Std 1588-2008, Page 42:
The PTP epoch is 1 January 1970 00:00:00 TAI, which is 31
December 1969 23:59:51.999918 UTC.The standard does permit using some other, arbitrary timescale, "set by an administrative procedure." But no other timescales are standardized by 1588.
Quoted 4 lines
But that's not the point anyway. My concern is that your patch not only adds the useless (and broken) feature to the existing syscall but also makes a permanent change to the public interface for your own use.
It is neither useless or broken. Using the new interface, you can estimate offset and frequency for a few seconds and jump directly into a closely synchronized state (like within 100 nanoseconds) relative to another clock on the network. That is pretty useful.
Your issue with leap seconds is really a non-issue. The time value of the ADJ_SETOFFSET mode is a time interval, *not* an absolute time.
Quoted 2 lines
That's what I'm against. So if you stop touching the struct timex,
I won't complain anymore.
I have no love for the timex interface. However, I used it for the new syscall because Arnd Bergmann and John Stultz specifically asked for it. Also, several other people have reviewed the new call without objecting to the new mode.
Richard
Richard Cochran
maintainerRe: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
In reply to Kuwahara,T.Quoted 2 lines · Kuwahara,T.
Another problem remains: How do you deal with leap seconds? I mean,
Since you have changed the topic, does that mean that you now agree with adding a new mode bit? ;)
Richard
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
In reply to Kuwahara,T.Quoted 9 lines · Kuwahara,T.
Quoted 1 line · Richard Cochran
we want to be able to jump the clock arbitrarily.
Another problem remains: How do you deal with leap seconds? I mean, given that 1 minute is not always 60 seconds, then what time was it
XXXXX seconds ago? Maybe some kind of lookup table is necessary, but
in such case, isn't it a better choice just to use the clock_settime/settimeofday syscall?
Leapsecond processing is done via an absolute hrtimer. Thus when the time offset is set, the hrtimers that should have expired will fire (just like with settimeofday) and the adjustment will then be made.
thanks
-john
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 3 lines · john stultz
Leapsecond processing is done via an absolute hrtimer. Thus when the time offset is set, the hrtimers that should have expired will fire (just like with settimeofday) and the adjustment will then be made.
How do you convert relative time to absolute time? It's not trivial because TAI offset is also a variable.
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 7 lines · Kuwahara,T.
Quoted 3 lines · john stultz
Leapsecond processing is done via an absolute hrtimer. Thus when the time offset is set, the hrtimers that should have expired will fire (just like with settimeofday) and the adjustment will then be made.
How do you convert relative time to absolute time? It's not trivial because TAI offset is also a variable.
I don't believe I understand what you're getting at.
The proposed interface is almost identical in functionality to a userland application doing the following:
offset = my_calculate_offset(); clock_gettime(CLOCK_REALTIME, &now); newtime = my_add_ts(now, offset); settimeofday(&newtime, 0);
The only difference is that you avoid the error from the delay between the gettime call and the settime call. It just adds the offset directly to the CLOCK_REALTIME.
thanks
-john
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 14 lines · john stultz
Quoted 7 lines · Kuwahara,T.
Quoted 3 lines · john stultz
Leapsecond processing is done via an absolute hrtimer. Thus when the time offset is set, the hrtimers that should have expired will fire (just like with settimeofday) and the adjustment will then be made.
How do you convert relative time to absolute time? It's not trivial because TAI offset is also a variable.
I don't believe I understand what you're getting at.
The proposed interface is almost identical in functionality to a userland application doing the following:
Quoted 8 lines
offset =
my_calculate_offset();
clock_gettime(CLOCK_REALTIME, &now);
newtime =my_add_ts(now, offset);
settimeofday(&newtime, 0);The only difference is that you avoid the error from the delay between the gettime call and the settime call. It just adds the offset directly to the
CLOCK_REALTIME.
For example, what time was it 3 seconds after 2008-12-31 23:59:59? You may say, of course it's 2009-01-01 00:00:02. But it's not true. You wonder why? Because a leap second had been added at midnight.
unix time UTC offset ---------- -------- --- 1230767997 23:59:57 -2 1230767998 23:59:58 -1 1230767999 23:59:59 0 1230768000 23:59:60 1 (leap second) 1230768000 00:00:00 2 1230768001 00:00:01 3 1230768002 00:00:02 4
That's why I said it's not trivial, and that your patch is broken and thus useless. Unfortunately, there's no remedy for this as long as a nonlinear timescale such as the unix time is being used, since the leap second insertion/deletion is a non-deterministic event.
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 38 lines · Kuwahara,T.
Quoted 14 lines · john stultz
Quoted 7 lines · Kuwahara,T.
Quoted 3 lines · john stultz
Leapsecond processing is done via an absolute hrtimer. Thus when the time offset is set, the hrtimers that should have expired will fire (just like with settimeofday) and the adjustment will then be made.
How do you convert relative time to absolute time? It's not trivial because TAI offset is also a variable.
I don't believe I understand what you're getting at.
The proposed interface is almost identical in functionality to a userland application doing the following:
Quoted 8 lines
offset = my_calculate_offset(); clock_gettime(CLOCK_REALTIME, &now); newtime = my_add_ts(now, offset); settimeofday(&newtime, 0);The only difference is that you avoid the error from the delay between the gettime call and the settime call. It just adds the offset directly to the
CLOCK_REALTIME.For example, what time was it 3 seconds after 2008-12-31 23:59:59? You may say, of course it's 2009-01-01 00:00:02. But it's not true. You wonder why? Because a leap second had been added at midnight.
unix time UTC offset ---------- -------- --- 1230767997 23:59:57 -2 1230767998 23:59:58 -1 1230767999 23:59:59 0 1230768000 23:59:60 1 (leap second) 1230768000 00:00:00 2 1230768001 00:00:01 3 1230768002 00:00:02 4
Quoted 2 lines
That's why I said it's not trivial, and that your patch is broken and thus useless.
So the kernel handles leap second insertion via a timer. Thus at the end of 23:59:59, it will inject a leapsecond by setting the time back by one second (back to 23:59:59) and setting the TIME_OOP flag.
This timer is an absolute timer, so if someone moves the clock forward across the 23:59:59 boundary, the adjustment will still be made.
The patch is not broken, nor useless.
Quoted 3 lines
Unfortunately, there's no remedy for this as long as a
nonlinear timescale such as the unix time is being used, since the leap second insertion/deletion is a non-deterministic event.
Indeed. Leapseconds in unix time are frustrating to deal with, and complicates applications having to be careful with them. But we do manage them properly and applications can detect that they are pending (via checking for TIME_INS) or if they are in effect (TIME_OOP).
Richards patch is in no different from settimeofday() solutions for correcting for an offset, with the exception of the fact that it does not introduce error due to delay beteween any gettime and settime call.
If your complaint is that leapseconds are ugly to deal with in unix time, then I agree. However, I'm at a total loss for understanding your passionate objections to Richard's patch.
thanks
-john
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 8 lines · john stultz
So the kernel handles leap second insertion via a timer. Thus at the end of 23:59:59, it will inject a leapsecond by setting the time back by one second (back to 23:59:59) and setting the
TIME_OOPflag.This timer is an absolute timer, so if someone moves the clock forward across the 23:59:59 boundary, the adjustment will still be made.
The patch is not broken, nor useless.
It takes into account only one upcoming leap second, but ignores all the others. That's not sufficient for arbitrary adjustments.
Re: [PATCH V8 02/13] ntp: add ADJ_SETOFFSET mode bit
Quoted 5 lines · Kuwahara,T.
Quoted 4 lines · john stultz
So the kernel handles leap second insertion via a timer. Thus at the end of 23:59:59, it will inject a leapsecond by setting the time back by one second (back to 23:59:59) and setting the
TIME_OOPflag.
Quoted 7 lines
Quoted 4 lines
This timer is an absolute timer, so if someone moves the clock forward across the 23:59:59 boundary, the adjustment will still be made.
The patch is not broken, nor useless.
It takes into account only one upcoming leap second, but ignores all the others. That's not sufficient for arbitrary adjustments.
If an application wants to manage the full historical table of leapseconds and compensate appropriately, then that's fine. The interface proposed still functions in a reasonable manner.
Again, I agree that leapseconds are annoying to deal with. It would be great if time() was defined as TAI time instead of UTC. I'm actually hoping to provide a CLOCK_TAI clockid someday.
thanks
-john
Richard Cochran
maintainerPATCH v8 3/13 posix clocks: introduce a syscall for clock tuning.
In reply to Richard CochranA new syscall is introduced that allows tuning of a POSIX clock. The new call, clock_adjtime, takes two parameters, the clock ID and a pointer to a struct timex. Any ADJTIMEX(2) operation may be requested via this system call, but various POSIX clocks may or may not support tuning.
--- drivers/char/mmtimer.c | 1 + include/linux/posix-timers.h | 4 + include/linux/syscalls.h | 2 + kernel/compat.c | 136 +++++++++++++++++++++++++++--------------- kernel/posix-cpu-timers.c | 6 ++ kernel/posix-timers.c | 35 +++++++++++ 6 files changed, 136 insertions(+), 48 deletions(-)
drivers/char/mmtimer.c +1 -0
@@ -767,6 +767,7 @@ static struct k_clock sgi_clock = { .res = 0, .clock_set = sgi_clock_set, .clock_get = sgi_clock_get, + .clock_adj = do_posix_clock_noadjtime, .timer_create = sgi_timer_create, .nsleep = do_posix_clock_nonanosleep, .timer_set = sgi_timer_set,
include/linux/posix-timers.h +4 -0
@@ -4,6 +4,7 @@#include <linux/spinlock.h> #include <linux/list.h> #include <linux/sched.h> +#include <linux/timex.h> union cpu_time_count {cputime_t cpu;
@@ -71,6 +72,7 @@ struct k_clock {int (*clock_getres) (const clockid_t which_clock,struct timespec *tp);int (*clock_set) (const clockid_t which_clock,struct timespec * tp);int (*clock_get) (const clockid_t which_clock,struct timespec * tp); +int (*clock_adj) (const clockid_t which_clock,struct timex *tx);int (*timer_create) (struct k_itimer *timer);int (*nsleep) (const clockid_t which_clock,int flags,struct timespec *,struct timespec __user *);
@@ -90,6 +92,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);int do_posix_clock_nonanosleep (const clockid_t ,int flags,struct timespec *,struct timespec __user *);int do_posix_clock_nosettime (const clockid_t ,struct timespec *tp); +int do_posix_clock_noadjtime (const clockid_t ,struct timex *tx);/* function to call to trigger timer event */ int posix_timer_event (struct k_itimer *timr,int si_private);
@@ -97,6 +100,7 @@ int posix_timer_event(struct k_itimer *timr, int si_private);int posix_cpu_clock_getres (const clockid_t which_clock,struct timespec *ts);int posix_cpu_clock_get (const clockid_t which_clock,struct timespec *ts);int posix_cpu_clock_set (const clockid_t which_clock,const struct timespec *ts); +int posix_cpu_clock_adj (const clockid_t which_clock,struct timex *tx);int posix_cpu_timer_create (struct k_itimer *timer);int posix_cpu_nsleep (const clockid_t which_clock,int flags,struct timespec *rqtp,struct timespec __user *rmtp);
include/linux/syscalls.h +2 -0
@@ -313,6 +313,8 @@ asmlinkage long sys_clock_settime(clockid_t which_clock, const struct timespec __user *tp);asmlinkage long sys_clock_gettime (clockid_t which_clock,struct timespec __user *tp); +asmlinkage long sys_clock_adjtime (clockid_t which_clock, +struct timex __user *tx);asmlinkage long sys_clock_getres (clockid_t which_clock,struct timespec __user *tp); asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
kernel/compat.c +88 -48
158 lines not on this page · raw message
kernel/posix-cpu-timers.c +6 -0
@@ -207,6 +207,10 @@ int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)return error; } +int posix_cpu_clock_adj (const clockid_t which_clock,struct timex *tx) +{ +return -EOPNOTSUPP ; +}/* * Sample a per-thread clock for the given task.
@@ -1610,6 +1614,7 @@ static __init int init_posix_cpu_timers(void) .clock_getres = process_cpu_clock_getres, .clock_get = process_cpu_clock_get, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = process_cpu_timer_create, .nsleep = process_cpu_nsleep, .nsleep_restart = process_cpu_nsleep_restart,
@@ -1618,6 +1623,7 @@ static __init int init_posix_cpu_timers(void) .clock_getres = thread_cpu_clock_getres, .clock_get = thread_cpu_clock_get, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = thread_cpu_timer_create, .nsleep = thread_cpu_nsleep, .nsleep_restart = thread_cpu_nsleep_restart,
kernel/posix-timers.c +35 -0
@@ -197,6 +197,11 @@ static int common_timer_create(struct k_itimer *new_timer)return 0 ; } +static inline int common_clock_adj (const clockid_t which_clock,struct timex *t) +{ +return do_adjtimex (t); +} +static int no_timer_create (struct k_itimer *new_timer) {return -EOPNOTSUPP ;
@@ -273,11 +278,13 @@ static __init int init_posix_timers(void) .clock_getres = hrtimer_get_res, .clock_get = posix_ktime_get_ts, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, };struct k_clock clock_monotonic_raw = { .clock_getres = hrtimer_get_res, .clock_get = posix_get_monotonic_raw, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, };
@@ -285,6 +292,7 @@ static __init int init_posix_timers(void) .clock_getres = posix_get_coarse_res, .clock_get = posix_get_realtime_coarse, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, };
@@ -292,6 +300,7 @@ static __init int init_posix_timers(void) .clock_getres = posix_get_coarse_res, .clock_get = posix_get_monotonic_coarse, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, };
@@ -928,6 +937,12 @@ int do_posix_clock_nosettime(const clockid_t clockid, struct timespec *tp) }EXPORT_SYMBOL_GPL (do_posix_clock_nosettime); +int do_posix_clock_noadjtime (const clockid_t which_clock,struct timex *t) +{ +return -EOPNOTSUPP ; +} +EXPORT_SYMBOL_GPL (do_posix_clock_noadjtime); +int do_posix_clock_nonanosleep (const clockid_t clock,int flags,struct timespec *t,struct timespec __user *r) {
@@ -969,6 +984,26 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, } +SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, + struct timex __user *, utx) +{ +struct timex ktx; +int err; + +if (copy_from_user (&ktx, utx,sizeof (ktx))) +return -EFAULT ; + +if (invalid_clockid (which_clock)) +return -EINVAL ; + + err =CLOCK_DISPATCH (which_clock, clock_adj, (which_clock, &ktx)); + +if (copy_to_user (utx, &ktx,sizeof (ktx))) +return -EFAULT ; + +return err; +} + SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp) {
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 4/13 posix_clocks: add clock_adjtime for arm
In reply to Richard CochranThis patch adds the clock_adjtime system call to the arm architecture.
--- arch/arm/include/asm/unistd.h | 1 + arch/arm/kernel/calls.S | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/unistd.h +1 -0
@@ -396,6 +396,7 @@#define __NR_fanotify_init (__NR_SYSCALL_BASE+367)#define __NR_fanotify_mark (__NR_SYSCALL_BASE+368)#define __NR_prlimit64 (__NR_SYSCALL_BASE+369) +#define __NR_clock_adjtime (__NR_SYSCALL_BASE+370)/* * The following SWIs are ARM private.
arch/arm/kernel/calls.S +1 -0
@@ -379,6 +379,7 @@ CALL(sys_fanotify_init) CALL(sys_fanotify_mark) CALL(sys_prlimit64) +/* 370 */ CALL(sys_clock_adjtime) #ifndef syscalls_counted .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls #define syscalls_counted
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 5/13 posix_clocks: add clock_adjtime for blackfin
In reply to Richard CochranThis patch adds the clock_adjtime system call to the blackfin architecture.
--- arch/blackfin/include/asm/unistd.h | 3 ++- arch/blackfin/mach-common/entry.S | 1 + 2 files changed, 3 insertions(+), 1 deletions(-)
arch/blackfin/include/asm/unistd.h +2 -1
@@ -393,8 +393,9 @@#define __NR_fanotify_mark 372#define __NR_prlimit64 373#define __NR_cacheflush 374 +#define __NR_clock_adjtime 375 -#define __NR_syscall 375 +#define __NR_syscall 376#define NR_syscalls __NR_syscall/* Old optional stuff no one actually uses */
arch/blackfin/mach-common/entry.S +1 -0
@@ -1738,6 +1738,7 @@ ENTRY(_sys_call_table) .long _sys_fanotify_mark .long _sys_prlimit64 .long _sys_cacheflush + .long _sys_clock_adjtime /* 375 */ .rept NR_syscalls-(.-_sys_call_table)/4 .long _sys_ni_syscall
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 6/13 posix_clocks: add clock_adjtime for powerpc
In reply to Richard CochranThis patch adds the clock_adjtime system call to the powerpc architecture.
--- arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/systbl.h +1 -0
@@ -348,3 +348,4 @@ COMPAT_SYS_SPU(sendmsg) COMPAT_SYS_SPU(recvmsg) COMPAT_SYS_SPU(recvmmsg) SYSCALL_SPU(accept4) +COMPAT_SYS_SPU(clock_adjtime)
arch/powerpc/include/asm/unistd.h +2 -1
@@ -367,10 +367,11 @@#define __NR_recvmsg 342#define __NR_recvmmsg 343#define __NR_accept4 344 +#define __NR_clock_adjtime 345#ifdef __KERNEL__ -#define __NR_syscalls 345 +#define __NR_syscalls 346#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 7/13 posix_clocks: add clock_adjtime for x86
In reply to Richard CochranThis patch adds the clock_adjtime system call to the x86 architecture.
--- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 3 ++- arch/x86/include/asm/unistd_64.h | 2 ++ arch/x86/kernel/syscall_table_32.S | 1 + 4 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/ia32/ia32entry.S +1 -0
@@ -851,4 +851,5 @@ ia32_sys_call_table: .quad sys_fanotify_init .quad sys32_fanotify_mark .quad sys_prlimit64 /* 340 */ + .quad compat_sys_clock_adjtime ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +2 -1
@@ -346,10 +346,11 @@#define __NR_fanotify_init 338#define __NR_fanotify_mark 339#define __NR_prlimit64 340 +#define __NR_clock_adjtime 341#ifdef __KERNEL__ -#define NR_syscalls 341 +#define NR_syscalls 342#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
arch/x86/include/asm/unistd_64.h +2 -0
@@ -669,6 +669,8 @@ __SYSCALL(__NR_fanotify_init, sys_fanotify_init) __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)#define __NR_prlimit64 302 __SYSCALL(__NR_prlimit64, sys_prlimit64) +#define __NR_clock_adjtime 303 +__SYSCALL(__NR_clock_adjtime, sys_clock_adjtime)#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
arch/x86/kernel/syscall_table_32.S +1 -0
@@ -340,3 +340,4 @@ ENTRY(sys_call_table) .long sys_fanotify_init .long sys_fanotify_mark .long sys_prlimit64 /* 340 */ + .long sys_clock_adjtime
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 8/13 posix clocks: cleanup the CLOCK_DISPTACH macro
In reply to Richard CochranParaphrasing tglx:
This patch simplifies and clarifies the code, doing the normal thing with function pointer structures. Stuff which is not implemented does not magically become called via some common function. There is no point in doing that.
We fill in the various k_clock structs with the correct pointers in the first place and let the NULL case return a sensible error value. The data structure does not become larger that way. It's a little bit more init code, but that's fine if we make the code better in general. In that case it's not even more init code, it's just filling the data structures which we register.
My own words:
For now, each of the registered k_clocks has the previously NULL functions assigned to the common_xyz function, since that usage was implicitly enforced by the CLOCK_DISPTACH macro. These functions are marked with a /* default: */ comment.
As as possible further improvement for the future, one could go through and replace the various no_xyz function pointers in the k_clocks with NULL pointers.
--- include/linux/posix-timers.h | 14 +++ include/linux/time.h | 2 + kernel/posix-timers.c | 241 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 213 insertions(+), 44 deletions(-)
include/linux/posix-timers.h +14 -0
@@ -18,6 +18,18 @@ struct cpu_timer_list {int firing; }; +/* Bit fields within a clockid: +* +* The most significant 29 bits hold either a pid or a file descriptor. +* +* Bit 2 indicates whether a cpu clock refers to a thread or a process. +* +* Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. +* +* A clockid is invalid if bits 2, 1, and 0 all set (see also CLOCK_INVALID +* in include/linux/time.h) +*/ +#define CPUCLOCK_PID (clock) ((pid_t) ~((clock) >> 3))#define CPUCLOCK_PERTHREAD (clock) \ (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
@@ -29,6 +41,8 @@ struct cpu_timer_list {#define CPUCLOCK_VIRT 1#define CPUCLOCK_SCHED 2#define CPUCLOCK_MAX 3 +#define CLOCKFD CPUCLOCK_MAX +#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)#define MAKE_PROCESS_CPUCLOCK (pid, clock) \ ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
include/linux/time.h +2 -0
@@ -300,6 +300,8 @@ struct itimerval {#define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC)#define CLOCKS_MONO CLOCK_MONOTONIC +#define CLOCK_INVALID -1 +/* * The various flags for setting POSIX.1b interval timers: */
kernel/posix-timers.c +197 -44
328 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
Quoted 1 line · Richard Cochran
+#define
CLOCK_DISPATCH(clock, call, arglist)dispatch_##call arglist
How about you run something like:
:% s/CLOCK_DISPATCH([^,]*, \([^,]*\), \([^)]*)\))/dispatch_\1\2/g
and remove that cruft all together?
Richard Cochran
maintainerRe: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
Quoted 8 lines · Peter Zijlstra
Quoted 1 line · Richard Cochran
+#define
CLOCK_DISPATCH(clock, call, arglist)dispatch_##call arglistHow about you run something like:
:% s/CLOCK_DISPATCH([^,]*, \([^,]*\), \([^)]*)\))/dispatch_\1\2/g
and remove that cruft all together?
Gladly ;^)
Richard
Re: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
In reply to Richard CochranQuoted 7 lines · Richard Cochran
kernel/posix-timers.c +7
-0+static inline bool clock_is_posix_cpu (const clockid_t id) +{ +if ((id &CLOCKFD_MASK ) ==CLOCKFD ) +return false; +else +return true; +}
kernel/posix-timers.c static void release_posix_timer(struct k_itimer *tmr, int it_id_set) · line 546
Quoted 10 lines
kernel/posix-timers.c +10
-0+ +static inline int dispatch_clock_getres (const clockid_t id,struct timespec *ts) +{ +if (id >=0 ) { +return posix_clocks[id].clock_getres ? + posix_clocks[id].clock_getres (id, ts) : -EINVAL ; + } + +if (clock_is_posix_cpu (id)) +return posix_cpu_clock_getres (id, ts);
I wonder whether we should be a bit more clever here and create an extra entry for posix_cpu_timers in the posix_clocks array and do the following:
/* These are local to posix-timer.c and not exposed to anything else */
#define POSIX_INV_CLOCK_ID MAX_CLOCKS
#define POSIX_CPU_CLOCK_ID (MAX_CLOCKS + 1)
#define NR_CLOCK_ENTRIES (MAX_CLOCKS + 2)
static struct k_clock posix_clocks[NR_CLOCK_ENTRIES];
static __init int init_posix_timers(void)
{
......
/*
* We leave the POSIX_INV_CLOCK_ID entries zeroed out, so the
* the dispatch code will return -EINVAL.
*/
init_posix_cpu_timer_entries();
}static clockid_t clock_get_array_id(const clockid_t id)
{
if (id >= 0)
return id < MAX_CLOCKS ? id : POSIX_INV_CLOCK_ID;
if (clock_is_posix_cpu(id))
return POSIX_CPU_CLOCK_ID;
return POSIX_INV_CLOCK_ID;
}static inline int dispatch_clock_getres(const clockid_t id, struct timespec *ts)
{
struct k_clock *clk = &posix_clocks[clock_get_array_id(id)];
return clk->clock_getres ? clk->clock_getres(id, ts) : -EINVAL;
}That reduces the code significantly and the MAX_CLOCKS check in clock_get_array_id() replaces the invalid_clock() check in the syscalls as well. It does not matter whether we check this before or after copying stuff from user.
Adding your new stuff requires just another entry in the array, the setup of the function pointers and the CLOCKFD check in clock_get_array_id(). Everything else just falls in place.
kernel/posix-timers.c static void release_posix_timer(struct k_itimer *tmr, int it_id_set) · line 683
Quoted 3 lines
kernel/posix-timers.c +3
-0+ +#define CLOCK_DISPATCH (clock, call, arglist) dispatch_##call arglist +
Can we get rid of this completely please ?
kernel/posix-timers.c static int common_nsleep_restart(struct restart_block *restart_block) · line 1072
Quoted 4 lines
clock_nanosleep_restart(struct restart_block *restart_block){kernel/posix-timers.c +0
-2-clockid_t which_clock = restart_block->arg0; -
How does that compile ?
kernel/posix-timers.c static int common_nsleep_restart(struct restart_block *restart_block) · line 1228
Quoted 3 lines
kernel/posix-timers.c +0
-0return CLOCK_DISPATCH (which_clock, nsleep_restart, (restart_block)); }
Thanks,
tglx
Richard Cochran
maintainerRe: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
Quoted 3 lines · Thomas Gleixner
I wonder whether we should be a bit more clever here and create an extra entry for
posix_cpu_timersin theposix_clocksarray and do the following:
...
Quoted 4 lines
That reduces the code significantly and the
MAX_CLOCKScheck inclock_get_array_id()replaces theinvalid_clock()check in the syscalls as well. It does not matter whether we check this before or after copying stuff from user.
Well, this does reduce the number of LOC, but the number of comparisons is the same. I think the code size would be also no different.
Quoted 3 lines
Adding your new stuff requires just another entry in the array, the setup of the function pointers and the CLOCKFD check in
clock_get_array_id(). Everything else just falls in place.
For me, I am not sure if either version is really very pretty or easy to understand.
My instinct is to keep the posix_cpu_X and pc_X functions out of the array of static clock id functions, if only to make the distinction between the legacy static ids and new dynamic ids clear.
The conclusion from the "dynamic clock as file" discussion was that we don't want to add any more static clock ids, and new clocks should use the new, dynamic clock API. So, we should discourage any future attempt to add to that function array!
Having said that, if you insist on it, I won't mind reworking the dispatch code as you suggested.
Quoted 5 lines
kernel/posix-timers.c static void release_posix_timer(struct k_itimer *tmr, int it_id_set) · line 683
Quoted 3 lines
kernel/posix-timers.c +3
-0+ +#define CLOCK_DISPATCH (clock, call, arglist) dispatch_##call arglist +Can we get rid of this completely please ?
Yes, gladly.
Quoted 6 lines
kernel/posix-timers.c static int common_nsleep_restart(struct restart_block *restart_block) · line 1072
Quoted 4 lines
clock_nanosleep_restart(struct restart_block *restart_block){kernel/posix-timers.c +0
-2-clockid_t which_clock = restart_block->arg0; -How does that compile ?
Because the CLOCK_DISPATCH macro, above, makes no use of the first argument! I have removed the macro for the next round.
Quoted 3 lines
kernel/posix-timers.c static int common_nsleep_restart(struct restart_block *restart_block) · line 1228
Quoted 3 lines
kernel/posix-timers.c +0
-0return CLOCK_DISPATCH (which_clock, nsleep_restart, (restart_block)); }
Thanks,
Richard
Re: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
Quoted 5 lines · Richard Cochran
Quoted 3 lines · Thomas Gleixner
I wonder whether we should be a bit more clever here and create an extra entry for
posix_cpu_timersin theposix_clocksarray and do the following:...
Quoted 8 lines
Quoted 4 lines
That reduces the code significantly and the
MAX_CLOCKScheck inclock_get_array_id()replaces theinvalid_clock()check in the syscalls as well. It does not matter whether we check this before or after copying stuff from user.Well, this does reduce the number of LOC, but the number of comparisons is the same. I think the code size would be also no different.
Right, It's about lines of code and ever repeated if / else constructs in the dispatch functions. The number of comparisons is probably the same, but I'm sure that the binary size will be smaller.
We probably can remove the dispatch inlines that way completely and do the call directly from the syscall function.
Quoted 6 lines
Quoted 3 lines
Adding your new stuff requires just another entry in the array, the setup of the function pointers and the CLOCKFD check in
clock_get_array_id(). Everything else just falls in place.For me, I am not sure if either version is really very pretty or easy to understand.
Well, if we document clock_get_array_id() proper, then it's easier to follow than 10 dispatch functions which have all the same checks and comparisons inside.
Quoted 8 lines
My instinct is to keep the
posix_cpu_Xandpc_Xfunctions out of the array of static clock id functions, if only to make the distinction between the legacy static ids and new dynamic ids clear.The conclusion from the "dynamic clock as file" discussion was that we don't want to add any more static clock ids, and new clocks should use the new, dynamic clock API. So, we should discourage any future attempt to add to that function array!
These IDs are not public, they are helpers to make the code simpler, nothing else. I agree, that we don't want to extend the static ids for public consumption, but implementation wise we can do that confined to posix-timers.c.
Quoted 2 lines
Having said that, if you insist on it, I won't mind reworking the dispatch code as you suggested.
I'm not insisting. I just saw the repeated if/else constructs and added the clockfd check mentally :) That's where I started to wonder about a way to do the same thing with way less lines of code.
Quoted 8 lines
Quoted 6 lines
kernel/posix-timers.c static int common_nsleep_restart(struct restart_block *restart_block) · line 1072
Quoted 4 lines
clock_nanosleep_restart(struct restart_block *restart_block){kernel/posix-timers.c +0
-2-clockid_t which_clock = restart_block->arg0; -How does that compile ?
Because the
CLOCK_DISPATCHmacro, above, makes no use of the first
Missed that, sorry.
Quoted 1 line
argument! I have removed the macro for the next round.
Cool.
Thanks,
tglx
Richard Cochran
maintainerRe: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
Quoted 3 lines · Thomas Gleixner
We probably can remove the dispatch inlines that way completely and do the call directly from the syscall function.
Right, okay. I also wanted to put the whole logic into the syscall itself. I'll try it that way.
Thanks,
Richard
Richard Cochran
maintainerRe: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
In reply to Thomas GleixnerQuoted 12 lines · Thomas Gleixner
static
clockid_tclock_get_array_id(const clockid_t id){ if (id >= 0) return id < MAX_CLOCKS ? id : POSIX_INV_CLOCK_ID; if (clock_is_posix_cpu(id)) return POSIX_CPU_CLOCK_ID; return POSIX_INV_CLOCK_ID; }
Quoted 6 lines
static inline int
dispatch_clock_getres(const clockid_t id, struct timespec *ts){ struct k_clock *clk = &posix_clocks[clock_get_array_id(id)]; return clk->clock_getres ? clk->clock_getres(id, ts) : -EINVAL; }
I would like to take this idea one step further, like so:
static struct k_clock *clockid_to_kclock(const clockid_t id)
{
if (id >= 0)
return id < MAX_CLOCKS ?
&posix_clocks[id] : &posix_clocks[POSIX_INV_CLOCK_ID];
...
}SYSCALL( ... , const clockid_t id, struct timespec *ts)
{
struct k_clock *clk = clockid_to_kclock(id);
return clk->clock_getres ? clk->clock_getres(id, ts) : -EINVAL;
}What do you think?
Thanks,
Richard
Re: [PATCH V8 08/13] posix clocks: cleanup the CLOCK_DISPTACH macro
Quoted 30 lines · Richard Cochran
Quoted 12 lines · Thomas Gleixner
static
clockid_tclock_get_array_id(const clockid_t id){ if (id >= 0) return id < MAX_CLOCKS ? id : POSIX_INV_CLOCK_ID; if (clock_is_posix_cpu(id)) return POSIX_CPU_CLOCK_ID; return POSIX_INV_CLOCK_ID; }Quoted 6 lines
static inline int
dispatch_clock_getres(const clockid_t id, struct timespec *ts){ struct k_clock *clk = &posix_clocks[clock_get_array_id(id)]; return clk->clock_getres ? clk->clock_getres(id, ts) : -EINVAL; }I would like to take this idea one step further, like so:
static struct
k_clock*clockid_to_kclock(constclockid_tid){ if (id >= 0) return id < MAX_CLOCKS ? &posix_clocks[id] : &posix_clocks[POSIX_INV_CLOCK_ID]; ... }
Quoted 8 lines
SYSCALL( ... , const
clockid_tid, struct timespec *ts){ struct k_clock *clk = clockid_to_kclock(id); return clk->clock_getres ? clk->clock_getres(id, ts) : -EINVAL; }What do you think?
Yeah, that's even better!
Richard Cochran
maintainerPATCH v8 9/13 posix clocks: introduce dynamic clocks
In reply to Richard CochranThis patch adds support for adding and removing posix clocks. The clock lifetime cycle is patterned after usb devices. Each clock is represented by a standard character device. In addition, the driver may optionally implemented custom character device operations.
The posix clock and timer system calls listed below now work with dynamic posix clocks, as well as the traditional static clocks. For the performance critical calls (eg clock_gettime) the code path from the traditional static clocks is preserved.
The following system calls are affected:
- clock_adjtime (brand new syscall)
- clock_gettime
- clock_getres
- clock_settime
- timer_create
- timer_delete
- timer_gettime
- timer_settime
--- include/linux/posix-clock.h | 137 +++++++++++ include/linux/posix-timers.h | 5 +- kernel/posix-timers.c | 19 +- kernel/time/Makefile | 3 +- kernel/time/posix-clock-syscalls.h | 39 +++ kernel/time/posix-clock.c | 454 ++++++++++++++++++++++++++++++++++++ 6 files changed, 648 insertions(+), 9 deletions(-) create mode 100644 include/linux/posix-clock.h create mode 100644 kernel/time/posix-clock-syscalls.h create mode 100644 kernel/time/posix-clock.c
include/linux/posix-clock.h new file +137 -0
@@ -0,0 +1,137 @@ +/* +* posix-clock.h - support for dynamic clock devices +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef _LINUX_POSIX_CLOCK_H_ +#define _LINUX_POSIX_CLOCK_H_ + +#include <linux/fs.h> +#include <linux/poll.h> +#include <linux/posix-timers.h> + +/** +* struct posix_clock_operations - functional interface to the clock +* +* Every posix clock is represented by a character device. Drivers may +* optionally offer extended capabilities by implementing the +* character device methods. The character device file operations are +* first handled by the clock device layer, then passed on to the +* driver by calling these functions. +* +* Drivers should embed their posix_clock_operations within a private +* structure, obtaining a reference to it using container_of(). +* +* @owner: The clock driver should set to THIS_MODULE +* @clock_adjtime: Adjust the clock +* @clock_gettime: Read the current time +* @clock_getres: Get the clock resolution +* @clock_settime: Set the current time value +* @timer_create: Create a new timer +* @timer_delete: Remove a previously created timer +* @timer_gettime: Get remaining time and interval of a timer +* @timer_setttime: Set a timer's initial expiration and interval +* @fasync: Optional character device fasync method +* @mmap: Optional character device mmap method +* @open: Optional character device open method +* @release: Optional character device release method +* @ioctl: Optional character device ioctl method +* @read: Optional character device read method +* @poll: Optional character device poll method +*/ +struct posix_clock_operations { +struct module *owner; + +int (*clock_adjtime)(struct posix_clock_operations *pc, +struct timex *tx); + +int (*clock_gettime)(struct posix_clock_operations *pc, +struct timespec *ts); + +int (*clock_getres) (struct posix_clock_operations *pc, +struct timespec *ts); + +int (*clock_settime)(struct posix_clock_operations *pc, +const struct timespec *ts); + +int (*timer_create) (struct posix_clock_operations *pc, +struct k_itimer *kit); + +int (*timer_delete) (struct posix_clock_operations *pc, +struct k_itimer *kit); + +void (*timer_gettime)(struct posix_clock_operations *pc, +struct k_itimer *kit,struct itimerspec *tsp); + +int (*timer_settime)(struct posix_clock_operations *pc, +struct k_itimer *kit,int flags, +struct itimerspec *tsp,struct itimerspec *old); +/* +* Optional character device methods: +*/ +int (*fasync) (struct posix_clock_operations *pc, +int fd,struct file *file,int on); + +long (*ioctl) (struct posix_clock_operations *pc, +unsigned int cmd,unsigned long arg); + +int (*mmap) (struct posix_clock_operations *pc, +struct vm_area_struct *vma); + +int (*open) (struct posix_clock_operations *pc,fmode_t f_mode); + +uint (*poll) (struct posix_clock_operations *pc, +struct file *file,poll_table *wait); + +int (*release) (struct posix_clock_operations *pc); + +ssize_t (*read) (struct posix_clock_operations *pc, +uint flags,char __user *buf,size_t cnt); +}; + +/** +* struct posix_clock - an opaque type +*/ +struct posix_clock ; + +/** +* posix_clock_create() - register a new clock +* @cops: Pointer to the clock's interface +* @devid: Allocated device id +* @priv: Private data passed back to the driver via the interface functions +* +* A clock driver calls this function to register itself with the +* clock device subsystem. The 'cops' argument must point to +* persistent data, so the caller should pass a static global. +* +* Returns a pointer to a new clock device, or PTR_ERR on error. +*/ +struct posix_clock *posix_clock_create (struct posix_clock_operations *pc, +dev_t devid); + +/** +* posix_clock_destroy() - unregister a clock +* @clk: Pointer obtained via posix_clock_create() +* +* A clock driver calls this function to remove itself from the clock +* device subsystem. The posix_clock itself will remain (in an +* inactive state) until its reference count drops to zero, at which +* point it will be deallocated. +*/ +void posix_clock_destroy (struct posix_clock *clk); + +#endif
include/linux/posix-timers.h +4 -1
@@ -33,7 +33,7 @@ struct cpu_timer_list {#define CPUCLOCK_PID (clock) ((pid_t) ~((clock) >> 3))#define CPUCLOCK_PERTHREAD (clock) \ (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) -#define CPUCLOCK_PID_MASK 7 +#define CPUCLOCK_PERTHREAD_MASK 4#define CPUCLOCK_WHICH (clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)#define CPUCLOCK_CLOCK_MASK 3
@@ -49,6 +49,9 @@ struct cpu_timer_list {#define MAKE_THREAD_CPUCLOCK (tid, clock) \ MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) +#define FD_TO_CLOCKID (fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) +#define CLOCKID_TO_FD (clk) ((unsigned int) ~((clk) >> 3)) +/* POSIX.1b interval timer structure. */ struct k_itimer {struct list_head list;/* free/ allocate list */
kernel/posix-timers.c +12 -7
@@ -41,12 +41,15 @@#include <linux/init.h> #include <linux/compiler.h> #include <linux/idr.h> +#include <linux/posix-clock.h> #include <linux/posix-timers.h> #include <linux/syscalls.h> #include <linux/wait.h> #include <linux/workqueue.h> #include <linux/module.h> +#include "time/posix-clock-syscalls.h" +/* * Management arrays for POSIX timers. Timers are kept in slab memory * Timer ids are allocated by an external routine that keeps track of the
@@ -545,7 +548,7 @@ static inline int dispatch_clock_getres(const clockid_t id, struct timespec *ts)if (clock_is_posix_cpu (id))return posix_cpu_clock_getres (id, ts); -return -EINVAL ; +return pc_clock_getres (id, ts); }static inline int dispatch_clock_set (const clockid_t id,struct timespec *ts)
@@ -558,7 +561,7 @@ static inline int dispatch_clock_set(const clockid_t id, struct timespec *ts)if (clock_is_posix_cpu (id))return posix_cpu_clock_set (id, ts); -return -EINVAL ; +return pc_clock_settime (id, ts); }static inline int dispatch_clock_get (const clockid_t id,struct timespec *ts)
@@ -571,7 +574,7 @@ static inline int dispatch_clock_get(const clockid_t id, struct timespec *ts)if (clock_is_posix_cpu (id))return posix_cpu_clock_get (id, ts); -return -EINVAL ; +return pc_clock_gettime (id, ts); }static inline int dispatch_clock_adj (const clockid_t id,struct timex *tx)
@@ -584,7 +587,7 @@ static inline int dispatch_clock_adj(const clockid_t id, struct timex *tx)if (clock_is_posix_cpu (id))return posix_cpu_clock_adj (id, tx); -return -EINVAL ; +return pc_clock_adjtime (id, tx); }static inline int dispatch_timer_create (struct k_itimer *kit)
@@ -599,7 +602,7 @@ static inline int dispatch_timer_create(struct k_itimer *kit)if (clock_is_posix_cpu (id))return posix_cpu_timer_create (kit); -return -EINVAL ; +return pc_timer_create (kit); } static inline int dispatch_nsleep(const clockid_t id, int flags,
@@ -647,7 +650,7 @@ static inline int dispatch_timer_set(struct k_itimer *kit, int flags,if (clock_is_posix_cpu (id))return posix_cpu_timer_set (kit, flags, tsp, old); -return -EINVAL ; +return pc_timer_settime (kit, flags, tsp, old); }static inline int dispatch_timer_del (struct k_itimer *kit)
@@ -662,7 +665,7 @@ static inline int dispatch_timer_del(struct k_itimer *kit)if (clock_is_posix_cpu (id))return posix_cpu_timer_del (kit); -return -EINVAL ; +return pc_timer_delete (kit); } static inline void dispatch_timer_get(struct k_itimer *kit,
@@ -677,6 +680,8 @@ static inline void dispatch_timer_get(struct k_itimer *kit,else if (clock_is_posix_cpu (id))posix_cpu_timer_get (kit, tsp); +else +pc_timer_gettime (kit, tsp); }#define CLOCK_DISPATCH (clock, call, arglist) dispatch_##call arglist
kernel/time/Makefile +2 -1
@@ -1,4 +1,5 @@ -obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o timeconv.o +obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o +obj-y += timeconv.o posix-clock.o obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD) += clockevents.o obj-$(CONFIG_GENERIC_CLOCKEVENTS) += tick-common.o
kernel/time/posix-clock-syscalls.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* posix-clock-syscalls.h - support for dynamic clock devices +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef _POSIX_CLOCK_SYSCALLS_H_ +#define _POSIX_CLOCK_SYSCALLS_H_ + +#include <linux/posix-timers.h> + +/* +* The following functions are only to be called from posix-timers.c +*/ + +int pc_clock_adjtime (clockid_t id,struct timex *tx); +int pc_clock_gettime (clockid_t id,struct timespec *ts); +int pc_clock_getres (clockid_t id,struct timespec *ts); +int pc_clock_settime (clockid_t id,const struct timespec *ts); +int pc_timer_create (struct k_itimer *kt); +int pc_timer_delete (struct k_itimer *kt); +void pc_timer_gettime (struct k_itimer *kt,struct itimerspec *ts); +int pc_timer_settime (struct k_itimer *kt,int flags, +struct itimerspec *ts,struct itimerspec *old); + +#endif
kernel/time/posix-clock.c new file +454 -0
454 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Arnd Bergmann
maintainerRe: [PATCH V8 09/13] posix clocks: introduce dynamic clocks
Quoted 9 lines · Richard Cochran
This patch adds support for adding and removing posix clocks. The clock lifetime cycle is patterned after usb devices. Each clock is represented by a standard character device. In addition, the driver may optionally implemented custom character device operations.
The posix clock and timer system calls listed below now work with dynamic posix clocks, as well as the traditional static clocks. For the performance critical calls (eg
clock_gettime) the code path from the traditional static clocks is preserved.
Combining the operations structures and using container_of as you did looks much better than before, but I had something slightly different in mind:
The way that other subsystems do this is to pass a pointer to the actual low-level object (struct posix_clock in your case) to the abstracted functions, while you pass a pointer to the operations structure. This has the advantage of keeping the definition of posix_clock private to posix-clock.c, but it is something we do very rarely.
I can see disadvantages with your approach: You still need to dynamically allocate the posix_clock in posix_clock_create(), and the operations structure cannot be const, which is a theoretical security problem if there is a hole that can replace one of the pointers with a reference to user memory.
I would recommend changing this to the more common model, where you passs the (publically defined) struct posix_clock to all operations and can do something like:
struct my_posix_clock {
...
struct posix_clock pclk;
} this_clock = {
...
.pclk = {
.ops = &my_posix_clock_operations,
}
};int my_init(void)
{
return posix_clock_operations_register(&my_posix_clock.pclk);
}void my_exit(void)
{
posix_clock_operations_unregister(&my_posix_clock.pclk);
}It should be just a trivial change and just affect how easy it is for other people to understand the code if they are already familiar with other kernel code.
Overall, your series looks really good now, it would be nice if this could still make it into 2.6.38.
Arnd
Richard Cochran
maintainerRe: [PATCH V8 09/13] posix clocks: introduce dynamic clocks
Quoted 3 lines · Arnd Bergmann
It should be just a trivial change and just affect how easy it is for other people to understand the code if they are already familiar with other kernel code.
Okay, I'll get right on it.
Quoted 2 lines
Overall, your series looks really good now, it would be nice if this could still make it into 2.6.38.
Yes, that would be great.
Thanks,
Richard
Richard Cochran
maintainerPATCH v8 10/13 ptp: Added a brand new class driver for ptp clocks.
In reply to Richard CochranThis patch adds an infrastructure for hardware clocks that implement IEEE 1588, the Precision Time Protocol (PTP). A class driver offers a registration method to particular hardware clock drivers. Each clock is presented as a standard POSIX clock.
The ancillary clock features are exposed in two different ways, via the sysfs and by a character device.
--- Documentation/ABI/testing/sysfs-ptp | 97 ++++++++++ Documentation/ptp/ptp.txt | 93 +++++++++ Documentation/ptp/testptp.c | 352 +++++++++++++++++++++++++++++++++++ Documentation/ptp/testptp.mk | 33 ++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ptp/Kconfig | 27 +++ drivers/ptp/Makefile | 6 + drivers/ptp/ptp_chardev.c | 146 +++++++++++++++ drivers/ptp/ptp_clock.c | 318 +++++++++++++++++++++++++++++++ drivers/ptp/ptp_private.h | 86 +++++++++ drivers/ptp/ptp_sysfs.c | 226 ++++++++++++++++++++++ include/linux/Kbuild | 1 + include/linux/ptp_clock.h | 79 ++++++++ include/linux/ptp_clock_kernel.h | 141 ++++++++++++++ 15 files changed, 1608 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-ptp create mode 100644 Documentation/ptp/ptp.txt create mode 100644 Documentation/ptp/testptp.c create mode 100644 Documentation/ptp/testptp.mk create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_chardev.c create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_private.h create mode 100644 drivers/ptp/ptp_sysfs.c create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h
Documentation/ABI/testing/sysfs-ptp new file +97 -0
@@ -0,0 +1,97 @@ +What: /sys/class/ptp/ +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This directory contains files and directories + providing a standardized interface to the ancillary + features of PTP hardware clocks. + +What: /sys/class/ptp/ptpN/ +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This directory contains the attributes of the Nth PTP + hardware clock registered into the PTP class driver + subsystem. + +What: /sys/class/ptp/ptpN/clock_name +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the name of the PTP hardware clock + as a human readable string. + +What: /sys/class/ptp/ptpN/max_adjustment +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the PTP hardware clock's maximum + frequency adjustment value (a positive integer) in + parts per billion. + +What: /sys/class/ptp/ptpN/n_alarms +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of periodic or one shot + alarms offer by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/n_external_timestamps +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of external timestamp + channels offered by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/n_periodic_outputs +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of programmable periodic + output channels offered by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/pps_avaiable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file indicates whether the PTP hardware clock + supports a Pulse Per Second to the host CPU. Reading + "1" means that the PPS is supported, while "0" means + not supported. + +What: /sys/class/ptp/ptpN/extts_enable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables external + timestamps. To enable external timestamps, write the + channel index followed by a "1" into the file. + To disable external timestamps, write the channel + index followed by a "0" into the file. + +What: /sys/class/ptp/ptpN/fifo +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file provides timestamps on external events, in + the form of three integers: channel index, seconds, + and nanoseconds. + +What: /sys/class/ptp/ptpN/period +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables periodic + outputs. To enable a periodic output, write three + integers into the file: channel index, seconds, and + nanoseconds. To disable a periodic output, set seconds + and nanoseconds to zero. + +What: /sys/class/ptp/ptpN/pps_enable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables delivery of + PPS events to the Linux PPS subsystem. To enable PPS + events, write a "1" into the file. To disable events, + write a "0" into the file.
Documentation/ptp/ptp.txt new file +93 -0
93 lines not on this page · raw message
Documentation/ptp/testptp.c new file +352 -0
352 lines not on this page · raw message
Documentation/ptp/testptp.mk new file +33 -0
@@ -0,0 +1,33 @@ +# PTP 1588 clock support - User space test program +# +# Copyright (C) 2010 OMICRON electronics GmbH +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +CC = $(CROSS_COMPILE)gcc +INC = -I$(KBUILD_OUTPUT)/usr/include +CFLAGS = -Wall $(INC) +LDLIBS = -lrt +PROGS = testptp + +all: $(PROGS) + +testptp: testptp.o + +clean: + rm -f testptp.o + +distclean: clean + rm -f $(PROGS)
drivers/Kconfig +2 -0
@@ -52,6 +52,8 @@ source "drivers/spi/Kconfig" source "drivers/pps/Kconfig" +source "drivers/ptp/Kconfig" + source "drivers/gpio/Kconfig" source "drivers/w1/Kconfig"
drivers/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-y += i2c/ media/ obj-$(CONFIG_PPS) += pps/ +obj-$(CONFIG_PTP_1588_CLOCK) += ptp/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_POWER_SUPPLY) += power/ obj-$(CONFIG_HWMON) += hwmon/
drivers/ptp/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ +# +# PTP clock support configuration +# + +menu "PTP clock support" + +config PTP_1588_CLOCK + tristate "PTP clock support" + depends on EXPERIMENTAL + depends on PPS + help + The IEEE 1588 standard defines a method to precisely + synchronize distributed clocks over Ethernet networks. The + standard defines a Precision Time Protocol (PTP), which can + be used to achieve synchronization within a few dozen + microseconds. In addition, with the help of special hardware + time stamping units, it can be possible to achieve + synchronization to within a few hundred nanoseconds. + + This driver adds support for PTP clocks as character + devices. If you want to use a PTP clock, then you should + also enable at least one clock driver as well. + + To compile this driver as a module, choose M here: the module + will be called ptp. + +endmenu
drivers/ptp/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for PTP 1588 clock support. +# + +ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o +obj-$(CONFIG_PTP_1588_CLOCK) += ptp.o
drivers/ptp/ptp_chardev.c new file +146 -0
146 lines not on this page · raw message
drivers/ptp/ptp_clock.c new file +318 -0
318 lines not on this page · raw message
drivers/ptp/ptp_private.h new file +86 -0
86 lines not on this page · raw message
drivers/ptp/ptp_sysfs.c new file +226 -0
226 lines not on this page · raw message
include/linux/Kbuild +1 -0
@@ -295,6 +295,7 @@ header-y += ppp-comp.h header-y += ppp_defs.h header-y += pps.h header-y += prctl.h +header-y += ptp_clock.h header-y += ptrace.h header-y += qnx4_fs.h header-y += qnxtypes.h
include/linux/ptp_clock.h new file +79 -0
79 lines not on this page · raw message
include/linux/ptp_clock_kernel.h new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 11/13 ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Richard CochranThe eTSEC includes a PTP clock with quite a few features. This patch adds support for the basic clock adjustment functions, plus two external time stamps, one alarm, and the PPS callback.
--- Documentation/powerpc/dts-bindings/fsl/tsec.txt | 57 +++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + drivers/net/Makefile | 1 + drivers/net/gianfar_ptp.c | 448 +++++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 ++++++ drivers/ptp/Kconfig | 13 + 9 files changed, 688 insertions(+), 0 deletions(-) create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h
Documentation/powerpc/dts-bindings/fsl/tsec.txt +57 -0
@@ -74,3 +74,60 @@ Example: interrupt-parent = <&mpic>; phy-handle = <&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp" + - reg Offset and length of the register set for the device + - interrupts There should be at least two interrupts. Some devices + have as many as four PTP related interrupts. + +Clock Properties: + + - tclk-period Timer reference clock period in nanoseconds. + - tmr-prsc Prescaler, divides the output clock. + - tmr-add Frequency compensation value. + - cksel 0= external clock, 1= eTSEC system clock, 3= RTC clock input. + Currently the driver only supports choice "1". + - tmr-fiper1 Fixed interval period pulse generator. + - tmr-fiper2 Fixed interval period pulse generator. + - max-adj Maximum frequency adjustment in parts per billion. + + These properties set the operational parameters for the PTP + clock. You must choose these carefully for the clock to work right. + Here is how to figure good values: + + TimerOsc = system clock MHz + tclk_period = desired clock period nanoseconds + NominalFreq = 1000 / tclk_period MHz + FreqDivRatio = TimerOsc / NominalFreq (must be greater that 1.0) + tmr_add = ceil(2^32 / FreqDivRatio) + OutputClock = NominalFreq / tmr_prsc MHz + PulseWidth = 1 / OutputClock microseconds + FiperFreq1 = desired frequency in Hz + FiperDiv1 = 1000000 * OutputClock / FiperFreq1 + tmr_fiper1 = tmr_prsc * tclk_period * FiperDiv1 - tclk_period + max_adj = 1000000000 * (FreqDivRatio - 1.0) - 1 + + The calculation for tmr_fiper2 is the same as for tmr_fiper1. The + driver expects that tmr_fiper1 will be correctly set to produce a 1 + Pulse Per Second (PPS) signal, since this will be offered to the PPS + subsystem to synchronize the Linux clock. + +Example: + + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk-period = <10>; + tmr-prsc = <100>; + tmr-add = <0x999999A4>; + cksel = <0x1>; + tmr-fiper1 = <0x3B9AC9F6>; + tmr-fiper2 = <0x00018696>; + max-adj = <659999998>; + };
arch/powerpc/boot/dts/mpc8313erdb.dts +14 -0
@@ -208,6 +208,20 @@ sleep = <&pmc 0x00300000>; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk-period = <10>; + tmr-prsc = <100>; + tmr-add = <0x999999A4>; + cksel = <0x1>; + tmr-fiper1 = <0x3B9AC9F6>; + tmr-fiper2 = <0x00018696>; + max-adj = <659999998>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/mpc8572ds.dts +14 -0
@@ -324,6 +324,20 @@ }; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2 71 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xAAAAAAAB>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x3B9AC9FB>; + max-adj = <499999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/p2020ds.dts +14 -0
@@ -336,6 +336,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xCCCCCCCD>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x0001869B>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/p2020rdb.dts +14 -0
@@ -396,6 +396,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xCCCCCCCD>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x0001869B>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
drivers/net/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_ATL2) += atlx/ obj-$(CONFIG_ATL1E) += atl1e/ obj-$(CONFIG_ATL1C) += atl1c/ obj-$(CONFIG_GIANFAR) += gianfar_driver.o +obj-$(CONFIG_PTP_1588_CLOCK_GIANFAR) += gianfar_ptp.o obj-$(CONFIG_TEHUTI) += tehuti.o obj-$(CONFIG_ENIC) += enic/ obj-$(CONFIG_JME) += jme.o
drivers/net/gianfar_ptp.c new file +448 -0
448 lines not on this page · raw message
drivers/net/gianfar_ptp_reg.h new file +113 -0
113 lines not on this page · raw message
drivers/ptp/Kconfig +13 -0
@@ -24,4 +24,17 @@ config PTP_1588_CLOCK To compile this driver as a module, choose M here: the module will be called ptp. +config PTP_1588_CLOCK_GIANFAR + tristate "Freescale eTSEC as PTP clock" + depends on PTP_1588_CLOCK + depends on GIANFAR + help + This driver adds support for using the eTSEC as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + To compile this driver as a module, choose M here: the module + will be called gianfar_ptp. + endmenu
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v8 12/13 ptp: Added a clock driver for the IXP46x.
In reply to Richard CochranThis patch adds a driver for the hardware time stamping unit found on the IXP465. The basic clock operations and an external trigger are implemented.
--- arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h | 78 ++++++ drivers/net/arm/ixp4xx_eth.c | 191 ++++++++++++++ drivers/ptp/Kconfig | 13 + drivers/ptp/Makefile | 1 + drivers/ptp/ptp_ixp46x.c | 344 +++++++++++++++++++++++++ 5 files changed, 627 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h create mode 100644 drivers/ptp/ptp_ixp46x.c
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h new file +78 -0
@@ -0,0 +1,78 @@ +/* +* PTP 1588 clock using the IXP46X +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _IXP46X_TS_H_ +#define _IXP46X_TS_H_ + +#define DEFAULT_ADDEND 0xF0000029 +#define TICKS_NS_SHIFT 4 + +struct ixp46x_channel_ctl { +u32 Ch_Control;/* 0x40 Time Synchronization Channel Control */ +u32 Ch_Event;/* 0x44 Time Synchronization Channel Event */ +u32 TxSnapLo;/* 0x48 Transmit Snapshot Low Register */ +u32 TxSnapHi;/* 0x4C Transmit Snapshot High Register */ +u32 RxSnapLo;/* 0x50 Receive Snapshot Low Register */ +u32 RxSnapHi;/* 0x54 Receive Snapshot High Register */ +u32 SrcUUIDLo;/* 0x58 Source UUID0 Low Register */ +u32 SrcUUIDHi;/* 0x5C Sequence Identifier/Source UUID0 High */ +}; + +struct ixp46x_ts_regs { +u32 Control;/* 0x00 Time Sync Control Register */ +u32 Event;/* 0x04 Time Sync Event Register */ +u32 Addend;/* 0x08 Time Sync Addend Register */ +u32 Accum;/* 0x0C Time Sync Accumulator Register */ +u32 Test;/* 0x10 Time Sync Test Register */ +u32 Unused;/* 0x14 */ +u32 RSysTime_Lo;/* 0x18 RawSystemTime_Low Register */ +u32 RSysTimeHi;/* 0x1C RawSystemTime_High Register */ +u32 SysTimeLo;/* 0x20 SystemTime_Low Register */ +u32 SysTimeHi;/* 0x24 SystemTime_High Register */ +u32 TrgtLo;/* 0x28 TargetTime_Low Register */ +u32 TrgtHi;/* 0x2C TargetTime_High Register */ +u32 ASMSLo;/* 0x30 Auxiliary Slave Mode Snapshot Low */ +u32 ASMSHi;/* 0x34 Auxiliary Slave Mode Snapshot High */ +u32 AMMSLo;/* 0x38 Auxiliary Master Mode Snapshot Low */ +u32 AMMSHi;/* 0x3C Auxiliary Master Mode Snapshot High */ + +struct ixp46x_channel_ctl channel[3 ]; +}; + +/* 0x00 Time Sync Control Register Bits */ +#define TSCR_AMM (1<<3) +#define TSCR_ASM (1<<2) +#define TSCR_TTM (1<<1) +#define TSCR_RST (1<<0) + +/* 0x04 Time Sync Event Register Bits */ +#define TSER_SNM (1<<3) +#define TSER_SNS (1<<2) +#define TTIPEND (1<<1) + +/* 0x40 Time Synchronization Channel Control Register Bits */ +#define MASTER_MODE (1<<0) +#define TIMESTAMP_ALL (1<<1) + +/* 0x44 Time Synchronization Channel Event Register Bits */ +#define TX_SNAPSHOT_LOCKED (1<<0) +#define RX_SNAPSHOT_LOCKED (1<<1) + +#endif
drivers/net/arm/ixp4xx_eth.c +191 -0
242 lines not on this page · raw message
drivers/ptp/Kconfig +13 -0
@@ -37,4 +37,17 @@ config PTP_1588_CLOCK_GIANFAR To compile this driver as a module, choose M here: the module will be called gianfar_ptp. +config PTP_1588_CLOCK_IXP46X + tristate "Intel IXP46x as PTP clock" + depends on PTP_1588_CLOCK + depends on IXP4XX_ETH + help + This driver adds support for using the IXP46X as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + To compile this driver as a module, choose M here: the module + will be called ptp_ixp46x. + endmenu
drivers/ptp/Makefile +1 -0
@@ -4,3 +4,4 @@ ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o obj-$(CONFIG_PTP_1588_CLOCK) += ptp.o +obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o
drivers/ptp/ptp_ixp46x.c new file +344 -0
344 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH V8 12/13] ptp: Added a clock driver for the IXP46x.
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h line 35
Quoted 9 lines · Richard Cochran
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h new file +9
-0+struct ixp46x_channel_ctl { +u32 Ch_Control;/* 0x40 Time Synchronization Channel Control */ +u32 Ch_Event;/* 0x44 Time Synchronization Channel Event */ +u32 TxSnapLo;/* 0x48 Transmit Snapshot Low Register */ +u32 TxSnapHi;/* 0x4C Transmit Snapshot High Register */ +u32 RxSnapLo;/* 0x50 Receive Snapshot Low Register */ +u32 RxSnapHi;/* 0x54 Receive Snapshot High Register */ +u32 SrcUUIDLo;/* 0x58 Source UUID0 Low Register */ +u32 SrcUUIDHi;/* 0x5C Sequence Identifier/Source UUID0 High */
I don't like these XxxYyyZzz either :-(
Quoted 37 lines
drivers/net/arm/ixp4xx_eth.c +37
-0+static void do_tx_timestamp (struct port *port,struct sk_buff *skb) +{ +#ifdef __ARMEB__ +struct skb_shared_hwtstamps shhwtstamps; +struct ixp46x_ts_regs *regs; +struct skb_shared_info *shtx; +u64 ns; +u32 ch, cnt, hi, lo, val; + + shtx =skb_shinfo (skb); +if (unlikely (shtx->tx_flags &SKBTX_HW_TSTAMP && port->hwts_tx_en)) + shtx->tx_flags |=SKBTX_IN_PROGRESS ; +else +return ; + + ch =PORT2CHANNEL (port); + + regs = (struct ixp46x_ts_regs __iomem *)IXP4XX_TIMESYNC_BASE_VIRT ; + +/* +* This really stinks, but we have to poll for the Tx time stamp. +* Usually, the time stamp is ready after 4 to 6 microseconds. +*/ +for (cnt =0 ; cnt <100 ; cnt++) { + val =__raw_readl (®s->channel[ch].Ch_Event); +if (val &TX_SNAPSHOT_LOCKED ) +break ; +udelay (1 ); + } +if (!(val &TX_SNAPSHOT_LOCKED )) { + shtx->tx_flags &= ~SKBTX_IN_PROGRESS ; +return ; + } + + lo =__raw_readl (®s->channel[ch].TxSnapLo); + hi =__raw_readl (®s->channel[ch].TxSnapHi); + ns = ((u64 ) hi) <<32 ;
drivers/net/arm/ixp4xx_eth.c static int ports_open; · line 376
Quoted 10 lines
drivers/net/arm/ixp4xx_eth.c +10
-0+ ns |= lo; + ns <<=TICKS_NS_SHIFT ; + +memset (&shhwtstamps,0 ,sizeof (shhwtstamps)); + shhwtstamps.hwtstamp =ns_to_ktime (ns); +skb_tstamp_tx (skb, &shhwtstamps); + +__raw_writel (TX_SNAPSHOT_LOCKED , ®s->channel[ch].Ch_Event); +#endif +}
And what if we're little-endian? Why does it depend on BE?
drivers/net/arm/ixp4xx_eth.c static int __devinit eth_init_one(struct platform_device *pdev) · line 1366
Quoted 11 lines
drivers/net/arm/ixp4xx_eth.c +5
-0@@ -1171,6 +1357,11 @@ static int __devinit eth_init_one(struct platform_device *pdev)char phy_id[MII_BUS_ID_SIZE +3 ];int err; +if (ptp_filter_init (ptp_filter,ARRAY_SIZE (ptp_filter))) { +pr_err ("ixp4xx_eth: bad ptp filter\n" ); +return -EINVAL ; + } +if (!(dev =alloc_etherdev (sizeof (struct port ))))return -ENOMEM ;
Shouldn't it depend on CPU type?
BTW which CPU is required? IXP46x (455/460/465)? Does it work on 43x?
Review static int __devinit eth_init_one(struct platform_device *pdev)
Quoted 2 lines
(quoted diff) +2
-0+ if (NO_IRQ == irq) + return NO_IRQ;
Don't like these either :-(
Not showstoppers but...
Also I don't like the ixp_read/ixp_write() trivial macros. Why not simply call __raw_readl() and __raw_writel()?
Signature · 1 line
Krzysztof Halasa
Richard Cochran
maintainerRe: [PATCH V8 12/13] ptp: Added a clock driver for the IXP46x.
Krzysztof,
Thanks for your review. I have some responses, below.
But before that, I have a big favor to ask you. Can you please look at the TODO in my patch and give me a hint? I don't know how to relate the port instance (NPE A,B,C) to the two time stamping channels.
Quoted 4 lines · Krzysztof Halasa
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h line 35
Quoted 1 line · Richard Cochran
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h new file +1
-0+u32 SrcUUIDHi;/* 0x5C Sequence Identifier/Source UUID0 High */ I don't like these XxxYyyZzz either :-(
Okay, I'll change that.
Quoted 3 lines
Quoted 3 lines
drivers/net/arm/ixp4xx_eth.c +3
-0+static void do_tx_timestamp (struct port *port,struct sk_buff *skb) +{ +#ifdef __ARMEB__
...
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#endif +}And what if we're little-endian?
It is a NOOP in that case.
Quoted 1 line
Why does it depend on BE?
The time stamp code clones the skb, but the LE version frees the skb too early. Perhaps we can move that dev_kfree_skb(skb) in the LE case to be the last statement in eth_xmit(). What do you think?
Quoted 5 lines
Quoted 5 lines
drivers/net/arm/ixp4xx_eth.c +0
-0@@ -1171,6 +1357,11 @@ static int __devinit eth_init_one(struct platform_device *pdev)char phy_id[MII_BUS_ID_SIZE +3 ];int err;
Quoted 9 lines
drivers/net/arm/ixp4xx_eth.c static int __devinit eth_init_one(struct platform_device *pdev) · line 1366
Quoted 7 lines
drivers/net/arm/ixp4xx_eth.c +5
-0+if (ptp_filter_init (ptp_filter,ARRAY_SIZE (ptp_filter))) { +pr_err ("ixp4xx_eth: bad ptp filter\n" ); +return -EINVAL ; + } +if (!(dev =alloc_etherdev (sizeof (struct port ))))return -ENOMEM ;Shouldn't it depend on CPU type?
It won't hurt to init the BPF unconditionally. The important bits are checked with cpu_is_ixp46x().
Quoted 1 line
BTW which CPU is required? IXP46x (455/460/465)? Does it work on 43x?
IIRC, it does not work on 43x.
I don't know about 455 and 460, but I can find out...
Quoted 4 lines
Review static int __devinit eth_init_one(struct platform_device *pdev)
Quoted 2 lines
(quoted diff) +2
-0+ if (NO_IRQ == irq) + return NO_IRQ;Don't like these either :-(
Do you mean, you don't like the constant on the left hand side?
Is that prohibited by CodingStyle or similar?
I got into the habit of writing it that way to prevent a typo like:
if (irq = NO_IRQ)
Quoted 4 lines
Not showstoppers but...
Also I don't like the ixp_read/ixp_write() trivial macros. Why not simply call
__raw_readl()and__raw_writel()?
Well, I have had the experience back in 2.4 days of having my drivers ruined by the changing IO macros in the kernel. The wrappers are supposed to help if that ever happens again. Seeing *two* leading underscores in the macro names certainly makes me nervous.
Thanks again,
Richard
Re: [PATCH V8 12/13] ptp: Added a clock driver for the IXP46x.
Quoted 3 lines · Richard Cochran
The time stamp code clones the skb, but the LE version frees the skb too early. Perhaps we can move that
dev_kfree_skb(skb)in the LE case to be the last statement ineth_xmit(). What do you think?
I think so. Or something similar.
Quoted 1 line
Do you mean, you don't like the constant on the left hand side?
Yes.
Quoted 1 line
Is that prohibited by CodingStyle or similar?
I don't think so. It's just a personal taste. I think it's based on things learned in primary school, they teach to write (comparisons) X = 4 instead of the other way around, and my brain seems to shock a bit on the opposite.
Quoted 3 lines
I got into the habit of writing it that way to prevent a typo like:
if (irq =
NO_IRQ)
I see. Unfortunately it doesn't prevent typos like this when the right side isn't a constant. Anyway gcc warns about them, even when both sides are variable.
Quoted 7 lines
Quoted 2 lines
Also I don't like the ixp_read/ixp_write() trivial macros. Why not simply call
__raw_readl()and__raw_writel()?Well, I have had the experience back in 2.4 days of having my drivers ruined by the changing IO macros in the kernel. The wrappers are supposed to help if that ever happens again. Seeing *two* leading underscores in the macro names certainly makes me nervous.
Well, these two underscores mainly mean it's arch-dependent, but so are the ixp4xx drivers. Using the __raw_read* directly is the preferred method (or, perhaps, in such case, it's the only way).
Actually, I was thinking about changing the macros some time ago, and it may eventually happen. But we'll fix all the code using them then.
Signature · 1 line
Krzysztof Halasa
Re: [PATCH V8 12/13] ptp: Added a clock driver for the IXP46x.
In reply to Richard CochranQuoted 3 lines · Richard Cochran
But before that, I have a big favor to ask you. Can you please look at the TODO in my patch and give me a hint? I don't know how to relate the port instance (NPE A,B,C) to the two time stamping channels.
I assume you mean this:
+ * PHYSICAL_ID(p->id) ?
+ * TODO - Figure out correct mapping.
Unfortunately I can's find this information in the devel manual. I think there are 3 channels (not two), each for one Ethernet port. IXP465 can have a port on each NPE.
PHYSICAL_ID etc. are described at the start of the file:
* logical port 0x00 0x10 0x20 * NPE 0 (NPE-A) 1 (NPE-B) 2 (NPE-C) * physical PortId 2 0 1
This means the first port (usually "eth0") is connected to NPE-B, the second port to NPE-C, and the third port to NPE-A (not available on IXP42x).
Also, the manual says NPE-B can serve 3 additional Ethernet ports (6 total).
I only have access to IXP425 (and 421) hardware. I think someone with the actual IXP465 has to check the details.
Signature · 1 line
Krzysztof Halasa
Richard Cochran
maintainerPATCH v8 13/13 ptp: Added a clock driver for the National Semiconductor PHYTER.
In reply to Richard CochranThis patch adds support for the PTP clock found on the DP83640. The basic clock operations and one external time stamp have been implemented.
--- drivers/net/phy/Kconfig | 29 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/dp83640.c | 896 +++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/dp83640_reg.h | 261 ++++++++++++ 4 files changed, 1187 insertions(+), 0 deletions(-) create mode 100644 drivers/net/phy/dp83640.c create mode 100644 drivers/net/phy/dp83640_reg.h
drivers/net/phy/Kconfig +29 -0
@@ -76,6 +76,35 @@ config NATIONAL_PHY ---help--- Currently supports the DP83865 PHY. +config DP83640_PHY + tristate "Driver for the National Semiconductor DP83640 PHYTER" + depends on PTP_1588_CLOCK + depends on NETWORK_PHY_TIMESTAMPING + ---help--- + Supports the DP83640 PHYTER with IEEE 1588 features. + + This driver adds support for using the DP83640 as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + In order for this to work, your MAC driver must also + implement the skb_tx_timetamp() function. + +config DP83640_PHY_STATUS_FRAMES + bool "DP83640 Status Frames" + default y + depends on DP83640_PHY + ---help--- + This option allows the DP83640 PHYTER driver to obtain time + stamps from the PHY via special status frames, rather than + reading over the MDIO bus. Using status frames is therefore + more efficient. However, if enabled, this option will cause + the driver to add a mutlicast address to the MAC. + + Say Y here, unless your MAC does not support multicast + destination addresses. + config STE10XP depends on PHYLIB tristate "Driver for STMicroelectronics STe10Xp PHYs"
drivers/net/phy/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_FIXED_PHY) += fixed.o obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o obj-$(CONFIG_MDIO_GPIO) += mdio-gpio.o obj-$(CONFIG_NATIONAL_PHY) += national.o +obj-$(CONFIG_DP83640_PHY) += dp83640.o obj-$(CONFIG_STE10XP) += ste10Xp.o obj-$(CONFIG_MICREL_PHY) += micrel.o obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
drivers/net/phy/dp83640.c new file +896 -0
896 lines not on this page · raw message
drivers/net/phy/dp83640_reg.h new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
1.7.0.4