osaf/services/saf/immsv/immnd/immnd_cb.h   |   4 +-
 osaf/services/saf/immsv/immnd/immnd_evt.c  |   9 +---
 osaf/services/saf/immsv/immnd/immnd_main.c |  25 ++++++-------
 osaf/services/saf/immsv/immnd/immnd_proc.c |  55 ++++++++++++++---------------
 4 files changed, 44 insertions(+), 49 deletions(-)


This patch just simply gets rid of time_t and uses timespec instead.

For now we don't have the advantages of timespec yet.
The interval for immnd_process_evt is still one second,
so we can't check for timeout at high frequency.

That can be improved in another ticket.

diff --git a/osaf/services/saf/immsv/immnd/immnd_cb.h 
b/osaf/services/saf/immsv/immnd/immnd_cb.h
--- a/osaf/services/saf/immsv/immnd/immnd_cb.h
+++ b/osaf/services/saf/immsv/immnd/immnd_cb.h
@@ -153,13 +153,13 @@ typedef struct immnd_cb_tag {
        int32_t pbePid2;  //Redundant PBE (2PBE) is running if pbePid2 > 0
        IMMND_SERVER_STATE mState;
        uint32_t mStep;         //Measures progress in immnd_proc_server
-       time_t mJobStart;       //Start time for major server tasks like start, 
load, sync.
+       struct timespec mJobStart;       //Start time for major server tasks 
like start, load, sync.
        char *mProgName;        //The full path name of the immnd executable.
        const char *mDir;       //The directory where imm.xml & pbe files reside
        const char *mFile;      //The imm.xml file to start from
        const char *mPbeFile;   //Pbe feature is configured (IMMSV_PBE_FILE).
        SaImmRepositoryInitModeT mRim; 
-       uint32_t mCleanedHouseAt; //When cleanTheHouse was executed 
(immnd_proc.c)
+       struct timespec mCleanedHouseAt; //When cleanTheHouse was executed 
(immnd_proc.c)
 
        uint8_t mExpectedNodes;
        uint8_t mWaitSecs;
diff --git a/osaf/services/saf/immsv/immnd/immnd_evt.c 
b/osaf/services/saf/immsv/immnd/immnd_evt.c
--- a/osaf/services/saf/immsv/immnd/immnd_evt.c
+++ b/osaf/services/saf/immsv/immnd/immnd_evt.c
@@ -8569,8 +8569,7 @@ uint32_t immnd_evt_proc_abort_sync(IMMND
                        cb->mState = IMM_SERVER_LOADING_PENDING;
                        LOG_WA("SERVER STATE: IMM_SERVER_SYNC_CLIENT --> 
IMM_SERVER_LOADING_PENDING (sync aborted)");
                        cb->mStep = 0;
-                       osaf_clock_gettime_sec(CLOCK_MONOTONIC, &cb->mJobStart);
-                       osafassert(cb->mJobStart >= ((time_t) 0));
+                       osaf_clock_gettime(CLOCK_MONOTONIC, &cb->mJobStart);
                        cb->mMyEpoch = 0;
                        cb->mSync = false;
                        osafassert(!(cb->mAccepted));
@@ -8704,8 +8703,7 @@ static uint32_t immnd_evt_proc_start_syn
                immModel_setScAbsenceAllowed(cb);
        } else if ((cb->mState == IMM_SERVER_SYNC_CLIENT) && 
(immnd_syncComplete(cb, SA_FALSE, cb->mStep))) {
                cb->mStep = 0;
-               osaf_clock_gettime_sec(CLOCK_MONOTONIC, &cb->mJobStart);
-               osafassert(cb->mJobStart >= ((time_t) 0));
+               osaf_clock_gettime(CLOCK_MONOTONIC, &cb->mJobStart);
                cb->mState = IMM_SERVER_READY;
                immnd_ackToNid(NCSCC_RC_SUCCESS);
                LOG_NO("SERVER STATE: IMM_SERVER_SYNC_CLIENT --> IMM SERVER 
READY (materialized by start sync)");
@@ -8838,8 +8836,7 @@ static uint32_t immnd_evt_proc_loading_o
                        LOG_NO("SERVER STATE: IMM_SERVER_LOADING_PENDING --> 
IMM_SERVER_LOADING_CLIENT (materialized by proc_loading_ok)");
                        cb->mState = IMM_SERVER_LOADING_CLIENT;
                        cb->mStep = 0;
-                       osaf_clock_gettime_sec(CLOCK_MONOTONIC, &cb->mJobStart);
-                       osafassert(cb->mJobStart >= ((time_t) 0));
+                       osaf_clock_gettime(CLOCK_MONOTONIC, &cb->mJobStart);
                        cb->mAccepted = true;
                        if(cb->mCanBeCoord) {cb->mIsOtherScUp = true;}
                }
diff --git a/osaf/services/saf/immsv/immnd/immnd_main.c 
b/osaf/services/saf/immsv/immnd/immnd_main.c
--- a/osaf/services/saf/immsv/immnd/immnd_main.c
+++ b/osaf/services/saf/immsv/immnd/immnd_main.c
@@ -255,7 +255,7 @@ int main(int argc, char *argv[])
        int eventCount = 0;     /* Used to regulate progress of background 
                                   server task when we are very bussy. */
        int maxEvt = 100;
-       int64_t start_time = 0LL;
+       struct timespec start_time;
        struct pollfd fds[3];
        int term_fd;
 
@@ -293,20 +293,19 @@ int main(int argc, char *argv[])
                /* Watch out for performance bug. Possibly change from 
event-count
                   to recalculated timer. */
                /* ABT 13/07 2009 actually using both event-count and 
recalculated timer now. */
-               uint32_t passed_time = (uint32_t) start_time ? 
(m_NCS_GET_TIME_MS - start_time) : 0;
+
+               /* calculate new elapsed time */
+               struct timespec now;
+               osaf_clock_gettime(CLOCK_MONOTONIC, &now);
+               struct timespec passed_time;
+               osaf_timespec_subtract(&now, &start_time, &passed_time);
+               uint64_t passed_time_ms = osaf_timespec_to_millis(&passed_time);
+
 
                maxEvt = (timeout == 100) ? 50 : 100;
 
-               /*
-                  TRACE("timeout:%u adjustedTimeout:%u", timeout, 
-                  (passed_time<timeout) ? (timeout - passed_time) : 0);
-                */
-
                /* Wait for events */
-               if (!start_time) {
-                       start_time = m_NCS_GET_TIME_MS;
-               }
-               int ret = poll(fds, 3, (passed_time < timeout) ? (timeout - 
passed_time) : 0);
+               int ret = poll(fds, 3, (passed_time_ms < timeout) ? (timeout - 
passed_time_ms) : 0);
 
                if (ret == -1) {
                        if (errno == EINTR)
@@ -366,7 +365,7 @@ int main(int argc, char *argv[])
                                        break;
                                }
                                eventCount = 0;
-                               start_time = 0LL;
+                               osaf_clock_gettime(CLOCK_MONOTONIC, 
&start_time);
                        }
                } else {
                        /* Timeout */
@@ -377,7 +376,7 @@ int main(int argc, char *argv[])
                                break;
                        }
                        eventCount = 0;
-                       start_time = 0LL;
+                       osaf_clock_gettime(CLOCK_MONOTONIC, &start_time);
                }
        }
 
diff --git a/osaf/services/saf/immsv/immnd/immnd_proc.c 
b/osaf/services/saf/immsv/immnd/immnd_proc.c
--- a/osaf/services/saf/immsv/immnd/immnd_proc.c
+++ b/osaf/services/saf/immsv/immnd/immnd_proc.c
@@ -607,8 +607,7 @@ void immnd_announceDump(IMMND_CB *cb)
                /* Reset jobStart timer to delay potential start of sync.
                   Reduces risk of epoch race with dump.
                 */
-               osaf_clock_gettime_sec(CLOCK_MONOTONIC, &cb->mJobStart);
-               osafassert(cb->mJobStart >= ((time_t) 0));
+               osaf_clock_gettime(CLOCK_MONOTONIC, &cb->mJobStart);
        }
 }
 
@@ -1663,12 +1662,12 @@ uint32_t immnd_proc_server(uint32_t *tim
        uint32_t rc = NCSCC_RC_SUCCESS;
        int32_t coord, newEpoch;
        int32_t printFrq = (*timeout > 100) ? 5 : 50;
-       time_t now;
-       osaf_clock_gettime_sec(CLOCK_MONOTONIC, &now);
-       osafassert(now >= ((time_t) 0));
-       uint32_t jobDuration = (uint32_t) now - cb->mJobStart;
+       struct timespec now;
+       osaf_clock_gettime(CLOCK_MONOTONIC, &now);
+       struct timespec jobDurationTs;
+       osaf_timespec_subtract(&now, &cb->mJobStart, &jobDurationTs);
+       SaUint32T jobDurationSec = (SaUint32T) jobDurationTs.tv_sec;
        SaBoolT pbeImmndDeadlock=SA_FALSE;
-       if(!jobDuration) {++jobDuration;} /* Avoid jobDuraton of zero */
        /*TRACE_ENTER(); */
 
        if ((cb->mStep % printFrq) == 0) {
@@ -1707,17 +1706,17 @@ uint32_t immnd_proc_server(uint32_t *tim
                if (coord != (-1)) {    /* (-1) Not ready; (1) coord; (0) 
non-coord */
                        if (coord) {
                                if ((cb->mNumNodes >= cb->mExpectedNodes) || 
-                                       (jobDuration >= cb->mWaitSecs)) {
-                                       TRACE_5("Nodes %u >= %u || Secs %u >= 
%u", cb->mNumNodes,
-                                               cb->mExpectedNodes, 
jobDuration, cb->mWaitSecs);
+                                       (jobDurationSec >= cb->mWaitSecs)) {
+                                       TRACE_5("Nodes %u >= %u || Secs %f >= 
%u", cb->mNumNodes,
+                                               cb->mExpectedNodes, 
osaf_timespec_to_double(&jobDurationTs), cb->mWaitSecs);
                                        cb->mState = IMM_SERVER_LOADING_PENDING;
                                        LOG_NO("SERVER STATE: 
IMM_SERVER_CLUSTER_WAITING -->"
                                               " IMM_SERVER_LOADING_PENDING");
                                        cb->mStep = 0;
                                        cb->mJobStart = now;
                                } else {
-                                       TRACE_5("Nodes %u < %u && %u < %u", 
cb->mNumNodes,
-                                               cb->mExpectedNodes, 
jobDuration, cb->mWaitSecs);
+                                       TRACE_5("Nodes %u < %u && %f < %u", 
cb->mNumNodes,
+                                               cb->mExpectedNodes, 
osaf_timespec_to_double(&jobDurationTs), cb->mWaitSecs);
                                }
                        } else {
                                /*Non coordinator goes directly to loading 
pending */
@@ -1731,8 +1730,8 @@ uint32_t immnd_proc_server(uint32_t *tim
                                if((cb->m2Pbe == 2) && !(cb->preLoadPid)) {
                                        cb->preLoadPid = immnd_forkLoader(cb, 
true);
                                }
-                       } else if (!(jobDuration%5)) { /* Every 5 seconds */
-                               LOG_WA("Resending introduce-me - problems with 
MDS ? %u", jobDuration);
+                       } else if (!(jobDurationSec%5)) { /* Every 5 seconds */
+                               LOG_WA("Resending introduce-me - problems with 
MDS ? %f", osaf_timespec_to_double(&jobDurationTs));
                                immnd_introduceMe(cb);
                        }
 
@@ -1751,8 +1750,8 @@ uint32_t immnd_proc_server(uint32_t *tim
                        }
                }
 
-               if (jobDuration > 50 && jobDuration > cb->mWaitSecs) {  /* No 
progress in 50 secs */
-                       LOG_ER("Failed to load/sync. Giving up after %u 
seconds, restarting..", jobDuration);
+               if (jobDurationSec > 50 && jobDurationSec > cb->mWaitSecs) {    
/* No progress in 50 secs */
+                       LOG_ER("Failed to load/sync. Giving up after %f 
seconds, restarting..", osaf_timespec_to_double(&jobDurationTs));
                        rc = NCSCC_RC_FAILURE;  /*terminate. */
                        immnd_ackToNid(rc);
                }
@@ -1786,7 +1785,7 @@ uint32_t immnd_proc_server(uint32_t *tim
                                   Epoch == -1 means still waiting for coord. 
                                   Be patient, give the coord 30 seconds to 
come up. */
 
-                               if (newEpoch == (-2) || (jobDuration > 30)) {
+                               if (newEpoch == (-2) || (jobDurationSec >= 30)) 
{
                                        /*Request to be synched instead. */
                                        LOG_IN("REQUESTING SYNC");
                                        if (immnd_requestSync(cb)) {
@@ -1838,7 +1837,7 @@ uint32_t immnd_proc_server(uint32_t *tim
                        }
 
                        if (!(cb->mStep % 200)) {
-                               LOG_IN("This node still waiting to be sync'ed 
after %u seconds", jobDuration);
+                               LOG_IN("This node still waiting to be sync'ed 
after %f seconds", osaf_timespec_to_double(&jobDurationTs));
                        }
                }
                break;
@@ -1848,7 +1847,7 @@ uint32_t immnd_proc_server(uint32_t *tim
                if (cb->mMyEpoch > cb->mRulingEpoch) {
                        TRACE_5("Wait for permission to start loading "
                                "My epoch:%u Ruling epoch:%u", cb->mMyEpoch, 
cb->mRulingEpoch);
-                       if (jobDuration > 15) {
+                       if (jobDurationSec >= 15) {
                                LOG_WA("MDS problem-2, giving up");
                                rc = NCSCC_RC_FAILURE;  /*terminate. */
                                immnd_ackToNid(rc);
@@ -1905,7 +1904,7 @@ uint32_t immnd_proc_server(uint32_t *tim
 
        case IMM_SERVER_LOADING_CLIENT:
                TRACE_5("IMM_SERVER_LOADING_CLIENT");
-               if (jobDuration > (cb->mWaitSecs ? (cb->mWaitSecs + 300) : 
300)) {
+               if (jobDurationSec >= (cb->mWaitSecs ? (cb->mWaitSecs + 300) : 
300)) {
                        LOG_WA("Loading client timed out, waiting to be loaded 
- terminating");
                        cb->mStep = 0;
                        cb->mJobStart = now;
@@ -1960,7 +1959,7 @@ uint32_t immnd_proc_server(uint32_t *tim
                break;
 
        case IMM_SERVER_SYNC_SERVER:
-               if (!immnd_ccbsTerminated(cb, jobDuration, &pbeImmndDeadlock)) {
+               if (!immnd_ccbsTerminated(cb, jobDurationSec, 
&pbeImmndDeadlock)) {
                        /*Phase 1 */
                        if(pbeImmndDeadlock) {
                                LOG_WA("Apparent deadlock detected between 
IMMND sync and restarting PBE, "
@@ -1977,11 +1976,11 @@ uint32_t immnd_proc_server(uint32_t *tim
                        }
                        if (!(cb->mStep % 60)) {
                                LOG_IN("Sync Phase-1, waiting for existing "
-                                      "Ccbs to terminate, seconds waited: %u", 
jobDuration);
+                                      "Ccbs to terminate, seconds waited: %f", 
osaf_timespec_to_double(&jobDurationTs));
                        }
-                       if (jobDuration > 20) {
+                       if (jobDurationSec >= 20) {
                                LOG_NO("Still waiting for existing Ccbs to 
terminate "
-                                      "after %u seconds. Aborting this sync 
attempt", jobDuration);
+                                      "after %f seconds. Aborting this sync 
attempt", osaf_timespec_to_double(&jobDurationTs));
                                immnd_abortSync(cb);
                                if(cb->syncPid > 0) {
                                        LOG_WA("STOPPING sync process pid %u", 
cb->syncPid);
@@ -2038,7 +2037,7 @@ uint32_t immnd_proc_server(uint32_t *tim
                                if (!(cb->mStep % 60)) {
                                        LOG_IN("Sync Phase-3: step:%u", 
cb->mStep);
                                }
-                               if (immnd_syncComplete(cb, true, jobDuration)) {
+                               if (immnd_syncComplete(cb, true, 
jobDurationSec)) {
                                        cb->mStep = 0;
                                        cb->mJobStart = now;
                                        cb->mState = IMM_SERVER_READY;
@@ -2145,9 +2144,9 @@ uint32_t immnd_proc_server(uint32_t *tim
                        }
                }
 
-               if((cb->mStep == 0) || (cb->mCleanedHouseAt != jobDuration) || 
cb->mForceClean) {
+               if((cb->mStep == 0) || 
(osaf_timespec_compare(&cb->mCleanedHouseAt, &jobDurationTs)) || 
cb->mForceClean) {
                        immnd_cleanTheHouse(cb, coord == 1);
-                       cb->mCleanedHouseAt = jobDuration;
+                       cb->mCleanedHouseAt = jobDurationTs;
                        if(cb->mForceClean) {
                                LOG_IN("ABT Cleaned the house: cb->mForceClean 
reset to false;");
                                cb->mForceClean = false;
@@ -2161,7 +2160,7 @@ uint32_t immnd_proc_server(uint32_t *tim
                                  to coordinator crash. Abort the sync. */
                                LOG_WA("ABORTING UNCOMPLETED SYNC - COORDINATOR 
MUST HAVE CRASHED");
                                immnd_abortSync(cb);
-                       } else if (jobDuration > 3) {
+                       } else if (jobDurationSec >= 3) {
                                newEpoch = immnd_syncNeeded(cb);
                                if (newEpoch) {
                                        if (cb->syncPid > 0) {

------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to