I have asked a similar question which everybody helped greately. The original thread is here: https://www.xcore.com/forum/viewtopic.php?f=26&t=4983
What I need to get as an info is how the core is being used at that instant, with what percentage. (e.g. Like in Raspberry Pi, tells you 63% of cpu is used).
Can anybody suggest any method to extend function in above thread for this purpose. Any ideas are appreciated, I am not asking for a full code necessarily.
Thanks in advance,
Best regards
Original final code:
Code: Select all
[[combinable]]
void monitorCores(client core_stats_if core_stats_interface)
{
short int t;
timer poll_tmr, print_tmr;
int poll_time, print_time;
poll_tmr :> poll_time;
print_time = poll_time + PRINT_MS;
float core_busy[8];
float core_idle[8];
short int core_usage[8];
for (t = 0; t <= 7; t++) {
core_busy[t] = 0;
core_idle[t] = 0;
}
int tile_id = get_local_tile_id();
while(1)
{
select {
case print_tmr when timerafter(print_time) :> void:
for (t = 0; t <= 7; t++) {
core_usage[t] = ((float)(core_busy[t] / (core_busy[t] + core_idle[t])))*100;
}
core_stats_interface.ShareCoreUsage (core_usage[0],
core_usage[1],
core_usage[2],
core_usage[3],
core_usage[4],
core_usage[5],
core_usage[6],
core_usage[7]);
/*printf("%d %d %d %d %d %d %d %d\n",core_usage[0],
core_usage[1],
core_usage[2],
core_usage[3],
core_usage[4],
core_usage[5],
core_usage[6],
core_usage[7]);*/
for (t = 0; t <= 7; t++) {
core_busy[t] = 0;
core_idle[t] = 0;
}
print_time += PRINT_MS;
break;
case poll_tmr when timerafter(poll_time) :> void:
for (t = 0; t <= 7; t++) {
// Read the processor state
int ps_value = getps(0x100*t+4);
// Read the status register
unsigned int sr_value;
read_pswitch_reg(tile_id, XS1_PSWITCH_T0_SR_NUM+t, sr_value);
const int in_use = (ps_value & 0x1);
const int waiting = (sr_value >> 6) & 0x1;
if (in_use && waiting) {
core_busy[t] += 1;
} else {
core_idle[t] += 1;
}
}
poll_time += POLLING_MS;
break;
}
}
}