]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: make ceph_clock_now() inlineable. 20443/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 14 Feb 2018 16:16:14 +0000 (17:16 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 14 Feb 2018 20:43:50 +0000 (21:43 +0100)
The `ceph_clock_now()` is a widely spread but thin routine.
All it does is wrap `clock_gettime` or `gettimeofday` with
accompanying conversion to `utime_t`.

Unfortunately, as it is defined outside of header, compilers
are enforced to generate a full-blown function. The overhead
is related not only the well visible stack smashing protection
but also to enforcing callers to go through PLT each time.

Taking into account the time getters are usually *user-space
syscalls* (leveraging e.g. the VDSO mechanism), eradicating
even small boilerplate might be beneficial.

```
0000000000000000 <ceph_clock_now()>:
   0:   48 83 ec 28             sub    $0x28,%rsp
   4:   31 ff                   xor    %edi,%edi
   6:   48 89 e6                mov    %rsp,%rsi
   9:   64 48 8b 04 25 28 00    mov    %fs:0x28,%rax
  10:   00 00
  12:   48 89 44 24 18          mov    %rax,0x18(%rsp)
  17:   31 c0                   xor    %eax,%eax
  19:   e8 00 00 00 00          callq  1e <ceph_clock_now()+0x1e>
  1e:   8b 44 24 08             mov    0x8(%rsp),%eax
  22:   48 c1 e0 20             shl    $0x20,%rax
  26:   48 89 c2                mov    %rax,%rdx
  29:   8b 04 24                mov    (%rsp),%eax
  2c:   48 09 d0                or     %rdx,%rax
  2f:   48 8b 4c 24 18          mov    0x18(%rsp),%rcx
  34:   64 48 33 0c 25 28 00    xor    %fs:0x28,%rcx
  3b:   00 00
  3d:   75 05                   jne    44 <ceph_clock_now()+0x44>
  3f:   48 83 c4 28             add    $0x28,%rsp
  43:   c3                      retq
  44:   e8 00 00 00 00          callq  49 <SubProcess::spawn()::__PRETTY_FUNCTION__+0x9>
```

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/CMakeLists.txt
src/common/Clock.cc [deleted file]
src/common/Clock.h
src/include/utime.h

index 9651c75041f81dff2040522b2ef0236e869742f2..1a99c9a85fcee35f60769a3f4e69ab4526f1d6ab 100644 (file)
@@ -418,7 +418,6 @@ set(libcommon_files
   common/escape.cc
   common/url_escape.cc
   common/io_priority.cc
-  common/Clock.cc
   common/ceph_time.cc
   common/mempool.cc
   common/Throttle.cc
diff --git a/src/common/Clock.cc b/src/common/Clock.cc
deleted file mode 100644 (file)
index 9412fac..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-
-#include "common/Clock.h"
-
-utime_t ceph_clock_now()
-{
-#if defined(__linux__)
-  struct timespec tp;
-  clock_gettime(CLOCK_REALTIME, &tp);
-  utime_t n(tp);
-#else
-  struct timeval tv;
-  gettimeofday(&tv, nullptr);
-  utime_t n(&tv);
-#endif
-  return n;
-}
index 9f3238f436e751f090d64754129eb417890b66bb..b47954ad1ce7d65d09c4c127a3ad4834c5912bd8 100644 (file)
 
 #include <time.h>
 
-utime_t ceph_clock_now();
+static inline utime_t ceph_clock_now()
+{
+#if defined(__linux__)
+  struct timespec tp;
+  clock_gettime(CLOCK_REALTIME, &tp);
+  utime_t n(tp);
+#else
+  struct timeval tv;
+  gettimeofday(&tv, nullptr);
+  utime_t n(&tv);
+#endif
+  return n;
+}
 
 #endif
index 63b4683161666b69e7b07d6fa7a3d13a639ecd4f..05418ff3b1f40293a517ec9ee5e915e49b77652e 100644 (file)
@@ -62,6 +62,8 @@ public:
   }
   utime_t(const struct timespec v)
   {
+    // NOTE: this is used by ceph_clock_now() so should be kept
+    // as thin as possible.
     tv.tv_sec = v.tv_sec;
     tv.tv_nsec = v.tv_nsec;
   }