Changeset b9ffb624 in rtems


Ignore:
Timestamp:
Nov 30, 2018, 12:57:04 PM (8 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
577d9a5
Parents:
d0a7f03
git-author:
Sebastian Huber <sebastian.huber@…> (11/30/18 12:57:04)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/03/18 08:45:37)
Message:

Convert CPU counter ticks to/from sbintime_t

The sbintime_t is an efficient time format. Add the ability to convert
CPU counter ticks to/from sbintime_t.

Files:
3 edited

Legend:

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

    rd0a7f03 rb9ffb624  
    7373
    7474/**
    75  * @brief Reads the current counter values.
     75 * @brief Reads the current counter value.
    7676 *
    77  * @return The current counter values.
     77 * @return The current counter value.
    7878 */
    7979static inline rtems_counter_ticks rtems_counter_read( void )
     
    105105 * @brief Converts counter ticks into nanoseconds.
    106106 *
    107  * @param[in] ticks Some counter ticks.
     107 * @param[in] ticks The counter ticks value to convert.
    108108 *
    109  * @return The nanoseconds corresponding to the counter ticks.  The value is
    110  * rounded up.
     109 * @return The nanoseconds value corresponding to the counter ticks.  The value
     110 * is rounded up.
    111111 */
    112112uint64_t rtems_counter_ticks_to_nanoseconds(
     
    117117 * @brief Converts nanoseconds into counter ticks.
    118118 *
    119  * @param[in] nanoseconds Some nanoseconds.
     119 * @param[in] nanoseconds The nanoseconds value to convert.
    120120 *
    121  * @return The counter ticks corresponding to the nanoseconds.  The value is
    122  * rounded up.
     121 * @return The counter ticks value corresponding to the nanoseconds value.  The
     122 * value is rounded up.
    123123 */
    124124rtems_counter_ticks rtems_counter_nanoseconds_to_ticks(
    125125  uint32_t nanoseconds
    126126);
     127
     128/**
     129 * @brief Converts counter ticks into signed binary time (sbintime_t).
     130 *
     131 * @param[in] ticks The counter ticks value to convert.
     132 *
     133 * @return The signed binary time value corresponding to the counter ticks
     134 * value.  The value is rounded up.
     135 */
     136int64_t rtems_counter_ticks_to_sbintime( rtems_counter_ticks ticks );
     137
     138/**
     139 * @brief Converts signed binary time (sbintime_t) into counter ticks.
     140 *
     141 * @param[in] sbt The signed binary time value to convert.
     142 *
     143 * @return The counter ticks value corresponding to the nanoseconds value.  The
     144 * value is rounded up.
     145 */
     146rtems_counter_ticks rtems_counter_sbintime_to_ticks( int64_t sbt );
    127147
    128148/**
  • cpukit/sapi/src/cpucounterconverter.c

    rd0a7f03 rb9ffb624  
    2222static uint64_t from_ns_scaler;
    2323
    24 uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks counter )
     24static uint64_t to_sbt_scaler;
     25
     26static uint64_t from_sbt_scaler;
     27
     28uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks ticks )
    2529{
    26   return (uint32_t) ((counter * to_ns_scaler) >> 32);
     30  return (uint32_t) ((ticks * to_ns_scaler) >> 32);
    2731}
    2832
     
    3236}
    3337
     38int64_t rtems_counter_ticks_to_sbintime( rtems_counter_ticks ticks )
     39{
     40  return (int64_t) ((ticks * to_sbt_scaler) >> 31);
     41}
     42
     43rtems_counter_ticks rtems_counter_sbintime_to_ticks( int64_t sbt )
     44{
     45  return (rtems_counter_ticks) (((uint64_t) sbt * from_sbt_scaler) >> 31);
     46}
     47
    3448void rtems_counter_initialize_converter( uint32_t frequency )
    3549{
    3650  uint64_t ns_per_s = UINT64_C(1000000000);
     51  uint64_t bin_per_s = UINT64_C(1) << 32;
    3752
    3853  to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
    3954  from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
     55
     56  to_sbt_scaler = ((bin_per_s << 31) + frequency - 1) / frequency;
     57  from_sbt_scaler = ((UINT64_C(1) << 31) * frequency + bin_per_s - 1) / bin_per_s;
    4058}
    4159
  • testsuites/sptests/spcpucounter01/init.c

    rd0a7f03 rb9ffb624  
    5454static void test_converter(void)
    5555{
    56   CPU_Counter_ticks frequency = rtems_counter_nanoseconds_to_ticks(1000000000);
    57   uint64_t ns = rtems_counter_ticks_to_nanoseconds(frequency);
     56  CPU_Counter_ticks frequency;
     57  CPU_Counter_ticks frequency2;
     58  uint64_t ns;
     59  int64_t sbt;
     60
     61  frequency = rtems_counter_nanoseconds_to_ticks(1000000000);
     62  ns = rtems_counter_ticks_to_nanoseconds(frequency);
    5863
    5964  printf("CPU counter frequency: %" PRIu32 "Hz\n", frequency);
     
    6166
    6267  rtems_test_assert(ns == 1000000000);
     68
     69  sbt = rtems_counter_ticks_to_sbintime(frequency);
     70  rtems_test_assert(sbt == (INT64_C(1) << 32));
     71
     72  frequency2 = rtems_counter_sbintime_to_ticks(sbt);
     73  rtems_test_assert(frequency == frequency2);
    6374}
    6475
Note: See TracChangeset for help on using the changeset viewer.