Commit 7ab20c28 authored by Joanne Hugé's avatar Joanne Hugé

Take into account tai offset when comparing txtime and timestamp

parent 33329637
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#define SERVER_PORT_INT 50000 #define SERVER_PORT_INT 50000
#define CLOCK_ID CLOCK_TAI #define CLOCK_ID CLOCK_TAI
#define MESSAGE ((uint32_t)0x00FACADE) #define MESSAGE ((uint32_t)0x00FACADE)
#define NSEC_PER_SEC 1000000000 #define NSEC_PER_SEC ((uint64_t)1000000000)
static void print_timestamps(struct msghdr *msg, uint64_t txtime); static void print_timestamps(struct msghdr *msg, uint64_t txtime);
static void process_timestamps(uint64_t txtime); static void process_timestamps(uint64_t txtime);
...@@ -51,6 +51,8 @@ static unsigned char tx_buffer[1024] = "Hi"; ...@@ -51,6 +51,8 @@ static unsigned char tx_buffer[1024] = "Hi";
static size_t tx_buffer_len = sizeof(tx_buffer); static size_t tx_buffer_len = sizeof(tx_buffer);
static int fd; static int fd;
static int64_t tai_offset;
static int so_timestamping_flags = static int so_timestamping_flags =
SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE; SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE;
...@@ -74,6 +76,12 @@ void init_udp_etf(int use_etf, int use_timestamps, int packet_priority, ...@@ -74,6 +76,12 @@ void init_udp_etf(int use_etf, int use_timestamps, int packet_priority,
char *network_if) { char *network_if) {
int index; int index;
struct timespec ts_mon;
struct timespec ts_tai;
clock_gettime(CLOCK_MONOTONIC, &ts_mon);
clock_gettime(CLOCK_TAI, &ts_tai);
tai_offset = (ts_mon.tv_sec - ts_tai.tv_sec) * NSEC_PER_SEC + (ts_mon.tv_nsec - ts_tai.tv_nsec);
so_priority = packet_priority; so_priority = packet_priority;
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
...@@ -211,7 +219,7 @@ static void print_timestamps(struct msghdr *msg, uint64_t txtime) { ...@@ -211,7 +219,7 @@ static void print_timestamps(struct msghdr *msg, uint64_t txtime) {
stamp->tv_sec * NSEC_PER_SEC + stamp->tv_nsec; stamp->tv_sec * NSEC_PER_SEC + stamp->tv_nsec;
printf("SO_TIMESTAMPING "); printf("SO_TIMESTAMPING ");
printf("SW %" PRIu64 " - %" PRIu64 " (%" PRIi64 ") ", timestamp_ns, printf("SW %" PRIu64 " - %" PRIu64 " (%" PRIi64 ") ", timestamp_ns,
txtime, ((int64_t)timestamp_ns) - txtime); txtime, ((int64_t)timestamp_ns) - txtime - tai_offset);
break; break;
} }
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment