From a9ff51d891726cb56ca0de3e1e64cdbfcefbfb59 Mon Sep 17 00:00:00 2001 From: sage Date: Thu, 14 Sep 2006 23:07:48 +0000 Subject: [PATCH] new clock stuff git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@857 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/TODO | 3 +++ ceph/common/Clock.h | 49 ++++++++++++++++++++++++++----------------- ceph/common/Cond.h | 13 +----------- ceph/common/Logger.cc | 6 ++++-- ceph/fakesyn.cc | 2 ++ ceph/newsyn.cc | 44 +++++++++++++++++++++++++++++++++++++- ceph/osd/PG.cc | 2 +- 7 files changed, 84 insertions(+), 35 deletions(-) diff --git a/ceph/TODO b/ceph/TODO index d850292688783..7d670169710e9 100644 --- a/ceph/TODO +++ b/ceph/TODO @@ -4,6 +4,9 @@ - how to get usage feedback to monitor? +- fix tare weirdness + + osd/rados - clean up writeahead logs - fix heartbeat wrt new replication diff --git a/ceph/common/Clock.h b/ceph/common/Clock.h index 2b369c71098db..10543a41cee76 100644 --- a/ceph/common/Clock.h +++ b/ceph/common/Clock.h @@ -40,6 +40,9 @@ class utime_t { } } + struct timeval& timeval() { return tv; } + friend class Clock; + public: // cons utime_t() { tv.tv_sec = 0; tv.tv_usec = 0; normalize(); } @@ -54,8 +57,6 @@ class utime_t { time_t& sec_ref() { return tv.tv_sec; } long& usec_ref() { return tv.tv_usec; } - struct timeval& timeval() { return tv; } - // cast to double operator double() { return (double)sec() + ((double)usec() / 1000000.0L); @@ -126,38 +127,48 @@ class Clock { public: Clock() { // set offset - //start_offset = now(); } - // relative time (from startup) - const utime_t& now() { - gettimeofday(&last.timeval(), NULL); - last -= zero; - //last = abs_last - start_offset; - return last; - } - - void realify(utime_t& t) { - t += zero; - } + // real time. utime_t real_now() { utime_t realnow; gettimeofday(&realnow.timeval(), NULL); return realnow; } - const utime_t& recent_now() { + // relative time (from startup) + void tare() { + gettimeofday(&zero.timeval(), NULL); + } + utime_t now() { + utime_t n; + gettimeofday(&n.timeval(), NULL); + n -= zero; + last = n; + return n; + } + utime_t recent_now() { return last; } - void tare() { - gettimeofday(&zero.timeval(), NULL); + void realify(utime_t& t) { + t += zero; + } + + void make_timespec(utime_t& t, struct timespec *ts) { + utime_t real = t; + realify(real); + + memset(ts, 0, sizeof(*ts)); + ts->tv_sec = real.sec(); + ts->tv_nsec = real.nsec(); } + + // absolute time time_t gettime() { - now(); - return last.sec(); + return now().sec(); } }; diff --git a/ceph/common/Cond.h b/ceph/common/Cond.h index 98cb7f9e009c4..fb764278f10ad 100644 --- a/ceph/common/Cond.h +++ b/ceph/common/Cond.h @@ -55,20 +55,9 @@ class Cond return r; } - int WaitUntil(Mutex &mutex, - struct timeval *tv) { - return WaitUntil(mutex, utime_t(tv->tv_sec, tv->tv_usec)); - } - int WaitUntil(Mutex &mutex, utime_t when) { - // make sure it's _real_ time - g_clock.realify(when); - - // timeval -> timespec struct timespec ts; - memset(&ts, 0, sizeof(ts)); - ts.tv_sec = when.sec(); - ts.tv_nsec = when.nsec(); + g_clock.make_timespec(when, &ts); //cout << "timedwait for " << ts.tv_sec << " sec " << ts.tv_nsec << " nsec" << endl; int r = pthread_cond_timedwait(&C, &mutex.M, &ts); return r; diff --git a/ceph/common/Logger.cc b/ceph/common/Logger.cc index 5523a215b8ee8..9d516dabc1f40 100644 --- a/ceph/common/Logger.cc +++ b/ceph/common/Logger.cc @@ -141,9 +141,11 @@ void Logger::flush(bool force) //cout << "opening log file " << filename << endl; } - utime_t fromstart = g_clock.recent_now(); - if (fromstart < start) + utime_t fromstart = g_clock.now(); + if (fromstart < start) { + cerr << "logger time jumped backwards from " << start << " to " << fromstart << endl; start = fromstart; + } fromstart -= start; while (force || diff --git a/ceph/fakesyn.cc b/ceph/fakesyn.cc index a647cc340397f..c53ccaa5da50d 100644 --- a/ceph/fakesyn.cc +++ b/ceph/fakesyn.cc @@ -57,6 +57,8 @@ int main(int argc, char **argv) assert(nargs.empty()); + g_clock.tare(); + MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); diff --git a/ceph/newsyn.cc b/ceph/newsyn.cc index 33568b2f85369..4912860952431 100644 --- a/ceph/newsyn.cc +++ b/ceph/newsyn.cc @@ -29,7 +29,49 @@ public: }; -#include "msg/new_mpistarter.cc" +/* + * start up NewMessenger via MPI. + */ +#include + +pair mpi_bootstrap_new(int& argc, char**& argv) +{ + MPI_Init(&argc, &argv); + + int mpi_world; + int mpi_rank; + MPI_Comm_size(MPI_COMM_WORLD, &mpi_world); + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); + + tcpaddr_t nsaddr; + memset(&nsaddr, 0, sizeof(nsaddr)); + + if (mpi_rank == 0) { + // i am root. + dout(-10) << "I am root" << endl; + rank.my_rank = 0; + rank.start_rank(nsaddr); + nsaddr = rank.get_listen_addr(); + } + + int r = MPI_Bcast(&nsaddr, sizeof(nsaddr), MPI_CHAR, + 0, MPI_COMM_WORLD); + + dout(-30) << "r = " << r << " ns tcpaddr is " << nsaddr << endl; + + if (mpi_rank != 0) { + rank.start_rank(nsaddr); + } + + MPI_Barrier(MPI_COMM_WORLD); + + dout(-10) << "tare" << endl; + g_clock.tare(); + + MPI_Finalize(); + + return pair(mpi_rank, mpi_world); +} utime_t tick_start; int tick_count = 0; diff --git a/ceph/osd/PG.cc b/ceph/osd/PG.cc index 1543df30b21c5..d4cbeedcfcb7e 100644 --- a/ceph/osd/PG.cc +++ b/ceph/osd/PG.cc @@ -24,7 +24,7 @@ #include "messages/MOSDPGRemove.h" #undef dout -#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_osd) cout << "osd" << osd->whoami << " " << (osd->osdmap ? osd->osdmap->get_epoch():0) << " " << *this << " " +#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_osd) cout << g_clock.now() << " osd" << osd->whoami << " " << (osd->osdmap ? osd->osdmap->get_epoch():0) << " " << *this << " " /******* PGLog ********/ -- 2.39.5