Skip to content
Snippets Groups Projects
Commit 55cd48a7 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

update to new time API

parent 477d6c76
No related branches found
No related tags found
1 merge request!587Events refactoring
......@@ -73,8 +73,8 @@ int dt_message_fill(Dnstap__Message *m,
const int protocol,
const void *wire,
const size_t len_wire,
const struct timeval *qtime,
const struct timeval *rtime)
const struct timespec *qtime,
const struct timespec *rtime)
{
if (m == NULL) {
return KNOT_EINVAL;
......@@ -116,7 +116,7 @@ int dt_message_fill(Dnstap__Message *m,
// Message.query_time_sec, Message.query_time_nsec
if (qtime != NULL) {
m->query_time_sec = qtime->tv_sec;
m->query_time_nsec = qtime->tv_usec * 1000;
m->query_time_nsec = qtime->tv_nsec;
m->has_query_time_sec = 1;
m->has_query_time_nsec = 1;
}
......@@ -124,7 +124,7 @@ int dt_message_fill(Dnstap__Message *m,
// Message.response_time_sec, Message.response_time_nsec
if (rtime != NULL) {
m->response_time_sec = rtime->tv_sec;
m->response_time_nsec = rtime->tv_usec * 1000;
m->response_time_nsec = rtime->tv_nsec;
m->has_response_time_sec = 1;
m->has_response_time_nsec = 1;
}
......
......@@ -66,7 +66,7 @@ int dt_message_fill(Dnstap__Message *m,
const int protocol,
const void *wire,
const size_t len_wire,
const struct timeval *qtime,
const struct timeval *rtime);
const struct timespec *qtime,
const struct timespec *rtime);
/*! @} */
......@@ -39,9 +39,9 @@ struct timespec time_diff(const struct timespec *begin, const struct timespec *e
return result;
}
float time_diff_ms(const struct timespec *begin, const struct timespec *end)
double time_diff_ms(const struct timespec *begin, const struct timespec *end)
{
struct timespec result = time_diff(begin, end);
return (result.tv_sec * 1000.0) + (result.tv_nsec / 1e6);
return (result.tv_sec * 1e3) + (result.tv_nsec / 1e6);
}
......@@ -39,6 +39,6 @@ struct timespec time_diff(const struct timespec *begin, const struct timespec *e
/*!
* \brief Get time elapsed between two events in miliseconds.
*/
float time_diff_ms(const struct timespec *begin, const struct timespec *end);
double time_diff_ms(const struct timespec *begin, const struct timespec *end);
/*! @} */
......@@ -117,9 +117,7 @@ int fdset_set_watchdog(fdset_t* set, int i, int interval)
}
/* Update clock. */
timev_t now;
if (time_now(&now) < 0)
return KNOT_ERROR;
struct timespec now = time_now();
set->timeout[i] = now.tv_sec + interval; /* Only seconds precision. */
return KNOT_EOK;
......@@ -132,10 +130,7 @@ int fdset_sweep(fdset_t* set, fdset_sweep_cb_t cb, void *data)
}
/* Get time threshold. */
timev_t now;
if (time_now(&now) < 0) {
return KNOT_ERROR;
}
struct timespec now = time_now();
unsigned i = 0;
while (i < set->n) {
......
......@@ -24,6 +24,7 @@
#include "contrib/dnstap/message.h"
#include "contrib/dnstap/dnstap.h"
#include "contrib/mempattern.h"
#include "contrib/time.h"
#include "libknot/libknot.h"
/* Module configuration scheme. */
......@@ -77,8 +78,7 @@ static int log_message(int state, const knot_pkt_t *pkt, struct query_data *qdat
/* Unless we want to measure the time it takes to process each query,
* we can treat Q/R times the same. */
struct timeval tv;
gettimeofday(&tv, NULL);
struct timespec tv = time_now();
/* Determine query / response. */
Dnstap__Message__Type msgtype = DNSTAP__MESSAGE__TYPE__AUTH_QUERY;
......
......@@ -29,7 +29,7 @@
#include "knot/events/events.h"
#include "libknot/libknot.h"
#include "contrib/net.h"
#include "contrib/print.h"
#include "contrib/time.h"
/* UPDATE-specific logging (internal, expects 'qdata' variable set). */
#define UPDATE_LOG(severity, msg, ...) \
......@@ -178,8 +178,7 @@ static void process_requests(conf_t *conf, zone_t *zone, list_t *requests)
assert(requests);
/* Keep original state. */
struct timeval t_start, t_end;
gettimeofday(&t_start, NULL);
struct timespec t_start = time_now();
const uint32_t old_serial = zone_contents_serial(zone->contents);
/* Process authenticated packet. */
......@@ -197,10 +196,10 @@ static void process_requests(conf_t *conf, zone_t *zone, list_t *requests)
return;
}
gettimeofday(&t_end, NULL);
struct timespec t_end = time_now();
log_zone_info(zone->name, "DDNS, update finished, serial %u -> %u, "
"%.02f seconds", old_serial, new_serial,
time_diff(&t_start, &t_end) / 1000.0);
time_diff_ms(&t_start, &t_end));
zone_events_schedule(zone, ZONE_EVENT_NOTIFY, ZONE_EVENT_NOW);
}
......
......@@ -47,14 +47,14 @@
/*! \brief TCP context data. */
typedef struct tcp_context {
knot_layer_t layer; /*!< Query processing layer. */
server_t *server; /*!< Name server structure. */
struct iovec iov[2]; /*!< TX/RX buffers. */
unsigned client_threshold; /*!< Index of first TCP client. */
timev_t last_poll_time; /*!< Time of the last socket poll. */
timev_t throttle_end; /*!< End of accept() throttling. */
fdset_t set; /*!< Set of server/client sockets. */
unsigned thread_id; /*!< Thread identifier. */
knot_layer_t layer; /*!< Query processing layer. */
server_t *server; /*!< Name server structure. */
struct iovec iov[2]; /*!< TX/RX buffers. */
unsigned client_threshold; /*!< Index of first TCP client. */
struct timespec last_poll_time; /*!< Time of the last socket poll. */
struct timespec throttle_end; /*!< End of accept() throttling. */
fdset_t set; /*!< Set of server/client sockets. */
unsigned thread_id; /*!< Thread identifier. */
} tcp_context_t;
/*
......@@ -249,7 +249,7 @@ static int tcp_wait_for_events(tcp_context_t *tcp)
int nfds = poll(set->pfd, set->n, TCP_SWEEP_INTERVAL * 1000);
/* Mark the time of last poll call. */
time_now(&tcp->last_poll_time);
tcp->last_poll_time = time_now();
bool is_throttled = (tcp->last_poll_time.tv_sec < tcp->throttle_end.tv_sec);
if (!is_throttled) {
/* Configuration limit, infer maximal pool size. */
......@@ -273,7 +273,7 @@ static int tcp_wait_for_events(tcp_context_t *tcp)
/* Master sockets */
if (i < tcp->client_threshold) {
if (!is_throttled && tcp_event_accept(tcp, i) == KNOT_EBUSY) {
time_now(&tcp->throttle_end);
tcp->throttle_end = time_now();
tcp->throttle_end.tv_sec += tcp_throttle();
}
/* Client sockets */
......@@ -335,8 +335,7 @@ int tcp_master(dthread_t *thread)
}
/* Initialize sweep interval. */
timev_t next_sweep = {0};
time_now(&next_sweep);
struct timespec next_sweep = time_now();
next_sweep.tv_sec += TCP_SWEEP_INTERVAL;
for(;;) {
......@@ -370,7 +369,7 @@ int tcp_master(dthread_t *thread)
/* Sweep inactive clients. */
if (tcp.last_poll_time.tv_sec >= next_sweep.tv_sec) {
fdset_sweep(&tcp.set, &tcp_sweep, NULL);
time_now(&next_sweep);
next_sweep = time_now();
next_sweep.tv_sec += TCP_SWEEP_INTERVAL;
}
}
......
......@@ -26,7 +26,8 @@
#include "utils/common/sign.h"
#include "libknot/libknot.h"
#include "contrib/sockaddr.h"
#include "contrib/print.h"
//#include "contrib/print.h"
#include "contrib/time.h"
#include "contrib/ucw/lists.h"
#if USE_DNSTAP
......@@ -34,13 +35,13 @@
# include "contrib/dnstap/message.h"
# include "contrib/dnstap/writer.h"
static int write_dnstap(dt_writer_t *writer,
const bool is_query,
const uint8_t *wire,
const size_t wire_len,
net_t *net,
const struct timeval *qtime,
const struct timeval *rtime)
static int write_dnstap(dt_writer_t *writer,
const bool is_query,
const uint8_t *wire,
const size_t wire_len,
net_t *net,
const struct timespec *qtime,
const struct timespec *rtime)
{
Dnstap__Message msg;
Dnstap__Message__Type msg_type;
......@@ -74,17 +75,17 @@ static int write_dnstap(dt_writer_t *writer,
static float get_query_time(const Dnstap__Dnstap *frame)
{
struct timeval from = {
struct timespec from = {
.tv_sec = frame->message->query_time_sec,
.tv_usec = frame->message->query_time_nsec / 1000
.tv_nsec = frame->message->query_time_nsec
};
struct timeval to = {
struct timespec to = {
.tv_sec = frame->message->response_time_sec,
.tv_usec = frame->message->response_time_nsec / 1000
.tv_nsec = frame->message->response_time_nsec
};
return time_diff(&from, &to);
return time_diff_ms(&from, &to);
}
static void fill_remote_addr(net_t *net, Dnstap__Message *message, bool is_initiator)
......@@ -523,14 +524,14 @@ static int process_query_packet(const knot_pkt_t *query,
const sign_context_t *sign_ctx,
const style_t *style)
{
struct timeval t_start, t_query, t_end;
struct timespec t_start, t_query, t_end;
knot_pkt_t *reply;
uint8_t in[MAX_PACKET_SIZE];
int in_len;
int ret;
// Get start query time.
gettimeofday(&t_start, NULL);
t_start = time_now();
// Connect to the server.
ret = net_connect(net);
......@@ -546,7 +547,7 @@ static int process_query_packet(const knot_pkt_t *query,
}
// Get stop query time and start reply time.
gettimeofday(&t_query, NULL);
t_query = time_now();
#if USE_DNSTAP
// Make the dnstap copy of the query.
......@@ -561,7 +562,7 @@ static int process_query_packet(const knot_pkt_t *query,
if (q != NULL) {
if (knot_pkt_parse(q, 0) == KNOT_EOK) {
print_packet(q, net, query->size,
time_diff(&t_start, &t_query), 0,
time_diff_ms(&t_start, &t_query), 0,
false, style);
} else {
ERR("can't print query packet\n");
......@@ -584,7 +585,7 @@ static int process_query_packet(const knot_pkt_t *query,
}
// Get stop reply time.
gettimeofday(&t_end, NULL);
t_end = time_now();
#if USE_DNSTAP
// Make the dnstap copy of the response.
......@@ -612,7 +613,7 @@ static int process_query_packet(const knot_pkt_t *query,
if (check_reply_id(reply, query)) {
break;
// Check for timeout.
} else if (time_diff(&t_query, &t_end) > 1000 * net->wait) {
} else if (time_diff_ms(&t_query, &t_end) > 1000 * net->wait) {
knot_pkt_free(&reply);
net_close(net);
return -1;
......@@ -639,7 +640,7 @@ static int process_query_packet(const knot_pkt_t *query,
check_reply_question(reply, query);
// Print reply packet.
print_packet(reply, net, in_len, time_diff(&t_query, &t_end), 0,
print_packet(reply, net, in_len, time_diff_ms(&t_query, &t_end), 0,
true, style);
// Verify signature if a key was specified.
......@@ -763,18 +764,18 @@ static int process_xfr_packet(const knot_pkt_t *query,
const sign_context_t *sign_ctx,
const style_t *style)
{
struct timeval t_start, t_query, t_end;
knot_pkt_t *reply;
uint8_t in[MAX_PACKET_SIZE];
int in_len;
int ret;
int64_t serial = 0;
size_t total_len = 0;
size_t msg_count = 0;
size_t rr_count = 0;
struct timespec t_start, t_query, t_end;
knot_pkt_t *reply;
uint8_t in[MAX_PACKET_SIZE];
int in_len;
int ret;
int64_t serial = 0;
size_t total_len = 0;
size_t msg_count = 0;
size_t rr_count = 0;
// Get start query time.
gettimeofday(&t_start, NULL);
t_start = time_now();
// Connect to the server.
ret = net_connect(net);
......@@ -790,7 +791,7 @@ static int process_xfr_packet(const knot_pkt_t *query,
}
// Get stop query time and start reply time.
gettimeofday(&t_query, NULL);
t_query = time_now();
#if USE_DNSTAP
// Make the dnstap copy of the query.
......@@ -805,7 +806,7 @@ static int process_xfr_packet(const knot_pkt_t *query,
if (q != NULL) {
if (knot_pkt_parse(q, 0) == KNOT_EOK) {
print_packet(q, net, query->size,
time_diff(&t_start, &t_query), 0,
time_diff_ms(&t_start, &t_query), 0,
false, style);
} else {
ERR("can't print query packet\n");
......@@ -828,7 +829,7 @@ static int process_xfr_packet(const knot_pkt_t *query,
}
// Get stop message time.
gettimeofday(&t_end, NULL);
t_end = time_now();
#if USE_DNSTAP
// Make the dnstap copy of the response.
......@@ -933,11 +934,11 @@ static int process_xfr_packet(const knot_pkt_t *query,
}
// Get stop reply time.
gettimeofday(&t_end, NULL);
t_end = time_now();
// Print trailing transfer information.
print_footer_xfr(total_len, msg_count, rr_count, net,
time_diff(&t_query, &t_end), 0, style);
time_diff_ms(&t_query, &t_end), 0, style);
net_close(net);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment