diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-07-30 09:18:35 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-07-30 09:18:35 +0100 |
commit | dd6832985c0ac4dd71b961010fb09916aa69d75a (patch) | |
tree | 90ded31f3acc43202c8a33101dfc63ef9257fb4c /tools | |
parent | 67e5041100ce387699722aec096a37e6d58a290e (diff) | |
download | xen-dd6832985c0ac4dd71b961010fb09916aa69d75a.tar.gz xen-dd6832985c0ac4dd71b961010fb09916aa69d75a.tar.bz2 xen-dd6832985c0ac4dd71b961010fb09916aa69d75a.zip |
xenconsoled: replace gettimeofday with clock_gettime
Currently if someone changes the date on the host, xenconsoled may
behave incorrectly due to the use of gettimeofday for the rate control
algorithm. For example I was able to hang the console connected to a
guest just setting the date forward 20 years. To solve the problem we
need to use a time source that doesn't change start point, that is
clock_gettime with CLOCK_MONOTONIC. The only bad side effect is that
it introduces a dependency to librt, but I think is well worth it.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/console/Makefile | 2 | ||||
-rw-r--r-- | tools/console/daemon/io.c | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/tools/console/Makefile b/tools/console/Makefile index 3d7e0fe307..10e909a0b6 100644 --- a/tools/console/Makefile +++ b/tools/console/Makefile @@ -21,7 +21,7 @@ clean: xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c)) $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) \ - $(UTIL_LIBS) $(SOCKET_LIBS) + $(UTIL_LIBS) $(SOCKET_LIBS) -lrt xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c)) $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) \ diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 16a0b6c27e..78aea83ed7 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -622,9 +622,9 @@ static struct domain *create_domain(int domid) { struct domain *dom; char *s; - struct timeval tv; + struct timespec ts; - if (gettimeofday(&tv, NULL) < 0) { + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) { dolog(LOG_ERR, "Cannot get time of day %s:%s:L%d", __FILE__, __FUNCTION__, __LINE__); return NULL; @@ -666,7 +666,7 @@ static struct domain *create_domain(int domid) dom->buffer.capacity = 0; dom->buffer.max_capacity = 0; dom->event_count = 0; - dom->next_period = (tv.tv_sec * 1000) + (tv.tv_usec / 1000) + RATE_LIMIT_PERIOD; + dom->next_period = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD; dom->next = NULL; dom->ring_ref = -1; @@ -971,7 +971,7 @@ void handle_io(void) struct domain *d, *n; int max_fd = -1; struct timeval timeout; - struct timeval tv; + struct timespec ts; long long now, next_timeout = 0; FD_ZERO(&readfds); @@ -985,9 +985,9 @@ void handle_io(void) max_fd = MAX(xc_evtchn_fd(xce_handle), max_fd); } - if (gettimeofday(&tv, NULL) < 0) + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return; - now = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); + now = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000); /* Re-calculate any event counter allowances & unblock domains with new allowance */ |