add __cpu_perf__

This commit is contained in:
Gabriel Wang 2024-02-28 20:02:30 +00:00
parent 901d161b07
commit 90c90747b8
2 changed files with 41 additions and 2 deletions

View File

@ -380,14 +380,14 @@ __asm(".global __ensure_systick_wrapper\n\t");
E.g.
\code
while (1) {
__cpu_time__(100) {
__cpu_usage__(100) {
delay_us(5000);
}
delay_us(5000);
}
\endcode
*/
#define __cpu_time__(__CNT, ...) \
#define __cpu_usage__(__CNT, ...) \
static int64_t SAFE_NAME(s_lTimestamp) = 0, SAFE_NAME(s_lTotal) = 0; \
static uint32_t s_wLoopCounter = (__CNT); \
using(float __usage__ = 0, ({ \
@ -412,6 +412,8 @@ __asm(".global __ensure_systick_wrapper\n\t");
({SAFE_NAME(s_lTotal) += stop_task_cycle_counter(); \
s_wLoopCounter--;}))
#define __cpu_time__ __cpu_usage__
/*!
* \addtogroup gBasicTimerService 1.2 Timer Service
* \ingroup gBasic

View File

@ -23,6 +23,43 @@
/*============================ MACROS ========================================*/
/*============================ MACROFIED FUNCTIONS ===========================*/
#define __cpu_perf__(__str, ...) \
using( \
struct { \
uint64_t dwNoInstr; \
int64_t lCycles; \
uint32_t wCalib; \
float fCPI; \
} __PERF_INFO__ = {0}, \
({ \
__PERF_INFO__.dwNoInstr = perfc_pmu_get_instruction_count(); \
__PERF_INFO__.wCalib = perfc_pmu_get_instruction_count() \
- __PERF_INFO__.dwNoInstr; \
__PERF_INFO__.dwNoInstr = perfc_pmu_get_instruction_count(); \
}), \
({ \
__PERF_INFO__.dwNoInstr = perfc_pmu_get_instruction_count() \
- __PERF_INFO__.dwNoInstr \
- __PERF_INFO__.wCalib; \
__PERF_INFO__.fCPI = (float)( (double)__PERF_INFO__.lCycles \
/ (double)__PERF_INFO__.dwNoInstr); \
if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \
printf( "\r\n" \
"[Report for " __str "]\r\n" \
"-----------------------------------------\r\n" \
"Instruction executed: %lld\r\n" \
"Cycle Used: %lld\r\n" \
"Cycles per Instructions: %3.3f \r\n", \
__PERF_INFO__.dwNoInstr, \
__PERF_INFO__.lCycles, \
__PERF_INFO__.fCPI); \
} else { \
__VA_ARGS__ \
} \
})) \
__cycleof__("", { __PERF_INFO__.lCycles = __cycle_count__; })
/*============================ TYPES =========================================*/
typedef uint32_t perfc_global_interrupt_status_t;