Professional Documents
Culture Documents
~ Introduction to linuxptp
Ken ICHIKAWA
FUJITSU LIMITED.
LinuxCon Japan 2014
Agenda
Background
Overview of Precision Time Protocol (PTP)
About PTP on Linux
Tips
Background
Event ordering is very important
for incident analysis, performance analysis and so on
Event 2
Event 1
Event 3
4
Server A
Server B
Copyright 2014 FUJITSU LIMITED
Server A
diff:-1
Event 2
Event 1
Server B
diff:+3
Event 3
9
10
11
time
Time
Event
Time
Event
Event 1
Event 1
Event 2
Event 3
Event 3
Event 2
reverse!
Server A
diff:-0.001 1.999
2.999
3.999
4.999
5.999
6.999
7.999
Event 2
Event 1
Server B
diff:+0.003 2.003
3.003
4.003
5.003
Event 3
6.003
7.003
8.003
time
Time
Event
Time
Event
Event 1
2.999
Event 1
Event 2
5.003
Event 2
Event 3
6.999
Event 3
correct!
Agenda
Background
Overview of Precision Time Protocol (PTP)
Whats PTP
Term explanation
About packet timestamp
Term explanation
GPS
10
Term explanation
GPS
Grandmaster Clock
(Ordinary Clock)
Original time source for the
PTP network
Typically synchronize its
clock to external time (GPS,
NTP and so on)
11
Term explanation
GPS
Boundary Clock
Typically its switch
Synchronize its clock to a
master
Term explanation
GPS
13
Packet timestamp
Time offset between master
and slave clocks is calculated
based on timestamps at packet
sending and receiving
1
+
2
1
= 2 1 { 4 1 3 2 }
2
= 2 1
15
Timestamp timing
Ideally, we want timestamps of the time just
sending (or receiving) packet
But in reality, there is deference between timestamp
timing and packet sending (or receiving) timing
Ideal timestamp timing
timestamp here
error
timestamp here
no error
transmit here
transmit here
16
Type of timestamping
Software timestamping
Timestamp at Application or OS layer
Get time from system clock
Application
timestamp
Sys
Clock
OS
error
MAC
PHY
transmit
17
Hardware Timestamping
Application
Application
timestamp
Sys
Clock
OS
OS
error
MAC
PHY
small
error
transmit
MAC
PHY
timestamp PHC
transmit
18
Agenda
Background
Overview of Precision Time Protocol (PTP)
About PTP on Linux
Kernel features
Tips
For easy trial or development
19
20
21
Linuxptp Applications
ptp4l
Implementation of PTP (Ordinary Clock, Boundary
Clock)
phc2sys
Synchronize two clocks (typically PHC and system clock)
22
ptp4l
Implementation of PTP
Ordinary / Boundary clock
23
phc2sys
Synchronize two clocks (typically PHC and system
clock)
24
phc2sys adjusts
system clock
ptp4l adjusts
system clock
25
28
An example of synchronization
between Linux servers
Directly connect two Linux servers (Grandmaster
and Slave)
Setup
Linux server
(Grandmaster)
Linux server
(Slave)
31
An example of synchronization
between Linux servers
The offsets between the PHCs, observed by ptp4l
max 116 ns
min -89 ns
RMS 31.19 ns
very stable!
offset (ns)
-500
-1000
-1500
Agenda
Background
Overview of Precision Time Protocol (PTP)
About PTP on Linux
Tips
Workaround against bad GM behavior
Improve system clock stability
34
Bad GM behavior
I encountered a Grandmaster product
The GM sometimes occurs a few hundred
microsecond level errors
Setup
GM product
(Grandmaster)
Linux server
(Slave)
35
Bad GM behavior
The offsets between the GM and the Linux
servers PHC, observed by ptp4l
max 352129 ns (= 352 us)
min -231644 ns (= -232 us)
RMS 13664.71 ns (= 14 us)
between GM and PHC
400000
300000
200000
100000
0
-100000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
offset (ns)
-200000
-300000
Whats happening?
GM sends a timestamp including huge error
It appears as a huge plus offset
200000
100000
0
-100000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
offset (ns)
-200000
-300000
Whats happening?
GMs next timestamp does not include so much
error
But, PHCs frequency was changed too much
A huge minus offset appears against normal GMs
timetamp
between GM and PHC
400000
300000
200000
100000
0
-100000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
offset (ns)
-200000
-300000
400000
300000
200000
100000
0
-100000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
offset (ns)
-200000
-300000
Tuning sensitivity
Anyway, by tuning the servo parameters, we can
adjust how clock sensitivity react to the offset
42
Ki 0.3
Previous result used this configuration
Sensitive
Ki 0.001
Insensitive
43
80000
offset (ns)
-20000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
30000
-70000
130000
80000
-70000
-120000
10000
8000
6000
4000
2000
offset (ns)
0
-2000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
-20000
1
127
253
379
505
631
757
883
1009
1135
1261
1387
1513
1639
1765
1891
2017
2143
2269
2395
2521
2647
2773
2899
30000
-4000
Zoom
-6000
-8000
-10000
45
Agenda
Background
Overview of Precision Time Protocol (PTP)
About PTP on Linux
Tips
Countermeasure against bad GM behavior
Improve system clock stability
46
(nohz=on is default)
47
Comparison
The offsets between PHC and system clock,
observed by phc2sys
between PHC and sys clock
10000
8000
8000
6000
6000
4000
4000
2000
2000
-2000
1
61
121
181
241
301
361
421
481
541
601
661
721
781
841
901
961
1021
1081
1141
1201
1261
1321
1381
1441
10000
-2000
-4000
-4000
-6000
-6000
-8000
-8000
nohz=on
max 9550 ns
min -8134 ns
RMS 1589.3 ns
1
61
121
181
241
301
361
421
481
541
601
661
721
781
841
901
961
1021
1081
1141
1201
1261
1321
1381
1441
offset (ns)
48
nohz=off
max 32 ns
min -26 ns
RMS 9.3 ns
6000
4000
2000
-4000
-6000
40
-8000
30
20
10
offset (ns)
0
-10
Zoom
1
59
117
175
233
291
349
407
465
523
581
639
697
755
813
871
929
987
1045
1103
1161
1219
1277
1335
1393
1451
-2000
1
61
121
181
241
301
361
421
481
541
601
661
721
781
841
901
961
1021
1081
1141
1201
1261
1321
1381
1441
-20
-30
49
author
1st patch
2nd patch
John
Jan
2014
3rd patch
John
Apr 2014
50
date
Agenda
Background
Overview of Precision Time Protocol (PTP)
About PTP on Linux
Tips
Countermeasure against bad GM behavior
Improve system clock stability
51
Note:
Run two Virtual Machines (for GM and Slave)
Recommend to use OS supporting linuxptp
e.g. recent Fedora, RHEL6.5, 7.0
53