Skip to content

Commit

Permalink
add __cpu_perf__
Browse files Browse the repository at this point in the history
  • Loading branch information
GorgonMeducer committed Feb 28, 2024
1 parent 901d161 commit 90c9074
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ({ \
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions perfc_port_pmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 90c9074

Please sign in to comment.