pps: several fixes and improvements
Subsystems (4)
v3 cover pps: several fixes and improvements
This patchset contains several changes that improve an overall design/performance of PPS subsystem. I'd like these patches to be merged mainline if no one objects.
Patches 1-3 are bugfixes.
Patches 4-11 are other improvements to PPS subsystem. Patches 12-14 add kernel consumer support. Patch 15 adds parallel port PPS client.
Patch 16 adds parallel port PPS generator.
You can find description for my previous patchset (it describes patches 12-16 in more detailed) here: http://lkml.org/lkml/2010/2/24/189
This patchset is tested against the vanilla 2.6.35 kernel. But we are actually using it on 2.6.33.7-rt29 rt-preempt kernel most of the time. Those who are interested in other versions of the patchset can find them in my git repository:git://github.com/ago/linux-2.6.git
There is one problem however: kernel consumer works bad (if enabled) when CONFIG_NO_HZ is enabled. The reason for this is commit a092ff0f90cae22b2ac8028ecd2c6f6c1a9e4601. Without it hardpps() is able to sync to 1us precision in about 10 seconds. With CONFIG_NO_HZ it is not syncing at all. This only affects patches 12-14, others are ok.
2John Stultz: the problem is not with logarithmic accumulation because it works good if NTP_INTERVAL_FREQ is set to 2.
Changelog
v2 -> v3:
* add patches 1-11
* add clear_wait parameter to pps_parport
* add delay parameter to pps_gen_parport
* fix seqlock unlocking
* fix issues pointed out by Rodolfo Giometti:
* move CONFIG_NTP_PPS to drivers/pps/Kconfig
* swap parport client and generator patches
* style and typo fixes
* move patch that adds unified timestamp gathering to be the beginning
v1 -> v2:
* fix issues pointed out by John Stultz:
* style fixes
* add a about the authorship of the original code
* replace timespec with pps_normtime struct where timespec is used in a wrong way
* fix seqlock usage in hardpps()
* unbind kernel consumer on device removal
* send raw timestamp instead of the last difference to hardpps() which simplifies the code and is less error-prone
* update comments in the kernel consumer code to match the reality
* split the patch that adds MONOTONIC_RAW timestmaps into two
* other small fixes
Alexander Gordeev (16):
pps: trivial fixes
pps: declare variables where they are used in switch
pps: fix race in PPS_FETCH handler
pps: unify timestamp gathering
pps: access pps device by direct pointer
pps: convert printk/pr_* to dev_*
pps: move idr stuff to pps.c
pps: add async PPS event handler
pps: don't disable interrupts when using spin locks
pps: use BUG_ON for kernel API safety checks
pps: simplify conditions a bit
ntp: add hardpps implementation
pps: capture MONOTONIC_RAW timestamps as well
pps: add kernel consumer support
pps: add parallel port PPS client
pps: add parallel port PPS signal generator
Documentation/ioctl/ioctl-number.txt | 2 +- drivers/pps/Kconfig | 10 + drivers/pps/Makefile | 2 +- drivers/pps/clients/Kconfig | 7 + drivers/pps/clients/Makefile | 1 + drivers/pps/clients/pps-ktimer.c | 43 ++-- drivers/pps/clients/pps-ldisc.c | 49 ++-- drivers/pps/clients/pps_parport.c | 244 +++++++++++++++++ drivers/pps/generators/Kconfig | 17 ++ drivers/pps/generators/Makefile | 9 + drivers/pps/generators/pps_gen_parport.c | 274 +++++++++++++++++++ drivers/pps/kapi.c | 330 +++++++++++------------- drivers/pps/pps.c | 201 +++++++++++--- include/linux/pps.h | 7 + include/linux/pps_kernel.h | 64 ++++- include/linux/serial_core.h | 5 +- include/linux/time.h | 2 + include/linux/timex.h | 1 + include/linux/tty_ldisc.h | 5 +- kernel/time/ntp.c | 421 ++++++++++++++++++++++++++++- kernel/time/timekeeping.c | 34 +++ 21 files changed, 1419 insertions(+), 309 deletions(-) create mode 100644 drivers/pps/clients/pps_parport.c create mode 100644 drivers/pps/generators/Kconfig create mode 100644 drivers/pps/generators/Makefile create mode 100644 drivers/pps/generators/pps_gen_parport.c
PATCH v3 1/16 pps: trivial fixes
Here are some very trivial fixes combined:
* add macro definitions to protect header file from including several times
* remove declaration for an unexistent array
* fix typos
--- drivers/pps/kapi.c | 2 +- include/linux/pps_kernel.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/pps/kapi.c +1 -1
@@ -324,7 +324,7 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) captured = ~0 ; } -/* Wake up iif captured somthing */ +/* Wake up if captured something */ if (captured) { pps->go = ~0 ;wake_up_interruptible (&pps->queue);
include/linux/pps_kernel.h +6 -1
@@ -18,6 +18,9 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef LINUX_PPS_KERNEL_H +#define LINUX_PPS_KERNEL_H +#include <linux/pps.h> #include <linux/cdev.h>
@@ -71,7 +74,6 @@ struct pps_device {extern spinlock_t pps_idr_lock;extern struct idr pps_idr; -extern struct timespec pps_irq_ts[];extern struct device_attribute pps_attrs[];
@@ -87,3 +89,6 @@ extern void pps_unregister_source(int source);extern int pps_register_cdev (struct pps_device *pps);extern void pps_unregister_cdev (struct pps_device *pps);extern void pps_event (int source,struct pps_ktime *ts,int event,void *data); + +#endif /* LINUX_PPS_KERNEL_H */ +
Signature · 1 line
1.7.1
Re: [PATCHv3 01/16] pps: trivial fixes
Quoted 55 lines · Alexander Gordeev
Here are some very trivial fixes combined:
* add macro definitions to protect header file from including several times
* remove declaration for an unexistent array
* fix typosSigned-off-by Alexander Gordeev <[email protected]>--- drivers/pps/kapi.c | 2 +- include/linux/pps_kernel.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)drivers/pps/kapi.c +1
-1@@ -324,7 +324,7 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) captured = ~0 ; } -/* Wake up iif captured somthing */ +/* Wake up if captured something */ if (captured) { pps->go = ~0 ;wake_up_interruptible (&pps->queue);include/linux/pps_kernel.h +6
-1@@ -18,6 +18,9 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef LINUX_PPS_KERNEL_H +#define LINUX_PPS_KERNEL_H +#include <linux/pps.h> #include <linux/cdev.h> @@ -71,7 +74,6 @@ struct pps_device {extern spinlock_t pps_idr_lock;extern struct idr pps_idr; -extern struct timespec pps_irq_ts[];extern struct device_attribute pps_attrs[];@@ -87,3 +89,6 @@ extern void pps_unregister_source(int source);extern int pps_register_cdev (struct pps_device *pps);extern void pps_unregister_cdev (struct pps_device *pps);extern void pps_event (int source,struct pps_ktime *ts,int event,void *data); + +#endif /* LINUX_PPS_KERNEL_H */ +Signature · 1 line
1.7.1
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
PATCH v3 2/16 pps: declare variables where they are used in switch
In reply to Alexander GordeevMove variable declarations where they are used in pps_cdev_ioctl.
--- drivers/pps/pps.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/pps/pps.c +6 -4
@@ -61,8 +61,6 @@ static long pps_cdev_ioctl(struct file *file, {struct pps_device *pps = file->private_data;struct pps_kparams params; -struct pps_fdata fdata; -unsigned long ticks;void __user *uarg = (void __user *) arg;int __user *iuarg = (int __user *) arg;int err;
@@ -136,7 +134,9 @@ static long pps_cdev_ioctl(struct file *file,break ; -case PPS_FETCH : +case PPS_FETCH : { +struct pps_fdata fdata; +pr_debug ("PPS_FETCH: source %d\n" , pps->id); err =copy_from_user (&fdata, uarg,sizeof (struct pps_fdata ));
@@ -149,6 +149,8 @@ static long pps_cdev_ioctl(struct file *file,if (fdata.timeout.flags &PPS_TIME_INVALID ) err =wait_event_interruptible (pps->queue, pps->go);else { +unsigned long ticks; +pr_debug ("timeout %lld.%09d\n" , (long long ) fdata.timeout.sec, fdata.timeout.nsec);
@@ -185,7 +187,7 @@ static long pps_cdev_ioctl(struct file *file,return -EFAULT ;break ; - + }default :return -ENOTTY ;break ;
Signature · 1 line
1.7.1
Re: [PATCHv3 02/16] pps: declare variables where they are used in switch
Quoted 51 lines · Alexander Gordeev
Move variable declarations where they are used in
pps_cdev_ioctl.Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/pps.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)drivers/pps/pps.c +6
-4@@ -61,8 +61,6 @@ static long pps_cdev_ioctl(struct file *file, {struct pps_device *pps = file->private_data;struct pps_kparams params; -struct pps_fdata fdata; -unsigned long ticks;void __user *uarg = (void __user *) arg;int __user *iuarg = (int __user *) arg;int err;@@ -136,7 +134,9 @@ static long pps_cdev_ioctl(struct file *file,break ; -case PPS_FETCH : +case PPS_FETCH : { +struct pps_fdata fdata; +pr_debug ("PPS_FETCH: source %d\n" , pps->id); err =copy_from_user (&fdata, uarg,sizeof (struct pps_fdata ));@@ -149,6 +149,8 @@ static long pps_cdev_ioctl(struct file *file,if (fdata.timeout.flags &PPS_TIME_INVALID ) err =wait_event_interruptible (pps->queue, pps->go);else { +unsigned long ticks; +pr_debug ("timeout %lld.%09d\n" , (long long ) fdata.timeout.sec, fdata.timeout.nsec);@@ -185,7 +187,7 @@ static long pps_cdev_ioctl(struct file *file,return -EFAULT ;break ; - + }default :return -ENOTTY ;break ;Signature · 1 line
1.7.1
I don't like such definitions but I know it is just a stylistic problem, so it's ok for me. :)
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
PATCH v3 3/16 pps: fix race in PPS_FETCH handler
In reply to Alexander GordeevThere was a race in PPS_FETCH ioctl handler when several processes want to obtain PPS data simultaneously using sleeping PPS_FETCH. They all sleep most of the time in the system call.
With the old approach when the first process waiting on the pps queue is waken up it makes new system call right away and zeroes pps->go. So other processes continue to sleep. This is a clear race condition because of the global 'go' variable.
With the new approach pps->last_ev holds some value increasing at each PPS event. PPS_FETCH ioctl handler saves current value to the local variable at the very beginning so it can safely check that there is a new event by just comparing both variables.
--- drivers/pps/kapi.c | 4 ++-- drivers/pps/pps.c | 10 +++++++--- include/linux/pps_kernel.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)
drivers/pps/kapi.c +2 -2
@@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)/* Wake up if captured something */ if (captured) { - pps->go = ~0 ; -wake_up_interruptible (&pps->queue); + pps->last_ev++; +wake_up_interruptible_all (&pps->queue);kill_fasync (&pps->async_queue,SIGIO ,POLL_IN ); }
drivers/pps/pps.c +7 -3
@@ -136,6 +136,7 @@ static long pps_cdev_ioctl(struct file *file,case PPS_FETCH : {struct pps_fdata fdata; +unsigned int ev;pr_debug ("PPS_FETCH: source %d\n" , pps->id);
@@ -143,11 +144,12 @@ static long pps_cdev_ioctl(struct file *file,if (err)return -EFAULT ; - pps->go =0 ; + ev = pps->last_ev;/* Manage the timeout */ if (fdata.timeout.flags &PPS_TIME_INVALID ) - err =wait_event_interruptible (pps->queue, pps->go); + err =wait_event_interruptible (pps->queue, + ev < pps->last_ev);else {unsigned long ticks;
@@ -159,7 +161,9 @@ static long pps_cdev_ioctl(struct file *file,if (ticks !=0 ) { err =wait_event_interruptible_timeout ( - pps->queue, pps->go, ticks); + pps->queue, + ev < pps->last_ev, + ticks);if (err ==0 )return -ETIMEDOUT ; }
include/linux/pps_kernel.h +1 -1
@@ -55,7 +55,7 @@ struct pps_device {struct pps_ktime clear_tu;int current_mode;/* PPS mode at event time */ -int go;/* PPS event is arrived? */ +unsigned int last_ev;/* last PPS event id */ wait_queue_head_t queue;/* PPS event queue */ unsigned int id;/* PPS source unique ID */
Signature · 1 line
1.7.1
Re: [PATCHv3 03/16] pps: fix race in PPS_FETCH handler
Quoted 24 lines · Alexander Gordeev
There was a race in
PPS_FETCHioctl handler when several processes want to obtain PPS data simultaneously using sleepingPPS_FETCH. They all sleep most of the time in the system call.
With the old approach when the first process waiting on the pps queue is waken up it makes new system call right away and zeroespps->go. So other processes continue to sleep. This is a clear race condition because of the global 'go' variable.
With the new approachpps->last_evholds some value increasing at each PPS event.PPS_FETCHioctl handler saves current value to the local variable at the very beginning so it can safely check that there is a new event by just comparing both variables.Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/kapi.c | 4 ++-- drivers/pps/pps.c | 10 +++++++--- include/linux/pps_kernel.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)drivers/pps/kapi.c +0
-0
drivers/pps/kapi.c void pps_event(int source, struct pps_ktime *ts, int event, void *data) · line 330
Quoted 7 lines
drivers/pps/kapi.c +2
-2@@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)/* Wake up if captured something */ if (captured) { - pps->go = ~0 ; -wake_up_interruptible (&pps->queue); + pps->last_ev++; +wake_up_interruptible_all (&pps->queue);
What happens if pps->last_ev overflows? Seems to me it would freeze
pps.
Cheers,
Vita
Re: [PATCHv3 03/16] pps: fix race in PPS_FETCH handler
Hi Vitezslav,
В Thu, 5 Aug 2010 07:19:29 +0200
Vitezslav Samel <[email protected]> пишет:
Quoted 26 lines · Alexander Gordeev
Quoted 25 lines
There was a race in
PPS_FETCHioctl handler when several processes want to obtain PPS data simultaneously using sleepingPPS_FETCH. They all sleep most of the time in the system call.
With the old approach when the first process waiting on the pps queue is waken up it makes new system call right away and zeroespps->go. So other processes continue to sleep. This is a clear race condition because of the global 'go' variable.
With the new approachpps->last_evholds some value increasing at each PPS event.PPS_FETCHioctl handler saves current value to the local variable at the very beginning so it can safely check that there is a new event by just comparing both variables.Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/kapi.c | 4 ++-- drivers/pps/pps.c | 10 +++++++--- include/linux/pps_kernel.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)drivers/pps/kapi.c +0
-0@@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)
Quoted 9 lines
drivers/pps/kapi.c void pps_event(int source, struct pps_ktime *ts, int event, void *data) · line 330
Quoted 6 lines
drivers/pps/kapi.c +2
-2/* Wake up if captured something */ if (captured) { - pps->go = ~0 ; -wake_up_interruptible (&pps->queue); + pps->last_ev++; +wake_up_interruptible_all (&pps->queue);What happens if
pps->last_evoverflows? Seems to me it would freeze
pps.
Yes, it will freeze the fds (if they don't use timeouts). But in normal circumstances, i.e. when pps_event is called twice a second, it will overflow after ~68 years of uninterrupted work. Well, it's the same kind of problem as an overflow of struct timespec. I thought it's not actually a problem. Should I use u64 instead of unsigned int or add a runtime check somewhere?
Signature · 1 line
Alexander
Re: [PATCHv3 03/16] pps: fix race in PPS_FETCH handler
Quoted 41 lines · Alexander Gordeev
Hi Vitezslav,
В Thu, 5 Aug 2010 07:19:29 +0200
Vitezslav Samel <[email protected]> пишет:Quoted 26 lines · Alexander Gordeev
Quoted 25 lines
There was a race in
PPS_FETCHioctl handler when several processes want to obtain PPS data simultaneously using sleepingPPS_FETCH. They all sleep most of the time in the system call.
With the old approach when the first process waiting on the pps queue is waken up it makes new system call right away and zeroespps->go. So other processes continue to sleep. This is a clear race condition because of the global 'go' variable.
With the new approachpps->last_evholds some value increasing at each PPS event.PPS_FETCHioctl handler saves current value to the local variable at the very beginning so it can safely check that there is a new event by just comparing both variables.Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/kapi.c | 4 ++-- drivers/pps/pps.c | 10 +++++++--- include/linux/pps_kernel.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)drivers/pps/kapi.c +0
-0@@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)Quoted 9 lines
drivers/pps/kapi.c void pps_event(int source, struct pps_ktime *ts, int event, void *data) · line 330
Quoted 6 lines
drivers/pps/kapi.c +2
-2/* Wake up if captured something */ if (captured) { - pps->go = ~0 ; -wake_up_interruptible (&pps->queue); + pps->last_ev++; +wake_up_interruptible_all (&pps->queue);What happens if
pps->last_evoverflows? Seems to me it would freeze
pps.
Quoted 6 lines
Yes, it will freeze the fds (if they don't use timeouts). But in normal circumstances, i.e. when
pps_eventis called twice a second, it will overflow after ~68 years of uninterrupted work. Well, it's the same kind of problem as an overflow of struct timespec. I thought it's not actually a problem. Should I use u64 instead of unsigned int or add a runtime check somewhere?
If we're using 1PPS it's ~68 years, but someone is trying 5PPS now
(it would overflow in ~13.6 years) - what if someone tries e.g. 100PPS? It's not the same as overflow of struct timespec! I think it deserves some treatment.
Cheers,
Vita
Re: [PATCHv3 03/16] pps: fix race in PPS_FETCH handler
В Thu, 5 Aug 2010 13:07:50 +0200
Vitezslav Samel <[email protected]> пишет:
Quoted 49 lines · Alexander Gordeev
Quoted 41 lines
Hi Vitezslav,
В Thu, 5 Aug 2010 07:19:29 +0200
Vitezslav Samel <[email protected]> пишет:Quoted 26 lines · Alexander Gordeev
Quoted 25 lines
There was a race in
PPS_FETCHioctl handler when several processes want to obtain PPS data simultaneously using sleepingPPS_FETCH. They all sleep most of the time in the system call.
With the old approach when the first process waiting on the pps queue is waken up it makes new system call right away and zeroespps->go. So other processes continue to sleep. This is a clear race condition because of the global 'go' variable.
With the new approachpps->last_evholds some value increasing at each PPS event.PPS_FETCHioctl handler saves current value to the local variable at the very beginning so it can safely check that there is a new event by just comparing both variables.Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/kapi.c | 4 ++-- drivers/pps/pps.c | 10 +++++++--- include/linux/pps_kernel.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)drivers/pps/kapi.c +0
-0@@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)Quoted 9 lines
drivers/pps/kapi.c void pps_event(int source, struct pps_ktime *ts, int event, void *data) · line 330
Quoted 6 lines
drivers/pps/kapi.c +2
-2/* Wake up if captured something */ if (captured) { - pps->go = ~0 ; -wake_up_interruptible (&pps->queue); + pps->last_ev++; +wake_up_interruptible_all (&pps->queue);What happens if
pps->last_evoverflows? Seems to me it would freeze
pps.Quoted 6 lines
Yes, it will freeze the fds (if they don't use timeouts). But in normal circumstances, i.e. when
pps_eventis called twice a second, it will overflow after ~68 years of uninterrupted work. Well, it's the same kind of problem as an overflow of struct timespec. I thought it's not actually a problem. Should I use u64 instead of unsigned int or add a runtime check somewhere?
Quoted 4 lines
If we're using 1PPS it's ~68 years, but someone is trying 5PPS now
(it would overflow in ~13.6 years) - what if someone tries e.g. 100PPS? It's not the same as overflow of struct timespec! I think it deserves some treatment.
You are right. :)
I'll use u64 here then which should be enough for sure, ok?
Thanks for the note!
Signature · 1 line
Alexander
Re: [PATCHv3 03/16] pps: fix race in PPS_FETCH handler
In reply to Alexander GordeevQuoted 87 lines · Alexander Gordeev
There was a race in
PPS_FETCHioctl handler when several processes want to obtain PPS data simultaneously using sleepingPPS_FETCH. They all sleep most of the time in the system call.
With the old approach when the first process waiting on the pps queue is waken up it makes new system call right away and zeroespps->go. So other processes continue to sleep. This is a clear race condition because of the global 'go' variable.
With the new approachpps->last_evholds some value increasing at each PPS event.PPS_FETCHioctl handler saves current value to the local variable at the very beginning so it can safely check that there is a new event by just comparing both variables.Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/kapi.c | 4 ++-- drivers/pps/pps.c | 10 +++++++--- include/linux/pps_kernel.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)drivers/pps/kapi.c +2
-2@@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)/* Wake up if captured something */ if (captured) { - pps->go = ~0 ; -wake_up_interruptible (&pps->queue); + pps->last_ev++; +wake_up_interruptible_all (&pps->queue);kill_fasync (&pps->async_queue,SIGIO ,POLL_IN ); }drivers/pps/pps.c +7
-3@@ -136,6 +136,7 @@ static long pps_cdev_ioctl(struct file *file,case PPS_FETCH : {struct pps_fdata fdata; +unsigned int ev;pr_debug ("PPS_FETCH: source %d\n" , pps->id);@@ -143,11 +144,12 @@ static long pps_cdev_ioctl(struct file *file,if (err)return -EFAULT ; - pps->go =0 ; + ev = pps->last_ev;/* Manage the timeout */ if (fdata.timeout.flags &PPS_TIME_INVALID ) - err =wait_event_interruptible (pps->queue, pps->go); + err =wait_event_interruptible (pps->queue, + ev < pps->last_ev);else {unsigned long ticks;@@ -159,7 +161,9 @@ static long pps_cdev_ioctl(struct file *file,if (ticks !=0 ) { err =wait_event_interruptible_timeout ( - pps->queue, pps->go, ticks); + pps->queue, + ev < pps->last_ev, + ticks);if (err ==0 )return -ETIMEDOUT ; }include/linux/pps_kernel.h +1
-1@@ -55,7 +55,7 @@ struct pps_device {struct pps_ktime clear_tu;int current_mode;/* PPS mode at event time */ -int go;/* PPS event is arrived? */ +unsigned int last_ev;/* last PPS event id */ wait_queue_head_t queue;/* PPS event queue */ unsigned int id;/* PPS source unique ID */ Signature · 1 line
1.7.1
Yes. It was added when we passed from ioctl to unlocked_ioctl...
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
PATCH v3 4/16 pps: unify timestamp gathering
In reply to Alexander GordeevAdd a helper function to gather timestamps. This way clients don't have to duplicate it.
--- drivers/pps/clients/pps-ktimer.c | 9 ++------- drivers/pps/clients/pps-ldisc.c | 18 ++++++------------ drivers/pps/kapi.c | 19 ++++++++++++------- include/linux/pps_kernel.h | 19 ++++++++++++++++++- include/linux/serial_core.h | 5 +++-- include/linux/tty_ldisc.h | 5 +++-- 6 files changed, 44 insertions(+), 31 deletions(-)
drivers/pps/clients/pps-ktimer.c +2 -7
@@ -40,18 +40,13 @@ static struct timer_list ktimer;static void pps_ktimer_event (unsigned long ptr) { -struct timespec __ts; -struct pps_ktime ts; +struct pps_event_time ts;/* First of all we get the time stamp... */ -getnstimeofday (&__ts); +pps_get_ts (&ts);pr_info ("PPS event at %lu\n" , jiffies); -/* ... and translate it to PPS time data struct */ - ts.sec = __ts.tv_sec; - ts.nsec = __ts.tv_nsec; -pps_event (source, &ts,PPS_CAPTUREASSERT ,NULL );mod_timer (&ktimer, jiffies +HZ );
drivers/pps/clients/pps-ldisc.c +6 -12
@@ -27,26 +27,20 @@#define PPS_TTY_MAGIC 0x0001static void pps_tty_dcd_change (struct tty_struct *tty,unsigned int status, -struct timespec *ts) +struct pps_event_time *ts) {int id = (long )tty->disc_data; -struct timespec __ts; -struct pps_ktime pps_ts; +struct pps_event_time __ts;/* First of all we get the time stamp... */ -getnstimeofday (&__ts); +pps_get_ts (&__ts);/* Does caller give us a timestamp? */ -if (ts) {/* Yes. Let's use it! */ - pps_ts.sec = ts->tv_sec; - pps_ts.nsec = ts->tv_nsec; - }else {/* No. Do it ourself! */ - pps_ts.sec = __ts.tv_sec; - pps_ts.nsec = __ts.tv_nsec; - } +if (!ts)/* No. Do it ourself! */ + ts = &__ts;/* Now do the PPS event report */ -pps_event (id, &pps_ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR , +pps_event (id, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR ,NULL ); pr_debug("PPS %s at %lu on source #%d\n",
drivers/pps/kapi.c +12 -7
@@ -268,11 +268,12 @@ EXPORT_SYMBOL(pps_unregister_source);* pps->info.echo(source, event, data); */ -void pps_event (int source,struct pps_ktime *ts,int event,void *data) +void pps_event (int source,struct pps_event_time *ts,int event,void *data) {struct pps_device *pps;unsigned long flags;int captured =0 ; +struct pps_ktime ts_real;if ((event & (PPS_CAPTUREASSERT |PPS_CAPTURECLEAR )) ==0 ) { printk(KERN_ERR "pps: unknown event (%x) for source %d\n",
@@ -284,8 +285,10 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)if (!pps)return ; -pr_debug ("PPS event on source %d at %llu.%06u\n" , - pps->id, (unsigned long long ) ts->sec, ts->nsec); +pr_debug ("PPS event on source %d at %ld.%09ld\n" , + pps->id, ts->ts_real.tv_sec, ts->ts_real.tv_nsec); + +timespec_to_pps_ktime (&ts_real, ts->ts_real);spin_lock_irqsave (&pps->lock, flags);
@@ -299,10 +302,11 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) (pps->params.mode & PPS_CAPTUREASSERT)) {/* We have to add an offset? */ if (pps->params.mode &PPS_OFFSETASSERT ) -pps_add_offset (ts, &pps->params.assert_off_tu); +pps_add_offset (&ts_real, + &pps->params.assert_off_tu);/* Save the time stamp */ - pps->assert_tu = *ts; + pps->assert_tu = ts_real; pps->assert_sequence++;pr_debug ("capture assert seq #%u for source %d\n" , pps->assert_sequence, source);
@@ -313,10 +317,11 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data) (pps->params.mode & PPS_CAPTURECLEAR)) {/* We have to add an offset? */ if (pps->params.mode &PPS_OFFSETCLEAR ) -pps_add_offset (ts, &pps->params.clear_off_tu); +pps_add_offset (&ts_real, + &pps->params.clear_off_tu);/* Save the time stamp */ - pps->clear_tu = *ts; + pps->clear_tu = ts_real; pps->clear_sequence++;pr_debug ("capture clear seq #%u for source %d\n" , pps->clear_sequence, source);
include/linux/pps_kernel.h +18 -1
@@ -43,6 +43,10 @@ struct pps_source_info {struct device *dev; }; +struct pps_event_time { +struct timespec ts_real; +}; +/* The main struct */ struct pps_device {struct pps_source_info info;/* PSS source info */
@@ -88,7 +92,20 @@ extern int pps_register_source(struct pps_source_info *info,extern void pps_unregister_source (int source);extern int pps_register_cdev (struct pps_device *pps);extern void pps_unregister_cdev (struct pps_device *pps); -extern void pps_event (int source,struct pps_ktime *ts,int event,void *data); +extern void pps_event (int source,struct pps_event_time *ts,int event, +void *data); + +static inline void timespec_to_pps_ktime (struct pps_ktime *kt, +struct timespec ts) +{ + kt->sec = ts.tv_sec; + kt->nsec = ts.tv_nsec; +} + +static inline void pps_get_ts (struct pps_event_time *ts) +{ +getnstimeofday (&ts->ts_real); +}#endif /* LINUX_PPS_KERNEL_H */
include/linux/serial_core.h +3 -2
@@ -196,6 +196,7 @@#include <linux/tty.h> #include <linux/mutex.h> #include <linux/sysrq.h> +#include <linux/pps_kernel.h> struct uart_port ;struct serial_struct ;
@@ -497,10 +498,10 @@ uart_handle_dcd_change(struct uart_port *uport, unsigned int status)struct uart_state *state = uport->state;struct tty_port *port = &state->port;struct tty_ldisc *ld =tty_ldisc_ref (port->tty); -struct timespec ts; +struct pps_event_time ts;if (ld && ld->ops->dcd_change) -getnstimeofday (&ts); +pps_get_ts (&ts); uport->icount.dcd++;#ifdef CONFIG_HARD_PPS
include/linux/tty_ldisc.h +3 -2
@@ -101,7 +101,7 @@* any pending driver I/O is completed. * * void (*dcd_change)(struct tty_struct *tty, unsigned int status, -* struct timespec *ts) +* struct pps_event_time *ts) * * Tells the discipline that the DCD pin has changed its status and * the relative timestamp. Pointer ts can be NULL.
@@ -109,6 +109,7 @@#include <linux/fs.h> #include <linux/wait.h> +#include <linux/pps_kernel.h> struct tty_ldisc_ops {int magic;
@@ -143,7 +144,7 @@ struct tty_ldisc_ops { char *fp, int count);void (*write_wakeup)(struct tty_struct *);void (*dcd_change)(struct tty_struct *,unsigned int , -struct timespec *); +struct pps_event_time *);struct module *owner;
Signature · 1 line
1.7.1
Re: [PATCHv3 04/16] pps: unify timestamp gathering
Quoted 4 lines · Alexander Gordeev
Add a helper function to gather timestamps. This way clients don't have to duplicate it.
Signed-off-by Alexander Gordeev <[email protected]>
Quoted 8 lines
--- drivers/pps/clients/pps-ktimer.c | 9 ++------- drivers/pps/clients/pps-ldisc.c | 18 ++++++------------ drivers/pps/kapi.c | 19 ++++++++++++------- include/linux/pps_kernel.h | 19 ++++++++++++++++++- include/linux/serial_core.h | 5 +++-- include/linux/tty_ldisc.h | 5 +++-- 6 files changed, 44 insertions(+), 31 deletions(-)
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
PATCH v3 5/16 pps: access pps device by direct pointer
In reply to Alexander GordeevUsing device index as a pointer needs some unnecessary work to be done every time the pointer is needed (in irq handler for example). Using a direct pointer is much more easy (and safe as well).
--- drivers/pps/clients/pps-ktimer.c | 30 ++++----- drivers/pps/clients/pps-ldisc.c | 33 +++++----- drivers/pps/kapi.c | 124 ++++++++----------------------------- drivers/pps/pps.c | 22 ++----- include/linux/pps_kernel.h | 21 +++---- 5 files changed, 70 insertions(+), 160 deletions(-)
drivers/pps/clients/pps-ktimer.c +13 -17
@@ -31,7 +31,7 @@* Global variables */ -static int source; +static struct pps_device *pps;;static struct timer_list ktimer;/*
@@ -47,7 +47,7 @@ static void pps_ktimer_event(unsigned long ptr)pr_info ("PPS event at %lu\n" , jiffies); -pps_event (source, &ts,PPS_CAPTUREASSERT ,NULL ); +pps_event (pps, &ts,PPS_CAPTUREASSERT ,NULL );mod_timer (&ktimer, jiffies +HZ ); }
@@ -56,12 +56,11 @@ static void pps_ktimer_event(unsigned long ptr)* The echo function */ -static void pps_ktimer_echo (int source,int event,void *data) +static void pps_ktimer_echo (struct pps_device *pps,int event,void *data) { -pr_info ("echo %s %s for source %d\n" , +dev_info (pps->dev,"echo %s %s\n" , event &PPS_CAPTUREASSERT ?"assert" :"" , - event &PPS_CAPTURECLEAR ?"clear" :"" , - source); + event &PPS_CAPTURECLEAR ?"clear" :"" ); }/*
@@ -84,30 +83,27 @@ static struct pps_source_info pps_ktimer_info = { static void __exit pps_ktimer_exit(void) { -del_timer_sync (&ktimer); -pps_unregister_source (source); +dev_info (pps->dev,"ktimer PPS source unregistered\n" ); -pr_info ("ktimer PPS source unregistered\n" ); +del_timer_sync (&ktimer); +pps_unregister_source (pps); }static int __init pps_ktimer_init (void ) { -int ret; - - ret =pps_register_source (&pps_ktimer_info, + pps =pps_register_source (&pps_ktimer_info,PPS_CAPTUREASSERT |PPS_OFFSETASSERT ); -if (ret <0 ) { +if (pps ==NULL ) {printk (KERN_ERR "cannot register ktimer source\n" ); -return ret; +return -ENOMEM ; } - source = ret;setup_timer (&ktimer, pps_ktimer_event,0 );mod_timer (&ktimer, jiffies +HZ ); -pr_info ("ktimer PPS source registered at %d\n" , source); +dev_info (pps->dev,"ktimer PPS source registered\n" ); -return 0 ; +return 0 ; }module_init (pps_ktimer_init);
drivers/pps/clients/pps-ldisc.c +16 -17
@@ -29,7 +29,7 @@static void pps_tty_dcd_change (struct tty_struct *tty,unsigned int status,struct pps_event_time *ts) { -int id = (long )tty->disc_data; +struct pps_device *pps = (struct pps_device *)tty->disc_data;struct pps_event_time __ts;/* First of all we get the time stamp... */
@@ -40,11 +40,11 @@ static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, ts = &__ts;/* Now do the PPS event report */ -pps_event (id, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR , +pps_event (pps, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR ,NULL ); -pr_debug ("PPS %s at %lu on source #%d\n" , - status ?"assert" :"clear" , jiffies, id); +dev_dbg (pps->dev,"PPS %s at %lu\n" , status ?"assert" :"clear" , + jiffies); }static int (*alias_n_tty_open)(struct tty_struct *tty);
@@ -54,7 +54,7 @@ static int pps_tty_open(struct tty_struct *tty)struct pps_source_info info;struct tty_driver *drv = tty->driver;int index = tty->index + drv->name_base; -int ret; +struct pps_device *pps; info.owner =THIS_MODULE ; info.dev =NULL ;
@@ -64,20 +64,19 @@ static int pps_tty_open(struct tty_struct *tty)PPS_OFFSETASSERT |PPS_OFFSETCLEAR | \PPS_CANWAIT |PPS_TSFMT_TSPEC ; - ret =pps_register_source (&info,PPS_CAPTUREBOTH | \ + pps =pps_register_source (&info,PPS_CAPTUREBOTH | \PPS_OFFSETASSERT |PPS_OFFSETCLEAR ); -if (ret <0 ) { +if (pps ==NULL ) {pr_err ("cannot register PPS source \"%s\"\n" , info.path); -return ret; +return -ENOMEM ; } - tty->disc_data = (void *)(long )ret; + tty->disc_data = pps;/* Should open N_TTY ldisc too */ - ret =alias_n_tty_open (tty); -if (ret <0 ) -pps_unregister_source ((long )tty->disc_data); +if (alias_n_tty_open (tty) <0 ) +pps_unregister_source (pps); -pr_info ("PPS source #%d \"%s\" added\n" , ret, info.path); +dev_info (pps->dev,"source \"%s\" added\n" , info.path);return 0 ; }
@@ -86,12 +85,12 @@ static void (*alias_n_tty_close)(struct tty_struct *tty);static void pps_tty_close (struct tty_struct *tty) { -int id = (long )tty->disc_data; +struct pps_device *pps = (struct pps_device *)tty->disc_data; -pps_unregister_source (id); -alias_n_tty_close (tty); +dev_info (pps->dev,"removed\n" ); -pr_info ("PPS source #%d removed\n" , id); +pps_unregister_source (pps); +alias_n_tty_close (tty); }static struct tty_ldisc_ops pps_ldisc_ops;
drivers/pps/kapi.c +27 -97
221 lines not on this page · raw message
drivers/pps/pps.c +6 -16
@@ -204,12 +204,6 @@ static int pps_cdev_open(struct inode *inode, struct file *file) {struct pps_device *pps =container_of (inode->i_cdev, struct pps_device, cdev); -int found; - - found =pps_get_source (pps->id) !=0 ; -if (!found) -return -ENODEV ; - file->private_data = pps;return 0 ;
@@ -217,11 +211,6 @@ static int pps_cdev_open(struct inode *inode, struct file *file)static int pps_cdev_release (struct inode *inode,struct file *file) { -struct pps_device *pps = file->private_data; - -/* Free the PPS source and wake up (possible) deregistration */ -pps_put_source (pps); -return 0 ; }
@@ -242,22 +231,23 @@ static const struct file_operations pps_cdev_fops = {int pps_register_cdev (struct pps_device *pps) {int err; +dev_t devt; + + devt =MKDEV (MAJOR (pps_devt), pps->id); - pps->devno =MKDEV (MAJOR (pps_devt), pps->id);cdev_init (&pps->cdev, &pps_cdev_fops); pps->cdev.owner = pps->info.owner; - err =cdev_add (&pps->cdev, pps->devno,1 ); + err =cdev_add (&pps->cdev, devt,1 );if (err) {printk (KERN_ERR "pps: %s: failed to add char device %d:%d\n" , pps->info.name,MAJOR (pps_devt), pps->id);return err; } - pps->dev =device_create (pps_class, pps->info.dev, pps->devno,NULL , + pps->dev =device_create (pps_class, pps->info.dev, devt, pps,"pps%d" , pps->id);if (IS_ERR (pps->dev)) goto del_cdev; -dev_set_drvdata (pps->dev, pps);pr_debug ("source %s got cdev (%d:%d)\n" , pps->info.name,MAJOR (pps_devt), pps->id);
@@ -272,7 +262,7 @@ del_cdev:void pps_unregister_cdev (struct pps_device *pps) { -device_destroy (pps_class, pps->devno); +device_destroy (pps_class, pps->dev->devt);cdev_del (&pps->cdev); }
include/linux/pps_kernel.h +8 -13
@@ -31,13 +31,16 @@* Global defines */ +struct pps_device ; +/* The specific PPS source info */ struct pps_source_info {char name[PPS_MAX_NAME_LEN ];/* simbolic name */ char path[PPS_MAX_NAME_LEN ];/* path of connected device */ int mode;/* PPS's allowed mode */ -void (*echo)(int source,int event,void *data);/* PPS echo function */ +void (*echo)(struct pps_device *pps, +int event,void *data);/* PPS echo function */ struct module *owner;struct device *dev;
@@ -65,34 +68,26 @@ struct pps_device {unsigned int id;/* PPS source unique ID */ struct cdev cdev;struct device *dev; -int devno;struct fasync_struct *async_queue;/* fasync method */ spinlock_t lock; - -atomic_t usage;/* usage count */ };/* * Global variables */ -extern spinlock_t pps_idr_lock; -extern struct idr pps_idr; -extern struct device_attribute pps_attrs[];/* * Exported functions */ -struct pps_device *pps_get_source (int source); -extern void pps_put_source (struct pps_device *pps); -extern int pps_register_source (struct pps_source_info *info, -int default_params); -extern void pps_unregister_source (int source); +extern struct pps_device *pps_register_source ( +struct pps_source_info *info,int default_params); +extern void pps_unregister_source (struct pps_device *pps);extern int pps_register_cdev (struct pps_device *pps);extern void pps_unregister_cdev (struct pps_device *pps); -extern void pps_event (int source,struct pps_event_time *ts,int event, +extern void pps_event (struct pps_device *pps,struct pps_event_time *ts,int event,void *data); static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
Signature · 1 line
1.7.1
Rodolfo Giometti
maintainerRe: [PATCHv3 05/16] pps: access pps device by direct pointer
Quoted 238 lines · Alexander Gordeev
Using device index as a pointer needs some unnecessary work to be done every time the pointer is needed (in irq handler for example). Using a direct pointer is much more easy (and safe as well).
Signed-off-by Alexander Gordeev <[email protected]>--- drivers/pps/clients/pps-ktimer.c | 30 ++++----- drivers/pps/clients/pps-ldisc.c | 33 +++++----- drivers/pps/kapi.c | 124 ++++++++----------------------------- drivers/pps/pps.c | 22 ++----- include/linux/pps_kernel.h | 21 +++---- 5 files changed, 70 insertions(+), 160 deletions(-)drivers/pps/clients/pps-ktimer.c +13
-17@@ -31,7 +31,7 @@* Global variables */ -static int source; +static struct pps_device *pps;;static struct timer_list ktimer;/* @@ -47,7 +47,7 @@ static void pps_ktimer_event(unsigned long ptr)pr_info ("PPS event at %lu\n" , jiffies); -pps_event (source, &ts,PPS_CAPTUREASSERT ,NULL ); +pps_event (pps, &ts,PPS_CAPTUREASSERT ,NULL );mod_timer (&ktimer, jiffies +HZ ); }@@ -56,12 +56,11 @@ static void pps_ktimer_event(unsigned long ptr)* The echo function */ -static void pps_ktimer_echo (int source,int event,void *data) +static void pps_ktimer_echo (struct pps_device *pps,int event,void *data) { -pr_info ("echo %s %s for source %d\n" , +dev_info (pps->dev,"echo %s %s\n" , event &PPS_CAPTUREASSERT ?"assert" :"" , - event &PPS_CAPTURECLEAR ?"clear" :"" , - source); + event &PPS_CAPTURECLEAR ?"clear" :"" ); }/* @@ -84,30 +83,27 @@ static struct pps_source_info pps_ktimer_info = { static void __exit pps_ktimer_exit(void) { -del_timer_sync (&ktimer); -pps_unregister_source (source); +dev_info (pps->dev,"ktimer PPS source unregistered\n" ); -pr_info ("ktimer PPS source unregistered\n" ); +del_timer_sync (&ktimer); +pps_unregister_source (pps); }static int __init pps_ktimer_init (void ) { -int ret; - - ret =pps_register_source (&pps_ktimer_info, + pps =pps_register_source (&pps_ktimer_info,PPS_CAPTUREASSERT |PPS_OFFSETASSERT ); -if (ret <0 ) { +if (pps ==NULL ) {printk (KERN_ERR "cannot register ktimer source\n" ); -return ret; +return -ENOMEM ; } - source = ret;setup_timer (&ktimer, pps_ktimer_event,0 );mod_timer (&ktimer, jiffies +HZ ); -pr_info ("ktimer PPS source registered at %d\n" , source); +dev_info (pps->dev,"ktimer PPS source registered\n" ); -return 0 ; +return 0 ; }module_init (pps_ktimer_init);drivers/pps/clients/pps-ldisc.c +16
-17@@ -29,7 +29,7 @@static void pps_tty_dcd_change (struct tty_struct *tty,unsigned int status,struct pps_event_time *ts) { -int id = (long )tty->disc_data; +struct pps_device *pps = (struct pps_device *)tty->disc_data;struct pps_event_time __ts;/* First of all we get the time stamp... */ @@ -40,11 +40,11 @@ static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, ts = &__ts;/* Now do the PPS event report */ -pps_event (id, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR , +pps_event (pps, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR ,NULL ); -pr_debug ("PPS %s at %lu on source #%d\n" , - status ?"assert" :"clear" , jiffies, id); +dev_dbg (pps->dev,"PPS %s at %lu\n" , status ?"assert" :"clear" , + jiffies); }static int (*alias_n_tty_open)(struct tty_struct *tty);@@ -54,7 +54,7 @@ static int pps_tty_open(struct tty_struct *tty)struct pps_source_info info;struct tty_driver *drv = tty->driver;int index = tty->index + drv->name_base; -int ret; +struct pps_device *pps; info.owner =THIS_MODULE ; info.dev =NULL ;@@ -64,20 +64,19 @@ static int pps_tty_open(struct tty_struct *tty)PPS_OFFSETASSERT |PPS_OFFSETCLEAR | \PPS_CANWAIT |PPS_TSFMT_TSPEC ; - ret =pps_register_source (&info,PPS_CAPTUREBOTH | \ + pps =pps_register_source (&info,PPS_CAPTUREBOTH | \PPS_OFFSETASSERT |PPS_OFFSETCLEAR ); -if (ret <0 ) { +if (pps ==NULL ) {pr_err ("cannot register PPS source \"%s\"\n" , info.path); -return ret; +return -ENOMEM ; } - tty->disc_data = (void *)(long )ret; + tty->disc_data = pps;/* Should open N_TTY ldisc too */ - ret =alias_n_tty_open (tty); -if (ret <0 ) -pps_unregister_source ((long )tty->disc_data); +if (alias_n_tty_open (tty) <0 ) +pps_unregister_source (pps); -pr_info ("PPS source #%d \"%s\" added\n" , ret, info.path); +dev_info (pps->dev,"source \"%s\" added\n" , info.path);return 0 ; }@@ -86,12 +85,12 @@ static void (*alias_n_tty_close)(struct tty_struct *tty);static void pps_tty_close (struct tty_struct *tty) { -int id = (long )tty->disc_data; +struct pps_device *pps = (struct pps_device *)tty->disc_data; -pps_unregister_source (id); -alias_n_tty_close (tty); +dev_info (pps->dev,"removed\n" ); -pr_info ("PPS source #%d removed\n" , id); +pps_unregister_source (pps); +alias_n_tty_close (tty); }static struct tty_ldisc_ops pps_ldisc_ops;drivers/pps/kapi.c +3
-46@@ -32,11 +32,11 @@#include <linux/slab.h> /* -* Global variables +* Local variables */ -DEFINE_SPINLOCK (pps_idr_lock); -DEFINE_IDR (pps_idr); +static DEFINE_SPINLOCK (pps_idr_lock); +static DEFINE_IDR (pps_idr);/* * Local functions @@ -60,60 +60,6 @@ static void pps_add_offset(struct pps_ktime *ts, struct pps_ktime *offset)* Exported functions */ -/* pps_get_source - find a PPS source -* @source: the PPS source ID. -* -* This function is used to find an already registered PPS source into the -* system. -* -* The function returns NULL if found nothing, otherwise it returns a pointer -* to the PPS source data struct (the refcounter is incremented by 1). -*/ - -struct pps_device *pps_get_source (int source) -{ -struct pps_device *pps; -unsigned long flags; - -spin_lock_irqsave (&pps_idr_lock, flags); - - pps =idr_find (&pps_idr, source); -if (pps !=NULL ) -atomic_inc (&pps->usage); - -spin_unlock_irqrestore (&pps_idr_lock, flags); - -return pps; -} - -/* pps_put_source - free the PPS source data -* @pps: a pointer to the PPS source. -* -* This function is used to free a PPS data struct if its refcount is 0. -*/ - -void pps_put_source (struct pps_device *pps) -{ -unsigned long flags; - -spin_lock_irqsave (&pps_idr_lock, flags); -BUG_ON (atomic_read (&pps->usage) ==0 ); - -if (!atomic_dec_and_test (&pps->usage)) { - pps =NULL ; - goto exit; - }
drivers/pps/kapi.c static void pps_add_offset(struct pps_ktime *ts, struct pps_ktime *offset) · line 115
Quoted 10 lines
drivers/pps/kapi.c +0
-10- -/* No more reference to the PPS source. We can safely remove the -* PPS data struct. -*/ -idr_remove (&pps_idr, pps->id); - -exit: -spin_unlock_irqrestore (&pps_idr_lock, flags); -kfree (pps); -}
If you remove these functions you can't be sure anymore that nobodies may call pps_event() over a non existent device...
Quoted 106 lines
drivers/pps/kapi.c +17
-26/* pps_register_source - add a PPS source in the system * @info: the PPS info struct * @default_params: the default PPS parameters of the new source @@ -122,10 +68,11 @@ exit:* source is described by info's fields and it will have, as default PPS * parameters, the ones specified into default_params. * -* The function returns, in case of success, the PPS source ID. +* The function returns, in case of success, the PPS device. Otherwise NULL. */ -int pps_register_source (struct pps_source_info *info,int default_params) +struct pps_device *pps_register_source (struct pps_source_info *info, +int default_params) {struct pps_device *pps;int id;@@ -168,7 +115,6 @@ int pps_register_source(struct pps_source_info *info, int default_params)init_waitqueue_head (&pps->queue);spin_lock_init (&pps->lock); -atomic_set (&pps->usage,1 );/* Get new ID for the new PPS source */ if (idr_pre_get (&pps_idr,GFP_KERNEL ) ==0 ) {@@ -211,7 +157,7 @@ int pps_register_source(struct pps_source_info *info, int default_params)pr_info ("new PPS source %s at ID %d\n" , info->name, id); -return id; +return pps; free_idr:spin_lock_irq (&pps_idr_lock);@@ -224,38 +170,31 @@ kfree_pps: pps_register_source_exit:printk (KERN_ERR "pps: %s: unable to register source\n" , info->name); -return err; +return NULL ; }EXPORT_SYMBOL (pps_register_source);/* pps_unregister_source - remove a PPS source from the system -* @source: the PPS source ID +* @pps: the PPS source * * This function is used to remove a previously registered PPS source from * the system. */ -void pps_unregister_source (int source) +void pps_unregister_source (struct pps_device *pps) { -struct pps_device *pps; +unsigned int id = pps->id; +pps_unregister_cdev (pps); +spin_lock_irq (&pps_idr_lock); - pps =idr_find (&pps_idr, source); - -if (!pps) { -BUG (); -spin_unlock_irq (&pps_idr_lock); -return ; - } +idr_remove (&pps_idr, pps->id);spin_unlock_irq (&pps_idr_lock); - -pps_unregister_cdev (pps); -pps_put_source (pps); }EXPORT_SYMBOL (pps_unregister_source);/* pps_event - register a PPS event into the system -* @source: the PPS source ID +* @pps: the PPS device * @ts: the event timestamp * @event: the event type * @data: userdef pointer @@ -263,30 +202,24 @@ EXPORT_SYMBOL(pps_unregister_source);* This function is used by each PPS client in order to register a new * PPS event into the system (it's usually called inside an IRQ handler). * -* If an echo function is associated with the PPS source it will be called +* If an echo function is associated with the PPS device it will be called * as: -* pps->info.echo(source, event, data); +* pps->info.echo(pps, event, data); */ - -void pps_event (int source,struct pps_event_time *ts,int event,void *data) +void pps_event (struct pps_device *pps,struct pps_event_time *ts,int event, +void *data) { -struct pps_device *pps;unsigned long flags;int captured =0 ;struct pps_ktime ts_real;if ((event & (PPS_CAPTUREASSERT |PPS_CAPTURECLEAR )) ==0 ) { -printk (KERN_ERR "pps: unknown event (%x) for source %d\n" , - event, source); +dev_err (pps->dev,"unknown event (%x)\n" , event);return ;
drivers/pps/kapi.c EXPORT_SYMBOL(pps_unregister_source); · line 222
Quoted 10 lines
drivers/pps/kapi.c +2
-6} - pps =pps_get_source (source); -if (!pps) -return ; - -pr_debug ("PPS event on source %d at %ld.%09ld\n" , - pps->id, ts->ts_real.tv_sec, ts->ts_real.tv_nsec); +dev_dbg (pps->dev,"PPS event at %ld.%09ld\n" , + ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
By dropping pps_get_source you may be here by a call from (i.e.) a serial port driver whose doesn't know if your PPS source is gone or not...
I don't understand how your modifications may resolve this problem.
Quoted 172 lines
drivers/pps/kapi.c +5
-8timespec_to_pps_ktime (&ts_real, ts->ts_real);@@ -294,7 +227,7 @@ void pps_event(int source, struct pps_event_time *ts, int event, void *data)/* Must call the echo function? */ if ((pps->params.mode & (PPS_ECHOASSERT |PPS_ECHOCLEAR ))) - pps->info.echo (source, event, data); + pps->info.echo (pps, event, data);/* Check the event */ pps->current_mode = pps->params.mode;@@ -308,8 +241,8 @@ void pps_event(int source, struct pps_event_time *ts, int event, void *data)/* Save the time stamp */ pps->assert_tu = ts_real; pps->assert_sequence++; -pr_debug ("capture assert seq #%u for source %d\n" , - pps->assert_sequence, source); +dev_dbg (pps->dev,"capture assert seq #%u\n" , + pps->assert_sequence); captured = ~0 ; }@@ -323,8 +256,8 @@ void pps_event(int source, struct pps_event_time *ts, int event, void *data)/* Save the time stamp */ pps->clear_tu = ts_real; pps->clear_sequence++; -pr_debug ("capture clear seq #%u for source %d\n" , - pps->clear_sequence, source); +dev_dbg (pps->dev,"capture clear seq #%u\n" , + pps->clear_sequence); captured = ~0 ; }@@ -338,8 +271,5 @@ void pps_event(int source, struct pps_event_time *ts, int event, void *data) }spin_unlock_irqrestore (&pps->lock, flags); - -/* Now we can release the PPS source for (possible) deregistration */ -pps_put_source (pps); }EXPORT_SYMBOL (pps_event);drivers/pps/pps.c +6
-16@@ -204,12 +204,6 @@ static int pps_cdev_open(struct inode *inode, struct file *file) {struct pps_device *pps =container_of (inode->i_cdev, struct pps_device, cdev); -int found; - - found =pps_get_source (pps->id) !=0 ; -if (!found) -return -ENODEV ; - file->private_data = pps;return 0 ;@@ -217,11 +211,6 @@ static int pps_cdev_open(struct inode *inode, struct file *file)static int pps_cdev_release (struct inode *inode,struct file *file) { -struct pps_device *pps = file->private_data; - -/* Free the PPS source and wake up (possible) deregistration */ -pps_put_source (pps); -return 0 ; }@@ -242,22 +231,23 @@ static const struct file_operations pps_cdev_fops = {int pps_register_cdev (struct pps_device *pps) {int err; +dev_t devt; + + devt =MKDEV (MAJOR (pps_devt), pps->id); - pps->devno =MKDEV (MAJOR (pps_devt), pps->id);cdev_init (&pps->cdev, &pps_cdev_fops); pps->cdev.owner = pps->info.owner; - err =cdev_add (&pps->cdev, pps->devno,1 ); + err =cdev_add (&pps->cdev, devt,1 );if (err) {printk (KERN_ERR "pps: %s: failed to add char device %d:%d\n" , pps->info.name,MAJOR (pps_devt), pps->id);return err; } - pps->dev =device_create (pps_class, pps->info.dev, pps->devno,NULL , + pps->dev =device_create (pps_class, pps->info.dev, devt, pps,"pps%d" , pps->id);if (IS_ERR (pps->dev)) goto del_cdev; -dev_set_drvdata (pps->dev, pps);pr_debug ("source %s got cdev (%d:%d)\n" , pps->info.name,MAJOR (pps_devt), pps->id);@@ -272,7 +262,7 @@ del_cdev:void pps_unregister_cdev (struct pps_device *pps) { -device_destroy (pps_class, pps->devno); +device_destroy (pps_class, pps->dev->devt);cdev_del (&pps->cdev); }include/linux/pps_kernel.h +8
-13@@ -31,13 +31,16 @@* Global defines */ +struct pps_device ; +/* The specific PPS source info */ struct pps_source_info {char name[PPS_MAX_NAME_LEN ];/* simbolic name */ char path[PPS_MAX_NAME_LEN ];/* path of connected device */ int mode;/* PPS's allowed mode */ -void (*echo)(int source,int event,void *data);/* PPS echo function */ +void (*echo)(struct pps_device *pps, +int event,void *data);/* PPS echo function */ struct module *owner;struct device *dev;@@ -65,34 +68,26 @@ struct pps_device {unsigned int id;/* PPS source unique ID */ struct cdev cdev;struct device *dev; -int devno;struct fasync_struct *async_queue;/* fasync method */ spinlock_t lock; - -atomic_t usage;/* usage count */ };/* * Global variables */ -extern spinlock_t pps_idr_lock; -extern struct idr pps_idr; -extern struct device_attribute pps_attrs[];/* * Exported functions */ -struct pps_device *pps_get_source (int source); -extern void pps_put_source (struct pps_device *pps); -extern int pps_register_source (struct pps_source_info *info, -int default_params); -extern void pps_unregister_source (int source); +extern struct pps_device *pps_register_source ( +struct pps_source_info *info,int default_params); +extern void pps_unregister_source (struct pps_device *pps);extern int pps_register_cdev (struct pps_device *pps);extern void pps_unregister_cdev (struct pps_device *pps); -extern void pps_event (int source,struct pps_event_time *ts,int event, +extern void pps_event (struct pps_device *pps,struct pps_event_time *ts,int event,void *data); static inline void timespec_to_pps_ktime(struct pps_ktime *kt,Signature · 1 line
1.7.1
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
Re: [PATCHv3 05/16] pps: access pps device by direct pointer
В Thu, 5 Aug 2010 11:32:36 +0200
Rodolfo Giometti <[email protected]> пишет:
Quoted 6 lines · Alexander Gordeev
Quoted 5 lines
Using device index as a pointer needs some unnecessary work to be done every time the pointer is needed (in irq handler for example). Using a direct pointer is much more easy (and safe as well).
Signed-off-by Alexander Gordeev <[email protected]>
[snip]
Quoted 3 lines
If you remove these functions you can't be sure anymore that nobodies may call
pps_event()over a non existent device...
[snip]
Quoted 5 lines
By dropping
pps_get_sourceyou may be here by a call from (i.e.) a serial port driver whose doesn't know if your PPS source is gone or not...I don't understand how your modifications may resolve this problem.
Well, this can happen only if PPS client module calls pps_event before calling pps_register_source() or after pps_unregister_source(). This means that it's broken! If we try to handle/workaround broken clients it affects performance. So we have to choose what is the priority:
security or performance. My guru told me I shouldn't bother too much about broken kernel-space code which my code interacts with. If it's broken it should be fixed. Some assertions enabled by DEBUG define are enough. For me it makes sense but I don't know what should I check here?
Well I can add something like that to pps_event:
BUG_ON((pps == NULL) || (pps_get_source(pps->id) != pps));
where pps_get_source is:
static inline struct pps_device *pps_get_source(int source)
{
struct pps_device *pps;
unsigned long flags;
spin_lock_irqsave(&pps_idr_lock, flags);
pps = idr_find(&pps_idr, source);
spin_unlock_irqrestore(&pps_idr_lock, flags);
return pps;
}BTW, while looking at the code to answer your question I've found a
bug: struct pps_device was not kfree'd on device destruction. The fix will appear soon. Perhaps with an assertion above if you like it.
Signature · 1 line
Alexander
Rodolfo Giometti
maintainerRe: [PATCHv3 05/16] pps: access pps device by direct pointer
Quoted 20 lines · Alexander Gordeev
?? Thu, 5 Aug 2010 11:32:36 +0200
Rodolfo Giometti <[email protected]> ??????????:Quoted 6 lines · Alexander Gordeev
Quoted 5 lines
Using device index as a pointer needs some unnecessary work to be done every time the pointer is needed (in irq handler for example). Using a direct pointer is much more easy (and safe as well).
Signed-off-by Alexander Gordeev <[email protected]>[snip]
Quoted 3 lines
If you remove these functions you can't be sure anymore that nobodies may call
pps_event()over a non existent device...[snip]
Quoted 4 lines
By dropping
pps_get_sourceyou may be here by a call from (i.e.) a serial port driver whose doesn't know if your PPS source is gone or not...
Quoted 5 lines
Quoted 1 line
I don't understand how your modifications may resolve this problem.
Well, this can happen only if PPS client module calls
pps_eventbefore callingpps_register_source()or afterpps_unregister_source(). This means that it's broken! If we try to handle/workaround broken clients it
Suppose we are using pps-ldisc client. How can you assure that nobodies may execute pps_tty_close() while you are into the pps_event() related to the same serial port?
You can't disable serial interrupts in order to avoid pps_tty_dcd_change calls...
Quoted 5 lines
affects performance. So we have to choose what is the priority:
security or performance. My guru told me I shouldn't bother too much about broken kernel-space code which my code interacts with. If it's broken it should be fixed. Some assertions enabled by DEBUG define are enough. For me it makes sense but I don't know what should I check here?
I'm sorry but I disagree with you. Kernel code can't allow userland programs to corrupt it!
We are not discussing about security or performance but about reliability.
Ciao,
Rodolfo
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
Re: [PATCHv3 05/16] pps: access pps device by direct pointer
В Thu, 5 Aug 2010 14:31:47 +0200
Rodolfo Giometti <[email protected]> пишет:
Quoted 27 lines · Alexander Gordeev
Quoted 20 lines
?? Thu, 5 Aug 2010 11:32:36 +0200
Rodolfo Giometti <[email protected]> ??????????:Quoted 6 lines · Alexander Gordeev
Quoted 5 lines
Using device index as a pointer needs some unnecessary work to be done every time the pointer is needed (in irq handler for example). Using a direct pointer is much more easy (and safe as well).
Signed-off-by Alexander Gordeev <[email protected]>[snip]
Quoted 3 lines
If you remove these functions you can't be sure anymore that nobodies may call
pps_event()over a non existent device...[snip]
Quoted 4 lines
By dropping
pps_get_sourceyou may be here by a call from (i.e.) a serial port driver whose doesn't know if your PPS source is gone or not...Quoted 5 lines
Quoted 1 line
I don't understand how your modifications may resolve this problem.
Well, this can happen only if PPS client module calls
pps_eventbefore callingpps_register_source()or afterpps_unregister_source(). This means that it's broken! If we try to handle/workaround broken clients it
Quoted 6 lines
Suppose we are using pps-ldisc client. How can you assure that nobodies may execute
pps_tty_close()while you are into thepps_event()related to the same serial port?You can't disable serial interrupts in order to avoid
pps_tty_dcd_changecalls...
Hmm, yes, I see...
But this is custom problem of only one client. I think it should be fixed in place instead of trying to fix it in the subsystem.
Are you 100% sure dcd_change can be called before open or after close? Then I'll try to deal with this.
Quoted 11 lines
Quoted 5 lines
affects performance. So we have to choose what is the priority:
security or performance. My guru told me I shouldn't bother too much about broken kernel-space code which my code interacts with. If it's broken it should be fixed. Some assertions enabled by DEBUG define are enough. For me it makes sense but I don't know what should I check here?I'm sorry but I disagree with you. Kernel code can't allow userland programs to corrupt it!
We are not discussing about security or performance but about reliability.
Sure, now I see the problem (in the pps-ldisc).
Signature · 1 line
Alexander
Rodolfo Giometti
maintainerRe: [PATCHv3 05/16] pps: access pps device by direct pointer
Quoted 4 lines · Alexander Gordeev
Hmm, yes, I see...
But this is custom problem of only one client. I think it should be fixed in place instead of trying to fix it in the subsystem.
I agree with you but I had no luck in doing it in the past... :'(
Maybe you can ask some help to the serial port maintainers or you can try in pushing the PPS_IRQ_EVENTS solution (see my repository) into main tree, in fact that solution could resolve two problems at once:
* this one, since we simply read PPS data into an array in RAM, and
* the weak PPS resolution in recording PPS timestamps into normal IRQ
* handlers.
However, the big issue on this solution is about the call of gettimeofday() for each IRQs into the system (see old mails into this list about this topic) which slows down the machine's performance.
A workaround (as suggested by Alan Cox if I well remember) could be adding a flag for each IRQs in order to know if the timestamp must be recorded or not (testing a flag is not a bit issue for the machine's performance).
Quoted 2 lines
Are you 100% sure
dcd_changecan be called before open or after close? Then I'll try to deal with this.
Before the open there are no problems since the line discipline is off, the problem is during the close.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
affects performance. So we have to choose what is the priority:
security or performance. My guru told me I shouldn't bother too much about broken kernel-space code which my code interacts with. If it's broken it should be fixed. Some assertions enabled by DEBUG define are enough. For me it makes sense but I don't know what should I check here?
Quoted 7 lines
Quoted 5 lines
I'm sorry but I disagree with you. Kernel code can't allow userland programs to corrupt it!
We are not discussing about security or performance but about reliability.
Sure, now I see the problem (in the pps-ldisc).
Yes, the problem is there (and globally in all drivers whose not directly take care off PPS issues). Unluckely the pps-ldisc is the most currently used by PPS users...
Ciao,
Rodolfo
Signature · 5 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
PATCH v3 6/16 pps: convert printk/pr_* to dev_*
In reply to Alexander GordeevSince we now have direct pointers to struct pps_device everywhere it's easy to use dev_* functions to print messages instead of plain printks. Where dev_* cannot be used printks are converted to pr_*.
--- drivers/pps/clients/pps-ktimer.c | 4 ++-- drivers/pps/kapi.c | 14 +++++++------- drivers/pps/pps.c | 24 ++++++++++++------------ 3 files changed, 21 insertions(+), 21 deletions(-)
drivers/pps/clients/pps-ktimer.c +2 -2
@@ -45,7 +45,7 @@ static void pps_ktimer_event(unsigned long ptr)/* First of all we get the time stamp... */ pps_get_ts (&ts); -pr_info ("PPS event at %lu\n" , jiffies); +dev_info (pps->dev,"PPS event at %lu\n" , jiffies);pps_event (pps, &ts,PPS_CAPTUREASSERT ,NULL );
@@ -94,7 +94,7 @@ static int __init pps_ktimer_init(void) pps =pps_register_source (&pps_ktimer_info,PPS_CAPTUREASSERT |PPS_OFFSETASSERT );if (pps ==NULL ) { -printk (KERN_ERR "cannot register ktimer source\n" ); +pr_err ("cannot register ktimer source\n" );return -ENOMEM ; }
drivers/pps/kapi.c +7 -7
@@ -80,20 +80,20 @@ struct pps_device *pps_register_source(struct pps_source_info *info,/* Sanity checks */ if ((info->mode & default_params) != default_params) { -printk (KERN_ERR "pps: %s: unsupported default parameters\n" , +pr_err ("pps: %s: unsupported default parameters\n" , info->name); err = -EINVAL ; goto pps_register_source_exit; }if ((info->mode & (PPS_ECHOASSERT |PPS_ECHOCLEAR )) !=0 && info->echo ==NULL ) { -printk (KERN_ERR "pps: %s: echo function is not defined\n" , +pr_err ("pps: %s: echo function is not defined\n" , info->name); err = -EINVAL ; goto pps_register_source_exit; }if ((info->mode & (PPS_TSFMT_TSPEC |PPS_TSFMT_NTPFP )) ==0 ) { -printk (KERN_ERR "pps: %s: unspecified time format\n" , +pr_err ("pps: %s: unspecified time format\n" , info->name); err = -EINVAL ; goto pps_register_source_exit;
@@ -138,7 +138,7 @@ struct pps_device *pps_register_source(struct pps_source_info *info,if (id >=PPS_MAX_SOURCES ) {spin_unlock_irq (&pps_idr_lock); -printk (KERN_ERR "pps: %s: too many PPS sources in the system\n" , +pr_err ("pps: %s: too many PPS sources in the system\n" , info->name); err = -EBUSY ; goto free_idr;
@@ -150,12 +150,12 @@ struct pps_device *pps_register_source(struct pps_source_info *info,/* Create the char device */ err =pps_register_cdev (pps);if (err <0 ) { -printk (KERN_ERR "pps: %s: unable to create char device\n" , +pr_err ("pps: %s: unable to create char device\n" , info->name); goto free_idr; } -pr_info ("new PPS source %s at ID %d\n" , info->name, id); +dev_info (pps->dev,"new PPS source %s\n" , info->name);return pps;
@@ -168,7 +168,7 @@ kfree_pps:kfree (pps); pps_register_source_exit: -printk (KERN_ERR "pps: %s: unable to register source\n" , info->name); +pr_err ("pps: %s: unable to register source\n" , info->name);return NULL ; }
drivers/pps/pps.c +12 -12
@@ -67,7 +67,7 @@ static long pps_cdev_ioctl(struct file *file,switch (cmd) {case PPS_GETPARAMS : -pr_debug ("PPS_GETPARAMS: source %d\n" , pps->id); +dev_dbg (pps->dev,"PPS_GETPARAMS\n" );spin_lock_irq (&pps->lock);
@@ -83,7 +83,7 @@ static long pps_cdev_ioctl(struct file *file,break ;case PPS_SETPARAMS : -pr_debug ("PPS_SETPARAMS: source %d\n" , pps->id); +dev_dbg (pps->dev,"PPS_SETPARAMS\n" );/* Check the capabilities */ if (!capable (CAP_SYS_TIME ))
@@ -93,14 +93,14 @@ static long pps_cdev_ioctl(struct file *file,if (err)return -EFAULT ;if (!(params.mode & (PPS_CAPTUREASSERT |PPS_CAPTURECLEAR ))) { -pr_debug ("capture mode unspecified (%x)\n" , +dev_dbg (pps->dev,"capture mode unspecified (%x)\n" , params.mode);return -EINVAL ; }/* Check for supported capabilities */ if ((params.mode & ~pps->info.mode) !=0 ) { -pr_debug ("unsupported capabilities (%x)\n" , +dev_dbg (pps->dev,"unsupported capabilities (%x)\n" , params.mode);return -EINVAL ; }
@@ -113,7 +113,7 @@ static long pps_cdev_ioctl(struct file *file,/* Restore the read only parameters */ if ((params.mode & (PPS_TSFMT_TSPEC |PPS_TSFMT_NTPFP )) ==0 ) {/* section 3.3 of RFC 2783 interpreted */ -pr_debug ("time format unspecified (%x)\n" , +dev_dbg (pps->dev,"time format unspecified (%x)\n" , params.mode); pps->params.mode |=PPS_TSFMT_TSPEC ; }
@@ -126,7 +126,7 @@ static long pps_cdev_ioctl(struct file *file,break ;case PPS_GETCAP : -pr_debug ("PPS_GETCAP: source %d\n" , pps->id); +dev_dbg (pps->dev,"PPS_GETCAP\n" ); err =put_user (pps->info.mode, iuarg);if (err)
@@ -138,7 +138,7 @@ static long pps_cdev_ioctl(struct file *file,struct pps_fdata fdata;unsigned int ev; -pr_debug ("PPS_FETCH: source %d\n" , pps->id); +dev_dbg (pps->dev,"PPS_FETCH\n" ); err =copy_from_user (&fdata, uarg,sizeof (struct pps_fdata ));if (err)
@@ -153,7 +153,7 @@ static long pps_cdev_ioctl(struct file *file,else {unsigned long ticks; -pr_debug ("timeout %lld.%09d\n" , +dev_dbg (pps->dev,"timeout %lld.%09d\n" , (long long ) fdata.timeout.sec, fdata.timeout.nsec); ticks = fdata.timeout.sec *HZ ;
@@ -171,7 +171,7 @@ static long pps_cdev_ioctl(struct file *file,/* Check for pending signals */ if (err == -ERESTARTSYS ) { -pr_debug ("pending signal caught\n" ); +dev_dbg (pps->dev,"pending signal caught\n" );return -EINTR ; }
@@ -240,7 +240,7 @@ int pps_register_cdev(struct pps_device *pps) err =cdev_add (&pps->cdev, devt,1 );if (err) { -printk (KERN_ERR "pps: %s: failed to add char device %d:%d\n" , +pr_err ("pps: %s: failed to add char device %d:%d\n" , pps->info.name,MAJOR (pps_devt), pps->id);return err; }
@@ -282,14 +282,14 @@ static int __init pps_init(void) pps_class =class_create (THIS_MODULE ,"pps" );if (!pps_class) { -printk (KERN_ERR "pps: failed to allocate class\n" ); +pr_err ("pps: failed to allocate class\n" );return -ENOMEM ; } pps_class->dev_attrs = pps_attrs; err =alloc_chrdev_region (&pps_devt,0 ,PPS_MAX_SOURCES ,"pps" );if (err <0 ) { -printk (KERN_ERR "pps: failed to allocate char device region\n" ); +pr_err ("pps: failed to allocate char device region\n" ); goto remove_class; }
Signature · 1 line
1.7.1
PATCH v3 7/16 pps: move idr stuff to pps.c
In reply to Alexander GordeevSince now idr is only used to manage char device id's and not used in kernel API anymore it should be moved to pps.c. This also makes it possible to release id only at actual device freeing so nobody can register a pps device with the same id while our device is not freed yet.
--- drivers/pps/kapi.c | 53 +--------------------------------------------------- drivers/pps/pps.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 54 deletions(-)
drivers/pps/kapi.c +1 -52
@@ -26,19 +26,11 @@#include <linux/sched.h> #include <linux/time.h> #include <linux/spinlock.h> -#include <linux/idr.h> #include <linux/fs.h> #include <linux/pps_kernel.h> #include <linux/slab.h> /* -* Local variables -*/ - -static DEFINE_SPINLOCK (pps_idr_lock); -static DEFINE_IDR (pps_idr); - -/* * Local functions */
@@ -75,7 +67,6 @@ struct pps_device *pps_register_source(struct pps_source_info *info, int default_params) {struct pps_device *pps; -int id;int err;/* Sanity checks */
@@ -116,54 +107,18 @@ struct pps_device *pps_register_source(struct pps_source_info *info,init_waitqueue_head (&pps->queue);spin_lock_init (&pps->lock); -/* Get new ID for the new PPS source */ -if (idr_pre_get (&pps_idr,GFP_KERNEL ) ==0 ) { - err = -ENOMEM ; - goto kfree_pps; - } - -spin_lock_irq (&pps_idr_lock); - -/* Now really allocate the PPS source. -* After idr_get_new() calling the new source will be freely available -* into the kernel. -*/ - err =idr_get_new (&pps_idr, pps, &id); -if (err <0 ) { -spin_unlock_irq (&pps_idr_lock); - goto kfree_pps; - } - - id = id &MAX_ID_MASK ; -if (id >=PPS_MAX_SOURCES ) { -spin_unlock_irq (&pps_idr_lock); - -pr_err ("pps: %s: too many PPS sources in the system\n" , - info->name); - err = -EBUSY ; - goto free_idr; - } - pps->id = id; - -spin_unlock_irq (&pps_idr_lock); -/* Create the char device */ err =pps_register_cdev (pps);if (err <0 ) {pr_err ("pps: %s: unable to create char device\n" , info->name); - goto free_idr; + goto kfree_pps; }dev_info (pps->dev,"new PPS source %s\n" , info->name);return pps; -free_idr: -spin_lock_irq (&pps_idr_lock); -idr_remove (&pps_idr, id); -spin_unlock_irq (&pps_idr_lock); - kfree_pps:kfree (pps);
@@ -183,13 +138,7 @@ EXPORT_SYMBOL(pps_register_source);void pps_unregister_source (struct pps_device *pps) { -unsigned int id = pps->id; -pps_unregister_cdev (pps); - -spin_lock_irq (&pps_idr_lock); -idr_remove (&pps_idr, pps->id); -spin_unlock_irq (&pps_idr_lock); }EXPORT_SYMBOL (pps_unregister_source);
drivers/pps/pps.c +49 -2
91 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v3 8/16 pps: add async PPS event handler
In reply to Alexander GordeevThis handler should be called from an IRQ handler. It uses per-device workqueue internally.
--- drivers/pps/clients/pps-ktimer.c | 2 +- drivers/pps/clients/pps-ldisc.c | 2 +- drivers/pps/kapi.c | 95 ++++++++++++++++++++++++++++++++++++-- drivers/pps/pps.c | 14 +++++- include/linux/pps_kernel.h | 16 ++++++- 5 files changed, 119 insertions(+), 10 deletions(-)
drivers/pps/clients/pps-ktimer.c +1 -1
@@ -47,7 +47,7 @@ static void pps_ktimer_event(unsigned long ptr)dev_info (pps->dev,"PPS event at %lu\n" , jiffies); -pps_event (pps, &ts,PPS_CAPTUREASSERT ,NULL ); +pps_event_irq (pps, &ts,PPS_CAPTUREASSERT ,NULL );mod_timer (&ktimer, jiffies +HZ ); }
drivers/pps/clients/pps-ldisc.c +1 -1
@@ -40,7 +40,7 @@ static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, ts = &__ts;/* Now do the PPS event report */ -pps_event (pps, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR , +pps_event_irq (pps, ts, status ?PPS_CAPTUREASSERT :PPS_CAPTURECLEAR ,NULL ); dev_dbg(pps->dev, "PPS %s at %lu\n", status ? "assert" : "clear",
drivers/pps/kapi.c +91 -4
120 lines not on this page · raw message
drivers/pps/pps.c +12 -2
@@ -319,18 +319,26 @@ void pps_unregister_cdev(struct pps_device *pps) static void __exit pps_exit(void) { -class_destroy (pps_class);unregister_chrdev_region (pps_devt,PPS_MAX_SOURCES ); +class_destroy (pps_class); +destroy_workqueue (pps_event_workqueue); }static int __init pps_init (void ) {int err; + pps_event_workqueue =create_rt_workqueue ("pps" ); +if (!pps_event_workqueue) { +pr_err ("pps: failed to create workqueue\n" ); +return -ENOMEM ; + } + pps_class =class_create (THIS_MODULE ,"pps" );if (!pps_class) {pr_err ("pps: failed to allocate class\n" ); -return -ENOMEM ; + err = -ENOMEM ; + goto destroy_workqueue; } pps_class->dev_attrs = pps_attrs;
@@ -348,6 +356,8 @@ static int __init pps_init(void) remove_class:class_destroy (pps_class); +destroy_workqueue: +destroy_workqueue (pps_event_workqueue);return err; }
include/linux/pps_kernel.h +14 -2
@@ -26,6 +26,7 @@#include <linux/cdev.h> #include <linux/device.h> #include <linux/time.h> +#include <linux/workqueue.h> /* * Global defines
@@ -70,6 +71,13 @@ struct pps_device {struct device *dev;struct fasync_struct *async_queue;/* fasync method */ spinlock_t lock; + +struct work_struct assert_work; +struct work_struct clear_work; +struct pps_event_time assert_work_ts; +struct pps_event_time clear_work_ts; +void *assert_work_data; +void *clear_work_data; };/*
@@ -78,6 +86,8 @@ struct pps_device {extern struct device_attribute pps_attrs[]; +extern struct workqueue_struct *pps_event_workqueue; +/* * Exported functions */
@@ -87,8 +97,10 @@ extern struct pps_device *pps_register_source(extern void pps_unregister_source (struct pps_device *pps);extern int pps_register_cdev (struct pps_device *pps);extern void pps_unregister_cdev (struct pps_device *pps); -extern void pps_event (struct pps_device *pps,struct pps_event_time *ts,int event, -void *data); +extern void pps_event (struct pps_device *pps, +struct pps_event_time *ts,int event,void *data); +extern void pps_event_irq (struct pps_device *pps, +struct pps_event_time *ts,int event,void *data);static inline void timespec_to_pps_ktime (struct pps_ktime *kt,struct timespec ts)
Signature · 1 line
1.7.1
PATCH v3 9/16 pps: don't disable interrupts when using spin locks
In reply to Alexander GordeevNow all PPS spin locks are never used in interrupt context so we can safely replace spin_lock_irq*/spin_unlock_irq* with plain spin_lock/spin_unlock.
--- drivers/pps/kapi.c | 5 ++--- drivers/pps/pps.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-)
drivers/pps/kapi.c +2 -3
@@ -172,7 +172,6 @@ EXPORT_SYMBOL(pps_unregister_source);void pps_event (struct pps_device *pps,struct pps_event_time *ts,int event,void *data) { -unsigned long flags;int captured =0 ;struct pps_ktime ts_real;
@@ -186,7 +185,7 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,timespec_to_pps_ktime (&ts_real, ts->ts_real); -spin_lock_irqsave (&pps->lock, flags); +spin_lock (&pps->lock);/* Must call the echo function? */ if ((pps->params.mode & (PPS_ECHOASSERT |PPS_ECHOCLEAR )))
@@ -233,7 +232,7 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,kill_fasync (&pps->async_queue,SIGIO ,POLL_IN ); } -spin_unlock_irqrestore (&pps->lock, flags); +spin_unlock (&pps->lock); }EXPORT_SYMBOL (pps_event);
drivers/pps/pps.c +12 -12
@@ -73,12 +73,12 @@ static long pps_cdev_ioctl(struct file *file,case PPS_GETPARAMS :dev_dbg (pps->dev,"PPS_GETPARAMS\n" ); -spin_lock_irq (&pps->lock); +spin_lock (&pps->lock);/* Get the current parameters */ params = pps->params; -spin_unlock_irq (&pps->lock); +spin_unlock (&pps->lock); err =copy_to_user (uarg, ¶ms,sizeof (struct pps_kparams ));if (err)
@@ -109,7 +109,7 @@ static long pps_cdev_ioctl(struct file *file,return -EINVAL ; } -spin_lock_irq (&pps->lock); +spin_lock (&pps->lock);/* Save the new parameters */ pps->params = params;
@@ -125,7 +125,7 @@ static long pps_cdev_ioctl(struct file *file, pps->params.mode |=PPS_CANWAIT ; pps->params.api_version =PPS_API_VERS ; -spin_unlock_irq (&pps->lock); +spin_unlock (&pps->lock);break ;
@@ -180,7 +180,7 @@ static long pps_cdev_ioctl(struct file *file, }/* Return the fetched timestamp */ -spin_lock_irq (&pps->lock); +spin_lock (&pps->lock); fdata.info.assert_sequence = pps->assert_sequence; fdata.info.clear_sequence = pps->clear_sequence;
@@ -188,7 +188,7 @@ static long pps_cdev_ioctl(struct file *file, fdata.info.clear_tu = pps->clear_tu; fdata.info.current_mode = pps->current_mode; -spin_unlock_irq (&pps->lock); +spin_unlock (&pps->lock); err =copy_to_user (uarg, &fdata,sizeof (struct pps_fdata ));if (err)
@@ -238,9 +238,9 @@ static void pps_device_destruct(struct device *dev)/* release id here to protect others from using it while it's * still in use */ -spin_lock_irq (&pps_idr_lock); +spin_lock (&pps_idr_lock);idr_remove (&pps_idr, pps->id); -spin_unlock_irq (&pps_idr_lock); +spin_unlock (&pps_idr_lock);kfree (dev); }
@@ -258,9 +258,9 @@ int pps_register_cdev(struct pps_device *pps)* After idr_get_new() calling the new source will be freely available * into the kernel. */ -spin_lock_irq (&pps_idr_lock); +spin_lock (&pps_idr_lock); err =idr_get_new (&pps_idr, pps, &pps->id); -spin_unlock_irq (&pps_idr_lock); +spin_unlock (&pps_idr_lock);if (err <0 )return err;
@@ -300,9 +300,9 @@ del_cdev:cdev_del (&pps->cdev); free_idr: -spin_lock_irq (&pps_idr_lock); +spin_lock (&pps_idr_lock);idr_remove (&pps_idr, pps->id); -spin_unlock_irq (&pps_idr_lock); +spin_unlock (&pps_idr_lock);return err; }
Signature · 1 line
1.7.1
PATCH v3 10/16 pps: use BUG_ON for kernel API safety checks
In reply to Alexander GordeevThis way less overhead is involved when running production kernel. If you want to debug a pps client module please define DEBUG to enable the checks.
--- drivers/pps/kapi.c | 33 ++++++++++----------------------- 1 files changed, 10 insertions(+), 23 deletions(-)
drivers/pps/kapi.c +10 -23
@@ -80,25 +80,14 @@ struct pps_device *pps_register_source(struct pps_source_info *info,int err;/* Sanity checks */ -if ((info->mode & default_params) != default_params) { -pr_err ("pps: %s: unsupported default parameters\n" , - info->name); - err = -EINVAL ; - goto pps_register_source_exit; - } -if ((info->mode & (PPS_ECHOASSERT |PPS_ECHOCLEAR )) !=0 && - info->echo ==NULL ) { -pr_err ("pps: %s: echo function is not defined\n" , - info->name); - err = -EINVAL ; - goto pps_register_source_exit; - } -if ((info->mode & (PPS_TSFMT_TSPEC |PPS_TSFMT_NTPFP )) ==0 ) { -pr_err ("pps: %s: unspecified time format\n" , - info->name); - err = -EINVAL ; - goto pps_register_source_exit; - } + +/* default_params should be supported */ +BUG_ON ((info->mode & default_params) != default_params); +/* echo function should be defined if we are asked to call it */ +BUG_ON ((info->mode & (PPS_ECHOASSERT |PPS_ECHOCLEAR )) !=0 && + info->echo ==NULL ); +/* time format should be specified */ +BUG_ON ((info->mode & (PPS_TSFMT_TSPEC |PPS_TSFMT_NTPFP )) ==0 );/* Allocate memory for the new PPS source struct */ pps =kzalloc (sizeof (struct pps_device ),GFP_KERNEL );
@@ -175,10 +164,8 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,int captured =0 ;struct pps_ktime ts_real; -if ((event & (PPS_CAPTUREASSERT |PPS_CAPTURECLEAR )) ==0 ) { -dev_err (pps->dev,"unknown event (%x)\n" , event); -return ; - } +/* check event type */ +BUG_ON ((event & (PPS_CAPTUREASSERT |PPS_CAPTURECLEAR )) ==0 );dev_dbg (pps->dev,"PPS event at %ld.%09ld\n" , ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
Signature · 1 line
1.7.1
PATCH v3 11/16 pps: simplify conditions a bit
In reply to Alexander GordeevBitwise conjunction is distributive so we can simplify some conditions.
--- drivers/pps/kapi.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/pps/kapi.c +2 -4
@@ -180,8 +180,7 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,/* Check the event */ pps->current_mode = pps->params.mode; -if ((event &PPS_CAPTUREASSERT ) & - (pps->params.mode &PPS_CAPTUREASSERT )) { +if (event & pps->params.mode &PPS_CAPTUREASSERT ) {/* We have to add an offset? */ if (pps->params.mode &PPS_OFFSETASSERT ) pps_add_offset(&ts_real,
@@ -195,8 +194,7 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event, captured = ~0 ; } -if ((event &PPS_CAPTURECLEAR ) & - (pps->params.mode &PPS_CAPTURECLEAR )) { +if (event & pps->params.mode &PPS_CAPTURECLEAR ) {/* We have to add an offset? */ if (pps->params.mode &PPS_OFFSETCLEAR ) pps_add_offset(&ts_real,
Signature · 1 line
1.7.1
PATCH v3 12/16 ntp: add hardpps implementation
In reply to Alexander GordeevThis commit adds hardpps() implementation based upon the original one from the NTPv4 reference kernel code from David Mills. However, it is highly optimized towards very fast syncronization and maximum stickness to PPS signal. The typical error is less then a microsecond. To make it sync faster I had to throw away exponential phase filter so that the full phase offset is corrected immediately. Then I also had to throw away median phase filter because it gives a bigger error itself if used without exponential filter.
Maybe we will find an appropriate filtering scheme in the future but it's not necessary if the signal quality is ok.
--- drivers/pps/Kconfig | 7 + include/linux/timex.h | 1 + kernel/time/ntp.c | 421 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 414 insertions(+), 15 deletions(-)
drivers/pps/Kconfig +7 -0
@@ -30,6 +30,13 @@ config PPS_DEBUG messages to the system log. Select this if you are having a problem with PPS support and want to see more of what is going on. +config NTP_PPS + bool "PPS kernel consumer support" + depends on PPS + help + This option adds support for direct in-kernel time + syncronization using an external PPS signal. + source drivers/pps/clients/Kconfig endmenu
include/linux/timex.h +1 -0
@@ -268,6 +268,7 @@ extern u64 tick_length;extern void second_overflow (void );extern void update_ntp_one_tick (void );extern int do_adjtimex (struct timex *); +extern void hardpps (const struct timespec *,const struct timespec *);int read_current_timer (unsigned long *timer_val);
kernel/time/ntp.c +406 -15
480 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCHv3 12/16] ntp: add hardpps implementation
Quoted 12 lines · Alexander Gordeev
This commit adds
hardpps()implementation based upon the original one from the NTPv4 reference kernel code from David Mills. However, it is highly optimized towards very fast syncronization and maximum stickness to PPS signal. The typical error is less then a microsecond. To make it sync faster I had to throw away exponential phase filter so that the full phase offset is corrected immediately. Then I also had to throw away median phase filter because it gives a bigger error itself if used without exponential filter.
Maybe we will find an appropriate filtering scheme in the future but it's not necessary if the signal quality is ok.Signed-off-by Alexander Gordeev <[email protected]>
[snip]
kernel/time/ntp.c int do_adjtimex(struct timex *txc) · line 702
Quoted 6 lines
kernel/time/ntp.c +6
-0+#ifdef CONFIG_NTP_PPS + +struct pps_normtime { +__kernel_time_t sec;/* seconds */ +long nsec;/* nanoseconds */ +};
I don't quite remember the history here (it may be I suggested you use this instead of overloading a timespec? I honestly don't recall), but could you add some extra context in a comment here for what a pps_normtime structure represents and why its used instead of a timespec? The comment below sort of hints at it, but it would be useful if it was more explicit.
Quoted 6 lines
kernel/time/ntp.c +6
-0+/* normalize the timestamp so that nsec is in the +( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */ +static inline struct pps_normtime pps_normalize_ts (struct timespec ts) +{ +struct pps_normtime norm = { + .sec = ts.tv_sec,
kernel/time/ntp.c int do_adjtimex(struct timex *txc) · line 719
Quoted 10 lines
kernel/time/ntp.c +10
-0+ .nsec = ts.tv_nsec + }; + +if (norm.nsec > (NSEC_PER_SEC >>1 )) { + norm.nsec -=NSEC_PER_SEC ; + norm.sec++; + } + +return norm; +}
Otherwise the code looks pretty good to me.
thanks
-john
Re: [PATCHv3 12/16] ntp: add hardpps implementation
В Wed, 04 Aug 2010 15:49:47 -0700
john stultz <[email protected]> пишет:
Quoted 16 lines · Alexander Gordeev
Quoted 12 lines
This commit adds
hardpps()implementation based upon the original one from the NTPv4 reference kernel code from David Mills. However, it is highly optimized towards very fast syncronization and maximum stickness to PPS signal. The typical error is less then a microsecond. To make it sync faster I had to throw away exponential phase filter so that the full phase offset is corrected immediately. Then I also had to throw away median phase filter because it gives a bigger error itself if used without exponential filter.
Maybe we will find an appropriate filtering scheme in the future but it's not necessary if the signal quality is ok.Signed-off-by Alexander Gordeev <[email protected]>[snip]
Quoted 13 lines
kernel/time/ntp.c int do_adjtimex(struct timex *txc) · line 702
Quoted 6 lines
kernel/time/ntp.c +6
-0+#ifdef CONFIG_NTP_PPS + +struct pps_normtime { +__kernel_time_t sec;/* seconds */ +long nsec;/* nanoseconds */ +};I don't quite remember the history here (it may be I suggested you use this instead of overloading a timespec? I honestly don't recall), but could you add some extra context in a comment here for what a
pps_normtimestructure represents and why its used instead of a timespec? The comment below sort of hints at it, but it would be useful if it was more explicit.
Yes, you asked me to do this. :)
Sure, I'll add an explicit comment.
Quoted 19 lines
Quoted 6 lines
kernel/time/ntp.c +6
-0+/* normalize the timestamp so that nsec is in the +( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */ +static inline struct pps_normtime pps_normalize_ts (struct timespec ts) +{ +struct pps_normtime norm = { + .sec = ts.tv_sec,kernel/time/ntp.c int do_adjtimex(struct timex *txc) · line 719
Quoted 10 lines
kernel/time/ntp.c +10
-0+ .nsec = ts.tv_nsec + }; + +if (norm.nsec > (NSEC_PER_SEC >>1 )) { + norm.nsec -=NSEC_PER_SEC ; + norm.sec++; + } + +return norm; +}Otherwise the code looks pretty good to me.
Quoted 1 line
Acked-by John Stultz <[email protected]>
Thanks!
Signature · 1 line
Alexander
Re: [PATCHv3 12/16] ntp: add hardpps implementation
In reply to Alexander Gordeevsigh. The amount of inlining which this patch does is nutty.
But I don't think I'll bother making a fuss over it.
Re: [PATCHv3 12/16] ntp: add hardpps implementation
Quoted 1 line · Andrew Morton
sigh. The amount of inlining which this patch does is nutty.
Well one could ask about the rationale behind it all and hope that it wasn't purely gratuitous.
David Daney
Quoted 2 lines
But I don't think I'll bother making a fuss over it.
Re: [PATCHv3 12/16] ntp: add hardpps implementation
Quoted 6 lines · On Wed, 04 Aug 2010 16:39:13 -0700 David Daney <[email protected]>…
Quoted 1 line · Andrew Morton
sigh. The amount of inlining which this patch does is nutty.
Well one could ask about the rationale behind it all and hope that it wasn't purely gratuitous.
Rationale needs rethinking, because removing every one of those inlines makes no change at all to the generated code.
PATCH v3 13/16 pps: capture MONOTONIC_RAW timestamps as well
In reply to Alexander GordeevMONOTONIC_RAW clock timestamps are ideally suited for frequency calculation and also fit well into the original NTP hardpps design. Now phase and frequency can be adjusted separately: the former based on REALTIME clock and the latter based on MONOTONIC_RAW clock. A new function getnstime_raw_and_real is added to timekeeping subsystem to capture both timestamps at the same time and atomically.
--- include/linux/pps_kernel.h | 3 ++- include/linux/time.h | 2 ++ kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletions(-)
include/linux/pps_kernel.h +2 -1
@@ -48,6 +48,7 @@ struct pps_source_info { };struct pps_event_time { +struct timespec ts_raw;struct timespec ts_real; };
@@ -111,7 +112,7 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,static inline void pps_get_ts (struct pps_event_time *ts) { -getnstimeofday (&ts->ts_real); +getnstime_raw_and_real (&ts->ts_raw, &ts->ts_real); }#endif /* LINUX_PPS_KERNEL_H */
include/linux/time.h +2 -0
@@ -143,6 +143,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);extern int do_getitimer (int which,struct itimerval *value);extern void getnstimeofday (struct timespec *tv);extern void getrawmonotonic (struct timespec *ts); +extern void getnstime_raw_and_real (struct timespec *ts_raw, +struct timespec *ts_real);extern void getboottime (struct timespec *ts);extern void monotonic_to_bootbased (struct timespec *ts);
kernel/time/timekeeping.c +34 -0
@@ -286,6 +286,40 @@ void ktime_get_ts(struct timespec *ts)EXPORT_SYMBOL_GPL (ktime_get_ts);/** +* getnstime_raw_and_real - Returns both the time of day an raw +* monotonic time in a timespec format +* @ts_mono_raw: pointer to the timespec to be set to raw +* monotonic time +* @ts_real: pointer to the timespec to be set to the time +* of day +*/ +void getnstime_raw_and_real (struct timespec *ts_raw,struct timespec *ts_real) +{ +unsigned long seq; +s64 nsecs_raw, nsecs_real; + +WARN_ON (timekeeping_suspended); + +do { + seq =read_seqbegin (&xtime_lock); + + *ts_raw = raw_time; + *ts_real = xtime; + + nsecs_raw =timekeeping_get_ns_raw (); + nsecs_real =timekeeping_get_ns (); + +/* If arch requires, add in gettimeoffset() */ + nsecs_real +=arch_gettimeoffset (); + + }while (read_seqretry (&xtime_lock, seq)); + +timespec_add_ns (ts_raw, nsecs_raw); +timespec_add_ns (ts_real, nsecs_real); +} +EXPORT_SYMBOL (getnstime_raw_and_real); + +/** * do_gettimeofday - Returns the time of day in a timeval * @tv: pointer to the timeval to be set *
Signature · 1 line
1.7.1
Re: [PATCHv3 13/16] pps: capture MONOTONIC_RAW timestamps as well
Quoted 71 lines · Alexander Gordeev
MONOTONIC_RAWclock timestamps are ideally suited for frequency calculation and also fit well into the original NTP hardpps design. Now phase and frequency can be adjusted separately: the former based on REALTIME clock and the latter based onMONOTONIC_RAWclock. A new functiongetnstime_raw_and_realis added to timekeeping subsystem to capture both timestamps at the same time and atomically.Signed-off-by Alexander Gordeev <[email protected]>--- include/linux/pps_kernel.h | 3 ++- include/linux/time.h | 2 ++ kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletions(-)include/linux/pps_kernel.h +2
-1@@ -48,6 +48,7 @@ struct pps_source_info { };struct pps_event_time { +struct timespec ts_raw;struct timespec ts_real; };@@ -111,7 +112,7 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,static inline void pps_get_ts (struct pps_event_time *ts) { -getnstimeofday (&ts->ts_real); +getnstime_raw_and_real (&ts->ts_raw, &ts->ts_real); }#endif /* LINUX_PPS_KERNEL_H */ include/linux/time.h +2
-0@@ -143,6 +143,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);extern int do_getitimer (int which,struct itimerval *value);extern void getnstimeofday (struct timespec *tv);extern void getrawmonotonic (struct timespec *ts); +extern void getnstime_raw_and_real (struct timespec *ts_raw, +struct timespec *ts_real);extern void getboottime (struct timespec *ts);extern void monotonic_to_bootbased (struct timespec *ts);kernel/time/timekeeping.c +15
-0@@ -286,6 +286,40 @@ void ktime_get_ts(struct timespec *ts)EXPORT_SYMBOL_GPL (ktime_get_ts);/** +* getnstime_raw_and_real - Returns both the time of day an raw +* monotonic time in a timespec format +* @ts_mono_raw: pointer to the timespec to be set to raw +* monotonic time +* @ts_real: pointer to the timespec to be set to the time +* of day +*/ +void getnstime_raw_and_real (struct timespec *ts_raw,struct timespec *ts_real) +{ +unsigned long seq; +s64 nsecs_raw, nsecs_real; + +WARN_ON (timekeeping_suspended); + + do {
kernel/time/timekeeping.c void ktime_get_ts(struct timespec *ts) · line 313
Quoted 10 lines
kernel/time/timekeeping.c +10
-0+ seq =read_seqbegin (&xtime_lock); + + *ts_raw = raw_time; + *ts_real = xtime; + + nsecs_raw =timekeeping_get_ns_raw (); + nsecs_real =timekeeping_get_ns (); + +/* If arch requires, add in gettimeoffset() */ + nsecs_real +=arch_gettimeoffset ();
Hmm. So this brings up an interesting point. If the system is an one which uses arch_gettimeoffset() (which means it doesn't have clocksources), I'm not sure if this function would return what you'd expect.
The issue is that jiffies is the basic clocksource that is in use on these systems, but the arch_gettimeoffset() function returns an inter-tick time value (usually by reading the interrupt generating decrementer or whatnot). So in this case, you'd get a CLOCK_MONOTONIC_RAW time that is based off the raw jiffies value at the last tick, and CLOCK_REALTIME time value at the exact time of the call.
That offset between the two would then vary depending on when in the inter-tick period the call was made.
The two solutions would be:
1) Add the arch_gettimeoffset() value to nsecs_raw as well. Should be safe, as any freq variance from the raw freq will be limited to 1 tick length and won't accumulate.
2) Don't add arch_gettimeoffset to either value, providing the raw and real time values at the last tick.
I'd probably go with #1.
Otherwise, the code looks good.
thanks
-john
Re: [PATCHv3 13/16] pps: capture MONOTONIC_RAW timestamps as well
В Wed, 04 Aug 2010 16:03:57 -0700
john stultz <[email protected]> пишет:
Quoted 104 lines · Alexander Gordeev
Quoted 71 lines
MONOTONIC_RAWclock timestamps are ideally suited for frequency calculation and also fit well into the original NTP hardpps design. Now phase and frequency can be adjusted separately: the former based on REALTIME clock and the latter based onMONOTONIC_RAWclock. A new functiongetnstime_raw_and_realis added to timekeeping subsystem to capture both timestamps at the same time and atomically.Signed-off-by Alexander Gordeev <[email protected]>--- include/linux/pps_kernel.h | 3 ++- include/linux/time.h | 2 ++ kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletions(-)include/linux/pps_kernel.h +2
-1@@ -48,6 +48,7 @@ struct pps_source_info { };struct pps_event_time { +struct timespec ts_raw;struct timespec ts_real; };@@ -111,7 +112,7 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,static inline void pps_get_ts (struct pps_event_time *ts) { -getnstimeofday (&ts->ts_real); +getnstime_raw_and_real (&ts->ts_raw, &ts->ts_real); }#endif /* LINUX_PPS_KERNEL_H */ include/linux/time.h +2
-0@@ -143,6 +143,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);extern int do_getitimer (int which,struct itimerval *value);extern void getnstimeofday (struct timespec *tv);extern void getrawmonotonic (struct timespec *ts); +extern void getnstime_raw_and_real (struct timespec *ts_raw, +struct timespec *ts_real);extern void getboottime (struct timespec *ts);extern void monotonic_to_bootbased (struct timespec *ts);kernel/time/timekeeping.c +15
-0@@ -286,6 +286,40 @@ void ktime_get_ts(struct timespec *ts)EXPORT_SYMBOL_GPL (ktime_get_ts);/** +* getnstime_raw_and_real - Returns both the time of day an raw +* monotonic time in a timespec format +* @ts_mono_raw: pointer to the timespec to be set to raw +* monotonic time +* @ts_real: pointer to the timespec to be set to the time +* of day +*/ +void getnstime_raw_and_real (struct timespec *ts_raw,struct timespec *ts_real) +{ +unsigned long seq; +s64 nsecs_raw, nsecs_real; + +WARN_ON (timekeeping_suspended); + + do {kernel/time/timekeeping.c void ktime_get_ts(struct timespec *ts) · line 313
Quoted 10 lines
kernel/time/timekeeping.c +10
-0+ seq =read_seqbegin (&xtime_lock); + + *ts_raw = raw_time; + *ts_real = xtime; + + nsecs_raw =timekeeping_get_ns_raw (); + nsecs_real =timekeeping_get_ns (); + +/* If arch requires, add in gettimeoffset() */ + nsecs_real +=arch_gettimeoffset ();Hmm. So this brings up an interesting point. If the system is an one which uses
arch_gettimeoffset()(which means it doesn't have clocksources), I'm not sure if this function would return what you'd expect.The issue is that jiffies is the basic clocksource that is in use on these systems, but the
arch_gettimeoffset()function returns an inter-tick time value (usually by reading the interrupt generating decrementer or whatnot). So in this case, you'd get aCLOCK_MONOTONIC_RAWtime that is based off the raw jiffies value at the last tick, andCLOCK_REALTIMEtime value at the exact time of the call.That offset between the two would then vary depending on when in the inter-tick period the call was made.
The two solutions would be:
1) Add thearch_gettimeoffset()value tonsecs_rawas well. Should be safe, as any freq variance from the raw freq will be limited to 1 tick length and won't accumulate.
Quoted 6 lines
2) Don't add
arch_gettimeoffsetto either value, providing the raw and real time values at the last tick.I'd probably go with #1.
Otherwise, the code looks good.
Ok, thanks for the point! I'll use #1 then.
Signature · 1 line
Alexander
Re: [PATCHv3 13/16] pps: capture MONOTONIC_RAW timestamps as well
In reply to Alexander GordeevQuoted 9 lines · On Thu, 5 Aug 2010 01:06:50 +0400 Alexander Gordeev <[email protected]>…
kernel/time/timekeeping.c +3
-0@@ -286,6 +286,40 @@ void ktime_get_ts(struct timespec *ts)EXPORT_SYMBOL_GPL (ktime_get_ts);/** +* getnstime_raw_and_real - Returns both the time of day an raw +* monotonic time in a timespec format +* @ts_mono_raw: pointer to the timespec to be set to raw
kernel/time/timekeeping.c void ktime_get_ts(struct timespec *ts) · line 301
Quoted 10 lines
kernel/time/timekeeping.c +10
-0+* monotonic time +* @ts_real: pointer to the timespec to be set to the time +* of day +*/ +void getnstime_raw_and_real (struct timespec *ts_raw,struct timespec *ts_real) +{ +unsigned long seq; +s64 nsecs_raw, nsecs_real; + +WARN_ON (timekeeping_suspended);
I suspect that if this warning ever triggers, it'll trigger at some high frequency making a complete mess all over the floor.
WARN_ON_ONCE, perhaps? Or just remove it?
Re: [PATCHv3 13/16] pps: capture MONOTONIC_RAW timestamps as well
В Wed, 4 Aug 2010 16:29:07 -0700
Andrew Morton <[email protected]> пишет:
Quoted 26 lines
Quoted 9 lines · On Thu, 5 Aug 2010 01:06:50 +0400 Alexander Gordeev <[email protected]>…
kernel/time/timekeeping.c +3
-0@@ -286,6 +286,40 @@ void ktime_get_ts(struct timespec *ts)EXPORT_SYMBOL_GPL (ktime_get_ts);/** +* getnstime_raw_and_real - Returns both the time of day an raw +* monotonic time in a timespec format +* @ts_mono_raw: pointer to the timespec to be set to raw kernel/time/timekeeping.c void ktime_get_ts(struct timespec *ts) · line 301
Quoted 10 lines
kernel/time/timekeeping.c +10
-0+* monotonic time +* @ts_real: pointer to the timespec to be set to the time +* of day +*/ +void getnstime_raw_and_real (struct timespec *ts_raw,struct timespec *ts_real) +{ +unsigned long seq; +s64 nsecs_raw, nsecs_real; + +WARN_ON (timekeeping_suspended);I suspect that if this warning ever triggers, it'll trigger at some high frequency making a complete mess all over the floor.
Quoted 1 line
WARN_ON_ONCE, perhaps? Or just remove it?
Well, getnstime_raw_and_real() is actually just a merge of getnstimeofday() and getrawmonotonic(). The warning came from getnstimeofday(). Usually this code should be called once a second but the frequency can be higher. IMHO other functions like getnstimeofday() and ktime_get_ts() would be a bigger problem anyway because they have the same checks.
So I'm ok with either choice.
Hmm, will use WARN_ON_ONCE then if nobody objects.
Signature · 1 line
Alexander
PATCH v3 14/16 pps: add kernel consumer support
In reply to Alexander GordeevAdd an optional feature of PPSAPI, kernel consumer support, which uses the added hardpps() function.
--- Documentation/ioctl/ioctl-number.txt | 2 +- drivers/pps/Kconfig | 1 + drivers/pps/kapi.c | 23 ++++++++++++ drivers/pps/pps.c | 62 +++++++++++++++++++++++++++++++++- include/linux/pps.h | 7 ++++ include/linux/pps_kernel.h | 6 +++ 6 files changed, 99 insertions(+), 2 deletions(-)
Documentation/ioctl/ioctl-number.txt +1 -1
@@ -248,7 +248,7 @@ Code Seq#(hex) Include File Comments 'p' 40-7F linux/nvram.h 'p' 80-9F linux/ppdev.h user-space parport <mailto:[email protected]> -'p' A1-A4 linux/pps.h LinuxPPS +'p' A1-A5 linux/pps.h LinuxPPS <mailto:[email protected]> 'q' 00-1F linux/serio.h 'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK
drivers/pps/Kconfig +1 -0
@@ -7,6 +7,7 @@ menu "PPS support" config PPS tristate "PPS support" depends on EXPERIMENTAL + select NTP_PPS ---help--- PPS (Pulse Per Second) is a special pulse provided by some GPS antennae. Userland can use it to get a high-precision time
drivers/pps/kapi.c +23 -0
@@ -25,6 +25,7 @@#include <linux/init.h> #include <linux/sched.h> #include <linux/time.h> +#include <linux/timex.h> #include <linux/spinlock.h> #include <linux/fs.h> #include <linux/pps_kernel.h>
@@ -37,6 +38,12 @@/* PPS event workqueue */ struct workqueue_struct *pps_event_workqueue; +/* state variables to bind kernel consumer */ +/* PPS API (RFC 2783): current source and mode for ``kernel consumer'' */ +DEFINE_SPINLOCK (pps_kc_hardpps_lock); +void *pps_kc_hardpps_dev;/* some unique pointer to device */ +int pps_kc_hardpps_mode;/* mode bits for kernel consumer */ +/* * Local functions */
@@ -140,6 +147,16 @@ EXPORT_SYMBOL(pps_register_source);void pps_unregister_source (struct pps_device *pps) { +spin_lock (&pps_kc_hardpps_lock); +if (pps == pps_kc_hardpps_dev) { + pps_kc_hardpps_mode =0 ; + pps_kc_hardpps_dev =NULL ; +spin_unlock (&pps_kc_hardpps_lock); +dev_info (pps->dev,"unbound kernel consumer" +" on device removal\n" ); + }else +spin_unlock (&pps_kc_hardpps_lock); +pps_unregister_cdev (pps); }EXPORT_SYMBOL (pps_unregister_source);
@@ -209,6 +226,12 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event, captured = ~0 ; } +/* Pass some events to kernel consumer if activated */ +spin_lock (&pps_kc_hardpps_lock); +if (pps == pps_kc_hardpps_dev && event & pps_kc_hardpps_mode) +hardpps (&ts->ts_real, &ts->ts_raw); +spin_unlock (&pps_kc_hardpps_lock); +/* Wake up if captured something */ if (captured) { pps->last_ev++;
drivers/pps/pps.c +61 -1
70 lines not on this page · raw message
include/linux/pps.h +7 -0
@@ -114,11 +114,18 @@ struct pps_fdata { struct pps_ktime timeout; }; +struct pps_bind_args { +int tsformat;/* format of time stamps */ +int edge;/* selected event type */ +int consumer;/* selected kernel consumer */ +}; +#include <linux/ioctl.h> #define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *)#define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *)#define PPS_GETCAP _IOR('p', 0xa3, int *)#define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *) +#define PPS_KC_BIND _IOW('p', 0xa5, struct pps_bind_args *)#endif /* _PPS_H_ */
include/linux/pps_kernel.h +6 -0
@@ -87,6 +87,12 @@ struct pps_device {extern struct device_attribute pps_attrs[]; +/* state variables to bind kernel consumer */ +/* PPS API (RFC 2783): current source and mode for ``kernel consumer'' */ +extern spinlock_t pps_kc_hardpps_lock; +extern void *pps_kc_hardpps_dev;/* some unique pointer to device */ +extern int pps_kc_hardpps_mode;/* mode bits for kernel consumer */ +extern struct workqueue_struct *pps_event_workqueue;/*
Signature · 1 line
1.7.1
PATCH v3 15/16 pps: add parallel port PPS client
In reply to Alexander GordeevAdd parallel port PPS client. It uses a standard method for capturing timestamps for assert edge transitions: getting a timestamp soon after an interrupt has happened. This is not a very precise source of time information due to interrupt handling delays. However, timestamps for clear edge transitions are much more precise because the interrupt handler continuously polls hardware port until the transition is done. Hardware port operations require only about 1us so the maximum error should not exceed this value. This was my primary goal when developing this client.
Clear edge capture could be disabled using clear_wait parameter.
--- drivers/pps/clients/Kconfig | 7 + drivers/pps/clients/Makefile | 1 + drivers/pps/clients/pps_parport.c | 244 +++++++++++++++++++++++++++++++++++++ 3 files changed, 252 insertions(+), 0 deletions(-) create mode 100644 drivers/pps/clients/pps_parport.c
drivers/pps/clients/Kconfig +7 -0
@@ -22,4 +22,11 @@ config PPS_CLIENT_LDISC If you say yes here you get support for a PPS source connected with the CD (Carrier Detect) pin of your serial port. +config PPS_CLIENT_PARPORT + tristate "Parallel port PPS client" + depends on PPS && PARPORT + help + If you say yes here you get support for a PPS source connected + with the interrupt pin of your parallel port. + endif
drivers/pps/clients/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o +obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o ifeq ($(CONFIG_PPS_DEBUG),y) EXTRA_CFLAGS += -DDEBUG
drivers/pps/clients/pps_parport.c new file +244 -0
244 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCHv3 15/16] pps: add parallel port PPS client
Quoted 14 lines · On Thu, 5 Aug 2010 01:06:52 +0400 Alexander Gordeev <[email protected]>…
Add parallel port PPS client. It uses a standard method for capturing timestamps for assert edge transitions: getting a timestamp soon after an interrupt has happened. This is not a very precise source of time information due to interrupt handling delays. However, timestamps for clear edge transitions are much more precise because the interrupt handler continuously polls hardware port until the transition is done. Hardware port operations require only about 1us so the maximum error should not exceed this value. This was my primary goal when developing this client.
Clear edge capture could be disabled usingclear_waitparameter....
drivers/pps/clients/pps_parport.c line 60
Quoted 3 lines
drivers/pps/clients/pps_parport.c new file +3
-0+ +#define SIGNAL_IS_SET (port) \ + ((port->ops->read_status(port) & PARPORT_STATUS_ACK) != 0)
This could (and hence should) be implemented in a regular old C function.
Quoted 11 lines
...
drivers/pps/clients/pps_parport.c new file +8
-0+{ + struct pps_client_pp *device; + struct pps_source_info info = { + .name = DRVNAME, + .path = "", + .mode = PPS_CAPTUREBOTH | \ + PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \ + PPS_ECHOASSERT | PPS_ECHOCLEAR | \
drivers/pps/clients/pps_parport.c line 148
Quoted 10 lines
drivers/pps/clients/pps_parport.c new file +10
-0+ PPS_CANWAIT | PPS_TSFMT_TSPEC, + .echo = pps_echo, + .owner = THIS_MODULE, + .dev = NULL + }; + + device =kzalloc (sizeof (struct pps_client_pp ),GFP_KERNEL ); +if (!device) { +pr_err (DRVNAME ": memory allocation failed, not attaching\n" ); +return ;
eww. parport_driver.attach() returns void so there's no way to propagate the error code back. That sucks a bit.
Quoted 3 lines
...
Re: [PATCHv3 15/16] pps: add parallel port PPS client
В Wed, 4 Aug 2010 16:34:30 -0700
Andrew Morton <[email protected]> пишет:
Quoted 15 lines
Quoted 12 lines · On Thu, 5 Aug 2010 01:06:52 +0400 Alexander Gordeev <[email protected]>…
Add parallel port PPS client. It uses a standard method for capturing timestamps for assert edge transitions: getting a timestamp soon after an interrupt has happened. This is not a very precise source of time information due to interrupt handling delays. However, timestamps for clear edge transitions are much more precise because the interrupt handler continuously polls hardware port until the transition is done. Hardware port operations require only about 1us so the maximum error should not exceed this value. This was my primary goal when developing this client.
Clear edge capture could be disabled usingclear_waitparameter.
Quoted 8 lines
drivers/pps/clients/pps_parport.c line 60
Quoted 5 lines
...
drivers/pps/clients/pps_parport.c new file +3
-0+ +#define SIGNAL_IS_SET (port) \ + ((port->ops->read_status(port) & PARPORT_STATUS_ACK) != 0)This could (and hence should) be implemented in a regular old C function.
Ok, thanks!
Quoted 16 lines
Quoted 16 lines
...
drivers/pps/clients/pps_parport.c new file +13
-0+{ +struct pps_client_pp *device; +struct pps_source_info info = { + .name =DRVNAME , + .path ="" , + .mode =PPS_CAPTUREBOTH | \ +PPS_OFFSETASSERT |PPS_OFFSETCLEAR | \ +PPS_ECHOASSERT |PPS_ECHOCLEAR | \ +PPS_CANWAIT |PPS_TSFMT_TSPEC , + .echo = pps_echo, + .owner =THIS_MODULE , + .dev =NULL + };
Quoted 8 lines
drivers/pps/clients/pps_parport.c line 148
Quoted 5 lines
drivers/pps/clients/pps_parport.c new file +5
-0+ + device =kzalloc (sizeof (struct pps_client_pp ),GFP_KERNEL ); +if (!device) { +pr_err (DRVNAME ": memory allocation failed, not attaching\n" ); +return ;eww.
parport_driver.attach()returns void so there's no way to propagate the error code back. That sucks a bit.
IMHO, the whole parport thing currently sucks quite a bit.
Signature · 1 line
Alexander
PATCH v3 16/16 pps: add parallel port PPS signal generator
In reply to Alexander GordeevAdd PPS signal generator which utilizes STROBE pin of a parallel port to send PPS signals. It uses parport abstraction layer and hrtimers to precisely control the signal.
--- drivers/pps/Kconfig | 2 + drivers/pps/Makefile | 2 +- drivers/pps/generators/Kconfig | 17 ++ drivers/pps/generators/Makefile | 9 + drivers/pps/generators/pps_gen_parport.c | 274 ++++++++++++++++++++++++++++++ 5 files changed, 303 insertions(+), 1 deletions(-) create mode 100644 drivers/pps/generators/Kconfig create mode 100644 drivers/pps/generators/Makefile create mode 100644 drivers/pps/generators/pps_gen_parport.c
drivers/pps/Kconfig +2 -0
@@ -40,4 +40,6 @@ config NTP_PPS source drivers/pps/clients/Kconfig +source drivers/pps/generators/Kconfig + endmenu
drivers/pps/Makefile +1 -1
@@ -4,6 +4,6 @@ pps_core-y := pps.o kapi.o sysfs.o obj-$(CONFIG_PPS) := pps_core.o -obj-y += clients/ +obj-y += clients/ generators/ ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
drivers/pps/generators/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# +# PPS generators configuration +# + +if PPS + +comment "PPS generators support" + +config PPS_GENERATOR_PARPORT + tristate "Parallel port PPS signal generator" + depends on PARPORT != n && GENERIC_TIME + help + If you say yes here you get support for a PPS signal generator which + utilizes STROBE pin of a parallel port to send PPS signals. It uses + parport abstraction layer and hrtimers to precisely control the signal. + +endif
drivers/pps/generators/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for PPS generators. +# + +obj-$(CONFIG_PPS_GENERATOR_PARPORT) += pps_gen_parport.o + +ifeq ($(CONFIG_PPS_DEBUG),y) +EXTRA_CFLAGS += -DDEBUG +endif
drivers/pps/generators/pps_gen_parport.c new file +274 -0
274 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCHv3 16/16] pps: add parallel port PPS signal generator
drivers/pps/generators/pps_gen_parport.c line 48
Quoted 10 lines · On Thu, 5 Aug 2010 01:06:53 +0400 Alexander Gordeev <[email protected]>…
Add PPS signal generator which utilizes STROBE pin of a parallel port to send PPS signals. It uses parport abstraction layer and hrtimers to precisely control the signal.
..
drivers/pps/generators/pps_gen_parport.c new file +4
-0+static unsigned int send_delay =30000 ; +MODULE_PARM_DESC (delay, +"Delay between setting and dropping the signal (ns)" ); +module_param_named (delay, send_delay, uint,0 );
This code doesn't look easy to configure and use. For example, if some random person tries to get it going, how does he even know that this module parameter exists, let alone how to use it?
Please review Documentation/pps/pps.txt and check that it accurately and completely describes how to use the pps code after your changes, thanks.