Beispiel #1
0
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;
************/
}
Beispiel #2
0
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, &current_time);
  if ( !boot_time.tv_sec) {
    time_Asub( &boot_time, &current_time, &uptime_tics);
    *tp = uptime_tics;
  }
  else {
    time_Adiff( tp, &current_time, &boot_time);
    time_Dsub( &diff, tp, &uptime_tics);
    time_Dabs(NULL, &diff);
    if ( time_Dcomp(&diff, &max_diff) > 0) {
      time_Asub( &boot_time, &current_time, &uptime_tics);
      *tp = uptime_tics;
      *status = TIME__CLKCHANGE;
    }
  }

  if (ap != NULL)
    return time_Dadd(tp, tp, ap);
  else
    return tp;
}
int XttVideoMgmAimetis::check_session()
{
  pwr_tTime current;
  pwr_tDeltaTime timeout = {300,0};
  pwr_tDeltaTime dt;
  int sts = 1;

  // Check that current session hasn't timed out
  time_GetTime( &current);
  time_Adiff_NE( &dt, &current, &m_last_auth); 
  if ( time_Dcomp( &dt, &timeout) == 1)
    sts = authorize( m_op->User, m_op->Password);

  return sts;
}
Beispiel #4
0
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( &current_time);
  if ( !boot_time.tv_sec) {
    time_Asub( &boot_time, &current_time, &uptime_tics);
    *tp = uptime_tics;
  }
  else {
    time_Adiff( tp, &current_time, &boot_time);
    time_Dsub( &diff, tp, &uptime_tics);
    time_Dabs(NULL, &diff);
    if ( time_Dcomp(&diff, &max_diff) > 0) {
      time_Asub( &boot_time, &current_time, &uptime_tics);
      *tp = uptime_tics;
      if (status != NULL) {
        *status = TIME__CLKCHANGE;
      }
    }
  }

  if (ap != NULL)
    return time_Dadd(tp, tp, ap);
  else
    return tp;
}
Beispiel #5
0
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;
}
Beispiel #6
0
int csup_Exec(pwr_tStatus* status, lst_sEntry* lh, pwr_tDeltaTime* next_start,
    pwr_tDeltaTime* stop, pwr_tTime* now)
{
  int action = 0;
  csup_sObject* cp;
  pwr_tDeltaTime nextLimit;

  pwr_dStatus(sts, status, CSUP__SUCCESS);

  if (lh == NULL || next_start == NULL || now == NULL || stop == NULL)
    pwr_Return(NO, sts, CSUP__NULPOINT);

  while ((cp = lst_Succ(NULL, lh, &lh)) != NULL) {
    pwr_sClass_CycleSup* o = cp->o;

    if (cp->is_owner) {
      if (time_Dcomp(&o->NextLimit, NULL) > 0) {
        if (time_Dcomp(stop, &o->NextLimit) > 0) {
          if (!o->Delayed) {
            o->DelayedTime = *now;
            o->Delayed = TRUE;
            o->Timely = FALSE;
          }
          o->DelayCount++;
          o->LastDelay = *now;
          action = MAX(action, o->DelayAction);
        } else if (!o->Timely) {
          o->Timely = TRUE;
          o->TimelyTime = *now;
        }
      }
      if ((o->DelayLimit.tv_sec & 1 << 31)
          != (o->DelayLimit.tv_nsec & 1 << 31)) {
        // printf("DelayLimit.tv_sec: %d, DelayLimit.tv_nsec: %d\n",
        // o->DelayLimit.tv_sec, o->DelayLimit.tv_nsec);
        errh_Info("DelayLimit.tv_sec: %d, DelayLimit.tv_nsec: %d",
            o->DelayLimit.tv_sec, o->DelayLimit.tv_nsec);
      }
      if ((next_start->tv_sec & 1 << 31) != (next_start->tv_nsec & 1 << 31)) {
        // printf("next_start->tv_sec: %d, next_start->tv_nsec: %d\n",
        // next_start->tv_sec, next_start->tv_nsec);
        errh_Info("next_start->tv_sec: %d, next_start->tv_nsec: %d",
            next_start->tv_sec, next_start->tv_nsec);
      }
      time_Dadd(&nextLimit, next_start, &o->DelayLimit);

      /* If we update the tv_nsec field first it is
         possible that emon will detect a slip even if it is not. */

      o->NextLimit.tv_sec = nextLimit.tv_sec;
      o->NextLimit.tv_nsec = nextLimit.tv_nsec;

      o->CycleCount++;
    } else {
      /* Not owner, check stall delay */
      if (o->DelayAction == 2) {
        nextLimit.tv_nsec = o->NextLimit.tv_nsec;
        nextLimit.tv_sec = o->NextLimit.tv_sec;
        if (time_Dcomp(&nextLimit, NULL) > 0
            && time_Dcomp(stop, &nextLimit) > 0) {
          o->DelayCount++;
          o->LastDelay = *now;
          action = MAX(action, o->DelayAction);
        }
      }
    }
  }

  return action;
}
Beispiel #7
0
void
pwrs_Node_Exec (
)
{
  int i;
  pwr_tTime current_time;
  pwr_tDeltaTime diff;
  errh_eSeverity severity;
  errh_eSeverity system_severity;
  errh_eSeverity plc_severity;
  int new_idx = -1;
  static int supervise[80] = {
    0,0,0,0,1,1,1,0,1,1,
    1,1,1,0,0,1,0,1,1,1,
    1,1,1,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1};
  static int reboot_done = 0;

  if ( !np) {
    pwr_tOid oid;
    pwr_tStatus sts;

    sts = gdh_GetNodeObject( 0, &oid);
    if ( ODD(sts))
      gdh_ObjidToPointer( oid, (void **) &np);
    if ( EVEN(sts)) return;
  }

  if ( !np)
    return;

  if ( np->EmergBreakTrue) {
    switch ( np->EmergBreakSelect) {
    case 1: {
      /* Reboot */
      int sts;

      if ( !reboot_done) {
	errh_Fatal( "Emergency break action: reboot");
	sts = system("rt_prio --reboot");
	if ( sts != 0) 
	  errh_Fatal("Unable to reboot, sts %d", sts);
	reboot_done = 1;
      }
      break;
    }
    default: ;
    }
  }
  else
    reboot_done = 0;

  /* Calculate plc status */
  new_idx = -1;
  plc_severity = errh_Severity( np->ProcStatus[errh_eAnix_plc-1]);
  for ( i = errh_eAnix_plc1 - 1; i < errh_eAnix_plc1 - 1 + errh_cAnix_PlcSize; i++) {
    severity = errh_Severity( np->ProcStatus[i]);
    if ( np->ProcStatus[i] != 0 && EVEN(np->ProcStatus[i])) {
      if ( severity >= plc_severity) {
	new_idx = i;
        plc_severity = severity;
      }
    }
  }
  if ( new_idx != -1)
    np->ProcStatus[errh_eAnix_plc-1] = np->ProcStatus[new_idx];
  else if ( EVEN(np->ProcStatus[errh_eAnix_plc-1]))
    np->ProcStatus[errh_eAnix_plc-1] = PWR__SRUN;

  /* Calculate system status and check timestamp */
  new_idx = -1;
  system_severity = errh_Severity( np->SystemStatus);
  time_GetTime( &current_time);
  for ( i = 0; i < sizeof(np->ProcStatus)/sizeof(np->ProcStatus[0]); i++) {
    if ( np->ProcStatus[i] != 0 && supervise[i]) {
      time_Adiff( &diff, &np->ProcTimeStamp[i], &current_time);

      if ( time_Dcomp( &diff, 0) < 0) {
	if ( errh_Severity( np->ProcStatus[i]) < errh_Severity(PWR__PTIMEOUT))
	  np->ProcStatus[i] = PWR__PTIMEOUT;
      }
      else if ( np->ProcStatus[i] == PWR__PTIMEOUT) {
	np->ProcStatus[i] = (i < errh_cAnix_SrvSize) ? PWR__SRUN : PWR__ARUN;
      }
    }

    severity = errh_Severity( np->ProcStatus[i]);
    if ( np->ProcStatus[i] != 0 && EVEN(np->ProcStatus[i])) {
      if ( severity >= system_severity) {
	new_idx = i;
	system_severity = severity;
      }
    }

  }
  if ( new_idx != -1)
    np->SystemStatus = np->ProcStatus[new_idx];
  else if ( EVEN(np->SystemStatus))
    np->SystemStatus = PWR__RUNNING;
}