-
Notifications
You must be signed in to change notification settings - Fork 6
/
rtt.c
96 lines (76 loc) · 1.83 KB
/
rtt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 2017
* Authors: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/net_tstamp.h>
#include <time.h>
#include "rx_lat.h"
#include "tx_lat.h"
#include "rtt.h"
#include <stdio.h>
#include <unistd.h>
#include <poll.h>
#include <errno.h>
#define MAX_LATENCY 5000
static int rtt_proc(void)
{
int sid = plget->stream_id;
struct pollfd fds;
int timer, ret;
uint64_t exps;
timer = ts_correct(&plget->interval);
if (timer) {
fds.fd = plget->timer_fd;
fds.events = POLLIN;
ret = plget_start_timer();
if (ret)
return ret;
}
plget->inum = plget->pkt_num;
for (plget->icnt = 0; plget->icnt < plget->pkt_num; ++plget->icnt) {
if (plget->flags & PLF_PTP)
sid_wr(htons((plget->icnt & SEQ_ID_MASK) | sid));
tid_wr(plget->icnt);
txlat_proc_packet();
rxlat_proc_packet();
if (!timer)
continue;
ret = poll(&fds, 1, MAX_LATENCY);
if (ret <= 0)
return perror("Some error on timer poll()"), -errno;
ret = read(plget->timer_fd, &exps, sizeof(exps));
if (ret < 0)
return perror("Couldn't read timerfd"), -errno;
}
return 0;
}
static int rtt_init(void)
{
int ret;
if (!ts_correct(&plget->interval))
return 0;
ret = plget_create_timer();
if (ret)
return ret;
return 0;
}
int rtt(void)
{
int ret;
ret = rtt_init();
if (ret)
return ret;
ret = rtt_proc();
if (ts_correct(&plget->interval))
close(plget->timer_fd);
return ret;
}