Exemplo n.º 1
0
/**
 *  POSIX 1003.1b 4.5.2 - Get Process Times
 */
clock_t _times(
   struct tms  *ptms
)
{
  uint32_t   tick_interval;
  sbintime_t uptime;
  sbintime_t cpu_time_used;

  if ( !ptms )
    rtems_set_errno_and_return_minus_one( EFAULT );

  tick_interval = (uint32_t)
    (SBT_1US * rtems_configuration_get_microseconds_per_tick());

  ptms = memset( ptms, 0, sizeof( *ptms ) );

  _TOD_Get_zero_based_uptime( &uptime );
  ptms->tms_stime = ((clock_t) uptime) / tick_interval;

  /*
   *  RTEMS technically has no notion of system versus user time
   *  since there is no separation of OS from application tasks.
   *  But we can at least make a distinction between the number
   *  of ticks since boot and the number of ticks executed by this
   *  this thread.
   */
  _Thread_Get_CPU_time_used( _Thread_Get_executing(), &cpu_time_used );
  ptms->tms_utime = ((clock_t) cpu_time_used) / tick_interval;

  return ptms->tms_stime;
}
Exemplo n.º 2
0
void _Rate_monotonic_Restart(
  Rate_monotonic_Control *the_period,
  Thread_Control         *owner,
  ISR_lock_Context       *lock_context
)
{
  /*
   *  Set the starting point and the CPU time used for the statistics.
   */
  _TOD_Get_uptime( &the_period->time_period_initiated );
  _Thread_Get_CPU_time_used( owner, &the_period->cpu_usage_period_initiated );

  _Rate_monotonic_Release_job(
    the_period,
    owner,
    the_period->next_length,
    lock_context
  );
}
Exemplo n.º 3
0
bool _Rate_monotonic_Get_status(
  const Rate_monotonic_Control *the_period,
  Timestamp_Control            *wall_since_last_period,
  Timestamp_Control            *cpu_since_last_period
)
{
  Timestamp_Control        uptime;
  Thread_Control          *owning_thread = the_period->owner;
  Timestamp_Control        used;

  /*
   *  Determine elapsed wall time since period initiated.
   */
  _TOD_Get_uptime( &uptime );
  _Timestamp_Subtract(
    &the_period->time_period_initiated, &uptime, wall_since_last_period
  );

  /*
   *  Determine cpu usage since period initiated.
   */
  _Thread_Get_CPU_time_used( owning_thread, &used );

  /*
   *  The cpu usage info was reset while executing.  Can't
   *  determine a status.
   */
  if ( _Timestamp_Less_than( &used, &the_period->cpu_usage_period_initiated ) )
    return false;

   /* used = current cpu usage - cpu usage at start of period */
  _Timestamp_Subtract(
    &the_period->cpu_usage_period_initiated,
    &used,
    cpu_since_last_period
  );

  return true;
}
Exemplo n.º 4
0
/*
 * Create the sorted table with the current and total usage.
 */
static void
task_usage(Thread_Control* thread, void* arg)
{
  rtems_cpu_usage_data* data = (rtems_cpu_usage_data*) arg;
  Timestamp_Control     usage;
  Timestamp_Control     current = data->zero;
  int                   j;

  data->stack_size += thread->Start.Initial_stack.size;

  _Thread_Get_CPU_time_used(thread, &usage);

  for (j = 0; j < data->last_task_count; j++)
  {
    if (thread == data->last_tasks[j])
    {
      _Timestamp_Subtract(&data->last_usage[j], &usage, &current);
      break;
    }
  }

  /*
   * When not using nanosecond CPU usage resolution, we have to count the
   * number of "ticks" we gave credit for to give the user a rough guideline as
   * to what each number means proportionally.
   */
  _Timestamp_Add_to(&data->total, &usage);
  _Timestamp_Add_to(&data->current, &current);

  if (thread->Object.id == 0x09010001)
  {
    data->idle = usage;
    data->current_idle = current;
  }

  /*
   * Create the tasks to display soring as we create.
   */
  for (j = 0; j < data->task_count; j++)
  {
    if (data->tasks[j])
    {
      int k;

      /*
       * Sort on the current load.
       */
      switch (data->sort_order)
      {
        default:
          data->sort_order = RTEMS_TOP_SORT_CURRENT;
          /* drop through */
        case RTEMS_TOP_SORT_CURRENT:
          if (CPU_usage_Equal_to(&current, &data->zero) ||
              CPU_usage_Less_than(&current, &data->current_usage[j]))
            continue;
        case RTEMS_TOP_SORT_TOTAL:
          if (CPU_usage_Equal_to(&usage, &data->zero) ||
              CPU_usage_Less_than(&usage, &data->usage[j]))
            continue;
        case RTEMS_TOP_SORT_REAL_PRI:
          if (thread->Real_priority.priority > data->tasks[j]->Real_priority.priority)
            continue;
        case RTEMS_TOP_SORT_CURRENT_PRI:
          if (
            _Thread_Get_priority( thread )
              > _Thread_Get_priority( data->tasks[j] )
          ) {
            continue;
          }
        case RTEMS_TOP_SORT_ID:
          if (thread->Object.id < data->tasks[j]->Object.id)
            continue;
      }

      for (k = (data->task_count - 1); k >= j; k--)
      {
        data->tasks[k + 1] = data->tasks[k];
        data->usage[k + 1]  = data->usage[k];
        data->current_usage[k + 1]  = data->current_usage[k];
      }
    }
    data->tasks[j] = thread;
    data->usage[j] = usage;
    data->current_usage[j] = current;
    break;
  }
}