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>
common/escape.cc
common/url_escape.cc
common/io_priority.cc
- common/Clock.cc
common/ceph_time.cc
common/mempool.cc
common/Throttle.cc
+++ /dev/null
-// -*- 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;
-}
#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
}
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;
}