Skip to content

CPU and Stack Monitoring#1711

Open
AmirTajaddodi wants to merge 23 commits intomasterfrom
amir/cpu_usage
Open

CPU and Stack Monitoring#1711
AmirTajaddodi wants to merge 23 commits intomasterfrom
amir/cpu_usage

Conversation

@AmirTajaddodi
Copy link
Contributor

@AmirTajaddodi AmirTajaddodi commented Aug 29, 2025

Changelist

The purpose of this MR is to create a functionality in which we can measure cpu and stack usage within our system for all high compute ECU such as the VC and BMS

Testing Done

Resolved Tickets

FIRM-462

Copy link
Contributor

@Lucien950 Lucien950 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basic code style things, will look at functionality later. todo validate.

@Lucien950 Lucien950 added the Drivers Shared Hardware Abstractions throughout the boards. label Sep 8, 2025
@AmirTajaddodi AmirTajaddodi force-pushed the amir/cpu_usage branch 2 times, most recently from 10637da to e1e9bdd Compare October 10, 2025 08:00
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this autogenerated? otherwise same comment about setare's freertos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is part is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait this is not autogenerated, you added these in. Is there a better place we can put these to make it more clear?

Comment on lines +97 to +106
if (runTimeStats[task].xHandle == idleHandle)
{
idle_counter = runTimeStats[task].ulRunTimeCounter;

// Calculate total current cpu usage and max cpu usage
cpu_runtime_stat->cpu_curr_usage = 1.0f - ((float)idle_counter / (float)ulHighFrequencyTimerTick);

cpu_runtime_stat->cpu_max_usage = MAX(cpu_runtime_stat->cpu_curr_usage, cpu_runtime_stat->cpu_max_usage);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw this guy as a special case of the guys below, cuz you are 1) iterating over the same list anyways and 2) would be nice to have a built in exception detector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the reason there is two loops is because I need to find the idle_counter in the array first before I start calculating the cpu load for each task. Unless I mean I can go look through the source code to see if they place idle counter at a specific index in the array

// get the idle time that we need to calculate the cpu usage associated
if (tasks_runtime_stat[task] != NULL)
{
if ((idle_counter + runTimeStats[task].ulRunTimeCounter) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait I don't get this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how you calculate cpu load is make sure time spent in the task / time of task + cpu load. So I am just doing a divide by zero check

return EXIT_CODE_OK;
}

void hw_runTimeStat_hookCallBack(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a summarization? do you do the broadcasting here as well? I think that is a key component to the design of this sturcture is how do you do your broadcasting for each task

Copy link
Contributor

@Jugveer-Sandher Jugveer-Sandher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about providing support for h5 now too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait this is not autogenerated, you added these in. Is there a better place we can put these to make it more clear?

Comment on lines +60 to +66
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
__weak void configureTimerForRunTimeStats(void) {}

__weak unsigned long getRunTimeCounterValue(void)
{
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put these in the shared file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Drivers Shared Hardware Abstractions throughout the boards.

Development

Successfully merging this pull request may close these issues.

3 participants