Changeset 08bd7d3 in rtems


Ignore:
Timestamp:
Nov 12, 2019, 3:33:41 PM (4 months ago)
Author:
Joel Sherrill <joel@…>
Branches:
master
Children:
4e2e338
Parents:
b1b6dd71
git-author:
Joel Sherrill <joel@…> (11/12/19 15:33:41)
git-committer:
Joel Sherrill <joel@…> (12/11/19 21:22:33)
Message:

Add TOD Hooks to allow BSP to take action when TOD is set

Two use cases were envisioned for this.

1) a BSP or application which desires to update a real-time clock

when the RTEMS TOD is set.

2) a paravirtualized BSP can use this to propagate setting the time

in an RTEMS application to the hosting environment. This enables
the entire set of applications in the virtualized environments
to have a single consistent TOD.

Files:
7 added
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    rb1b6dd71 r08bd7d3  
    983983librtemscpu_a_SOURCES += score/src/coretodadjust.c
    984984librtemscpu_a_SOURCES += score/src/watchdoginsert.c
     985librtemscpu_a_SOURCES += score/src/coretodhookdata.c
     986librtemscpu_a_SOURCES += score/src/coretodhookregister.c
     987librtemscpu_a_SOURCES += score/src/coretodhookrun.c
     988librtemscpu_a_SOURCES += score/src/coretodhookunregister.c
    985989librtemscpu_a_SOURCES += score/src/watchdogremove.c
    986990librtemscpu_a_SOURCES += score/src/watchdogtick.c
  • cpukit/include/rtems/score/timecounter.h

    rb1b6dd71 r08bd7d3  
    203203
    204204/**
     205 * @brief Releases the timecounter lock.
     206 *
     207 * @param lock_context The lock context.
     208 *
     209 * See _Timecounter_Tick_simple().
     210 */
     211#define _Timecounter_Release(lock_context) \
     212   _ISR_lock_Release_and_ISR_enable(&_Timecounter_Lock, lock_context)
     213
     214/**
    205215 * @brief Performs a simple timecounter tick.
    206216 *
  • cpukit/include/rtems/score/todimpl.h

    rb1b6dd71 r08bd7d3  
    142142} TOD_Control;
    143143
     144/**
     145 * @brief TOD Management information
     146 */
    144147extern TOD_Control _TOD;
    145148
     
    172175{
    173176  _Timecounter_Acquire( lock_context );
     177}
     178
     179/**
     180 * @brief Releases the lock context for the timecounter.
     181 *
     182 * @param lock_context The lock to release.
     183 */
     184static inline void _TOD_Release( ISR_lock_Context *lock_context )
     185{
     186  _Timecounter_Release( lock_context );
    174187}
    175188
     
    184197 *   _TOD_Acquire().  The caller must be the owner of the TOD lock.  This
    185198 *   function will release the TOD lock.
    186  */
    187 void _TOD_Set(
     199 *
     200 * @retval true on success
     201 * @retval false on failure
     202 */
     203bool _TOD_Set(
    188204  const struct timespec *tod,
    189205  ISR_lock_Context      *lock_context
     
    321337/** @} */
    322338
     339/**
     340 * @defgroup RTEMSScoreTODHooks Time of Day Handler Action Hooks
     341 *
     342 * @ingroup RTEMSScoreTOD
     343 *
     344 * @brief Time of Day Handler Action Hooks
     345 *
     346 * The following support registering a hook which is invoked
     347 * when the TOD is set. These can be used by a paravirtualized
     348 * BSP to mirror time changes to the hosting environment or a
     349 * regular BSP to program a real-time clock when the RTEMS TOD
     350 * is set.
     351 *
     352 * @{
     353 */
     354
     355/**
     356 *  @brief Possible actions where a registered hook could be invoked
     357 */
     358typedef enum {
     359  /**
     360   *  @brief Constant to indicate the TOD is being set.
     361   */
     362  TOD_ACTION_SET_CLOCK
     363} TOD_Action;
     364
     365/**
     366 * @brief Structure to manage each TOD action hook
     367 */
     368typedef struct TOD_Hook {
     369  /** This is the chain node portion of an object. */
     370  Chain_Node Node;
     371
     372  /** This is the TOD action hook that is invoked. */
     373  bool (*handler)(TOD_Action, const struct timespec *);
     374} TOD_Hook;
     375
     376/**
     377 * @brief Set of registered methods for TOD Actions
     378 */
     379extern Chain_Control _TOD_Hooks;
     380
     381/**
     382 * @brief Add a TOD Action Hook
     383 *
     384 * This method is used to add a hook to the TOD action set.
     385 *
     386 * @brief hook is the action hook to register.
     387 *
     388 * @retval true if the hook is added.
     389 * @retval false if the hook cannot be added.
     390 */
     391void _TOD_Hook_Register(
     392  TOD_Hook *hook
     393);
     394
     395/**
     396 * @brief Remove a TOD Action Hook
     397 *
     398 * This method is used to remove a hook from the TOD action set.
     399 *
     400 * @brief hook is the action hook to unregister.
     401 *
     402 * @retval true if the hook is unregister.
     403 * @retval false if the hook cannot be unregister.
     404 */
     405void _TOD_Hook_Unregister(
     406  TOD_Hook *hook
     407);
     408
     409/**
     410 * @brief Run the TOD Action Hooks
     411 *
     412 * This method is used to invoke the set of TOD action hooks.
     413 *
     414 * @brief action is the action which triggered this run.
     415 * @brief tod is the current tod
     416 *
     417 * @retval true if the hooks can be run.
     418 * @retval false if the hook cannot be run.
     419 */
     420bool _TOD_Hook_Run(
     421  TOD_Action             action,
     422  const struct timespec *tod
     423);
     424
     425
     426/** @} */
     427
    323428#ifdef __cplusplus
    324429}
  • cpukit/posix/src/clocksettime.c

    rb1b6dd71 r08bd7d3  
    3333)
    3434{
     35  bool  retval;
     36
    3537  if ( !tp )
    3638    rtems_set_errno_and_return_minus_one( EINVAL );
     
    4446    _TOD_Lock();
    4547    _TOD_Acquire( &lock_context );
    46     _TOD_Set( tp, &lock_context );
     48      retval = _TOD_Set( tp, &lock_context );
    4749    _TOD_Unlock();
     50    if ( retval == false ) {
     51      rtems_set_errno_and_return_minus_one( EPERM );
     52    }
    4853  }
    4954#ifdef _POSIX_CPUTIME
    50   else if ( clock_id == CLOCK_PROCESS_CPUTIME_ID )
     55  else if ( clock_id == CLOCK_PROCESS_CPUTIME_ID ) {
    5156    rtems_set_errno_and_return_minus_one( ENOSYS );
     57  }
    5258#endif
    5359#ifdef _POSIX_THREAD_CPUTIME
    54   else if ( clock_id == CLOCK_THREAD_CPUTIME_ID )
     60  else if ( clock_id == CLOCK_THREAD_CPUTIME_ID ) {
    5561    rtems_set_errno_and_return_minus_one( ENOSYS );
     62  }
    5663#endif
    57   else
     64  else {
    5865    rtems_set_errno_and_return_minus_one( EINVAL );
     66  }
    5967
    6068  return 0;
  • cpukit/rtems/src/clockset.c

    rb1b6dd71 r08bd7d3  
    2727)
    2828{
     29  bool retval;
     30
    2931  if ( !tod )
    3032    return RTEMS_INVALID_ADDRESS;
     
    4042    _TOD_Lock();
    4143    _TOD_Acquire( &lock_context );
    42     _TOD_Set( &tod_as_timespec, &lock_context );
     44    retval = _TOD_Set( &tod_as_timespec, &lock_context );
    4345    _TOD_Unlock();
    4446
    45     return RTEMS_SUCCESSFUL;
     47    if ( retval == true ) {
     48      return RTEMS_SUCCESSFUL;
     49    }
     50    return RTEMS_IO_ERROR;
    4651  }
    4752
  • cpukit/score/src/coretodset.c

    rb1b6dd71 r08bd7d3  
    2323#include <rtems/score/watchdogimpl.h>
    2424
    25 void _TOD_Set(
     25bool _TOD_Set(
    2626  const struct timespec *tod,
    2727  ISR_lock_Context      *lock_context
     
    3232  uint32_t        cpu_max;
    3333  uint32_t        cpu_index;
     34  bool            retval;
    3435
    3536  _Assert( _TOD_Is_owner() );
     37
     38  retval = _TOD_Hook_Run( TOD_ACTION_SET_CLOCK, tod );
     39  if ( retval == false ) {
     40    _TOD_Release( lock_context );
     41    return false;
     42  }
    3643
    3744  timespec2bintime( tod, &tod_as_bintime );
     
    6875
    6976  _TOD.is_set = true;
     77
     78  return true;
    7079}
  • testsuites/sptests/Makefile.am

    rb1b6dd71 r08bd7d3  
    705705spclock_err02_SOURCES = spclock_err02/init.c
    706706spclock_err02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spclock_err02) \
     707        $(support_includes)
     708endif
     709
     710if TEST_spclock_todhook01
     711sp_tests += spclock_todhook01
     712sp_screens += spclock_todhook01/spclock_todhook01.scn
     713sp_docs += spclock_todhook01/spclock_todhook01.doc
     714spclock_todhook01_SOURCES = spclock_todhook01/init.c
     715spclock_todhook01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spclock_todhook01) \
    707716        $(support_includes)
    708717endif
  • testsuites/sptests/configure.ac

    rb1b6dd71 r08bd7d3  
    117117RTEMS_TEST_CHECK([spclock_err01])
    118118RTEMS_TEST_CHECK([spclock_err02])
     119RTEMS_TEST_CHECK([spclock_todhook01])
    119120RTEMS_TEST_CHECK([spconfig01])
    120121RTEMS_TEST_CHECK([spconfig02])
Note: See TracChangeset for help on using the changeset viewer.