From 9f78ac569c561a65acf194864bb34a98c01f5711 Mon Sep 17 00:00:00 2001 From: logwang Date: Fri, 19 Jan 2018 20:57:32 +0800 Subject: [PATCH] ff_kern_timeout: optimize the timecounter. This timecounter implementation retrieves the current time and reports it as the equivalent number of counts from a counter incrementing at 'hz'. --- freebsd/vm/uma_core.c | 3 --- lib/ff_dpdk_if.c | 9 +++++++++ lib/ff_host_interface.c | 11 ++++++++--- lib/ff_host_interface.h | 1 + lib/ff_kern_timeout.c | 5 +++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/freebsd/vm/uma_core.c b/freebsd/vm/uma_core.c index 5554a112..c7cdd648 100644 --- a/freebsd/vm/uma_core.c +++ b/freebsd/vm/uma_core.c @@ -462,9 +462,6 @@ zone_foreach_keg(uma_zone_t zone, void (*kegfn)(uma_keg_t)) static void uma_timeout(void *unused) { -#ifdef FSTACK - return; -#endif bucket_enable(); zone_foreach(zone_timeout); diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index fe4c8ade..f9a35a9d 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -1597,3 +1597,12 @@ ff_regist_packet_dispatcher(dispatch_func_t func) { packet_dispatcher = func; } + +uint64_t +ff_get_tsc_ns() +{ + uint64_t cur_tsc = rte_rdtsc(); + uint64_t hz = rte_get_tsc_hz(); + return ((double)cur_tsc/(double)hz) * NS_PER_S; +} + diff --git a/lib/ff_host_interface.c b/lib/ff_host_interface.c index 182028c6..2b1ffddc 100644 --- a/lib/ff_host_interface.c +++ b/lib/ff_host_interface.c @@ -167,7 +167,7 @@ ff_clock_gettime_ns(int id) { int64_t sec; long nsec; - + ff_clock_gettime(id, &sec, &nsec); return ((uint64_t)sec * ff_NSEC_PER_SEC + nsec); @@ -176,8 +176,13 @@ ff_clock_gettime_ns(int id) void ff_get_current_time(time_t *sec, long *nsec) { - *sec = current_ts.tv_sec; - *nsec = current_ts.tv_nsec; + if (sec) { + *sec = current_ts.tv_sec; + } + + if (nsec) { + *nsec = current_ts.tv_nsec; + } } void diff --git a/lib/ff_host_interface.h b/lib/ff_host_interface.h index a6cdc630..e9d4318d 100644 --- a/lib/ff_host_interface.h +++ b/lib/ff_host_interface.h @@ -56,6 +56,7 @@ void ff_free(void *p); void ff_clock_gettime(int id, int64_t *sec, long *nsec); uint64_t ff_clock_gettime_ns(int id); +uint64_t ff_get_tsc_ns(void); void ff_get_current_time(int64_t *sec, long *nsec); void ff_update_current_ts(void); diff --git a/lib/ff_kern_timeout.c b/lib/ff_kern_timeout.c index 93864a8f..b42a82a9 100644 --- a/lib/ff_kern_timeout.c +++ b/lib/ff_kern_timeout.c @@ -1657,8 +1657,9 @@ ff_hardclock(void) static unsigned int ff_tc_get_timecount(struct timecounter *tc) { - static u_int now; - return (++now); + uint64_t ns; + ns = ff_get_tsc_ns(); + return ((ns * tc->tc_frequency) / ff_NSEC_PER_SEC); } static struct timecounter ff_timecounter = {