/*--------------------------------------------------------------------*/
struct acct {
- time_t first;
+ double first;
uint64_t sess;
uint64_t req;
uint64_t pipe;
struct objhead *nobjhead;
struct object *nobj;
- time_t idle;
+ double idle;
int pipe[2];
unsigned busy;
unsigned len;
- time_t age;
- time_t entered;
- time_t ttl;
+ double age;
+ double entered;
+ double ttl;
- time_t last_modified;
+ double last_modified;
struct http http;
TAILQ_ENTRY(object) list;
TAILQ_HEAD(, sess) waitinglist;
- time_t lru_stamp;
+ double lru_stamp;
TAILQ_ENTRY(object) lru;
};
const char *doclose;
struct http *http;
- struct timespec t_open;
- struct timespec t_req;
- struct timespec t_resp;
- struct timespec t_end;
+ double t_open;
+ double t_req;
+ double t_resp;
+ double t_end;
enum step step;
unsigned handling;
/* cache_lru.c */
// void LRU_Init(void);
-void LRU_Enter(struct object *o, time_t stamp);
+void LRU_Enter(struct object *o, double stamp);
void LRU_Remove(struct object *o);
int LRU_DiscardOne(void);
int LRU_DiscardSpace(int64_t quota);
-int LRU_DiscardTime(time_t cutoff);
+int LRU_DiscardTime(double cutoff);
#define VCL_RET_MAC(l,u,b,n)
#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);
#include <sys/types.h>
#include <sys/socket.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#ifndef HAVE_SRANDOMDEV
#include "compat/srandomdev.h"
#endif
TCP_name(sp->sockaddr, sp->sockaddrlen,
sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port);
- sp->acct.first = sp->t_open.tv_sec;
+ sp->acct.first = sp->t_open;
if (need_test)
sock_test(sp->fd);
if (need_linger)
sp->fd = i;
sp->id = i;
- (void)clock_gettime(CLOCK_REALTIME, &sp->t_open);
+ sp->t_open = TIM_real();
http_RecvPrep(sp->http);
sp->step = STP_FIRST;
#include <sys/epoll.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
vca_main(void *arg)
{
struct epoll_event ev;
- struct timespec ts;
+ double deadline;
struct sess *sp, *sp2;
int i;
}
}
/* check for timeouts */
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec -= params->sess_timeout;
+ deadline = TIM_real() - params->sess_timeout
TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (sp->t_open.tv_sec > ts.tv_sec)
- continue;
- if (sp->t_open.tv_sec == ts.tv_sec &&
- sp->t_open.tv_nsec > ts.tv_nsec)
+ if (sp->t_open > deadline)
continue;
TAILQ_REMOVE(&sesshead, sp, list);
vca_del(sp->fd);
#include <sys/event.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
{
struct kevent ke[NKEV], *kp;
int j, n, dotimer;
- struct timespec ts;
+ double deadline;
struct sess *sp;
(void)arg;
}
if (!dotimer)
continue;
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec -= params->sess_timeout;
+ deadline = TIM_real() - params->sess_timeout;
for (;;) {
sp = TAILQ_FIRST(&sesshead);
if (sp == NULL)
break;
- if (sp->t_open.tv_sec > ts.tv_sec)
- break;
- if (sp->t_open.tv_sec == ts.tv_sec &&
- sp->t_open.tv_nsec > ts.tv_nsec)
+ if (sp->t_open > deadline)
break;
TAILQ_REMOVE(&sesshead, sp, list);
vca_close_session(sp, "timeout");
#include <unistd.h>
#include <poll.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
{
unsigned v;
struct sess *sp, *sp2;
- struct timespec ts;
+ double deadline;
int i, fd;
(void)arg;
TAILQ_INSERT_TAIL(&sesshead, sp, list);
vca_poll(sp->fd);
}
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec -= params->sess_timeout;
+ deadline = TIM_real() - params->sess_timeout;
TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
if (v == 0)
break;
SES_Delete(sp);
continue;
}
- if (sp->t_open.tv_sec > ts.tv_sec)
- continue;
- if (sp->t_open.tv_sec == ts.tv_sec &&
- sp->t_open.tv_nsec > ts.tv_nsec)
+ if (sp->t_open > deadline)
continue;
TAILQ_REMOVE(&sesshead, sp, list);
vca_unpoll(fd);
#include <string.h>
#include <unistd.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#ifndef HAVE_SRANDOMDEV
#include "compat/srandomdev.h"
#endif
DOT ]
*/
-static double
-cnt_dt(struct timespec *t1, struct timespec *t2)
-{
- double dt;
-
- dt = (t2->tv_sec - t1->tv_sec);
- dt += (t2->tv_nsec - t1->tv_nsec) * 1e-9;
- return (dt);
-}
-
static int
cnt_done(struct sess *sp)
{
sp->vcl = NULL;
}
- clock_gettime(CLOCK_REALTIME, &sp->t_end);
- sp->wrk->idle = sp->t_end.tv_sec;
+ sp->t_end = TIM_real();
+ sp->wrk->idle = sp->t_end;
if (sp->xid == 0) {
sp->t_req = sp->t_end;
sp->t_resp = sp->t_end;
}
- dp = cnt_dt(&sp->t_req, &sp->t_resp);
- da = cnt_dt(&sp->t_resp, &sp->t_end);
- dh = cnt_dt(&sp->t_open, &sp->t_req);
- WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %ld.%09ld %ld.%09ld %.9f %.9f %.9f",
- sp->xid,
- (long)sp->t_req.tv_sec, (long)sp->t_req.tv_nsec,
- (long)sp->t_end.tv_sec, (long)sp->t_end.tv_nsec,
- dh, dp, da);
+ dp = sp->t_resp - sp->t_req;
+ da = sp->t_end - sp->t_resp;
+ dh = sp->t_req - sp->t_open;
+ WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f",
+ sp->xid, sp->t_req, sp->t_end, dh, dp, da);
sp->xid = 0;
sp->t_open = sp->t_end;
assert(sp->xid == 0);
VCA_Prep(sp);
- sp->wrk->idle = sp->t_open.tv_sec;
+ sp->wrk->idle = sp->t_open;
sp->wrk->acct.sess++;
SES_RefSrcAddr(sp);
do
/* Update stats of various sorts */
VSL_stats->client_req++; /* XXX not locked */
- clock_gettime(CLOCK_REALTIME, &sp->t_req);
- sp->wrk->idle = sp->t_req.tv_sec;
+ sp->t_req = TIM_real();
+ sp->wrk->idle = sp->t_req;
sp->wrk->acct.req++;
/* Assign XID and log */
exp_hangman(void *arg)
{
struct object *o;
- time_t t;
+ double t;
(void)arg;
- t = time(NULL);
+ t = TIM_real();
while (1) {
LOCK(&exp_mtx);
TAILQ_FOREACH(o, &exp_deathrow, deathrow) {
{
struct worker ww;
struct object *o;
- time_t t;
+ double t;
struct sess *sp;
struct object *o2;
sleep(10); /* Takes time for VCL to arrive */
VCL_Get(&sp->vcl);
- t = time(NULL);
+ t = TIM_real();
while (1) {
LOCK(&exp_mtx);
o = binheap_root(exp_heap);
/* ignore */
} else if (o->ttl == 0) {
/* Object banned but not reaped yet */
- } else if (o->ttl <= sp->t_req.tv_sec) {
+ } else if (o->ttl <= sp->t_req) {
/* Object expired */
} else if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b)) {
o->ttl = 0;
if (o != NULL) {
UNLOCK(&oh->mtx);
(void)hash->deref(oh);
- LRU_Enter(o, sp->t_req.tv_sec);
+ LRU_Enter(o, sp->t_req);
return (o);
}
/* NB: do not deref objhead the new object inherits our reference */
UNLOCK(&oh->mtx);
BAN_NewObj(o);
- LRU_Enter(o, sp->t_req.tv_sec);
+ LRU_Enter(o, sp->t_req);
return (o);
}
* if it's already in it and hasn't moved in a while.
*/
void
-LRU_Enter(struct object *o, time_t stamp)
+LRU_Enter(struct object *o, double stamp)
{
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
* number of objects that were discarded.
*/
int
-LRU_DiscardTime(time_t cutoff)
+LRU_DiscardTime(double cutoff)
{
struct object *first = TAILQ_FIRST(&lru_list);
struct object *o;
#include <stdlib.h>
#include <sys/socket.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#include "shmlog.h"
#include "heritage.h"
#include "cache.h"
vbe_free_bereq(bereq);
bereq = NULL;
- clock_gettime(CLOCK_REALTIME, &sp->t_resp);
+ sp->t_resp = TIM_real();
memset(fds, 0, sizeof fds);
fds[0].fd = vc->fd;
static void *
wrk_reaperthread(void *priv)
{
- time_t now;
+ double now;
struct worker *w;
struct wq *qp;
unsigned u;
sleep(1);
if (VSL_stats->n_wrk <= params->wthread_min)
continue;
- now = time(NULL);
+ now = TIM_real();
for (u = 0; u < nwq; u++) {
qp = wq[u];
LOCK(&qp->mtx);
#include <sys/types.h>
#include <sys/time.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#include "shmlog.h"
#include "heritage.h"
#include "cache.h"
sp->http->logtag = HTTP_Tx;
http_SetResp(sp->http,
"HTTP/1.1", "304", "Not Modified");
- TIM_format(sp->t_req.tv_sec, lm);
+ TIM_format(sp->t_req, lm);
http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm);
http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid);
res_do_conds(struct sess *sp)
{
char *p;
- time_t ims;
+ double ims;
if (sp->obj->last_modified > 0 &&
http_GetHdr(sp->http, H_If_Modified_Since, &p)) {
ims = TIM_parse(p);
- if (ims > sp->t_req.tv_sec) /* [RFC2616 14.25] */
+ if (ims > sp->t_req) /* [RFC2616 14.25] */
return (0);
if (sp->obj->last_modified > ims) {
return (0);
else
http_PrintfHeader(sp->wrk, sp->fd, sp->http,
"X-Varnish: %u", sp->xid);
- http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u",
- sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %.0f",
+ sp->obj->age + sp->t_resp - sp->obj->entered);
http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
if (sp->doclose != NULL)
http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- clock_gettime(CLOCK_REALTIME, &sp->t_resp);
+ sp->t_resp = TIM_real();
WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
char addr[TCP_ADDRBUFSIZE];
unsigned nref;
- time_t ttl;
+ double ttl;
struct acct acct;
};
unsigned u, v;
struct srcaddr *c, *c2, *c3;
struct srcaddrhead *ch;
- time_t now;
+ double now;
if (params->srcaddr_ttl == 0) {
sp->srcaddr = NULL;
v = u % nsrchash;
ch = &srchash[v];
CHECK_OBJ(ch, SRCADDRHEAD_MAGIC);
- now = sp->t_open.tv_sec;
+ now = sp->t_open;
if (sp->wrk->srcaddr == NULL) {
sp->wrk->srcaddr = calloc(sizeof *sp->wrk->srcaddr, 1);
XXXAN(sp->wrk->srcaddr);
b = sp->srcaddr->acct;
UNLOCK(&sp->srcaddr->sah->mtx);
WSL(sp->wrk, SLT_StatAddr, 0,
- "%s 0 %d %ju %ju %ju %ju %ju %ju %ju",
- sp->srcaddr->addr, sp->t_end.tv_sec - b.first,
+ "%s 0 %.0f %ju %ju %ju %ju %ju %ju %ju",
+ sp->srcaddr->addr, sp->t_end - b.first,
b.sess, b.req, b.pipe, b.pass,
b.fetch, b.hdrbytes, b.bodybytes);
}
AZ(sp->vcl);
VSL_stats->n_sess--;
ses_relsrcaddr(sp);
- VSL(SLT_StatSess, sp->id, "%s %s %d %ju %ju %ju %ju %ju %ju %ju",
- sp->addr, sp->port, sp->t_end.tv_sec - b->first,
+ VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju",
+ sp->addr, sp->port, sp->t_end - b->first,
b->sess, b->req, b->pipe, b->pass,
b->fetch, b->hdrbytes, b->bodybytes);
if (sm->workspace != params->mem_workspace) {
#include <stdlib.h>
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
#include "shmlog.h"
#include "heritage.h"
#include "cache.h"
struct vsb vsb;
const char *msg;
char date[40];
- time_t now;
+ double now;
int fd;
assert(status >= 100 && status <= 999);
fd = sp->fd;
o = sp->obj;
h = &o->http;
- time(&now);
+ now = TIM_real();
/* look up HTTP response */
msg = http_StatusMessage(status);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
- WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %u",
- sp->obj->xid, a, sp->t_req.tv_sec);
+ WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %.0f",
+ sp->obj->xid, a, sp->t_req);
if (a < 0)
a = 0;
- sp->obj->ttl = sp->t_req.tv_sec + (int)a;
+ sp->obj->ttl = sp->t_req + a;
if (sp->obj->heap_idx != 0)
EXP_TTLchange(sp->obj);
}
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
- return (sp->obj->ttl - sp->t_req.tv_sec);
+ return (sp->obj->ttl - sp->t_req);
}
/*--------------------------------------------------------------------*/
double
VRT_r_now(struct sess *sp)
{
- struct timespec now;
(void)sp;
- /* XXX use of clock_gettime() needs review */
- clock_gettime(CLOCK_MONOTONIC, &now);
- return (now.tv_sec);
+ return (TIM_mono());
}
double
VRT_r_obj_lastuse(struct sess *sp)
{
- struct timespec now;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
- /* XXX use of clock_gettime() needs review */
- clock_gettime(CLOCK_MONOTONIC, &now);
- return (now.tv_sec - sp->obj->lru_stamp);
+ return (TIM_mono() - sp->obj->lru_stamp);
}
/*--------------------------------------------------------------------*/
ttd = min(ttd, our_clock + hard_upper_ttl)
#endif
-static time_t
+static double
RFC2616_Ttl(struct sess *sp, struct http *hp, struct object *obj)
{
int retirement_age;
unsigned u1, u2;
- time_t h_date, h_expires, ttd;
+ double h_date, h_expires, ttd;
char *p;
retirement_age = INT_MAX;