SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
Matt Provost
mattpro@yelp.com
Ping to Pong
Rewriting Ping as a Video Game
Yelp’s Mission
Connecting people with great
local businesses.
/*
* P I N G . C
*
* Using the InterNet Control Message Protocol (ICMP) "ECHO" facility,
* measure round-trip-delays and packet loss across network paths.
*
* Author -
* Mike Muuss
* U. S. Army Ballistic Research Laboratory
* December, 1983
* Modified at Uc Berkeley
* Record Route and verbose headers - Phil Dykstra, BRL, March 1988.
*
* Status -
* Public Domain. Distribution Unlimited.
*
* Bugs -
* More statistics could always be gathered.
* This program has to run SUID to ROOT to access the ICMP socket.
*/
Raspberry Pi Model B+ (700 MHz): Dhrystones per Second: 1481481
VAX MIPS rating = 843.19
Raspberry Pi 2 Model B (1000 MHz)*: Dhrystones per Second: 2085024
VAX MIPS rating = 1186.70
*using one core
while (true)
{
processInput();
update();
render();
}
http://gameprogrammingpatterns.com/game-loop.html
NAME
ping - send ICMP ECHO_REQUEST packets to network hosts
SYNOPSIS
ping [-dfnqrvR] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize]
OPTIONS
-f
Flood ping. Outputs packets as fast as they come back or one hundred times per
second, whichever is more. For every ECHO_REQUEST sent a period ``.'' is printed,
while for every ECHO_REPLY received a backspace is printed. This provides a rapid
display of how many packets are being dropped. Only the super-user may use this
option. This can be very hard on a network and should be used with caution.
-i wait
Wait wait seconds between sending each packet. The default is to wait for one
second between each packet. This option is incompatible with the -f option.
while (true)
{
double start = getCurrentTime();
processInput();
update();
render();
sleep(start + MS_PER_FRAME - getCurrentTime());
}
http://gameprogrammingpatterns.com/game-loop.html
/*
* C A T C H E R
*
* This routine causes another PING to be transmitted, and then
* schedules another SIGALRM for 1 second from now.
*
* Bug -
* Our sense of time will slowly skew (ie, packets will not be launched
* exactly at 1-second intervals). This does not affect the quality
* of the delay and loss statistics.
*/
catcher()
{
if (nreceived) {
waittime = 2 * tmax / 1000;
if (waittime == 0)
waittime = 1;
} else
waittime = PING_MAXWAIT; // 10
signal(SIGALRM, finish);
alarm(waittime);
}
}
NAME
alarm - schedule an alarm signal
SYNOPSIS
#include <unistd.h>
unsigned alarm(unsigned seconds);
DESCRIPTION
The alarm() function shall cause the system to generate a SIGALRM signal for the process after the number of realtime seconds
specified by seconds have elapsed. Processor scheduling delays may prevent the process from handling the signal as soon as it is
generated.
iputils/ping_common.c:
int __schedule_exit(int next)
{
if (nreceived) {
waittime = 2 * tmax;
if (waittime < 1000*interval)
waittime = 1000*interval;
} else
waittime = lingertime*1000;
// struct timeval it_value
it.it_value.tv_sec = waittime/1000000;
it.it_value.tv_usec = waittime%1000000;
setitimer(ITIMER_REAL, &it, NULL);
}
NAME
getitimer, setitimer - get and set value of interval timer
SYNOPSIS
#include <sys/time.h>
int setitimer(int which, const struct itimerval *restrict value, struct itimerval *restrict ovalue);
DESCRIPTION
The setitimer() function shall set the timer specified by which to the value specified in the structure pointed to by value, and if ovalue
is not a null pointer, store the previous value of the timer in the structure pointed to by ovalue.
A timer value is defined by the itimerval structure, specified in <sys/time.h>. If it_value is non-zero, it shall indicate the time to the
next timer expiration. If it_interval is non-zero, it shall specify a value to be used in reloading it_value when the timer expires.
An XSI-conforming implementation provides each process with at least three interval timers, which are indicated by the which
argument:
ITIMER_PROF
Decrements both in process virtual time and when the system is running on behalf of the process. It is designed to be
used by interpreters in statistically profiling the execution of interpreted programs. Each time the ITIMER_PROF timer expires,
the SIGPROF signal is delivered.
ITIMER_REAL
Decrements in real time. A SIGALRM signal is delivered when this timer expires.
ITIMER_VIRTUAL
Decrements in process virtual time. It runs only when the process is executing. A SIGVTALRM signal is delivered when
it expires.
$ rrdtool create target.rrd 
--start 1537445727 
--step 10 
DS:ping:GAUGE:60:0:10000 
RRA:AVERAGE:0.5:6:60 
RRA:AVERAGE:0.5:8640:31
Sent Elapsed ms RTT Average
1 0 118
2 1,118 125
3 2,243 109
4 3,352 113
5 4,465 127
6 5,592 121
7 6,713 123
8 7,836 117
9 8,953 116 119
10 10,069 129
Sent Elapsed ms RTT Average
9 8,953 116 119
10 10,069 129
11 11,198 111
12 12,309 487
13 13,796 353
14 15,149 673
15 16,822 731
16 18,553 365
17 19,918 212 382.625
18 21,130 212
Sent Elapsed ms RTT Average
17 19,918 212 382.625
18 21,130 212
19 22,342 145
20 23,487 119
21 24,606 1245
22 26,851 1561
23 29,412 1812 849
24 32,224 743
Sent Elapsed ms RTT Average
1 0 118
2 1,118 125
3 2,243 109
4 3,352 113
5 4,465 127
6 5,592 121
7 6,713 123
8 7,836 117
9 8,953 116 119
10 10,069 129
11 11,198 111
12 12,309 487
13 13,796 353
14 15,149 673
15 16,822 731
16 18,553 365
17 19,918 212 383
18 21,130 212
19 22,342 145
20 23,487 119
21 24,606 1345
22 26,951 1561
23 29,512 1812 866
24 32,324 743
http://rrdtool.vandenbogaerdt.nl/process.php
double lastTime = getCurrentTime();
while (true)
{
double current = getCurrentTime();
double elapsed = current - lastTime;
processInput();
update(elapsed);
render();
lastTime = current;
}
http://gameprogrammingpatterns.com/game-loop.html
Sent Elapsed ms RTT Average Actual Start Deadline Sleep Time Adjusted RTT Adjusted Avg
1 0 118 0 1,000 882 118
2 1,118 125 1,000 2,000 875 125
3 2,243 109 2,000 3,000 891 109
4 3,352 113 3,000 4,000 887 113
5 4,465 127 4,000 5,000 873 127
6 5,592 121 5,000 6,000 879 121
7 6,713 123 6,000 7,000 877 123
8 7,836 117 7,000 8,000 883 117
9 8,953 116 119 8,000 9,000 884 116 119
10 10,069 129 9,000 10,000 871 129
11 11,198 111 10,000 11,000 889 111
12 12,309 487 11,000 12,000 513 487
13 13,796 353 12,000 13,000 647 353
14 15,149 673 13,000 14,000 327 673
15 16,822 731 14,000 15,000 269 731
16 18,553 365 15,000 16,000 635 365
17 19,918 212 383 16,000 17,000 788 212 383
18 21,130 212 17,000 18,000 788 212
19 22,342 145 18,000 19,000 855 145
20 23,487 119 19,000 20,000 881 119
21 24,606 1345 20,000 21,000 0 1,345
22 26,951 1561 21,345 22,000 0 1,906
23 29,512 1812 866 22,906 23,000 0 2,718 1,074
24 32,324 743 24,718 24,000 0 2,461
NAME
fping - send ICMP ECHO_REQUEST packets to network hosts
SYNOPSIS
fping [ options ] [ systems... ]
OPTIONS
-i n The minimum amount of time (in milliseconds) between sending a ping packet to any
target (default is 25).
-p <n> In looping or counting modes (-l, -c, or -C), this parameter sets the time in
milliseconds that fping waits between successive packets to an individual target.
Default is 1000.
EXAMPLES
Generate 20 pings to two hosts in ca. 1 second (i.e. one ping every 50 ms to each host),
and report every ping RTT at the end:
$ fping −q −i=1 −C=20 −p=50 127.0.0.1 127.0.0.2
NAME
nfsping - send RPC NULL requests to NFS servers
SYNOPSIS
nfsping [-aAdDEGhKlLmMnNqRsTuv] [-c count] [-C count] [-g prefix] [-H hertz] [-i
interval] [-P port] [-Q interval ] [-S source] [-ttimeout] [-V version] <servers...>
OPTIONS
-H
The polling frequency in Hertz. This is the number of pings sent to each target per
second. Default = 10.
NFStash/src/nfsping.c:
/* calculate the sleep_time based on the frequency */
/* check for a frequency of 1, that's a simple case */
/* this doesn't support frequencies lower than 1Hz */
if (hertz == 1) {
sleep_time.tv_sec = 1;
sleep_time.tv_nsec = 0;
} else {
sleep_time.tv_sec = 0;
/* nanoseconds */
sleep_time.tv_nsec = 1000000000 / hertz;
}
NFStash/src/nfsping.c:
/* sleep between rounds */
/* measure how long the current round took, and subtract that from the sleep time */
/* this tries to ensure that each polling round takes the same time */
#ifdef CLOCK_MONOTONIC_RAW
clock_gettime(CLOCK_MONOTONIC_RAW, &loop_end);
#else
clock_gettime(CLOCK_MONOTONIC, &loop_end);
#endif
timespecsub(&loop_end, &loop_start, &loop_elapsed);
debug("Polling took %lld.%.9ldsn", (long long)loop_elapsed.tv_sec,loop_elapsed.tv_nsec);
/* don't sleep if we went over the sleep_time */
if (timespeccmp(&loop_elapsed, &sleep_time, >)) {
debug("Slow poll, not sleepingn");
} else {
timespecsub(&sleep_time, &loop_elapsed, &sleepy);
debug("Sleeping for %lld.%.9ldsn", (long long)sleepy.tv_sec, sleepy.tv_nsec);
nanosleep(&sleepy, NULL);
}
NAME
nanosleep - high resolution sleep (REALTIME)
SYNOPSIS
#include <time.h>
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
DESCRIPTION
The nanosleep() function shall cause the current thread to be suspended from execution until either the time interval specified by the
rqtp argument has elapsed or a signal is delivered to the calling thread, and its action is to invoke a signal-catching function or to
terminate the process. The suspension time may be longer than requested because the argument value is rounded up to an integer
multiple of the sleep resolution or because of the scheduling of other activity by the system. But, except for the case of being
interrupted by a signal, the suspension time shall not be less than the time specified by rqtp, as measured by the system clock
CLOCK_REALTIME.
The use of the nanosleep() function has no effect on the action or blockage of any signal.
NFStash/src/nfsping.c:
/* grab the wall clock time for output */
/* use the start time of the request */
/* the call_start timer is more important so do this first so we're not measuring the
time this call takes */
clock_gettime(CLOCK_REALTIME, &wall_clock);
/* first time marker */
/* the MONOTONIC clocks don't record the actual time but are good for measuring elapsed
time accurately */
#ifdef CLOCK_MONOTONIC_RAW
clock_gettime(CLOCK_MONOTONIC_RAW, &call_start);
#else
clock_gettime(CLOCK_MONOTONIC, &call_start);
#endif
/* the actual ping */
status = nfsproc3_null_3(NULL, target->client);
/* second time marker */
#ifdef CLOCK_MONOTONIC_RAW
clock_gettime(CLOCK_MONOTONIC_RAW, &call_end);
#else
clock_gettime(CLOCK_MONOTONIC, &call_end);
#endif
NAME
clock_getres, clock_gettime, clock_settime - clock and timer functions (REALTIME)
SYNOPSIS
#include <time.h>
int clock_getres(clockid_t clock_id, struct timespec *res);
int clock_gettime(clockid_t clock_id, struct timespec *tp);
int clock_settime(clockid_t clock_id, const struct timespec *tp);
DESCRIPTION
The clock_gettime() function shall return the current value tp for the specified clock, clock_id.
A clock may be system-wide (that is, visible to all processes) or per-process (measuring time that is meaningful only within a
process). All implementations shall support a clock_id of CLOCK_REALTIME as defined in <time.h>. This clock represents the realtime
clock for the system. For this clock, the values returned by clock_gettime() and specified by clock_settime() represent the amount of
time (in seconds and nanoseconds) since the Epoch. An implementation may also support additional clocks.
Setting the value of the CLOCK_REALTIME clock via clock_settime() shall have no effect on threads that are blocked waiting for a
relative time service based upon this clock, including the nanosleep() function; nor on the expiration of relative timers based upon
this clock. Consequently, these time services shall expire when the requested relative interval elapses, independently of the new or
old value of the clock.
If the Monotonic Clock option is supported, all implementations shall support a clock_id of CLOCK_MONOTONIC defined in <time.h>.
This clock represents the monotonic clock for the system. For this clock, the value returned by clock_gettime() represents the
amount of time (in seconds and nanoseconds) since an unspecified point in the past (for example, system start-up time, or the
Epoch). This point does not change after system start-up time. The value of the CLOCK_MONOTONIC clock cannot be set via
clock_settime().
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since
some unspecified starting point. This clock is not affected
by discontinuous jumps in the system time (e.g., if the system
administrator manually changes the clock), but is affected by
the incremental adjustments performed by adjtime(3) and NTP.
CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
Similar to CLOCK_MONOTONIC, but provides access to a raw hard ‐
ware-based time that is not subject to NTP adjustments or the
incremental adjustments performed by adjtime(3).
www.yelp.com/careers/
We're Hiring!
@YelpEngineering
fb.com/YelpEngineers
engineeringblog.yelp.com
github.com/yelp

Weitere ähnliche Inhalte

Was ist angesagt?

Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in RealtimeTikal Knowledge
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixCodemotion Tel Aviv
 
Linux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersLinux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersBrendan Gregg
 
Processing Big Data in Real-Time - Yanai Franchi, Tikal
Processing Big Data in Real-Time - Yanai Franchi, TikalProcessing Big Data in Real-Time - Yanai Franchi, Tikal
Processing Big Data in Real-Time - Yanai Franchi, TikalCodemotion Tel Aviv
 
Real-time streams and logs with Storm and Kafka
Real-time streams and logs with Storm and KafkaReal-time streams and logs with Storm and Kafka
Real-time streams and logs with Storm and KafkaAndrew Montalenti
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaFerdinand Jamitzky
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bccViller Hsiao
 
YOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at NetflixYOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at NetflixBrendan Gregg
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing ToolsBrendan Gregg
 
USENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsUSENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsBrendan Gregg
 
OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)
OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)
OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)Denny K
 
Nmap Discovery
Nmap DiscoveryNmap Discovery
Nmap DiscoveryTai Pan
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerSasha Goldshtein
 
Backtracking Algorithmic Complexity Attacks Against a NIDS
Backtracking Algorithmic Complexity Attacks Against a NIDSBacktracking Algorithmic Complexity Attacks Against a NIDS
Backtracking Algorithmic Complexity Attacks Against a NIDSamiable_indian
 

Was ist angesagt? (20)

Kafka short
Kafka shortKafka short
Kafka short
 
Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in Realtime
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, Wix
 
eBPF Basics
eBPF BasicseBPF Basics
eBPF Basics
 
Linux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersLinux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF Superpowers
 
Processing Big Data in Real-Time - Yanai Franchi, Tikal
Processing Big Data in Real-Time - Yanai Franchi, TikalProcessing Big Data in Real-Time - Yanai Franchi, Tikal
Processing Big Data in Real-Time - Yanai Franchi, Tikal
 
Real-time streams and logs with Storm and Kafka
Real-time streams and logs with Storm and KafkaReal-time streams and logs with Storm and Kafka
Real-time streams and logs with Storm and Kafka
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bcc
 
Deathstar
DeathstarDeathstar
Deathstar
 
YOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at NetflixYOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at Netflix
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
 
USENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsUSENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame Graphs
 
OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)
OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)
OSTU - hrPING QuickStart Part 1 (by Tony Fortunato & Peter Ciuffreda)
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Nmap Discovery
Nmap DiscoveryNmap Discovery
Nmap Discovery
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF Primer
 
test
testtest
test
 
Backtracking Algorithmic Complexity Attacks Against a NIDS
Backtracking Algorithmic Complexity Attacks Against a NIDSBacktracking Algorithmic Complexity Attacks Against a NIDS
Backtracking Algorithmic Complexity Attacks Against a NIDS
 

Ähnlich wie Ping to Pong

Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdfsupport58
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsMorteza Mahdilar
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoScyllaDB
 
Debugging Ruby
Debugging RubyDebugging Ruby
Debugging RubyAman Gupta
 
Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Julien SIMON
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby SystemsEngine Yard
 
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docxMARRY7
 
Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)Ontico
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementationRajan Kumar
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32HANCOM MDS
 
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Rakib Hossain
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source codeAndrey Karpov
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source codePVS-Studio
 
Real-time in the real world: DIRT in production
Real-time in the real world: DIRT in productionReal-time in the real world: DIRT in production
Real-time in the real world: DIRT in productionbcantrill
 
Advanced RAC troubleshooting: Network
Advanced RAC troubleshooting: NetworkAdvanced RAC troubleshooting: Network
Advanced RAC troubleshooting: NetworkRiyaj Shamsudeen
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15종인 전
 

Ähnlich wie Ping to Pong (20)

Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
 
Debugging Ruby
Debugging RubyDebugging Ruby
Debugging Ruby
 
Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby Systems
 
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 
Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementation
 
Npc13
Npc13Npc13
Npc13
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32
 
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
 
Unix presentation.pdf
Unix presentation.pdfUnix presentation.pdf
Unix presentation.pdf
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Gps c
Gps cGps c
Gps c
 
Real-time in the real world: DIRT in production
Real-time in the real world: DIRT in productionReal-time in the real world: DIRT in production
Real-time in the real world: DIRT in production
 
Advanced RAC troubleshooting: Network
Advanced RAC troubleshooting: NetworkAdvanced RAC troubleshooting: Network
Advanced RAC troubleshooting: Network
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15
 

Kürzlich hochgeladen

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Kürzlich hochgeladen (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Ping to Pong

  • 1. Matt Provost mattpro@yelp.com Ping to Pong Rewriting Ping as a Video Game
  • 2. Yelp’s Mission Connecting people with great local businesses.
  • 3. /* * P I N G . C * * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, * measure round-trip-delays and packet loss across network paths. * * Author - * Mike Muuss * U. S. Army Ballistic Research Laboratory * December, 1983 * Modified at Uc Berkeley * Record Route and verbose headers - Phil Dykstra, BRL, March 1988. * * Status - * Public Domain. Distribution Unlimited. * * Bugs - * More statistics could always be gathered. * This program has to run SUID to ROOT to access the ICMP socket. */
  • 4.
  • 5.
  • 6. Raspberry Pi Model B+ (700 MHz): Dhrystones per Second: 1481481 VAX MIPS rating = 843.19 Raspberry Pi 2 Model B (1000 MHz)*: Dhrystones per Second: 2085024 VAX MIPS rating = 1186.70 *using one core
  • 7.
  • 9. NAME ping - send ICMP ECHO_REQUEST packets to network hosts SYNOPSIS ping [-dfnqrvR] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize] OPTIONS -f Flood ping. Outputs packets as fast as they come back or one hundred times per second, whichever is more. For every ECHO_REQUEST sent a period ``.'' is printed, while for every ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. Only the super-user may use this option. This can be very hard on a network and should be used with caution. -i wait Wait wait seconds between sending each packet. The default is to wait for one second between each packet. This option is incompatible with the -f option.
  • 10. while (true) { double start = getCurrentTime(); processInput(); update(); render(); sleep(start + MS_PER_FRAME - getCurrentTime()); } http://gameprogrammingpatterns.com/game-loop.html
  • 11. /* * C A T C H E R * * This routine causes another PING to be transmitted, and then * schedules another SIGALRM for 1 second from now. * * Bug - * Our sense of time will slowly skew (ie, packets will not be launched * exactly at 1-second intervals). This does not affect the quality * of the delay and loss statistics. */ catcher() { if (nreceived) { waittime = 2 * tmax / 1000; if (waittime == 0) waittime = 1; } else waittime = PING_MAXWAIT; // 10 signal(SIGALRM, finish); alarm(waittime); } }
  • 12. NAME alarm - schedule an alarm signal SYNOPSIS #include <unistd.h> unsigned alarm(unsigned seconds); DESCRIPTION The alarm() function shall cause the system to generate a SIGALRM signal for the process after the number of realtime seconds specified by seconds have elapsed. Processor scheduling delays may prevent the process from handling the signal as soon as it is generated.
  • 13. iputils/ping_common.c: int __schedule_exit(int next) { if (nreceived) { waittime = 2 * tmax; if (waittime < 1000*interval) waittime = 1000*interval; } else waittime = lingertime*1000; // struct timeval it_value it.it_value.tv_sec = waittime/1000000; it.it_value.tv_usec = waittime%1000000; setitimer(ITIMER_REAL, &it, NULL); }
  • 14. NAME getitimer, setitimer - get and set value of interval timer SYNOPSIS #include <sys/time.h> int setitimer(int which, const struct itimerval *restrict value, struct itimerval *restrict ovalue); DESCRIPTION The setitimer() function shall set the timer specified by which to the value specified in the structure pointed to by value, and if ovalue is not a null pointer, store the previous value of the timer in the structure pointed to by ovalue. A timer value is defined by the itimerval structure, specified in <sys/time.h>. If it_value is non-zero, it shall indicate the time to the next timer expiration. If it_interval is non-zero, it shall specify a value to be used in reloading it_value when the timer expires. An XSI-conforming implementation provides each process with at least three interval timers, which are indicated by the which argument: ITIMER_PROF Decrements both in process virtual time and when the system is running on behalf of the process. It is designed to be used by interpreters in statistically profiling the execution of interpreted programs. Each time the ITIMER_PROF timer expires, the SIGPROF signal is delivered. ITIMER_REAL Decrements in real time. A SIGALRM signal is delivered when this timer expires. ITIMER_VIRTUAL Decrements in process virtual time. It runs only when the process is executing. A SIGVTALRM signal is delivered when it expires.
  • 15. $ rrdtool create target.rrd --start 1537445727 --step 10 DS:ping:GAUGE:60:0:10000 RRA:AVERAGE:0.5:6:60 RRA:AVERAGE:0.5:8640:31
  • 16.
  • 17. Sent Elapsed ms RTT Average 1 0 118 2 1,118 125 3 2,243 109 4 3,352 113 5 4,465 127 6 5,592 121 7 6,713 123 8 7,836 117 9 8,953 116 119 10 10,069 129
  • 18. Sent Elapsed ms RTT Average 9 8,953 116 119 10 10,069 129 11 11,198 111 12 12,309 487 13 13,796 353 14 15,149 673 15 16,822 731 16 18,553 365 17 19,918 212 382.625 18 21,130 212
  • 19. Sent Elapsed ms RTT Average 17 19,918 212 382.625 18 21,130 212 19 22,342 145 20 23,487 119 21 24,606 1245 22 26,851 1561 23 29,412 1812 849 24 32,224 743
  • 20. Sent Elapsed ms RTT Average 1 0 118 2 1,118 125 3 2,243 109 4 3,352 113 5 4,465 127 6 5,592 121 7 6,713 123 8 7,836 117 9 8,953 116 119 10 10,069 129 11 11,198 111 12 12,309 487 13 13,796 353 14 15,149 673 15 16,822 731 16 18,553 365 17 19,918 212 383 18 21,130 212 19 22,342 145 20 23,487 119 21 24,606 1345 22 26,951 1561 23 29,512 1812 866 24 32,324 743
  • 22. double lastTime = getCurrentTime(); while (true) { double current = getCurrentTime(); double elapsed = current - lastTime; processInput(); update(elapsed); render(); lastTime = current; } http://gameprogrammingpatterns.com/game-loop.html
  • 23. Sent Elapsed ms RTT Average Actual Start Deadline Sleep Time Adjusted RTT Adjusted Avg 1 0 118 0 1,000 882 118 2 1,118 125 1,000 2,000 875 125 3 2,243 109 2,000 3,000 891 109 4 3,352 113 3,000 4,000 887 113 5 4,465 127 4,000 5,000 873 127 6 5,592 121 5,000 6,000 879 121 7 6,713 123 6,000 7,000 877 123 8 7,836 117 7,000 8,000 883 117 9 8,953 116 119 8,000 9,000 884 116 119 10 10,069 129 9,000 10,000 871 129 11 11,198 111 10,000 11,000 889 111 12 12,309 487 11,000 12,000 513 487 13 13,796 353 12,000 13,000 647 353 14 15,149 673 13,000 14,000 327 673 15 16,822 731 14,000 15,000 269 731 16 18,553 365 15,000 16,000 635 365 17 19,918 212 383 16,000 17,000 788 212 383 18 21,130 212 17,000 18,000 788 212 19 22,342 145 18,000 19,000 855 145 20 23,487 119 19,000 20,000 881 119 21 24,606 1345 20,000 21,000 0 1,345 22 26,951 1561 21,345 22,000 0 1,906 23 29,512 1812 866 22,906 23,000 0 2,718 1,074 24 32,324 743 24,718 24,000 0 2,461
  • 24.
  • 25. NAME fping - send ICMP ECHO_REQUEST packets to network hosts SYNOPSIS fping [ options ] [ systems... ] OPTIONS -i n The minimum amount of time (in milliseconds) between sending a ping packet to any target (default is 25). -p <n> In looping or counting modes (-l, -c, or -C), this parameter sets the time in milliseconds that fping waits between successive packets to an individual target. Default is 1000. EXAMPLES Generate 20 pings to two hosts in ca. 1 second (i.e. one ping every 50 ms to each host), and report every ping RTT at the end: $ fping −q −i=1 −C=20 −p=50 127.0.0.1 127.0.0.2
  • 26. NAME nfsping - send RPC NULL requests to NFS servers SYNOPSIS nfsping [-aAdDEGhKlLmMnNqRsTuv] [-c count] [-C count] [-g prefix] [-H hertz] [-i interval] [-P port] [-Q interval ] [-S source] [-ttimeout] [-V version] <servers...> OPTIONS -H The polling frequency in Hertz. This is the number of pings sent to each target per second. Default = 10.
  • 27. NFStash/src/nfsping.c: /* calculate the sleep_time based on the frequency */ /* check for a frequency of 1, that's a simple case */ /* this doesn't support frequencies lower than 1Hz */ if (hertz == 1) { sleep_time.tv_sec = 1; sleep_time.tv_nsec = 0; } else { sleep_time.tv_sec = 0; /* nanoseconds */ sleep_time.tv_nsec = 1000000000 / hertz; }
  • 28. NFStash/src/nfsping.c: /* sleep between rounds */ /* measure how long the current round took, and subtract that from the sleep time */ /* this tries to ensure that each polling round takes the same time */ #ifdef CLOCK_MONOTONIC_RAW clock_gettime(CLOCK_MONOTONIC_RAW, &loop_end); #else clock_gettime(CLOCK_MONOTONIC, &loop_end); #endif timespecsub(&loop_end, &loop_start, &loop_elapsed); debug("Polling took %lld.%.9ldsn", (long long)loop_elapsed.tv_sec,loop_elapsed.tv_nsec); /* don't sleep if we went over the sleep_time */ if (timespeccmp(&loop_elapsed, &sleep_time, >)) { debug("Slow poll, not sleepingn"); } else { timespecsub(&sleep_time, &loop_elapsed, &sleepy); debug("Sleeping for %lld.%.9ldsn", (long long)sleepy.tv_sec, sleepy.tv_nsec); nanosleep(&sleepy, NULL); }
  • 29. NAME nanosleep - high resolution sleep (REALTIME) SYNOPSIS #include <time.h> int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); DESCRIPTION The nanosleep() function shall cause the current thread to be suspended from execution until either the time interval specified by the rqtp argument has elapsed or a signal is delivered to the calling thread, and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested because the argument value is rounded up to an integer multiple of the sleep resolution or because of the scheduling of other activity by the system. But, except for the case of being interrupted by a signal, the suspension time shall not be less than the time specified by rqtp, as measured by the system clock CLOCK_REALTIME. The use of the nanosleep() function has no effect on the action or blockage of any signal.
  • 30. NFStash/src/nfsping.c: /* grab the wall clock time for output */ /* use the start time of the request */ /* the call_start timer is more important so do this first so we're not measuring the time this call takes */ clock_gettime(CLOCK_REALTIME, &wall_clock); /* first time marker */ /* the MONOTONIC clocks don't record the actual time but are good for measuring elapsed time accurately */ #ifdef CLOCK_MONOTONIC_RAW clock_gettime(CLOCK_MONOTONIC_RAW, &call_start); #else clock_gettime(CLOCK_MONOTONIC, &call_start); #endif /* the actual ping */ status = nfsproc3_null_3(NULL, target->client); /* second time marker */ #ifdef CLOCK_MONOTONIC_RAW clock_gettime(CLOCK_MONOTONIC_RAW, &call_end); #else clock_gettime(CLOCK_MONOTONIC, &call_end); #endif
  • 31. NAME clock_getres, clock_gettime, clock_settime - clock and timer functions (REALTIME) SYNOPSIS #include <time.h> int clock_getres(clockid_t clock_id, struct timespec *res); int clock_gettime(clockid_t clock_id, struct timespec *tp); int clock_settime(clockid_t clock_id, const struct timespec *tp); DESCRIPTION The clock_gettime() function shall return the current value tp for the specified clock, clock_id. A clock may be system-wide (that is, visible to all processes) or per-process (measuring time that is meaningful only within a process). All implementations shall support a clock_id of CLOCK_REALTIME as defined in <time.h>. This clock represents the realtime clock for the system. For this clock, the values returned by clock_gettime() and specified by clock_settime() represent the amount of time (in seconds and nanoseconds) since the Epoch. An implementation may also support additional clocks. Setting the value of the CLOCK_REALTIME clock via clock_settime() shall have no effect on threads that are blocked waiting for a relative time service based upon this clock, including the nanosleep() function; nor on the expiration of relative timers based upon this clock. Consequently, these time services shall expire when the requested relative interval elapses, independently of the new or old value of the clock. If the Monotonic Clock option is supported, all implementations shall support a clock_id of CLOCK_MONOTONIC defined in <time.h>. This clock represents the monotonic clock for the system. For this clock, the value returned by clock_gettime() represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past (for example, system start-up time, or the Epoch). This point does not change after system start-up time. The value of the CLOCK_MONOTONIC clock cannot be set via clock_settime().
  • 32. CLOCK_MONOTONIC Clock that cannot be set and represents monotonic time since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP. CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific) Similar to CLOCK_MONOTONIC, but provides access to a raw hard ‐ ware-based time that is not subject to NTP adjustments or the incremental adjustments performed by adjtime(3).