[PATCH] score: Remove _CPU_Counter_difference()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Sep 8 07:44:42 UTC 2022


All CPU ports used the same _CPU_Counter_difference() implementation.  Remove
this CPU port interface and mandate a monotonically increasing CPU counter.

Close #3456.
---
 cpukit/include/rtems/counter.h                |  8 ++--
 cpukit/include/rtems/score/profiling.h        |  5 +--
 cpukit/include/rtems/score/smplockstats.h     |  4 +-
 .../cpu/aarch64/include/rtems/score/cpu.h     |  8 ----
 .../score/cpu/arm/include/rtems/score/cpu.h   |  8 ----
 .../score/cpu/bfin/include/rtems/score/cpu.h  |  8 ----
 .../score/cpu/i386/include/rtems/score/cpu.h  |  8 ----
 .../score/cpu/lm32/include/rtems/score/cpu.h  |  8 ----
 .../score/cpu/m68k/include/rtems/score/cpu.h  |  8 ----
 .../cpu/microblaze/include/rtems/score/cpu.h  |  8 ----
 .../score/cpu/mips/include/rtems/score/cpu.h  |  8 ----
 .../score/cpu/moxie/include/rtems/score/cpu.h |  8 ----
 .../score/cpu/nios2/include/rtems/score/cpu.h |  8 ----
 .../cpu/no_cpu/include/rtems/score/cpu.h      | 39 ++++++-------------
 .../score/cpu/or1k/include/rtems/score/cpu.h  |  8 ----
 .../cpu/powerpc/include/rtems/score/cpu.h     |  8 ----
 .../score/cpu/riscv/include/rtems/score/cpu.h |  8 ----
 cpukit/score/cpu/sh/include/rtems/score/cpu.h |  8 ----
 .../score/cpu/sparc/include/rtems/score/cpu.h |  8 ----
 .../cpu/sparc64/include/rtems/score/cpu.h     |  8 ----
 .../score/cpu/v850/include/rtems/score/cpu.h  |  8 ----
 .../cpu/x86_64/include/rtems/score/cpu.h      |  9 -----
 cpukit/score/src/profilingisrentryexit.c      |  5 +--
 23 files changed, 19 insertions(+), 187 deletions(-)

diff --git a/cpukit/include/rtems/counter.h b/cpukit/include/rtems/counter.h
index ad6d5517a3..61a0677bd3 100644
--- a/cpukit/include/rtems/counter.h
+++ b/cpukit/include/rtems/counter.h
@@ -99,20 +99,20 @@ static inline rtems_counter_ticks rtems_counter_read( void )
  * @brief Returns the difference between the second and first CPU counter
  * value.
  *
- * This operation may be carried out as a modulo operation depending on the
- * range of the CPU counter device.
+ * This function is provided for backward compatibility.
+ * You may use "second - first" directly in the code.
  *
  * @param[in] second The second CPU counter value.
  * @param[in] first The first CPU counter value.
  *
- * @return Returns second minus first modulo counter period.
+ * @return Returns second minus first.
  */
 static inline rtems_counter_ticks rtems_counter_difference(
   rtems_counter_ticks second,
   rtems_counter_ticks first
 )
 {
-  return _CPU_Counter_difference( second, first );
+  return second - first;
 }
 
 /**
diff --git a/cpukit/include/rtems/score/profiling.h b/cpukit/include/rtems/score/profiling.h
index 90e470a775..90d441b0d0 100644
--- a/cpukit/include/rtems/score/profiling.h
+++ b/cpukit/include/rtems/score/profiling.h
@@ -129,10 +129,7 @@ static inline void _Profiling_Thread_dispatch_enable(
   if ( new_thread_dispatch_disable_level == 0 ) {
     Per_CPU_Stats *stats = &cpu->Stats;
     CPU_Counter_ticks now = _CPU_Counter_read();
-    CPU_Counter_ticks delta = _CPU_Counter_difference(
-      now,
-      stats->thread_dispatch_disabled_instant
-    );
+    CPU_Counter_ticks delta = now - stats->thread_dispatch_disabled_instant;
 
     stats->total_thread_dispatch_disabled_time += delta;
 
diff --git a/cpukit/include/rtems/score/smplockstats.h b/cpukit/include/rtems/score/smplockstats.h
index 102fb6eac5..cebfb80bd6 100644
--- a/cpukit/include/rtems/score/smplockstats.h
+++ b/cpukit/include/rtems/score/smplockstats.h
@@ -235,7 +235,7 @@ static inline void _SMP_lock_Stats_acquire_end(
 
   second = _CPU_Counter_read();
   stats_context->acquire_instant = second;
-  delta = _CPU_Counter_difference( second, acquire_context->first );
+  delta = second - acquire_context->first;
 
   ++stats->usage_count;
 
@@ -270,7 +270,7 @@ static inline void _SMP_lock_Stats_release_update(
   stats = stats_context->stats;
   first = stats_context->acquire_instant;
   second = _CPU_Counter_read();
-  delta = _CPU_Counter_difference( second, first );
+  delta = second - first;
 
   stats->total_section_time += delta;
 
diff --git a/cpukit/score/cpu/aarch64/include/rtems/score/cpu.h b/cpukit/score/cpu/aarch64/include/rtems/score/cpu.h
index 282977853f..da91ba96e1 100644
--- a/cpukit/score/cpu/aarch64/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/aarch64/include/rtems/score/cpu.h
@@ -384,14 +384,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 void *_CPU_Thread_Idle_body( uintptr_t ignored );
 
 typedef enum {
diff --git a/cpukit/score/cpu/arm/include/rtems/score/cpu.h b/cpukit/score/cpu/arm/include/rtems/score/cpu.h
index 7ac180ac26..3715031d06 100644
--- a/cpukit/score/cpu/arm/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/arm/include/rtems/score/cpu.h
@@ -574,14 +574,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 void *_CPU_Thread_Idle_body( uintptr_t ignored );
 
 #if defined(ARM_MULTILIB_ARCH_V4)
diff --git a/cpukit/score/cpu/bfin/include/rtems/score/cpu.h b/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
index 91b1a91b07..f49f8928d3 100644
--- a/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
@@ -605,14 +605,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/i386/include/rtems/score/cpu.h b/cpukit/score/cpu/i386/include/rtems/score/cpu.h
index 1de9b7544c..715180fbd7 100644
--- a/cpukit/score/cpu/i386/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/i386/include/rtems/score/cpu.h
@@ -651,14 +651,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /**@}**/
 
 /** Type that can store a 32-bit integer or a pointer. */
diff --git a/cpukit/score/cpu/lm32/include/rtems/score/cpu.h b/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
index 9bceb3b892..073e2da733 100644
--- a/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
@@ -745,14 +745,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/m68k/include/rtems/score/cpu.h b/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
index e72b735501..2f9869a959 100644
--- a/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
@@ -621,14 +621,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 #if (M68K_HAS_FPSP_PACKAGE == 1)
 /*
  *  Hooks for the Floating Point Support Package (FPSP) provided by Motorola
diff --git a/cpukit/score/cpu/microblaze/include/rtems/score/cpu.h b/cpukit/score/cpu/microblaze/include/rtems/score/cpu.h
index a486c3d2b3..f65c18dde3 100644
--- a/cpukit/score/cpu/microblaze/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/microblaze/include/rtems/score/cpu.h
@@ -450,14 +450,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 void *_CPU_Thread_Idle_body( uintptr_t ignored );
 
 void bsp_interrupt_dispatch( uint32_t source );
diff --git a/cpukit/score/cpu/mips/include/rtems/score/cpu.h b/cpukit/score/cpu/mips/include/rtems/score/cpu.h
index fdb7ee4d73..4dbb053584 100644
--- a/cpukit/score/cpu/mips/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/mips/include/rtems/score/cpu.h
@@ -835,14 +835,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/moxie/include/rtems/score/cpu.h b/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
index 18329a5b3d..3a8a3087c6 100644
--- a/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
@@ -532,14 +532,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/nios2/include/rtems/score/cpu.h b/cpukit/score/cpu/nios2/include/rtems/score/cpu.h
index d7c484f9bc..81f454fd09 100644
--- a/cpukit/score/cpu/nios2/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/nios2/include/rtems/score/cpu.h
@@ -353,14 +353,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
index 5403cc8a10..63829b5272 100644
--- a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
@@ -1293,44 +1293,27 @@ static inline uint32_t CPU_swap_u32(
 typedef uint32_t CPU_Counter_ticks;
 
 /**
- * @brief Returns the current CPU counter frequency in Hz.
+ * @brief Gets the current CPU counter frequency in Hz.
  *
- * @return The current CPU counter frequency in Hz.
+ * @return Returns the current CPU counter frequency in Hz.
  */
 uint32_t _CPU_Counter_frequency( void );
 
 /**
- * @brief Returns the current CPU counter value.
+ * @brief Gets the current CPU counter value.
  *
- * A CPU counter is some free-running counter.  It ticks usually with a
- * frequency close to the CPU or system bus clock.  The board support package
- * must ensure that this function works before the RTEMS initialization.
- * Otherwise invalid profiling statistics will be gathered.
+ * A CPU counter should be some monotonically increasing free-running counter.
+ * It ticks usually with a frequency close to the CPU or system bus clock.  The
+ * counter should not be affected by power saving states so that it can be used
+ * for timestamps.  The CPU counter should be initialized at the
+ * RTEMS_SYSINIT_CPU_COUNTER initialization step if necessary.  If
+ * RTEMS_PROFILING is enabled, the CPU counter may have to work very early in
+ * the system initialization to avoid invalid profiling statistics.
  *
- * @return The current CPU counter value.
+ * @return Returns the current CPU counter value.
  */
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-/**
- * @brief Returns the difference between the second and first CPU counter
- * value.
- *
- * This operation may be carried out as a modulo operation depending on the
- * range of the CPU counter device.
- *
- * @param[in] second The second CPU counter value.
- * @param[in] first The first CPU counter value.
- *
- * @return Returns second minus first modulo counter period.
- */
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 #ifdef RTEMS_SMP
   /**
    * @brief Performs CPU specific SMP initialization in the context of the boot
diff --git a/cpukit/score/cpu/or1k/include/rtems/score/cpu.h b/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
index 83d46010ba..8d9aaee4f9 100644
--- a/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
@@ -578,14 +578,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
index 42900aeb1d..52fbddf5ba 100644
--- a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
@@ -729,14 +729,6 @@ static inline CPU_Counter_ticks _CPU_Counter_read( void )
   return value;
 }
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 #endif /* ASM */
 
 
diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
index 471c6c6c3e..03f2ed8120 100644
--- a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
@@ -459,14 +459,6 @@ extern volatile uint32_t * const _RISCV_Counter;
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 #ifdef RTEMS_SMP
 
 uint32_t _CPU_SMP_Initialize( void );
diff --git a/cpukit/score/cpu/sh/include/rtems/score/cpu.h b/cpukit/score/cpu/sh/include/rtems/score/cpu.h
index 2805e4244c..9ed7d584ff 100644
--- a/cpukit/score/cpu/sh/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sh/include/rtems/score/cpu.h
@@ -576,14 +576,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
index 225eaf96c6..c90071e01d 100644
--- a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
@@ -1158,14 +1158,6 @@ static inline CPU_Counter_ticks _CPU_Counter_read( void )
   return ( *_SPARC_Counter.read )();
 }
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
index 03f6e2aa63..eefe8f0510 100644
--- a/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
@@ -934,14 +934,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/v850/include/rtems/score/cpu.h b/cpukit/score/cpu/v850/include/rtems/score/cpu.h
index 958bed5dc3..76fd7869a3 100644
--- a/cpukit/score/cpu/v850/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/v850/include/rtems/score/cpu.h
@@ -674,14 +674,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 /** Type that can store a 32-bit integer or a pointer. */
 typedef uintptr_t CPU_Uint32ptr;
 
diff --git a/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h b/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
index bea8e05e39..23891acff3 100644
--- a/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
@@ -304,15 +304,6 @@ uint32_t _CPU_Counter_frequency( void );
 
 CPU_Counter_ticks _CPU_Counter_read( void );
 
-
-static inline CPU_Counter_ticks _CPU_Counter_difference(
-  CPU_Counter_ticks second,
-  CPU_Counter_ticks first
-)
-{
-  return second - first;
-}
-
 #ifdef RTEMS_SMP
    *
   uint32_t _CPU_SMP_Initialize( void );
diff --git a/cpukit/score/src/profilingisrentryexit.c b/cpukit/score/src/profilingisrentryexit.c
index 2619bdc0c0..2c33182056 100644
--- a/cpukit/score/src/profilingisrentryexit.c
+++ b/cpukit/score/src/profilingisrentryexit.c
@@ -54,10 +54,7 @@ void _Profiling_Outer_most_interrupt_entry_and_exit(
   _Assert( cpu->isr_nest_level == 1 );
 
   stats = &cpu->Stats;
-  delta = _CPU_Counter_difference(
-    interrupt_exit_instant,
-    interrupt_entry_instant
-  );
+  delta = interrupt_exit_instant - interrupt_entry_instant;
   ++stats->interrupt_count;
   stats->total_interrupt_time += delta;
 
-- 
2.35.3



More information about the devel mailing list