Changeset 3e2a3c4 in rtems


Ignore:
Timestamp:
06/20/16 11:55:37 (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
fa239ff2
Parents:
40b80d86
git-author:
Sebastian Huber <sebastian.huber@…> (06/20/16 11:55:37)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/20/16 11:56:34)
Message:

sptests/spcpucounter01: Add some statistics

Location:
testsuites/sptests/spcpucounter01
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/spcpucounter01/init.c

    r40b80d86 r3e2a3c4  
    11/*
    2  * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    3030#define NS_PER_TICK 1000000
    3131
     32#define N 10
     33
     34typedef struct {
     35  rtems_counter_ticks delay_ns_t[N][2];
     36  rtems_counter_ticks delay_ticks_t[N][2];
     37  rtems_counter_ticks overhead_t[N][5];
     38  rtems_counter_ticks overhead_delta;
     39} test_context;
     40
     41static test_context test_instance;
     42
    3243static rtems_interval sync_with_clock_tick(void)
    3344{
     
    5364}
    5465
    55 static void test_delay_nanoseconds(void)
    56 {
    57   rtems_counter_ticks start;
    58   rtems_counter_ticks end;
    59   rtems_counter_ticks delta;
     66static void test_delay_nanoseconds(test_context *ctx)
     67{
     68  int i;
     69
     70  for (i = 0; i < N; ++i) {
     71    rtems_counter_ticks t0;
     72    rtems_counter_ticks t1;
     73    rtems_interval tick;
     74
     75    tick = sync_with_clock_tick();
     76
     77    t0 = rtems_counter_read();
     78    rtems_counter_delay_nanoseconds(NS_PER_TICK);
     79    t1 = rtems_counter_read();
     80
     81    ctx->delay_ns_t[i][0] = t0;
     82    ctx->delay_ns_t[i][1] = t1;
     83
     84    rtems_test_assert(tick < rtems_clock_get_ticks_since_boot());
     85  }
     86}
     87
     88static void test_delay_ticks(test_context *ctx)
     89{
     90  rtems_counter_ticks ticks = rtems_counter_nanoseconds_to_ticks(NS_PER_TICK);
     91  int i;
     92
     93  for (i = 0; i < N; ++i) {
     94    rtems_counter_ticks t0;
     95    rtems_counter_ticks t1;
     96    rtems_interval tick;
     97
     98    tick = sync_with_clock_tick();
     99
     100    t0 = rtems_counter_read();
     101    rtems_counter_delay_ticks(ticks);
     102    t1 = rtems_counter_read();
     103
     104    ctx->delay_ticks_t[i][0] = t0;
     105    ctx->delay_ticks_t[i][1] = t1;
     106
     107    rtems_test_assert(tick < rtems_clock_get_ticks_since_boot());
     108  }
     109}
     110
     111static void test_overheads(test_context *ctx)
     112{
     113  int i;
     114
     115  for (i = 0; i < N; ++i) {
     116    rtems_counter_ticks t0;
     117    rtems_counter_ticks t1;
     118    rtems_counter_ticks t2;
     119    rtems_counter_ticks t3;
     120    rtems_counter_ticks t4;
     121    rtems_counter_ticks d;
     122
     123    t0 = rtems_counter_read();
     124    t1 = rtems_counter_read();
     125    d = rtems_counter_difference(t1, t0);
     126    t2 = rtems_counter_read();
     127    rtems_counter_delay_nanoseconds(0);
     128    t3 = rtems_counter_read();
     129    rtems_counter_delay_ticks(0);
     130    t4 = rtems_counter_read();
     131
     132    ctx->overhead_t[i][0] = t0;
     133    ctx->overhead_t[i][1] = t1;
     134    ctx->overhead_t[i][2] = t2;
     135    ctx->overhead_t[i][3] = t3;
     136    ctx->overhead_t[i][4] = t4;
     137    ctx->overhead_delta = d;
     138  }
     139}
     140
     141static void report_overhead(
     142  const char *name,
     143  rtems_counter_ticks t1,
     144  rtems_counter_ticks t0
     145)
     146{
     147  rtems_counter_ticks d;
     148  uint64_t ns;
     149
     150  d = rtems_counter_difference(t1, t0);
     151  ns = rtems_counter_ticks_to_nanoseconds(d);
     152
     153  printf(
     154    "overhead %s: %" PRIu64 " ticks, %" PRIu64 "ns\n",
     155    name,
     156    (uint64_t) d,
     157    ns
     158  );
     159}
     160
     161static void test_report(test_context *ctx)
     162{
    60163  double ns_per_tick = NS_PER_TICK;
    61   uint64_t ns_delta;
    62   rtems_interval tick;
    63   int n = 10;
    64   int i;
    65 
    66   printf("test delay nanoseconds (%i times)\n", n);
    67 
    68   for (i = 0; i < n; ++i) {
    69     tick = sync_with_clock_tick();
    70 
    71     start = rtems_counter_read();
    72     rtems_counter_delay_nanoseconds(NS_PER_TICK);
    73     end = rtems_counter_read();
    74 
    75     rtems_test_assert(tick < rtems_clock_get_ticks_since_boot());
    76 
    77     delta = rtems_counter_difference(end, start);
    78     ns_delta = rtems_counter_ticks_to_nanoseconds(delta);
    79 
    80     /* Special case for CPU counters using the clock driver counter */
    81     if (ns_delta < rtems_configuration_get_nanoseconds_per_tick()) {
    82       printf(
    83         "warning: the RTEMS counter seems to be unable to\n"
    84         "  measure intervals greater than the clock tick interval\n"
    85       );
    86 
    87       ns_delta += rtems_configuration_get_nanoseconds_per_tick();
    88     }
     164  rtems_counter_ticks d;
     165  uint64_t ns;
     166  size_t i;
     167
     168  printf("test delay nanoseconds (%i times)\n", N);
     169
     170  for (i = 0; i < N; ++i) {
     171    d = rtems_counter_difference(ctx->delay_ns_t[i][1], ctx->delay_ns_t[i][0]);
     172    ns = rtems_counter_ticks_to_nanoseconds(d);
    89173
    90174    printf(
    91       "busy wait duration: %" PRIu64 "ns\n"
    92       "busy wait relative to clock tick: %f\n",
    93       ns_delta,
    94       (ns_delta - ns_per_tick) / ns_per_tick
     175      "ns busy wait duration: %" PRIu64 "ns\n"
     176      "ns busy wait relative to clock tick: %f\n",
     177      ns,
     178      (ns - ns_per_tick) / ns_per_tick
    95179    );
    96180  }
     181
     182  printf("test delay ticks (%i times)\n", N);
     183
     184  for (i = 0; i < N; ++i) {
     185    d = rtems_counter_difference(
     186      ctx->delay_ticks_t[i][1],
     187      ctx->delay_ticks_t[i][0]
     188    );
     189    ns = rtems_counter_ticks_to_nanoseconds(d);
     190
     191    printf(
     192      "ticks busy wait duration: %" PRIu64 "ns\n"
     193      "ticks busy wait relative to clock tick: %f\n",
     194      ns,
     195      (ns - ns_per_tick) / ns_per_tick
     196    );
     197  }
     198
     199  printf("test overheads (%i times)\n", N);
     200
     201  for (i = 0; i < N; ++i) {
     202    report_overhead("read", ctx->overhead_t[i][1], ctx->overhead_t[i][0]);
     203    report_overhead("difference", ctx->overhead_t[i][2], ctx->overhead_t[i][1]);
     204    report_overhead("delay ns", ctx->overhead_t[i][3], ctx->overhead_t[i][2]);
     205    report_overhead("delay ticks", ctx->overhead_t[i][4], ctx->overhead_t[i][3]);
     206  }
    97207}
    98208
    99209static void Init(rtems_task_argument arg)
    100210{
     211  test_context *ctx = &test_instance;
     212
    101213  TEST_BEGIN();
    102214
     215  test_delay_nanoseconds(ctx);
     216  test_delay_ticks(ctx);
     217  test_overheads(ctx);
    103218  test_converter();
    104   test_delay_nanoseconds();
     219  test_report(ctx);
    105220
    106221  TEST_END();
  • testsuites/sptests/spcpucounter01/spcpucounter01.scn

    r40b80d86 r3e2a3c4  
    1 *** TEST SPCPUCOUNTER 1 ***
    2 CPU counter frequency: 25000000Hz
     1*** BEGIN OF TEST SPCPUCOUNTER 1 ***
     2CPU counter frequency: 1500000000Hz
    33nanoseconds for frequency count ticks: 1000000000
    44test delay nanoseconds (10 times)
    5 busy wait duration: 1000840ns
    6 busy wait relative to clock tick: 0.000840
    7 busy wait duration: 1001200ns
    8 busy wait relative to clock tick: 0.001200
    9 busy wait duration: 1001480ns
    10 busy wait relative to clock tick: 0.001480
    11 busy wait duration: 1001200ns
    12 busy wait relative to clock tick: 0.001200
    13 busy wait duration: 1001120ns
    14 busy wait relative to clock tick: 0.001120
    15 busy wait duration: 1001280ns
    16 busy wait relative to clock tick: 0.001280
    17 busy wait duration: 1001120ns
    18 busy wait relative to clock tick: 0.001120
    19 busy wait duration: 1001240ns
    20 busy wait relative to clock tick: 0.001240
    21 busy wait duration: 1001120ns
    22 busy wait relative to clock tick: 0.001120
    23 busy wait duration: 1001280ns
    24 busy wait relative to clock tick: 0.001280
     5ns busy wait duration: 1000062ns
     6ns busy wait relative to clock tick: 0.000062
     7ns busy wait duration: 1000017ns
     8ns busy wait relative to clock tick: 0.000017
     9ns busy wait duration: 1000025ns
     10ns busy wait relative to clock tick: 0.000025
     11ns busy wait duration: 1000017ns
     12ns busy wait relative to clock tick: 0.000017
     13ns busy wait duration: 1000043ns
     14ns busy wait relative to clock tick: 0.000043
     15ns busy wait duration: 1000040ns
     16ns busy wait relative to clock tick: 0.000040
     17ns busy wait duration: 1000043ns
     18ns busy wait relative to clock tick: 0.000043
     19ns busy wait duration: 1000022ns
     20ns busy wait relative to clock tick: 0.000022
     21ns busy wait duration: 1000028ns
     22ns busy wait relative to clock tick: 0.000028
     23ns busy wait duration: 1000023ns
     24ns busy wait relative to clock tick: 0.000023
     25test delay ticks (10 times)
     26ticks busy wait duration: 1000038ns
     27ticks busy wait relative to clock tick: 0.000038
     28ticks busy wait duration: 1000028ns
     29ticks busy wait relative to clock tick: 0.000028
     30ticks busy wait duration: 1000010ns
     31ticks busy wait relative to clock tick: 0.000010
     32ticks busy wait duration: 1000036ns
     33ticks busy wait relative to clock tick: 0.000036
     34ticks busy wait duration: 1000031ns
     35ticks busy wait relative to clock tick: 0.000031
     36ticks busy wait duration: 1000062ns
     37ticks busy wait relative to clock tick: 0.000062
     38ticks busy wait duration: 1000026ns
     39ticks busy wait relative to clock tick: 0.000026
     40ticks busy wait duration: 1000031ns
     41ticks busy wait relative to clock tick: 0.000031
     42ticks busy wait duration: 1000016ns
     43ticks busy wait relative to clock tick: 0.000016
     44ticks busy wait duration: 1000033ns
     45ticks busy wait relative to clock tick: 0.000033
     46test overheads (10 times)
     47overhead read: 1 ticks, 0ns
     48overhead difference: 1 ticks, 0ns
     49overhead delay ns: 272 ticks, 181ns
     50overhead delay ticks: 20 ticks, 13ns
     51overhead read: 1 ticks, 0ns
     52overhead difference: 1 ticks, 0ns
     53overhead delay ns: 20 ticks, 13ns
     54overhead delay ticks: 8 ticks, 5ns
     55overhead read: 1 ticks, 0ns
     56overhead difference: 1 ticks, 0ns
     57overhead delay ns: 34 ticks, 22ns
     58overhead delay ticks: 8 ticks, 5ns
     59overhead read: 1 ticks, 0ns
     60overhead difference: 1 ticks, 0ns
     61overhead delay ns: 34 ticks, 22ns
     62overhead delay ticks: 8 ticks, 5ns
     63overhead read: 1 ticks, 0ns
     64overhead difference: 1 ticks, 0ns
     65overhead delay ns: 24 ticks, 16ns
     66overhead delay ticks: 8 ticks, 5ns
     67overhead read: 1 ticks, 0ns
     68overhead difference: 1 ticks, 0ns
     69overhead delay ns: 23 ticks, 15ns
     70overhead delay ticks: 8 ticks, 5ns
     71overhead read: 1 ticks, 0ns
     72overhead difference: 1 ticks, 0ns
     73overhead delay ns: 23 ticks, 15ns
     74overhead delay ticks: 8 ticks, 5ns
     75overhead read: 1 ticks, 0ns
     76overhead difference: 1 ticks, 0ns
     77overhead delay ns: 23 ticks, 15ns
     78overhead delay ticks: 8 ticks, 5ns
     79overhead read: 1 ticks, 0ns
     80overhead difference: 1 ticks, 0ns
     81overhead delay ns: 23 ticks, 15ns
     82overhead delay ticks: 8 ticks, 5ns
     83overhead read: 1 ticks, 0ns
     84overhead difference: 1 ticks, 0ns
     85overhead delay ns: 23 ticks, 15ns
     86overhead delay ticks: 8 ticks, 5ns
    2587*** END OF TEST SPCPUCOUNTER 1 ***
Note: See TracChangeset for help on using the changeset viewer.