Changeset 1e483a62 in rtems


Ignore:
Timestamp:
Feb 2, 2018, 6:43:39 AM (21 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
cf56b18a
Parents:
63fab5aa
git-author:
Sebastian Huber <sebastian.huber@…> (02/02/18 06:43:39)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/02/18 06:48:49)
Message:

test: Add rtems_test_busy_cpu_usage()

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/test.h

    r63fab5aa r1e483a62  
    11/*
    2  * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    291291
    292292/**
     293 * @brief Performs a busy loop for the specified seconds and nanoseconds based
     294 * on the CPU usage of the executing thread.
     295 *
     296 * This function continuously reads the CPU usage of the executing thread.
     297 * This operation may lead to a scheduler instance lock contention in SMP
     298 * configurations.
     299 *
     300 * @param[in] seconds The busy seconds.
     301 * @param[in] nanoseconds The busy nanoseconds.
     302 */
     303void rtems_test_busy_cpu_usage(time_t seconds, long nanoseconds);
     304
     305/**
    293306 * @brief Performs a busy loop with the specified iteration count.
    294307 *
  • cpukit/libmisc/testsupport/testbusy.c

    r63fab5aa r1e483a62  
    11/*
    2  * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    2020#include <rtems/test.h>
    2121#include <rtems.h>
     22#include <rtems/score/threadimpl.h>
    2223
    2324static uint_fast32_t estimate_busy_loop_maximum( void )
     
    106107  return m;
    107108}
     109
     110void rtems_test_busy_cpu_usage( time_t seconds, long nanoseconds )
     111{
     112  Thread_Control    *executing;
     113  Timestamp_Control  busy;
     114  Timestamp_Control  start;
     115  Timestamp_Control  now;
     116
     117  executing = _Thread_Get_executing();
     118  _Thread_Get_CPU_time_used( executing, &start );
     119  _Timestamp_Set( &busy, seconds, nanoseconds );
     120
     121  do {
     122    _Thread_Get_CPU_time_used( executing, &now );
     123  } while ( now - start < busy );
     124}
Note: See TracChangeset for help on using the changeset viewer.