示例#1
0
void *main_loop(void *ptr) {
  int i;
  int rv = 0;	/* Thread exit code */
  unsigned long long cnt1, cnt2;
  qres_sid_t sid;

  qres_params_t *params = (qres_params_t *) ptr;

  qos_log_debug("Creating QRES Server with Q=" QRES_TIME_FMT
		", P=" QRES_TIME_FMT, params->Q, params->P);
  qos_chk_ok_exit(qres_create_server(params, &sid));
  qos_chk_ok_exit(qres_attach_thread(sid, 0, 0));

  cnt1 = count_and_wait();

  for (i = 0; i < (int) (sizeof(target_ratios) / sizeof(*target_ratios)); i++) {
    double target_ratio = target_ratios[i];
    double cnt2_exp, reldiff;
    params->Q = (qres_time_t) ((double) ORIG_Q * target_ratio);
    qos_log_debug("Changing QRES Parameters to Q=" QRES_TIME_FMT
		  ", P=" QRES_TIME_FMT, params->Q, params->P);
    qos_chk_ok_exit(qres_set_params(sid, params));

    cnt2_exp = target_ratio * cnt1;
    cnt2 = count_and_wait();

    reldiff = (((double) cnt2) - cnt2_exp) / cnt2_exp;
    qos_log_debug("%d: reldiff=%02.2g%% / 100.00%%", i, reldiff*100);
    if (fabs(reldiff) > RATIO_TOLERANCE) {
      qos_log_err("Expecting to count %g while counted %llu (reldiff=%g)",
		  cnt2_exp, cnt2, reldiff);
      qos_log_err("This is outside defined tolerance of %g",
		  RATIO_TOLERANCE);
      rv = -1;
    }
  }

  qos_log_debug("Destroying QRES Server");
  qos_chk_ok_exit(qres_destroy_server(sid));

  pthread_exit((void *) (intptr_t) rv);
}
示例#2
0
rtems_task Task_Periodic(
  rtems_task_argument argument
)
{
  rtems_id          rmid;
  rtems_status_code status;

  time_t approved_budget, exec_time, abs_time, current_budget;

  int start, stop, now;

  qres_sid_t server_id, tsid;
  qres_params_t params, tparams;

  params.P = Period;
  params.Q = Execution+1;

  printf( "Periodic task: Create server and Attach thread\n" );
  if ( qres_create_server( &params, &server_id ) )
    printf( "ERROR: CREATE SERVER FAILED\n" );
  if ( qres_attach_thread( server_id, 0, Task_id ) )
    printf( "ERROR: ATTACH THREAD FAILED\n" );

  printf( "Periodic task: ID and Get parameters\n" );
  if ( qres_get_sid( 0, Task_id, &tsid ) )
    printf( "ERROR: GET SERVER ID FAILED\n" );
  if ( tsid != server_id )
    printf( "ERROR: SERVER ID MISMATCH\n" );
  if ( qres_get_params( server_id, &tparams ) )
    printf( "ERROR: GET PARAMETERS FAILED\n" );
  if ( params.P != tparams.P ||
       params.Q != tparams.Q )
    printf( "ERROR: PARAMETERS MISMATCH\n" );

  printf( "Periodic task: Detach thread and Destroy server\n" );
  if ( qres_detach_thread( server_id, 0, Task_id ) )
    printf( "ERROR: DETACH THREAD FAILED\n" );
  if ( qres_destroy_server( server_id ) )
    printf( "ERROR: DESTROY SERVER FAILED\n" );
  if ( qres_create_server( &params, &server_id ) )
    printf( "ERROR: CREATE SERVER FAILED\n" );

  printf( "Periodic task: Current budget and Execution time\n" );
  if ( qres_get_curr_budget( server_id, &current_budget ) )
    printf( "ERROR: GET REMAINING BUDGET FAILED\n" );
  if ( current_budget != params.Q )
    printf( "ERROR: REMAINING BUDGET MISMATCH\n" );
  if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) )
    printf( "ERROR: GET EXECUTION TIME FAILED\n" );

  printf( "Periodic task: Set parameters\n" );
  if ( qres_attach_thread( server_id, 0, Task_id ) )
    printf( "ERROR: ATTACH THREAD FAILED\n" );
  params.P = Period * 2;
  params.Q = Execution * 2 +1;
  if ( qres_set_params( server_id, &params ) )
    printf( "ERROR: SET PARAMS FAILED\n" );
  if ( qres_get_params( server_id, &tparams ) )
    printf( "ERROR: GET PARAMS FAILED\n" );
  if ( params.P != tparams.P ||
       params.Q != tparams.Q )
    printf( "ERROR: PARAMS MISMATCH\n" );
  params.P = Period;
  params.Q = Execution+1;
  if ( qres_set_params( server_id, &params ) )
    printf( "ERROR: SET PARAMS FAILED\n" );
  if ( qres_get_appr_budget( server_id, &approved_budget ) )
    printf( "ERROR: GET APPROVED BUDGET FAILED\n" );

  printf( "Periodic task: Approved budget\n" );
  if ( approved_budget != params.Q )
    printf( "ERROR: APPROVED BUDGET MISMATCH\n" );

  status = rtems_rate_monotonic_create( argument, &rmid );
  directive_failed( status, "rtems_rate_monotonic_create" );

  /* Starting periodic behavior of the task */
  printf( "Periodic task: Starting periodic behavior\n" );
  status = rtems_task_wake_after( 1 + Phase );
  directive_failed( status, "rtems_task_wake_after" );

  while ( FOREVER ) {
    if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT )
      printf( "P%" PRIdPTR " - Deadline miss\n", argument );

    start = rtems_clock_get_ticks_since_boot();
    printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start );
    if ( start > 4*Period+Phase ) break; /* stop */
    /* active computing */
    while(FOREVER) {
      now = rtems_clock_get_ticks_since_boot();
      if ( now >= start + Execution ) break;

      if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) )
        printf( "ERROR: GET EXECUTION TIME FAILED\n" );
      if ( qres_get_curr_budget( server_id, &current_budget) )
        printf( "ERROR: GET CURRENT BUDGET FAILED\n" );
      if ( (current_budget + exec_time) > (Execution + 1) ) {
        printf( "ERROR: CURRENT BUDGET AND EXECUTION TIME MISMATCH\n" );
        rtems_test_exit( 0 );
      }
    }
    stop = rtems_clock_get_ticks_since_boot();
    printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop );
  }

  /* delete period and SELF */
  status = rtems_rate_monotonic_delete( rmid );
  if ( status != RTEMS_SUCCESSFUL ) {
    printf("rtems_rate_monotonic_delete failed with status of %d.\n", status);
    rtems_test_exit( 0 );
  }
  if ( qres_cleanup() )
    printf( "ERROR: QRES CLEANUP\n" );

  fflush(stdout);
  TEST_END();
  rtems_test_exit( 0 );
}
示例#3
0
文件: init.c 项目: greenmeent/rtems
rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;
  qres_sid_t server_id, server_id2;
  time_t approved_budget, exec_time, abs_time, current_budget;
  qres_params_t params, params1, params2, params3, params4;

  Priority = 30;
  Period    = 30;
  Execution = 10;
  Phase = 0;

  params.P = 1;
  params.Q = 1;

  params1 = params2 = params3 = params4 = params;
  params1.Q = -1;
  params2.Q = SCHEDULER_EDF_PRIO_MSB + 1;
  params3.P = -1;
  params4.P = SCHEDULER_EDF_PRIO_MSB + 1;

  TEST_BEGIN();


  status = rtems_task_create(
    rtems_build_name( 'P', 'T', '1', ' ' ),
    Priority,
    RTEMS_MINIMUM_STACK_SIZE * 4,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id
  );
  directive_failed( status, "rtems_task_create loop" );

  printf( "Init: Initializing the qres library\n" );
  if ( qres_init() )
    printf( "ERROR: QRES INITIALIZATION FAILED\n" );

  /* Error checks for Create server and Destroy server  */
  printf( "Init: Create server and Destroy server\n" );
  if ( qres_destroy_server( -5 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_destroy_server( 5 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_destroy_server( 0 ) != QOS_E_NOSERVER )
    printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params1, &server_id ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params2, &server_id ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params3, &server_id ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params4, &server_id ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params, &server_id2 ) )
    printf( "ERROR: CREATE SERVER FAILED\n" );
  if ( qres_create_server( &params, &server_id ) )
    printf( "ERROR: CREATE SERVER FAILED\n" );
  if ( qres_create_server( &params, &server_id ) !=
       QOS_E_FULL )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );

  /* Error checks for Attach thread and Detach thread */
  printf( "Init: Attach thread\n" );
  if ( qres_attach_thread( -5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( 5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( server_id, 0, 1234 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) )
    printf( "ERROR: ATTACH THREAD FAILED\n" );
  if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) !=
       QOS_E_FULL )
    printf( "ERROR: ATTACH THREAD AGAIN PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( server_id, 0, Task_id ) !=
       QOS_E_FULL )
    printf( "ERROR: ATTACH THREAD TO FULL SERVER PASSED UNEXPECTEDLY \n" );
  if ( qres_destroy_server( server_id ) )
    printf( "ERROR: DESTROY SERVER WITH THREAD ATTACHED FAILED\n" );
  if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );

  printf( "Init: Detach thread\n" );
  if ( qres_detach_thread( -5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_detach_thread( 5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_detach_thread( server_id2, 0, 1234 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY \n" );
  if ( qres_detach_thread( server_id, 0, RTEMS_SELF ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY4\n" );
  qres_destroy_server( server_id2 );

  /* Error checks for Set params and Get params */
  printf( "Init: Set params and Get params\n" );
  if ( qres_set_params( -5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( 5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( server_id, &params ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );

  if ( qres_get_params( -5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_get_params( 5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_get_params( server_id, &params ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );

  if ( qres_set_params( server_id, &params1 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( server_id, &params2 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( server_id, &params3 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( server_id, &params4 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get server id */
  printf( "Init: Get server id\n" );
  if ( qres_get_sid( 0, RTEMS_SELF, &server_id ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET SERVER ID PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get approved budget */
  printf( "Init: Get approved budget\n" );
  if ( qres_get_appr_budget( -5, &approved_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_appr_budget( 5, &approved_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_appr_budget( server_id, &approved_budget ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get current budget */
  printf( "Init: Get current budget\n" );
  if ( qres_get_curr_budget( -5, &current_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_curr_budget( 5, &current_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_curr_budget( server_id, &current_budget ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get execution time */
  printf( "Init: Get execution time\n" );
  if ( qres_get_exec_time( -5, &exec_time, &abs_time ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" );
  if ( qres_get_exec_time( 5, &exec_time, &abs_time ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" );
  if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" );

  /* Restart QRES library */
  printf( "Init: Cleaning up QRES\n" );
  if ( qres_cleanup() )
    printf( "ERROR: QRES CLEANUP FAILED\n" );
  printf( "Init: Initializing the QRES\n" );
  if ( qres_init() )
    printf( "ERROR: QRES INITIALIZATION FAILED\n" );

  /* Start periodic task */
  printf( "Init: Starting periodic task\n" );
  status = rtems_task_start( Task_id, Task_Periodic, 1 );
  directive_failed( status, "rtems_task_start periodic" );

  status = rtems_task_delete( RTEMS_SELF );
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
}