Time

From Braindump
Revision as of 11:30, 4 August 2023 by Jan (talk | contribs) (→‎=)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Timeanddate.com

https://timeanddate.com/

Timezone date

TZ=Europe/Helsinki
UTC+3h is UTC+2h + summer time 
EET+daylight saving time = EEST

The beginning of time

1847: GMT Time zone were introduced when rail travel spanned multiple timezones. GMT => TAI => UTC

1952:

1958: TAI = UT2

1967: Cs-133 A second was defined by the 13th General Conference on Weights and Measures: the duration of 9 192 631 770 cycles of microwave light absorbed or emitted by the hyperfine transition of cesium-133 atoms in their ground state undisturbed by external fields.

ET Ephemeris Time 1977: 1.0003725 TT = 1977 January 1.0000000 TAI

Time Formats

GMT is Greenwich Mean Time
Z   is Zulutime
UT1 observed solar time
TAI is international atomic time. UT + leapseconds
UTC is Universal Coordinated Time
SI seconds (by BIPM)
UTC (by ITU-R)
BIH/IERS is responsible for leap seconds 
ET - TAI = 32.184 seconds
ET - UT = ΔT
TT  Terrestrial Time (new ET) a coordinate time scale at Earth's surface
UT  Universal Time
UT is based on sidereal time, but with a scaling factor and other adjustments to make them closer to solar time.
UT = UTC / UT1
UT0 is the rotational time observed as the diurnal motion of stars or extraterrestrial radio sources.
UT1 is computed by correcting UT0 for the effect of polar motion
UT2 is a smoothed version of UT1, filtering out periodic seasonal variations, hardly in use
UT2R is a smoothed version of UT1, incorporating both the seasonal corrections of UT2 and the tidal corrections of UT1R

UNIX TIME seconds since 0:00 1 jan 1970


Standard time, observed v.s. coordinated. UTC Coordinated Universal Time is an atomic time scale designed to approximate Universal Time. UTC differs from TAI by an integral number of seconds TAI International Atomic Time (primary realisation of Terrestrial Time)

- The "posix" version is based on the Coordinated Universal Time (UTC).
- The "right" version is based on the International Atomic Time (TAI), and it includes the leap seconds.

Bulletin on the corrections between UTC and TAI http://hpiers.obspm.fr/iers/bul/bulc/bulletinc.dat from 2017 January 1, 0h UTC, until further notice : UTC-TAI = -37 s

Bulletin T on difference between UTC and UTC/NIST (synchronization delay/deviation) https://www.bipm.org/en/time-ftp/other-products

NIST runs NTP servers, most are UTC +/- a deviation in nanoseconds. 2 NTP servers report UT1.

The NIST servers will compute UT1 time by adding the DUT1 value for any MJD to UTC(NIST). The value used for DUT1 will be the value determined by http://www.iers.org

Why circle 360, 24 timezones

https://www.iflscience.com/why-are-there-360-degrees-in-a-circle-instead-of-something-useful-like-100-68919

MST mean solar time

The length of the mean solar day is increasing due to the tidal acceleration of the Moon by Earth, and the corresponding deceleration of the Earth by the Moon.

1820 86400 Seconds
+1.4 msec / 100 years
+1.7 msec / 100 years

Mean Sidereal measured against a away star. Time mean sidereal day is about 23 h 56 m 4.1 s in length

Computer Clock

Computers have a hardware clock for longtime clock keeping and the CPU keeps track of the software clock which is used in application to tell time. The software clock and hardware clock need to be calibrated, so it needs an external clock source.

My clock was running horribly wrong on my brand new computer. It's not a weak BIOS battery and it's not because it's a brand new AMD64. Heat will make clocks 'wobble' a bit, but the real reason was that I should have calibrated the clock. NTP will not correct clocks that are off by more than 500ms / minute. (or was it 500ms)

/etc/init.d/ntp stop
ntpdate stampertje.islief.com
hwclock --systohc
adjtimex -a
/etc/init.d/ntp start

Which clock?

There is a rtc / hardwareclock that runs even when the computer is switched off. There is a systemclock in the CPU that loads the hardware clock on startup, and updates the hardwareclock on shutdown. There are NTP clocks on the internet providing a stable time reference.

Hardwareclock

http://support.ntp.org/bin/view/Support/KnownOsIssues

There are a few different available hardware clocks in modern PC's. The linux kernel will use one as the clocksource for interupts and also will use one systemclock as the source.

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
acpi_pm
cat /sys/devices/system/clocksource/clocksource0/available_clocksource
tsc hpet acpi_pm jiffies 

The clocksource can be selected in the kernel options at bootup, so you can add clocksource to the kernel options.

vi /boot/grub/menu.lst
kernel ... clocksource=hpet

The hardwareclock can be read or written from/to the systemclock using

hwclock --systohc
hwclock --hctosys

The systemclock is updated every tick. A kernel generates by default roughly 100 ticks/second. To enhance the precision, the clock can be synchronized to the correct number of ticks and in my case the clock is always too slow, so I set the tick to 10003 which means that my system clock is not drifting as much as before. I previously incorrectly set the tick to 9700 causing a huge drift. adjtimex can calculate the difference between the systemclock and the hardware clock and will estimate what the tick should be. This is a very coarse setting, which can be fine tuned using NTP.

To print the current tick and freq

adjtimex -p

To adjust the tick / freq

adjtimex -a
/etc/init.d/adjtimex restart
/etc/default/adjtimex
TICK=100003
FREQ=4007068

Once the tick has been adjusted, and NTP is working the systemclock will be more accurate than the hardware clock. So the drift rate of the hardware clock will be calculated and stored. At startup it is calculated how much time the hardware clock has run undisciplined and the clocks will be corrected by the drift rate calculation.

cat /etc/adjtime

NTP

https://timeanddate.com/

the NTP daemon will use clocksources from the internet to dicipline the system clock. it will first poll the time servers every 64 seconds until it has enough data to check less frequently (every 11 minutes). After a few polls NTP decides which clocksources are reliable (+) and which one it selects as the best (*) it will use. NTP will then slew the clock into the correct time, so a clock which is running 500ms fast will be slowly brought back to the correct time. The longer a clock is diciplined by NTP the more accurate it will be. network traffic will cause a delay between the client and the server, because the network latency increases, which will decrease accuracy. The ntp drift is stored in the driftfile so that the drift can be monitored

https://www.vttresearch.com/fi/palvelut/suomen-aika-ntp-palvelu

pool time.mikes.fi

sidn time.nl

pool ntp.time.nl

https://developers.google.com/time/smear time.google.com https://aws.amazon.com/blogs/aws/look-before-you-leap-the-coming-leap-second-and-aws/ time.aws.com

https://tf.nist.gov/tf-cgi/servers.cgi

IPv6 https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml

FF0X::101 	Network Time Protocol (NTP)
0 	Reserved
1 	Interface-Local scope
2 	Link-Local scope
3 	Realm-Local scope
4 	Admin-Local scope
5 	Site-Local scope
6-7 	Unassigned
8 	Organization-Local scope
9-D 	Unassigned
E 	Global scope
F 	Reserved

OpenNTP

ntpq -np
cat /var/lib/ntp/ntp.drift 
ntpdc -c kerninfo

NTP starting up (state 4) and not diciplining the clock yet (unsync)

pll offset:           -0.063174 s
pll frequency:        -2.889 ppm
maximum error:        0.076516 s
estimated error:      1.6e-05 s
status:               0040  unsync
pll time constant:    4
precision:            1e-06 s
frequency tolerance:  500 ppm

NTP operational (state 6) and the clock in a phase locked loop (pll)

pll offset:           -0.074309 s
pll frequency:        -4.266 ppm
maximum error:        0.027339 s
estimated error:      0.027506 s
status:               0001  pll
pll time constant:    6
precision:            1e-06 s
frequency tolerance:  500 ppm

root@sneezy:~# ntpq -np

    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+192.168.1.2     194.100.100.141  3 u   35   64  377    1.299  -392.16  81.343
*193.180.251.38  192.36.144.22    2 u   33   64  377  187.899  -314.91 141.803
+82.118.208.35   213.203.238.82   3 u   36   64  377  154.986  -330.89 153.852
/etc/dhcp3/dhclient.conf
/etc/ntp.conf.dhcp
/etc/ntp.conf
server 192.168.1.2
restrict -4 default kod notrap nomodify nopeer noquery
/var/lib/ntp/ntp.drift
ntpq -np
ntpdate 192.168.1.2
http://www.ntp.org/ntpfaq/NTP-s-trouble.htm

Chrony

chronyc makestep
chronyc sources
chronyc sourcestats
chronyc serverstats
chronyc tracking
chronyc clients
chronyc add server ntp.dnafinland.fi
chronyc ntpdata

http://satsignal.eu/ntp/NTPandMRTG.html

https://store.uputronics.com/index.php?route=product/product&product_id=92

AWS and Google clock slewing

for the TAI correction, the AWS and Google NTP services slew the clock so the change is smeared out over a day, otherwise the clock could reach 23:59:60, which some applications (databases mainly) may not be able to cope.

Windows Time

https://docs.microsoft.com/en-us/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings

net stop w32time
w32tm /unregister
w32tm /register
net start w32time
w32tm /resync
w32tm /config /manualpeerlist:"10.0.0.5,0x8 ntp.dnafinland.com,0xa" /syncfromflags:manual /update
w32tm /stripchart /computer:time.windows.com /dataonly /samples:5
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w32time\Parameters\NtpServer

This seems to exist, but is not actually chosen?

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers

GPS Time

A sync source are the 31 31 operational GPS satellites. They all have a cesium or rubidium atomic clock on board and provide. Not all GPS receivers export a PPS pulse per second which can be used by the GPSD to synchronize to NTPD, the ones that do can have different accuracy based on the gps chip and the mode used. The generic NMEA in one line ASCII is less accurate than any propitiatory binary protocol.

ntpd will use a pseudo-ip address 127.127.1.34 which is a local loopback address, as network socket to the gps driver (gpsd)

In 2010 I bought an BU-353 for 65 Euro's. It contains the popular SiRF_Star_III chip, but it has no pulse per second, so I can't use it as sync source.

./configure --prefix=/usr --disable-garmin --enable-pps-on-cts --disable-evermore --disable-navcom --disable-ashtech --disable-itrax --disable-earthmate --disable-tripmate --disable-fv18 --disable-tsip --disable-ntrip --disable-rtcm104
gpsd -nN -D 5 /dev/ttyUSB0
gpsd -nN /dev/ttyUSB0

gpsctl -b
gpsctl: /dev/ttyUSB0 identified as SiRF binary GSW3.2.4_3.1.00.12-SDK003P1.00a  at 4800
gpsctl: /dev/ttyUSB0 identified as SiRF-II binary at 4800
http://wiki.openstreetmap.org/index.php/User:Dean_Earley/SiRF_Star_III
http://www.usglobalsat.com/downloads/SiRF_Binary_Protocol.pdf
http://www.mr-lee-catcam.de/BINARY/EM406a-datasheet.pdf

Mmmmh, this EM-406 looks like the stuff I saw when I disassembled the BU-353 (HA! those pins where really flimsy. That should teach me not to just pull them when drunk and trying to squeeze them back backwards =) ) ... do I have PPS on pin 6 EM-406a or a PPS-less model EM-406? and where does the PL-2303 RS232-USB converter come in to play??

http://www.usglobalsat.com/download/46/em406a_ug.pdf

In 2019 I bough a Beitan BN-280 with a U-Blox M8N chip with a PPS pulse per second line. I used an arduino uno with SoftwareSerial on pin 10 and 11 to the gps chip. http://arduino.cc/en/Reference/SoftwareSerial

https://www.u-blox.com/en/product/neo-m8-series#tab-documentation-resources

Through U-Center and the NMEA set it can be tested and configured on windows. It's also possible to switch to U-Blox binary

GPS Commands

setSerialPort
$PSRF100,0
$PSRF100,0,38400,8,1,0*0C
*switch to binary ??
$PASHQ,RI
Debug On
$PSRF105,1*3E
Debug Off
$PSRF105,0*3F
Enable PowerSave
$PSRF150,0,300,1000,1*10
Disable Trickle
$PSRF150,0,1000,1000,0*23
Enable SBAS(WAAS/EGNOS)
$PSRF151,01*0F
Disable SBAS(WAAS/EGNOS)
$PSRF151,00*0E