summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/timespec.c
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2017-09-25 16:44:06 +0530
committerJeff Darcy <jeff@pl.atyp.us>2017-11-06 14:23:49 +0000
commit125fc934e7f4c669f67e5eec5b0e3dae3a2b6d72 (patch)
tree24d1aa5139ad5766c4e9bc9e6add7e55df8fe329 /libglusterfs/src/timespec.c
parente86d71b7b4653ddd66db7f3a16074e46ed24848f (diff)
stack: change gettimeofday() to clock_gettime()
For achieving the above, needed below changes too. * more sanity into how 'frame->op' is assigned. * infra to have 'stats' as separate section in 'xlator_t' structure Updates #137 Change-Id: I36679bf9577f3ed00a695b4e7d92870dcb3db8e1 Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src/timespec.c')
-rw-r--r--libglusterfs/src/timespec.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c
index 903303d1380..932a18c0103 100644
--- a/libglusterfs/src/timespec.c
+++ b/libglusterfs/src/timespec.c
@@ -12,6 +12,7 @@
#include <inttypes.h>
#include <time.h>
#include <sys/time.h>
+#include <string.h>
#if defined GF_DARWIN_HOST_OS
#include <mach/mach_time.h>
@@ -21,17 +22,30 @@ static mach_timebase_info_data_t gf_timebase;
#include "logging.h"
#include "timespec.h"
#include "libglusterfs-messages.h"
+#include "common-utils.h"
void timespec_now (struct timespec *ts)
{
#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || defined GF_BSD_HOST_OS
- if (0 == clock_gettime(CLOCK_MONOTONIC, ts))
+ if (0 == clock_gettime(CLOCK_MONOTONIC, ts)) {
+ /* All good */
return;
- else {
- struct timeval tv;
- if (0 == gettimeofday(&tv, NULL))
- TIMEVAL_TO_TIMESPEC(&tv, ts);
}
+
+ /* Fall back, but there is hope in gettimeofday() syscall */
+ struct timeval tv;
+ if (0 == gettimeofday(&tv, NULL)) {
+ /* Again, all good */
+ TIMEVAL_TO_TIMESPEC(&tv, ts);
+ return;
+ }
+
+ /* If control hits here, there is surely a problem,
+ mainly because, as per man page too, these syscalls
+ shouldn't fail. Best way is to ABORT, because it is
+ not right */
+ GF_ABORT ("gettimeofday() failed!!");
+
#elif defined GF_DARWIN_HOST_OS
uint64_t time = mach_absolute_time();
static double scaling = 0.0;