Changeset 1ef8e4a8 in rtems


Ignore:
Timestamp:
Apr 27, 2016, 8:07:56 PM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
500a8e9c
Parents:
3888771
git-author:
Sebastian Huber <sebastian.huber@…> (04/27/16 20:07:56)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/02/16 05:46:16)
Message:

score: Avoid Giant lock for set time of day

Update #2555.
Update #2630.

Location:
cpukit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/src/adjtime.c

    r3888771 r1ef8e4a8  
    8383   * Now apply the adjustment
    8484   */
    85   _TOD_Adjust( delta_as_timestamp );
     85  _TOD_Adjust( &delta_as_timestamp );
    8686
    8787  return 0;
  • cpukit/posix/src/clocksettime.c

    r3888771 r1ef8e4a8  
    2020
    2121#include <time.h>
    22 #include <errno.h>
    2322
    24 #include <rtems/score/threaddispatch.h>
    2523#include <rtems/score/todimpl.h>
    2624#include <rtems/seterr.h>
     
    4240      rtems_set_errno_and_return_minus_one( EINVAL );
    4341
    44     _Thread_Disable_dispatch();
    45       _TOD_Set_with_timespec( tp );
    46     _Thread_Enable_dispatch();
     42    _TOD_Set_with_timespec( tp );
    4743  }
    4844#ifdef _POSIX_CPUTIME
  • cpukit/rtems/src/clockset.c

    r3888771 r1ef8e4a8  
    2020
    2121#include <rtems/rtems/clock.h>
    22 #include <rtems/score/threaddispatch.h>
    2322#include <rtems/score/todimpl.h>
    2423#include <rtems/config.h>
     
    3332  if ( _TOD_Validate( tod ) ) {
    3433    Timestamp_Control tod_as_timestamp;
    35     uint32_t seconds = _TOD_To_seconds( tod );
    36     uint32_t nanoseconds = tod->ticks
     34    uint32_t          seconds;
     35    uint32_t          nanoseconds;
     36    ISR_lock_Context  lock_context;
     37
     38    seconds = _TOD_To_seconds( tod );
     39    nanoseconds = tod->ticks
    3740      * rtems_configuration_get_nanoseconds_per_tick();
    38 
    3941    _Timestamp_Set( &tod_as_timestamp, seconds, nanoseconds );
    4042
    41     _Thread_Disable_dispatch();
    42       _TOD_Set( &tod_as_timestamp );
    43     _Thread_Enable_dispatch();
     43    _TOD_Lock();
     44    _TOD_Acquire( &lock_context );
     45    _TOD_Set( &tod_as_timestamp, &lock_context );
     46    _TOD_Unlock();
    4447
    4548    return RTEMS_SUCCESSFUL;
  • cpukit/score/include/rtems/score/timecounterimpl.h

    r3888771 r1ef8e4a8  
    3737 */
    3838
    39 void _Timecounter_Set_clock( const struct timespec *ts );
     39void _Timecounter_Set_clock(
     40  const struct bintime *bt,
     41  ISR_lock_Context     *lock_context
     42);
    4043
    4144/** @} */
  • cpukit/score/include/rtems/score/todimpl.h

    r3888771 r1ef8e4a8  
    2020
    2121#include <rtems/score/tod.h>
     22#include <rtems/score/apimutex.h>
    2223#include <rtems/score/timestamp.h>
    2324#include <rtems/score/timecounterimpl.h>
     
    143144extern TOD_Control _TOD;
    144145
     146static inline void _TOD_Lock( void )
     147{
     148  /* FIXME: https://devel.rtems.org/ticket/2630 */
     149  _API_Mutex_Lock( _Once_Mutex );
     150}
     151
     152static inline void _TOD_Unlock( void )
     153{
     154  _API_Mutex_Unlock( _Once_Mutex );
     155}
     156
     157static inline void _TOD_Acquire( ISR_lock_Context *lock_context )
     158{
     159  _Timecounter_Acquire( lock_context );
     160}
     161
    145162/**
    146163 * @brief Sets the time of day.
     164 *
     165 * The caller must be the owner of the TOD lock.
    147166 *
    148167 * @param tod_as_timestamp The new time of day in timestamp format representing
    149168 *   the time since UNIX Epoch.
     169 * @param lock_context The ISR lock context used for the corresponding
     170 *   _TOD_Acquire().  The caller must be the owner of the TOD lock.  This
     171 *   function will release the TOD lock.
    150172 */
    151173void _TOD_Set(
    152   const Timestamp_Control *tod_as_timestamp
     174  const Timestamp_Control *tod_as_timestamp,
     175  ISR_lock_Context        *lock_context
    153176);
    154177
     
    165188{
    166189  Timestamp_Control tod_as_timestamp;
     190  ISR_lock_Context  lock_context;
    167191
    168192  _Timestamp_Set(
     
    171195    tod_as_timespec->tv_nsec
    172196  );
    173   _TOD_Set( &tod_as_timestamp );
     197
     198  _TOD_Lock();
     199  _TOD_Acquire( &lock_context );
     200  _TOD_Set( &tod_as_timestamp, &lock_context );
     201  _TOD_Unlock();
    174202}
    175203
     
    297325 */
    298326void _TOD_Adjust(
    299   const Timestamp_Control timestamp
     327  const Timestamp_Control *delta
    300328);
    301329
  • cpukit/score/src/coretodadjust.c

    r3888771 r1ef8e4a8  
    1919#endif
    2020
    21 #include <rtems/score/threaddispatch.h>
    2221#include <rtems/score/todimpl.h>
    2322
    2423void _TOD_Adjust(
    25   const Timestamp_Control delta
     24  const Timestamp_Control *delta
    2625)
    2726{
    2827  Timestamp_Control tod;
     28  ISR_lock_Context  lock_context;
    2929
    3030  /*
     
    3636   */
    3737
    38   /*
    39    * This prevents context switches while we are adjusting the TOD
    40    */
    41   _Thread_Disable_dispatch();
    42 
    43     _TOD_Get( &tod );
    44 
    45     _Timestamp_Add_to( &tod, &delta );
    46 
    47     _TOD_Set( &tod );
    48 
    49   _Thread_Enable_dispatch();
     38  _TOD_Lock();
     39  _TOD_Acquire( &lock_context );
     40  _TOD_Get( &tod );
     41  _Timestamp_Add_to( &tod, delta );
     42  _TOD_Set( &tod, &lock_context );
     43  _TOD_Unlock();
    5044}
  • cpukit/score/src/coretodset.c

    r3888771 r1ef8e4a8  
    2020
    2121#include <rtems/score/todimpl.h>
    22 #include <rtems/score/threaddispatch.h>
     22#include <rtems/score/assert.h>
    2323#include <rtems/score/watchdogimpl.h>
    2424
    2525void _TOD_Set(
    26   const Timestamp_Control *tod_as_timestamp
     26  const Timestamp_Control *tod_as_timestamp,
     27  ISR_lock_Context        *lock_context
    2728)
    2829{
     
    3233  uint32_t        cpu_index;
    3334
     35  _Assert( _API_Mutex_Is_owner( _Once_Mutex ) );
     36
     37  _Timecounter_Set_clock( tod_as_timestamp, lock_context );
     38
    3439  _Timestamp_To_timespec( tod_as_timestamp, &tod_as_timespec );
    35 
    36   _Thread_Disable_dispatch();
    37 
    38   _Timecounter_Set_clock( &tod_as_timespec );
    39 
    4040  tod_as_ticks = _Watchdog_Ticks_from_timespec( &tod_as_timespec );
    4141  cpu_count = _SMP_Get_processor_count();
     
    4848
    4949  _TOD.is_set = true;
    50 
    51   _Thread_Enable_dispatch();
    5250}
  • cpukit/score/src/kern_tc.c

    r3888771 r1ef8e4a8  
    3434#define boottimebin _Timecounter_Boottimebin
    3535#include <rtems/score/timecounterimpl.h>
     36#include <rtems/score/smp.h>
    3637#include <rtems/score/todimpl.h>
    3738#include <rtems/score/watchdogimpl.h>
     
    216217#ifndef __rtems__
    217218static void cpu_tick_calibrate(int);
     219#else /* __rtems__ */
     220static void _Timecounter_Windup(ISR_lock_Context *lock_context);
    218221#endif /* __rtems__ */
    219222
     
    13451348 * XXX: not locked.
    13461349 */
    1347 #ifndef __rtems__
    1348 void
     1350void
     1351#ifndef __rtems__
    13491352tc_setclock(struct timespec *ts)
    13501353#else /* __rtems__ */
    1351 void
    1352 _Timecounter_Set_clock(const struct timespec *ts)
     1354_Timecounter_Set_clock(const struct bintime *_bt,
     1355    ISR_lock_Context *lock_context)
    13531356#endif /* __rtems__ */
    13541357{
     
    13611364        cpu_tick_calibrate(1);
    13621365        nanotime(&tbef);
    1363 #endif /* __rtems__ */
    13641366        timespec2bintime(ts, &bt);
     1367#else /* __rtems__ */
     1368        bt = *_bt;
     1369#endif /* __rtems__ */
    13651370        binuptime(&bt2);
    13661371        bintime_sub(&bt, &bt2);
     
    13691374#ifndef __rtems__
    13701375        bintime2timeval(&bt, &boottime);
    1371 #endif /* __rtems__ */
    13721376
    13731377        /* XXX fiddle all the little crinkly bits around the fiords... */
    13741378        tc_windup();
    1375 #ifndef __rtems__
    13761379        nanotime(&taft);
    13771380        if (timestepwarnings) {
     
    13831386        }
    13841387        cpu_tick_calibrate(1);
     1388#else /* __rtems__ */
     1389        _Timecounter_Windup(lock_context);
    13851390#endif /* __rtems__ */
    13861391}
     
    13931398static void
    13941399tc_windup(void)
     1400#ifdef __rtems__
     1401{
     1402        ISR_lock_Context lock_context;
     1403
     1404        _Timecounter_Acquire(&lock_context);
     1405        _Timecounter_Windup(&lock_context);
     1406}
     1407
     1408static void
     1409_Timecounter_Windup(ISR_lock_Context *lock_context)
     1410#endif /* __rtems__ */
    13951411{
    13961412        struct bintime bt;
     
    14001416        int i;
    14011417        time_t t;
    1402 #ifdef __rtems__
    1403         ISR_lock_Context lock_context;
    1404 
    1405         _Timecounter_Acquire(&lock_context);
    1406 #endif /* __rtems__ */
    14071418
    14081419        /*
     
    15661577#endif /* __rtems__ */
    15671578#ifdef __rtems__
    1568         _Timecounter_Release(&lock_context);
     1579        _Timecounter_Release(lock_context);
    15691580#endif /* __rtems__ */
    15701581}
     
    19791990                return;
    19801991        count = 0;
     1992        tc_windup();
     1993}
    19811994#else /* __rtems__ */
    1982 #include <rtems/score/smp.h>
    19831995void
    19841996_Timecounter_Tick(void)
     
    19871999
    19882000        if (_Per_CPU_Is_boot_processor(cpu_self)) {
    1989 #endif /* __rtems__ */
    1990         tc_windup();
    1991 #ifdef __rtems__
    1992         };
     2001                tc_windup();
     2002        }
    19932003
    19942004        _Watchdog_Tick(cpu_self);
    1995 #endif /* __rtems__ */
    1996 }
    1997 #ifdef __rtems__
     2005}
     2006
    19982007void
    19992008_Timecounter_Tick_simple(uint32_t delta, uint32_t offset,
Note: See TracChangeset for help on using the changeset viewer.