Gabriel Wang 2 жил өмнө
parent
commit
5660b13ea3

+ 11 - 7
GorgonMeducer.perf_counter.pdsc

@@ -16,7 +16,11 @@
   <repository type="git">https://github.com/GorgonMeducer/perf_counter.git</repository>
   
   <releases>
-    <release date="2023-06-12" version="2.2.2" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.2.2.2.pack">
+    <release date="2023-08-30" version="2.2.3" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.2.2.3.pack">
+      - Mitigate time-rolling-back issue when calling get_system_ticks in exception handlers that have higher priorities than the SysTick_Handler.
+      - Other minor updates
+    </release>
+    <release date="2023-06-12" version="2.2.2" url="https://github.com/GorgonMeducer/perf_counter/raw/124e98b3517aa46122ec7987c7726a065491823e/cmsis-pack/GorgonMeducer.perf_counter.2.2.2.pack">
       - Add __cpu_time__
       - Support reconfiguring the SysTick
       - Suppress warnings
@@ -243,7 +247,7 @@
   -->
 
     <components>
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="Core" Cvariant="Library" condition="CMSIS-CORE">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="Core" Cvariant="Library" condition="CMSIS-CORE">
               <description>A dedicated performance counter for Cortex-M systick.</description>
               <files>
                 <file category="header"     name="lib/perf_counter.h"/>
@@ -261,7 +265,7 @@
 #define __PERF_COUNTER_CFG_USE_SYSTICK_WRAPPER__ 1
               </Pre_Include_Global_h>
             </component>
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="Core" Cvariant="Source" isDefaultVariant="true" condition="CMSIS-CORE">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="Core" Cvariant="Source" isDefaultVariant="true" condition="CMSIS-CORE">
               <description>A dedicated performance counter for Cortex-M systick.</description>
               <files>
                 <file category="header"     name="lib/perf_counter.h"/>
@@ -304,7 +308,7 @@
               </Pre_Include_Global_h>
             </component>
 
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="RTX5 Patch" condition="RTX5 Patch">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="RTX5 Patch" condition="RTX5 Patch">
               <description>A Patch for RTX5</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_rtx5.c"/>
@@ -316,7 +320,7 @@
               </Pre_Include_Global_h>
             </component>
 
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="FreeRTOS Patch" condition="perf_counter">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="FreeRTOS Patch" condition="perf_counter">
               <description>A Patch for FreeRTOS</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_freertos.c"/>
@@ -339,7 +343,7 @@ extern void __freertos_evr_on_task_switched_in(void *ptTCB, unsigned int uxTopPr
               </Pre_Include_Global_h>
             </component>
             
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="RT-Thread Patch" condition="perf_counter">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="RT-Thread Patch" condition="perf_counter">
               <description>A Patch for RT-Thread</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_rt_thread.c"/>
@@ -357,7 +361,7 @@ extern void __rt_thread_scheduler_hook(struct rt_thread *from, struct rt_thread
               </Pre_Include_Global_h>
             </component>
             
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="ThreadX Patch" condition="perf_counter">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="ThreadX Patch" condition="perf_counter">
               <description>A Patch for ThreadX</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_threadx.c"/>

+ 2 - 4
README.md

@@ -1,4 +1,4 @@
-# perf_counter (v2.2.3-dev)
+# perf_counter (v2.2.3)
 A dedicated performance counter for Cortex-M Systick. It shares the SysTick with users' original SysTick function(s) without interfering with it. This library will bring new functionalities, such as performance counter,` delay_us` and `clock()` service defined in `time.h`.
 
 ### Features:
@@ -422,9 +422,7 @@ void SysTick_Handler(void)
 
 ### 3.2 Why do I see perf_counter in red in the MDK project manager?
 
-Since version v2.1.0 I removed the unnecessary bundle feature from the cmsis-pack, causing this problem if you have used the older version. 
-
-To solve this problem: 
+Since version v2.1.0 I removed the unnecessary bundle feature from the cmsis-pack. If you have used the older version, you will encounter this issue. To solve this problem: 
 
 1. please unselect ALL the performance components in RTE, press OK and close the uVision. 
 2. reopen the mdk project and select the perf_counter components in RTE

BIN
cmsis-pack/GorgonMeducer.perf_counter.2.2.2.pack → cmsis-pack/GorgonMeducer.perf_counter.2.2.3.pack


+ 11 - 7
cmsis-pack/GorgonMeducer.perf_counter.pdsc

@@ -16,7 +16,11 @@
   <repository type="git">https://github.com/GorgonMeducer/perf_counter.git</repository>
   
   <releases>
-    <release date="2023-06-12" version="2.2.2" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.2.2.2.pack">
+    <release date="2023-08-30" version="2.2.3" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.2.2.3.pack">
+      - Mitigate time-rolling-back issue when calling get_system_ticks in exception handlers that have higher priorities than the SysTick_Handler.
+      - Other minor updates
+    </release>
+    <release date="2023-06-12" version="2.2.2" url="https://github.com/GorgonMeducer/perf_counter/raw/124e98b3517aa46122ec7987c7726a065491823e/cmsis-pack/GorgonMeducer.perf_counter.2.2.2.pack">
       - Add __cpu_time__
       - Support reconfiguring the SysTick
       - Suppress warnings
@@ -243,7 +247,7 @@
   -->
 
     <components>
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="Core" Cvariant="Library" condition="CMSIS-CORE">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="Core" Cvariant="Library" condition="CMSIS-CORE">
               <description>A dedicated performance counter for Cortex-M systick.</description>
               <files>
                 <file category="header"     name="lib/perf_counter.h"/>
@@ -261,7 +265,7 @@
 #define __PERF_COUNTER_CFG_USE_SYSTICK_WRAPPER__ 1
               </Pre_Include_Global_h>
             </component>
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="Core" Cvariant="Source" isDefaultVariant="true" condition="CMSIS-CORE">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="Core" Cvariant="Source" isDefaultVariant="true" condition="CMSIS-CORE">
               <description>A dedicated performance counter for Cortex-M systick.</description>
               <files>
                 <file category="header"     name="lib/perf_counter.h"/>
@@ -304,7 +308,7 @@
               </Pre_Include_Global_h>
             </component>
 
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="RTX5 Patch" condition="RTX5 Patch">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="RTX5 Patch" condition="RTX5 Patch">
               <description>A Patch for RTX5</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_rtx5.c"/>
@@ -316,7 +320,7 @@
               </Pre_Include_Global_h>
             </component>
 
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="FreeRTOS Patch" condition="perf_counter">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="FreeRTOS Patch" condition="perf_counter">
               <description>A Patch for FreeRTOS</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_freertos.c"/>
@@ -339,7 +343,7 @@ extern void __freertos_evr_on_task_switched_in(void *ptTCB, unsigned int uxTopPr
               </Pre_Include_Global_h>
             </component>
             
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="RT-Thread Patch" condition="perf_counter">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="RT-Thread Patch" condition="perf_counter">
               <description>A Patch for RT-Thread</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_rt_thread.c"/>
@@ -357,7 +361,7 @@ extern void __rt_thread_scheduler_hook(struct rt_thread *from, struct rt_thread
               </Pre_Include_Global_h>
             </component>
             
-            <component Cclass="Utilities" Cversion="2.2.2" Cgroup="perf_counter" Csub="ThreadX Patch" condition="perf_counter">
+            <component Cclass="Utilities" Cversion="2.2.3" Cgroup="perf_counter" Csub="ThreadX Patch" condition="perf_counter">
               <description>A Patch for ThreadX</description>
               <files>
                 <file category="source"     name="lib/perf_os_patch_threadx.c"/>

BIN
lib/libperf_counter_gcc.a


+ 2 - 2
lib/perf_counter.h

@@ -35,7 +35,7 @@ extern "C" {
  */
 #define __PERF_COUNTER_VER_MAJOR__          2
 #define __PERF_COUNTER_VER_MINOR__          2
-#define __PERF_COUNTER_VER_REVISE__         2
+#define __PERF_COUNTER_VER_REVISE__         3
 
 #define __PERF_COUNTER_VER_STR__            ""
 
@@ -366,7 +366,7 @@ __asm(".global __ensure_systick_wrapper\n\t");
         SAFE_NAME(s_lTimestamp) = 0;                                            \
         SAFE_NAME(s_lTotal) = 0;                                                \
         if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) {                            \
-            printf("CPU Usage %3.2f%%\r\n", (double)__usage__);                 \
+            __perf_counter_printf__("CPU Usage %3.2f%%\r\n", (double)__usage__);                 \
         } else {                                                                \
             __VA_ARGS__                                                         \
         }                                                                       \

BIN
lib/perf_counter.lib


+ 1 - 4
lib/perf_os_patch_rt_thread.c

@@ -80,9 +80,8 @@ task_cycle_info_t * get_rtos_task_cycle_info(void)
 
 void __perf_os_patch_init(void)
 {
-#ifdef PKG_PERF_COUNTER_USING_THREAD_STATISTIC
     rt_tick_sethook(user_code_insert_to_systick_handler);
-#endif
+
 #if !defined(PKG_USING_PERF_COUNTER) || (defined(PKG_PERF_COUNTER_USING_THREAD_STATISTIC))
     rt_scheduler_sethook(__rt_thread_scheduler_hook);
 #endif
@@ -93,7 +92,6 @@ void __ensure_systick_wrapper(void)
 {
 }
 
-#ifdef PKG_PERF_COUNTER_USING_THREAD_STATISTIC
 #define DBG_TAG    "perf_counter"
 #define DBG_LVL    DBG_INFO
 #include <rtdbg.h>
@@ -106,5 +104,4 @@ static int _perf_counter_init(void)
     return 0;
 }
 INIT_PREV_EXPORT(_perf_counter_init);
-#endif /* PKG_PERF_COUNTER_USING_THREAD_STATISTIC */
 #endif /* PKG_USING_PERF_COUNTER */

+ 4 - 3
lib/perf_os_patch_threadx.c

@@ -44,9 +44,10 @@
 #define ORIG_FUNC(__NAME)       __ORIG_FUNC(__NAME)
 
 
-#ifndef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
-#error In order to use perf_counter:ThreadX-Patch, please define\
- TX_ENABLE_EXECUTION_CHANGE_NOTIFY in the project configuration.\
+#if defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) && defined(TX_EXECUTION_PROFILE_ENABLE)
+#error In order to use perf_counter:ThreadX-Patch, please define  \
+ TX_ENABLE_EXECUTION_CHANGE_NOTIFY or TX_EXECUTION_PROFILE_ENABLE \
+ in the project configuration, according to the version of thread.\
  If you don't want to use this patch, please un-select it in RTE\
  or remove this patch from the compilation.
 #endif

+ 16 - 0
perf_counter.c

@@ -169,6 +169,7 @@ extern uint32_t SystemCoreClock;
 
 /*============================ LOCAL VARIABLES ===============================*/
 volatile int64_t g_lLastTimeStamp = 0;
+volatile static int64_t s_lOldTimestamp;
 volatile int32_t g_nOffset = 0;
 volatile static int32_t s_nUSUnit = 1;
 volatile static int32_t s_nMSUnit = 1;
@@ -369,6 +370,21 @@ int64_t get_system_ticks(void)
 
     __IRQ_SAFE {
         lTemp = check_systick() + s_lSystemClockCounts;
+        
+        /* When calling get_system_ticks() in an exception handler that has a  
+         * higher priority than the SysTick_Handler, in some rare cases, the 
+         * lTemp might be temporarily smaller than the previous value (i.e. 
+         * s_lOldTimestamp), to mitigate the adverse effects of this problem,
+         * we use the following code to avoid time-rolling-back issue.
+         * 
+         * NOTE: the issue mentioned above doesn't accumulate or have long-lasting
+         *       effects.
+         */
+        if (lTemp < s_lOldTimestamp) {
+            lTemp = s_lOldTimestamp;
+        } else {
+            s_lOldTimestamp = lTemp;
+        }
     }
 
     return lTemp;

+ 1 - 1
perf_counter.h

@@ -37,7 +37,7 @@ extern "C" {
 #define __PERF_COUNTER_VER_MINOR__          2
 #define __PERF_COUNTER_VER_REVISE__         3
 
-#define __PERF_COUNTER_VER_STR__            "dev"
+#define __PERF_COUNTER_VER_STR__            ""
 
 #define __PER_COUNTER_VER__    (__PERF_COUNTER_VER_MAJOR__ * 10000ul            \
                                +__PERF_COUNTER_VER_MINOR__ * 100ul              \