From: Adam C. Emerson Date: Tue, 15 Sep 2020 17:58:30 +0000 (-0400) Subject: common/ceph_time: Don't define public things in time_detail X-Git-Tag: v17.0.0~1113^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=01f706ca0ffd39680dbfacf348750c9c0f851578;p=ceph.git common/ceph_time: Don't define public things in time_detail Defining things in a detail section and then using them outside turned out to not be the best idea. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index f68cfd5a74cb4..c450ef9af4218 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -55,11 +55,12 @@ int clock_gettime(int clk_id, struct timespec *tp) using namespace std::literals; namespace ceph { -namespace time_detail { +using std::chrono::seconds; +using std::chrono::nanoseconds; void real_clock::to_ceph_timespec(const time_point& t, struct ceph_timespec& ts) { ts.tv_sec = to_time_t(t); - ts.tv_nsec = (t.time_since_epoch() % seconds(1)).count(); + ts.tv_nsec = (t.time_since_epoch() % 1s).count(); } struct ceph_timespec real_clock::to_ceph_timespec(const time_point& t) { struct ceph_timespec ts; @@ -87,7 +88,6 @@ coarse_real_clock::time_point coarse_real_clock::from_ceph_timespec( return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec)); } -} using std::chrono::duration_cast; using std::chrono::seconds; diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index 091641f637715..ee95266afb348 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -21,8 +21,6 @@ #include #include -#include "include/ceph_assert.h" - #if defined(__APPLE__) #include @@ -35,11 +33,6 @@ int clock_gettime(int clk_id, struct timespec *tp); struct ceph_timespec; namespace ceph { -namespace time_detail { -using std::chrono::duration_cast; -using std::chrono::seconds; -using std::chrono::microseconds; -using std::chrono::nanoseconds; // Currently we use a 64-bit count of nanoseconds. // We could, if we wished, use a struct holding a uint64_t count @@ -49,13 +42,20 @@ using std::chrono::nanoseconds; // want. typedef uint64_t rep; -// A concrete duration, unsigned. The timespan Ceph thinks in. + +// duration is the concrete time representation for our code in the +// case that we are only interested in durations between now and the +// future. Using it means we don't have to have EVERY function that +// deals with a duration be a template. We can do so for user-facing +// APIs, however. typedef std::chrono::duration timespan; // Like the above but signed. typedef int64_t signed_rep; +// Similar to the above but for durations that can specify +// differences between now and a time point in the past. typedef std::chrono::duration signedspan; // We define our own clocks so we can have our choice of all time @@ -67,6 +67,8 @@ typedef std::chrono::duration signedspan; // One potential issue is that we should accept system_clock // timepoints in user-facing APIs alongside (or instead of) // ceph::real_clock times. + +// High-resolution real-time clock class real_clock { public: typedef timespan duration; @@ -97,26 +99,27 @@ public: static time_point to_system_time_point( const std::chrono::time_point& t) { return time_point(seconds(Clock::to_time_t(t)) + - duration_cast(t.time_since_epoch() % - seconds(1))); + std::chrono::duration_cast(t.time_since_epoch() % + std::chrono::seconds(1))); } template static std::chrono::time_point to_system_time_point( const time_point& t) { return (Clock::from_time_t(to_time_t(t)) + - duration_cast(t.time_since_epoch() % seconds(1))); + std::chrono::duration_cast(t.time_since_epoch() % + std::chrono::seconds(1))); } static time_t to_time_t(const time_point& t) noexcept { - return duration_cast(t.time_since_epoch()).count(); + return std::chrono::duration_cast(t.time_since_epoch()).count(); } static time_point from_time_t(const time_t& t) noexcept { - return time_point(seconds(t)); + return time_point(std::chrono::seconds(t)); } static void to_timespec(const time_point& t, struct timespec& ts) { ts.tv_sec = to_time_t(t); - ts.tv_nsec = (t.time_since_epoch() % seconds(1)).count(); + ts.tv_nsec = (t.time_since_epoch() % std::chrono::seconds(1)).count(); } static struct timespec to_timespec(const time_point& t) { struct timespec ts; @@ -124,7 +127,8 @@ public: return ts; } static time_point from_timespec(const struct timespec& ts) { - return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec)); + return time_point(std::chrono::seconds(ts.tv_sec) + + std::chrono::nanoseconds(ts.tv_nsec)); } static void to_ceph_timespec(const time_point& t, @@ -134,8 +138,8 @@ public: static void to_timeval(const time_point& t, struct timeval& tv) { tv.tv_sec = to_time_t(t); - tv.tv_usec = duration_cast(t.time_since_epoch() % - seconds(1)).count(); + tv.tv_usec = std::chrono::duration_cast( + t.time_since_epoch() % std::chrono::seconds(1)).count(); } static struct timeval to_timeval(const time_point& t) { struct timeval tv; @@ -143,18 +147,20 @@ public: return tv; } static time_point from_timeval(const struct timeval& tv) { - return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec)); + return time_point(std::chrono::seconds(tv.tv_sec) + + std::chrono::microseconds(tv.tv_usec)); } static double to_double(const time_point& t) { return std::chrono::duration(t.time_since_epoch()).count(); } static time_point from_double(const double d) { - return time_point(duration_cast( + return time_point(std::chrono::duration_cast( std::chrono::duration(d))); } }; +// Low-resolution but preusmably faster real-time clock class coarse_real_clock { public: typedef timespan duration; @@ -191,15 +197,16 @@ public: } static time_t to_time_t(const time_point& t) noexcept { - return duration_cast(t.time_since_epoch()).count(); + return std::chrono::duration_cast( + t.time_since_epoch()).count(); } static time_point from_time_t(const time_t t) noexcept { - return time_point(seconds(t)); + return time_point(std::chrono::seconds(t)); } static void to_timespec(const time_point& t, struct timespec& ts) { ts.tv_sec = to_time_t(t); - ts.tv_nsec = (t.time_since_epoch() % seconds(1)).count(); + ts.tv_nsec = (t.time_since_epoch() % std::chrono::seconds(1)).count(); } static struct timespec to_timespec(const time_point& t) { struct timespec ts; @@ -207,7 +214,8 @@ public: return ts; } static time_point from_timespec(const struct timespec& ts) { - return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec)); + return time_point(std::chrono::seconds(ts.tv_sec) + + std::chrono::nanoseconds(ts.tv_nsec)); } static void to_ceph_timespec(const time_point& t, @@ -217,8 +225,8 @@ public: static void to_timeval(const time_point& t, struct timeval& tv) { tv.tv_sec = to_time_t(t); - tv.tv_usec = duration_cast(t.time_since_epoch() % - seconds(1)).count(); + tv.tv_usec = std::chrono::duration_cast( + t.time_since_epoch() % std::chrono::seconds(1)).count(); } static struct timeval to_timeval(const time_point& t) { struct timeval tv; @@ -226,18 +234,20 @@ public: return tv; } static time_point from_timeval(const struct timeval& tv) { - return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec)); + return time_point(std::chrono::seconds(tv.tv_sec) + + std::chrono::microseconds(tv.tv_usec)); } static double to_double(const time_point& t) { return std::chrono::duration(t.time_since_epoch()).count(); } static time_point from_double(const double d) { - return time_point(duration_cast( + return time_point(std::chrono::duration_cast( std::chrono::duration(d))); } }; +// High-resolution monotonic clock class mono_clock { public: typedef timespan duration; @@ -249,7 +259,8 @@ public: static time_point now() noexcept { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec)); + return time_point(std::chrono::seconds(ts.tv_sec) + + std::chrono::nanoseconds(ts.tv_nsec)); } static bool is_zero(const time_point& t) { @@ -259,12 +270,10 @@ public: static time_point zero() { return time_point::min(); } - - // A monotonic clock's timepoints are only meaningful to the - // computer on which they were generated. Thus having an - // optional skew is meaningless. }; +// Low-resolution but, I would hope or there's no point, faster +// monotonic clock class coarse_mono_clock { public: typedef timespan duration; @@ -287,7 +296,8 @@ public: #warning Falling back to CLOCK_MONOTONIC, may be slow. clock_gettime(CLOCK_MONOTONIC, &ts); #endif - return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec)); + return time_point(std::chrono::seconds(ts.tv_sec) + + std::chrono::nanoseconds(ts.tv_nsec)); } static bool is_zero(const time_point& t) { @@ -299,9 +309,9 @@ public: } }; +namespace time_detail { // So that our subtractions produce negative spans rather than // arithmetic underflow. -namespace { template inline auto difference(std::chrono::duration minuend, @@ -336,32 +346,6 @@ inline auto difference( subtrahend.time_since_epoch()); } } -} // namespace time_detail - - // duration is the concrete time representation for our code in the - // case that we are only interested in durations between now and the - // future. Using it means we don't have to have EVERY function that - // deals with a duration be a template. We can do so for user-facing - // APIs, however. -using time_detail::timespan; - -// Similar to the above but for durations that can specify -// differences between now and a time point in the past. -using time_detail::signedspan; - -// High-resolution real-time clock -using time_detail::real_clock; - -// Low-resolution but preusmably faster real-time clock -using time_detail::coarse_real_clock; - - -// High-resolution monotonic clock -using time_detail::mono_clock; - -// Low-resolution but, I would hope or there's no point, faster -// monotonic clock -using time_detail::coarse_mono_clock; // Please note that the coarse clocks are disjoint. You cannot // subtract a real_clock timepoint from a coarse_real_clock @@ -430,7 +414,6 @@ auto ceil(const std::chrono::time_point& timepoint, ceil(timepoint.time_since_epoch(), precision)); } -namespace { inline timespan make_timespan(const double d) { return std::chrono::duration_cast( std::chrono::duration(d)); @@ -438,7 +421,6 @@ inline timespan make_timespan(const double d) { inline std::optional maybe_timespan(const double d) { return d ? std::make_optional(make_timespan(d)) : std::nullopt; } -} std::ostream& operator<<(std::ostream& m, const timespan& t); template signedspan::zero() ? std::chrono::duration_cast(z) : diff --git a/src/common/iso_8601.cc b/src/common/iso_8601.cc index 101334d2ea526..4d639053678d2 100644 --- a/src/common/iso_8601.cc +++ b/src/common/iso_8601.cc @@ -6,6 +6,7 @@ #include "iso_8601.h" #include "include/timegm.h" +#include "include/ceph_assert.h" namespace ceph { using std::chrono::duration_cast; diff --git a/src/messages/MOSDPing.h b/src/messages/MOSDPing.h index 126064252c73d..7131b246edc00 100644 --- a/src/messages/MOSDPing.h +++ b/src/messages/MOSDPing.h @@ -64,7 +64,7 @@ private: utime_t ping_stamp; ///< when the PING was sent ceph::signedspan mono_ping_stamp; ///< relative to sender's clock ceph::signedspan mono_send_stamp; ///< replier's send stamp - std::optional delta_ub; ///< ping sender + std::optional delta_ub; ///< ping sender epoch_t up_from = 0; uint32_t min_message_size = 0; @@ -75,7 +75,7 @@ private: ceph::signedspan mss, epoch_t upf, uint32_t min_message, - std::optional delta_ub = {}) + std::optional delta_ub = {}) : Message{MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION}, fsid(f), map_epoch(e), op(o), ping_stamp(s), diff --git a/src/rgw/rgw_sync_error_repo.h b/src/rgw/rgw_sync_error_repo.h index f5169c0b280aa..58b3b183eea5f 100644 --- a/src/rgw/rgw_sync_error_repo.h +++ b/src/rgw/rgw_sync_error_repo.h @@ -23,7 +23,7 @@ class RGWCoroutine; struct rgw_raw_obj; // decode a timestamp as a uint64_t for CMPXATTR_MODE_U64 -ceph::real_time rgw_error_repo_decode_value(const bufferlist& bl); +ceph::real_time rgw_error_repo_decode_value(const ceph::bufferlist& bl); // write an omap key iff the given timestamp is newer int rgw_error_repo_write(librados::ObjectWriteOperation& op,