Changeset 0a1f5df9 in rtems for cpukit


Ignore:
Timestamp:
May 3, 2018, 11:03:27 AM (18 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
7ee6437
Parents:
ef23838
git-author:
Sebastian Huber <sebastian.huber@…> (05/03/18 11:03:27)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/07/18 13:22:01)
Message:

Simplify _CPU_Counter_difference()

In order to simplify the use of CPU counter values it is beneficial to
have monotonic increasing values within the range of the CPU counter
ticks data type, e.g. 32-bit unsigned integer. This eases the use of
CPU counter timestamps in external tools which do not know the details
of the CPU counter hardware. The CPU counter is the fastest way to get
a time on an RTEMS system.

Such a CPU counter may be also used as the timecounter. Use it on SPARC
for this purpose to simplify the clock drivers.

Update #3456.

Location:
cpukit
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    ref23838 r0a1f5df9  
    17541754librtemscpu_a_SOURCES += score/cpu/sparc/sparc-context-volatile-clobber.S
    17551755librtemscpu_a_SOURCES += score/cpu/sparc/sparc-counter-asm.S
    1756 librtemscpu_a_SOURCES += score/cpu/sparc/sparc-counter.c
    17571756librtemscpu_a_SOURCES += score/cpu/sparc/syscall.S
    17581757librtemscpu_a_SOURCES += score/cpu/sparc/window.S
  • cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h

    ref23838 r0a1f5df9  
    12201220 * @return Returns second minus first modulo counter period.
    12211221 */
    1222 CPU_Counter_ticks _CPU_Counter_difference(
     1222static inline CPU_Counter_ticks _CPU_Counter_difference(
    12231223  CPU_Counter_ticks second,
    12241224  CPU_Counter_ticks first
    1225 );
     1225)
     1226{
     1227  return second - first;
     1228}
    12261229
    12271230#ifdef RTEMS_SMP
  • cpukit/score/cpu/or1k/include/rtems/score/cpu.h

    ref23838 r0a1f5df9  
    713713CPU_Counter_ticks _CPU_Counter_read( void );
    714714
    715 CPU_Counter_ticks _CPU_Counter_difference(
     715static inline CPU_Counter_ticks _CPU_Counter_difference(
    716716  CPU_Counter_ticks second,
    717717  CPU_Counter_ticks first
    718 );
     718)
     719{
     720  return second - first;
     721}
    719722
    720723/** Type that can store a 32-bit integer or a pointer. */
  • cpukit/score/cpu/sparc/include/rtems/score/cpu.h

    ref23838 r0a1f5df9  
    11041104typedef CPU_Counter_ticks ( *SPARC_Counter_read )( void );
    11051105
    1106 typedef CPU_Counter_ticks ( *SPARC_Counter_difference )(
    1107   CPU_Counter_ticks second,
    1108   CPU_Counter_ticks first
    1109 );
    1110 
    11111106/*
    11121107 * The SPARC processors supported by RTEMS have no built-in CPU counter
    11131108 * support.  We have to use some hardware counter module for this purpose, for
    11141109 * example the GPTIMER instance used by the clock driver.  The BSP must provide
    1115  * an implementation of the CPU counter read and difference functions.  This
    1116  * allows the use of dynamic hardware enumeration.
     1110 * an implementation of the CPU counter read function.  This allows the use of
     1111 * dynamic hardware enumeration.
    11171112 */
    11181113typedef struct {
    1119   SPARC_Counter_read                counter_read;
    1120   SPARC_Counter_difference          counter_difference;
    1121   volatile const CPU_Counter_ticks *counter_address;
     1114  SPARC_Counter_read                read_isr_disabled;
     1115  SPARC_Counter_read                read;
     1116  volatile const CPU_Counter_ticks *counter_register;
     1117  volatile const uint32_t          *pending_register;
     1118  uint32_t                          pending_mask;
     1119  CPU_Counter_ticks                 accumulated;
     1120  CPU_Counter_ticks                 interval;
    11221121} SPARC_Counter;
    11231122
     
    11261125static inline CPU_Counter_ticks _CPU_Counter_read( void )
    11271126{
    1128   return ( *_SPARC_Counter.counter_read )();
     1127  return ( *_SPARC_Counter.read )();
    11291128}
    11301129
     
    11341133)
    11351134{
    1136   return ( *_SPARC_Counter.counter_difference )( second, first );
     1135  return second - first;
    11371136}
    11381137
  • cpukit/score/cpu/sparc/include/rtems/score/sparcimpl.h

    ref23838 r0a1f5df9  
    11/*
    2  * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2016, 2018 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    2222#endif /* __cplusplus */
    2323
     24struct timecounter;
     25
    2426/*
    2527 * Provides a mutable alias to _SPARC_Counter for use in
     
    2931extern SPARC_Counter _SPARC_Counter_mutable;
    3032
    31 CPU_Counter_ticks _SPARC_Counter_read_address( void );
     33void _SPARC_Counter_at_tick_clock( void );
     34
     35CPU_Counter_ticks _SPARC_Counter_read_default( void );
     36
     37CPU_Counter_ticks _SPARC_Counter_read_up( void );
     38
     39CPU_Counter_ticks _SPARC_Counter_read_down( void );
     40
     41CPU_Counter_ticks _SPARC_Counter_read_clock_isr_disabled( void );
     42
     43CPU_Counter_ticks _SPARC_Counter_read_clock( void );
    3244
    3345CPU_Counter_ticks _SPARC_Counter_read_asr23( void );
    3446
    35 CPU_Counter_ticks _SPARC_Counter_difference_normal(
    36   CPU_Counter_ticks second,
    37   CPU_Counter_ticks first
    38 );
     47uint32_t _SPARC_Get_timecount_up( struct timecounter * );
    3948
    40 CPU_Counter_ticks _SPARC_Counter_difference_clock_period(
    41   CPU_Counter_ticks second,
    42   CPU_Counter_ticks first
    43 );
     49uint32_t _SPARC_Get_timecount_down( struct timecounter * );
    4450
    45 /*
    46  * Returns always a value of one regardless of the parameters.  This prevents
    47  * an infinite loop in rtems_counter_delay_ticks().  Its only a reasonably safe
    48  * default.
    49  */
    50 CPU_Counter_ticks _SPARC_Counter_difference_one(
    51   CPU_Counter_ticks second,
    52   CPU_Counter_ticks first
    53 );
     51uint32_t _SPARC_Get_timecount_clock( struct timecounter * );
    5452
    55 static inline void _SPARC_Counter_initialize(
    56   SPARC_Counter_read                counter_read,
    57   SPARC_Counter_difference          counter_difference,
    58   volatile const CPU_Counter_ticks *counter_address
    59 )
    60 {
    61   _SPARC_Counter_mutable.counter_read = counter_read;
    62   _SPARC_Counter_mutable.counter_difference = counter_difference;
    63   _SPARC_Counter_mutable.counter_address = counter_address;
    64 }
     53uint32_t _SPARC_Get_timecount_asr23( struct timecounter * );
    6554
    6655/*
     
    7665    "\t.align\t4\n" \
    7766    "\t.type\t_SPARC_Counter, #object\n" \
    78     "\t.size\t_SPARC_Counter, 12\n" \
     67    "\t.size\t_SPARC_Counter, 28\n" \
    7968    "_SPARC_Counter:\n" \
    8069    "_SPARC_Counter_mutable:\n" \
    81     "\t.long\t_SPARC_Counter_read_address\n" \
    82     "\t.long\t_SPARC_Counter_difference_one\n" \
    83     "\t.long\t_SPARC_Counter\n" \
     70    "\t.long\t_SPARC_Counter_read_default\n" \
     71    "\t.long\t_SPARC_Counter_read_default\n" \
     72    "\t.long\t0\n" \
     73    "\t.long\t0\n" \
     74    "\t.long\t0\n" \
     75    "\t.long\t0\n" \
     76    "\t.long\t0\n" \
    8477    "\t.previous\n" \
    8578  )
  • cpukit/score/cpu/sparc/sparc-counter-asm.S

    ref23838 r0a1f5df9  
    11/*
    2  * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2016, 2018 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1919#include <rtems/asm.h>
    2020
     21        /*
     22         * All functions except _SPARC_Counter_read_clock() in this module are
     23         * sometimes called with traps disabled.
     24         */
     25
    2126        .section        ".text"
    2227        .align  4
    2328
    24         PUBLIC(_SPARC_Counter_read_address)
    25 SYM(_SPARC_Counter_read_address):
     29        PUBLIC(_SPARC_Counter_read_default)
     30SYM(_SPARC_Counter_read_default):
     31        sethi   %hi(_SPARC_Counter + 12), %o1
     32        ld      [%o1 + %lo(_SPARC_Counter + 12)], %o0
     33        add     %o0, 1, %o0
     34        jmp     %o7 + 8
     35         st     %o0, [%o1 + %lo(_SPARC_Counter + 12)]
     36
     37        PUBLIC(_SPARC_Counter_read_up)
     38        PUBLIC(_SPARC_Get_timecount_up)
     39SYM(_SPARC_Counter_read_up):
     40SYM(_SPARC_Get_timecount_up):
    2641        sethi   %hi(_SPARC_Counter + 8), %o0
    2742        ld      [%o0 + %lo(_SPARC_Counter + 8)], %o0
     
    2944         ld     [%o0], %o0
    3045
     46        PUBLIC(_SPARC_Counter_read_down)
     47        PUBLIC(_SPARC_Get_timecount_down)
     48SYM(_SPARC_Counter_read_down):
     49SYM(_SPARC_Get_timecount_down):
     50        sethi   %hi(_SPARC_Counter + 8), %o0
     51        ld      [%o0 + %lo(_SPARC_Counter + 8)], %o0
     52        ld      [%o0], %o0
     53        jmp     %o7 + 8
     54         xnor   %g0, %o0, %o0
     55
     56        /*
     57         * For the corresponding C code is something like this:
     58         *
     59         * CPU_Counter_ticks _SPARC_Counter_read_clock_isr_disabled( void )
     60         * {
     61         *   const SPARC_Counter *ctr;
     62         *   CPU_Counter_ticks    ticks;
     63         *   CPU_Counter_ticks    accumulated;
     64         *
     65         *   ctr = &_SPARC_Counter;
     66         *   ticks = *ctr->counter_register;
     67         *   accumulated = ctr->accumulated;
     68         *
     69         *   if ( ( *ctr->pending_register & ctr->pending_mask ) != 0 ) {
     70         *     ticks = *ctr->counter_register;
     71         *     accumulated += ctr->interval;
     72         *   }
     73         *
     74         *   return accumulated - ticks;
     75         * }
     76         */
     77        PUBLIC(_SPARC_Counter_read_clock_isr_disabled)
     78SYM(_SPARC_Counter_read_clock_isr_disabled):
     79        sethi   %hi(_SPARC_Counter), %o5
     80        or      %o5, %lo(_SPARC_Counter), %o5
     81        ld      [%o5 + 8], %o3
     82        ld      [%o5 + 12], %o4
     83        ld      [%o5 + 16], %o2
     84        ld      [%o3], %o0
     85        ld      [%o4], %o1
     86        btst    %o1, %o2
     87        bne     .Lpending_isr_disabled
     88         ld     [%o5 + 20], %o4
     89        jmp     %o7 + 8
     90         sub    %o4, %o0, %o0
     91.Lpending_isr_disabled:
     92        ld      [%o5 + 24], %o5
     93        ld      [%o3], %o0
     94        add     %o4, %o5, %o4
     95        jmp     %o7 + 8
     96         sub    %o4, %o0, %o0
     97
     98        /*
     99         * For the corresponding C code see
     100         * _SPARC_Counter_read_clock_isr_disabled() above.
     101         */
     102        PUBLIC(_SPARC_Counter_read_clock)
     103        PUBLIC(_SPARC_Get_timecount_clock)
     104SYM(_SPARC_Counter_read_clock):
     105SYM(_SPARC_Get_timecount_clock):
     106        sethi   %hi(_SPARC_Counter), %o5
     107        or      %o5, %lo(_SPARC_Counter), %o5
     108        ta      SPARC_SWTRAP_IRQDIS
     109        ld      [%o5 + 8], %o3
     110        ld      [%o5 + 12], %o4
     111        ld      [%o5 + 16], %o2
     112        ld      [%o3], %o0
     113        ld      [%o4], %o1
     114        btst    %o1, %o2
     115        bne     .Lpending
     116         ld     [%o5 + 20], %o4
     117        ta      SPARC_SWTRAP_IRQEN
     118        jmp     %o7 + 8
     119         sub    %o4, %o0, %o0
     120.Lpending:
     121        ld      [%o5 + 24], %o5
     122        ld      [%o3], %o0
     123        ta      SPARC_SWTRAP_IRQEN
     124        add     %o4, %o5, %o4
     125        jmp     %o7 + 8
     126         sub    %o4, %o0, %o0
     127
    31128        PUBLIC(_SPARC_Counter_read_asr23)
     129        PUBLIC(_SPARC_Get_timecount_asr23)
    32130SYM(_SPARC_Counter_read_asr23):
     131SYM(_SPARC_Get_timecount_asr23):
    33132        jmp     %o7 + 8
    34133         mov    %asr23, %o0
Note: See TracChangeset for help on using the changeset viewer.