pwr_tDeltaTime * time_Uptime ( pwr_tStatus *status, pwr_tDeltaTime *tp, pwr_tDeltaTime *ap ) { pwr_tDeltaTime time; long tics; struct tms buff; static int tics_per_sec = 0; static pwr_tTime boot_time = {0,0}; static pwr_tDeltaTime max_diff = {0,20000000}; pwr_tDeltaTime uptime_tics; pwr_tTime current_time; pwr_tDeltaTime diff; pwr_dStatus(sts, status, TIME__SUCCESS); if ( !tics_per_sec) tics_per_sec = sysconf(_SC_CLK_TCK); if (tp == NULL) tp = &time; tics = times(&buff); uptime_tics.tv_sec = tics / tics_per_sec; uptime_tics.tv_nsec = (tics % tics_per_sec) * (1000000000 / tics_per_sec); // pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0); clock_gettime( CLOCK_REALTIME, ¤t_time); if ( !boot_time.tv_sec) { time_Asub( &boot_time, ¤t_time, &uptime_tics); *tp = uptime_tics; } else { time_Adiff( tp, ¤t_time, &boot_time); time_Dsub( &diff, tp, &uptime_tics); time_Dabs(NULL, &diff); if ( time_Dcomp(&diff, &max_diff) > 0) { time_Asub( &boot_time, ¤t_time, &uptime_tics); *tp = uptime_tics; *status = TIME__CLKCHANGE; } } if (ap != NULL) return time_Dadd(tp, tp, ap); else return tp; }
static int tlog_checktime( pwr_tDeltaTime *time_new, pwr_tDeltaTime *time_old, float maxdiff) { pwr_tDeltaTime tim_maxdiff; pwr_tDeltaTime tim_limlow; pwr_tDeltaTime tim_limhigh; int sts; time_FloatToD( &tim_maxdiff, maxdiff); time_Dadd( &tim_limhigh, time_new, &tim_maxdiff); time_Dsub( &tim_limlow, time_new, &tim_maxdiff); if ( time_Dcomp( time_old, &tim_limlow) == -1) return TLOG__TIME_LT; if ( time_Dcomp( time_old, &tim_limhigh) == 1) return TLOG__TIME_GT; return TLOG__TIME_EQ; /************* tim_maxdiff.high = -1; tim_maxdiff.low = -maxdiff * 10000000; if ( maxdiff == 0) tim_maxdiff.low = -1; sts = lib$add_times( time_new, &tim_maxdiff, &tim_limhigh); sts = lib$sub_times( time_new, &tim_maxdiff, &tim_limlow); if ( sts == LIB$_NEGTIM) { tim_limlow.high = -1; tim_limlow.low = -1; } sts = lib$sub_times( time_old, &tim_limlow, &testtime); if ( sts == LIB$_NEGTIM) return TLOG__TIME_LT; sts = lib$sub_times( &tim_limhigh, time_old, &testtime); if ( sts == LIB$_NEGTIM) return TLOG__TIME_GT; return TLOG__TIME_EQ; ************/ }
pwr_tDeltaTime * time_Uptime ( pwr_tStatus *status, pwr_tDeltaTime *tp, pwr_tDeltaTime *ap ) { pwr_tDeltaTime time; unsigned long tics; static pwr_tUInt64 tics_64; struct tms buff; static int tics_per_sec = 0; static pwr_tTime boot_time = {0,0}; static pwr_tDeltaTime max_diff = {0, 20000000}; pwr_tDeltaTime uptime_tics; pwr_tTime current_time; pwr_tDeltaTime diff; static pwr_tUInt16 msb_flips = 0; static pwr_tBoolean old_high_bit = 0; pwr_tBoolean high_bit; lldiv_t uptime_s; pwr_dStatus(sts, status, TIME__SUCCESS); if ( !tics_per_sec) tics_per_sec = sysconf(_SC_CLK_TCK); if (tp == NULL) tp = &time; tics = times(&buff); high_bit = tics >> (32 - 1); if (!high_bit && old_high_bit) msb_flips++; old_high_bit = high_bit; tics_64 = ((pwr_tUInt64) msb_flips << 32) | tics; uptime_s = lldiv(tics_64, (pwr_tInt64) tics_per_sec); uptime_tics.tv_sec = (pwr_tInt64) uptime_s.quot; uptime_tics.tv_nsec = ((pwr_tUInt64) uptime_s.rem) * (1000000000 / tics_per_sec); // pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0); time_GetTime( ¤t_time); if ( !boot_time.tv_sec) { time_Asub( &boot_time, ¤t_time, &uptime_tics); *tp = uptime_tics; } else { time_Adiff( tp, ¤t_time, &boot_time); time_Dsub( &diff, tp, &uptime_tics); time_Dabs(NULL, &diff); if ( time_Dcomp(&diff, &max_diff) > 0) { time_Asub( &boot_time, ¤t_time, &uptime_tics); *tp = uptime_tics; if (status != NULL) { *status = TIME__CLKCHANGE; } } } if (ap != NULL) return time_Dadd(tp, tp, ap); else return tp; }
static pwr_tStatus restart ( ini_sContext *cp ) { pwr_tStatus sts; char time[24]; lst_sEntry *pl; ini_sProc *pp; ini_CheckContext(&sts, cp); ini_ReadBootFile(&sts, cp); ini_CheckNode(&sts, cp); checkErrors(cp); if (cp->flags.b.verbose) logCardinality(cp); qcom_SignalAnd(&sts, &qcom_cQini, 0); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_swapInit); ini_ReloadNode(&sts, cp); if (cp->flags.b.verbose) logChanges(cp); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_rebuildInit); ini_RebuildNode(&sts, cp); ini_DecodeBodies(&sts, cp, 0); ini_DecodeBodies(&sts, cp, 1); if (cp->flags.b.verbose) errh_LogInfo(&cp->log, "Update bodies of io objects"); ini_UpdateBodies(&sts, cp, 1); io_init_signals(); ini_ProcTable(&sts, cp); // ini_ProcLoad(&sts, cp, cp->plc); // ini_ProcStart(&sts, cp, cp->plc); ini_ProcIter(&sts, cp, proc_mProcess_user, ini_mProc_plc, ini_ProcLoad); ini_ProcIter(&sts, cp, proc_mProcess_user, ini_mProc_plc, ini_ProcStart); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInit); qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_newPlcInitDone | cp->plc_sigmask, qcom_cTmoEternal); errh_LogInfo(&cp->log, "Entering time critical period, stopping old PLC"); qcom_SignalAnd(&sts, &qcom_cQini, ~cp->plc_sigmask); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStop); qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_oldPlcStopDone | cp->plc_sigmask, qcom_cTmoEternal); qcom_SignalAnd(&sts, &qcom_cQini, ~ini_mEvent_oldPlcStop); ini_UpdateBodies(&sts, cp, 0); qcom_SignalAnd(&sts, &qcom_cQini, ~cp->plc_sigmask); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcStart); qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal); errh_LogInfo(&cp->log, "Time critical period over, new PLC is running"); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_swapDone); for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) { if ( pp->flags.m & ini_mProc_plc && pp->objectp) { pwr_sClass_PlcProcess *plc = pp->objectp; time_GetTime(&plc->LastChgTime); if ( time_Dcomp(&plc->StartTime, &plc->StopTime) == 1) time_Dsub(&plc->StallTime, &plc->StartTime, &plc->StopTime); else plc->StallTime = pwr_cNDeltaTime; time_DtoAscii(&plc->StallTime, 1, time, sizeof(time)); cp->np->RestartStallTime = plc->StallTime; } } cp->log.put.type.s = 2; errh_LogInfo(&cp->log, "IO stall time: %s", time); ini_FreeBodies(&sts, cp, 0); ini_FreeBodies(&sts, cp, 1); return sts; }
void pwrb_PlcThread_Exec ( plc_sThread *tp ) { pwr_tDeltaTime last; int meanCount; pwr_sClass_PlcThread *o = tp->PlcThread; if (o == NULL) return; o->ActualScanTime = tp->ActualScanTime; meanCount = o->ScanTimeMeanCount; if ((meanCount != 0) && (o->Count % meanCount == 0)) { if (o->Count != 0) { double diff; time_Dsub(&last, (pwr_tDeltaTime *) &tp->before_scan_abs, (pwr_tDeltaTime *)&o->ScanTimeStart); diff = last.tv_sec + last.tv_nsec * cNanoSec; o->ScanTimeMean = diff / meanCount; } o->ScanTimeStart.tv_sec = tp->before_scan_abs.tv_sec; o->ScanTimeStart.tv_nsec = tp->before_scan_abs.tv_nsec; } o->Count++; if (o->Count != 1) { double scanTime; time_Dsub(&last, (pwr_tDeltaTime *)&tp->before_scan_abs, (pwr_tDeltaTime *)&tp->one_before_scan_abs); scanTime = last.tv_nsec * cNanoSec + last.tv_sec; if (scanTime < o->ScanTimeMin) o->ScanTimeMin = scanTime; if (scanTime > o->ScanTimeMax) o->ScanTimeMax = scanTime; } time_Dsub(&last, (pwr_tDeltaTime *)&tp->after_scan_abs, (pwr_tDeltaTime *)&tp->before_scan_abs); o->Last = last.tv_nsec * cNanoSec + last.tv_sec; if (o->Last < o->Min) o->Min = o->Last; if (o->Last > o->Max) o->Max = o->Last; o->Sum += o->Last; o->Mean = o->Sum / o->Count; o->Coverage = 0.99 * o->Coverage + 0.01 * (o->Last / o->ScanTime) * 100.0; if (o->Last < o->Limit_1_8) o->Count_1_8++; else if (o->Last < o->Limit_1_4) o->Count_1_4++; else if (o->Last < o->Limit_1_2) o->Count_1_2++; else if (o->Last < o->Limit_1_1) o->Count_1_1++; else if (o->Last < o->Limit_2_1) o->Count_2_1++; else if (o->Last < o->Limit_4_1) o->Count_4_1++; else if (o->Last < o->Limit_8_1) o->Count_8_1++; else o->CountHigh++; o->SlipCount = tp->sliped; }