adjusting the monotonic system time (from inside the kernel)
Hello,
I'm looking at how to adjust the (monotonic) system time from inside the kernel.
Use case is that I have a hw-clock which (not necessarily) regulary sends a timestamp with millisecond precision which I want to use to adjust the system time.
It seems the usual solution to do such, is to use NTP which uses it's own driver (which usually seems to be based on some serial connection):
hw-clock --serial--> kernel --serial-device--> ntpd -> kernel -> system-time
So one solution would be to emulate such a serial device:
hw-clock --> kernel --emulated-serial-device--> ntpd -> kernel -> system-time
Another solution would be to "invent" a ntp-device and write a driver for ntpd to use it:
hw-clock --> kernel --ntp-device--> ntpd -> kernel -> system-time
But I would prefer the following:
hw-clock --> kernel -> system-time
Problem is that the hw-clock in question doesn't offer something like a tick. It just might send a timestamp with millisecond precision whenever it wants.
Because I don't want to reinvent the wheel and because I think there are some people which already have spend some thoughts on similiar things, I'm asking here before I try to implement something which then never might find it's way into the mainline kernel.
Any hints, suggestions, whatever?
Regards,
Alexander Holler
Am 06.05.2013 16:02, schrieb Alexander Holler:
Quoted 9 lines
But I would prefer the following:
hw-clock --> kernel -> system-time
Problem is that the hw-clock in question doesn't offer something like a tick. It just might send a timestamp with millisecond precision whenever it wants.
Quoted 6 lines
Because I don't want to reinvent the wheel and because I think there are some people which already have spend some thoughts on similiar things, I'm asking here before I try to implement something which then never might find it's way into the mainline kernel.
Any hints, suggestions, whatever?
To offer something for discussion I'm thinking about:
When a timestamp with millisecond precision is received, instruct the kernel to adjust the system time in the next minute for the calculated offset.
Question here would be what to choose as window to adjust the time (the "next minute" above"). I think that should depend on the offset. But what are acceptable values? One minute to adjust the clock for offsets up to +-500ms? Two minutes if the offset is one second? ...
As I never spend a thought about such before, I just don't have any pointers what would be acceptable.
Regards,
Alexander
Quoted 20 lines · Alexander Holler
Hello,
I'm looking at how to adjust the (monotonic) system time from inside the kernel.
Use case is that I have a hw-clock which (not necessarily) regulary sends a timestamp with millisecond precision which I want to use to adjust the system time.
It seems the usual solution to do such, is to use NTP which uses it's own driver (which usually seems to be based on some serial connection):
hw-clock --serial--> kernel --serial-device--> ntpd -> kernel -> system-time
So one solution would be to emulate such a serial device:
hw-clock --> kernel --emulated-serial-device--> ntpd -> kernel -> system-time
Another solution would be to "invent" a ntp-device and write a driver for ntpd to use it:
hw-clock --> kernel --ntp-device--> ntpd -> kernel -> system-time
But I would prefer the following:
Quoted 7 lines
hw-clock --> kernel -> system-time
Problem is that the hw-clock in question doesn't offer something like a tick. It just might send a timestamp with millisecond precision whenever it wants.
Because I don't want to reinvent the wheel and because I think there are some people which already have spend some thoughts on similiar things, I'm asking here before I try to implement something which then never might find it's way into the mainline kernel.
Any hints, suggestions, whatever?
Sorry on the delay to reply here, just noticed this in my spam folder (hopefully I've trained it not to catch your mails now).
You probably want to check out do_adjtimex() in the kernel. It has a number of ways that allow for the clock to be slewed or jumped. Otherwise you probably should look into the PPS subsystems to see if it could be extended to support your needs.
thanks
-john
Am 08.06.2013 01:49, schrieb John Stultz:
Quoted 41 lines · Alexander Holler
Quoted 33 lines
Hello,
I'm looking at how to adjust the (monotonic) system time from inside the kernel.
Use case is that I have a hw-clock which (not necessarily) regulary sends a timestamp with millisecond precision which I want to use to adjust the system time.
It seems the usual solution to do such, is to use NTP which uses it's own driver (which usually seems to be based on some serial connection):
hw-clock --serial--> kernel --serial-device--> ntpd -> kernel -> system-time
So one solution would be to emulate such a serial device:
hw-clock --> kernel --emulated-serial-device--> ntpd -> kernel -> system-time
Another solution would be to "invent" a ntp-device and write a driver for ntpd to use it:
hw-clock --> kernel --ntp-device--> ntpd -> kernel -> system-time
But I would prefer the following:
hw-clock --> kernel -> system-time
Problem is that the hw-clock in question doesn't offer something like a tick. It just might send a timestamp with millisecond precision whenever it wants.
Quoted 6 lines
Because I don't want to reinvent the wheel and because I think there are some people which already have spend some thoughts on similiar things, I'm asking here before I try to implement something which then never might find it's way into the mainline kernel.
Any hints, suggestions, whatever?
Quoted 7 lines
Sorry on the delay to reply here, just noticed this in my spam folder (hopefully I've trained it not to catch your mails now).
You probably want to check out
do_adjtimex()in the kernel. It has a number of ways that allow for the clock to be slewed or jumped. Otherwise you probably should look into the PPS subsystems to see if it could be extended to support your needs.
Thanks, I've already digged around in the source for adjtimex to get a clue about the ntp-api and how it works. At first view wasn't that enlightened. ;)
But that now has to wait. If the new hctosys mechanism ends up in the kernel, the millisecond support for rtc-hid-sensor-time will disappear because rtc-hid-sensor-time will not set the time itself afterwards.
So I have to figure out and implement a new way to feed a timestamp with milliseconds to hctosys.
My first idea would be to add a read_timeval() or even read_timespec() to rtc_class_ops which would be used by hctosys instead of read_time() if it exists.
Regards,
Alexander