Processor utilization in percent

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Processor utilization in percent

Postby rudi ;-) » Thu Mar 09, 2017 5:21 pm

hi guys

honest have not searched for,
have not uses before,
so i ask:

can we display ( monitoring ) processor utilization in percent for
core 0
core 1

have we api or are there RTOS func's for it?

now i will google ;-)

best wishes
rudi ;-)

edit:
http://www.embedded.com/design/prototyp ... tilization
http://www.freertos.org/FreeRTOS_Suppor ... 66946.html

edit:
https://e2e.ti.com/support/microcontrol ... 6/t/198811
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: Processor utilization in percent

Postby Hans Dorn » Thu Mar 09, 2017 7:01 pm

Hi Rudi,

if everything else fails, you can always run a counter loop in a low priority task and measure how fast it runs, with and without your main task running.

It's a bit crude and not terribly precise, but it will also catch all the context switching overhead that other methods might not see.


Cheers
Hans

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Processor utilization in percent

Postby kolban » Thu Mar 09, 2017 7:30 pm

I'm going to say that chapter 11.5 Viewing run-time and task state information in the FreeRTOS book found here ... will likely be a good help.

http://www.freertos.org/Documentation/1 ... _Guide.pdf

I would imagine that this would assume that all CPU utilization of the ESP32 is governed by FreeRTOS ... if one has written code that does not run within the context of a task, then this won't be seen by FreeRTOS.

I would also suggest that there might be a puzzle in the question itself. For there to be utilization to be measured, it must be measured against "something". It isn't at all clear to me that if there were only going to be one task in an ESP32 and that task was "blocked" ... would that mean that the ESP32 has stopped consuming CPU cycles? The answer to that would be down at the assembly level and hardware. To say that the ESP32 isn't consuming CPU is not the same thing as saying that the ESP32 isn't running any tasks. If the ESP32 doesn't have a task to run, then it may still be consuming JUST AS MUCH CPU cycles polling for the determination that an event has occurred means a task is now ready to run.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: Processor utilization in percent

Postby Hans Dorn » Thu Mar 09, 2017 8:26 pm

kolban wrote: I would also suggest that there might be a puzzle in the question itself. For there to be utilization to be measured, it must be measured against "something". It isn't at all clear to me that if there were only going to be one task in an ESP32 and that task was "blocked" ... would that mean that the ESP32 has stopped consuming CPU cycles?
Well, we can venture an educated guess by utilizing the CPU's integrated cycle counter.

I used it to time a loop several times, and the lowest cycle counts suggest that an iteration will take exactly 11 clock cycles.
This would be our baseline.

We can now compare the actual runtime of our loop against the expected runtime to see how long the CPU was used by higher priority tasks:

Code: Select all

uint32_t inline IRAM_ATTR cycles()
{
    uint32_t ccount;
    __asm__ __volatile__ ( "rsr     %0, ccount" : "=a" (ccount) );
    return ccount;
}


#define CYCLECOUNT 1000000
volatile uint32_t idlectr = 0;

void loop()
{
  uint32_t t00,t01;

  t00=cycles();
  for(int i=0; i<CYCLECOUNT;i++) {
    idlectr++;
  }
  t01=cycles();

  uint32_t cycles_expected = 11 * CYCLECOUNT;
  uint32_t cycles_used = t01-t00;

  float cpu_load = 100.0 * (cycles_used - cycles_expected)/cycles_used;
  
}

In the arduino environment this yields exactly 0.468% of CPU load with no higher priority user tasks running on CPU1,
and about 5.4% if I switch on the timer ISR I'm playing around with right now.

Cheers
Hans

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: Processor utilization in percent

Postby rudi ;-) » Thu Mar 09, 2017 9:43 pm

hi guys

thank you

i started with smal steps with vTaskList /
otherwise with vTaskGetRunTimeStats
but get break:

Code: Select all


#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"     // have included
#include "esp_system.h"
#include "nvs_flash.h"

extern void vTaskGetRunTimeStats( char *pcWriteBuffer );

void example_1_task(void *pvParameter) {
	while (1) {
	printf("hello from task 1\n");
	vTaskDelay(873 / portTICK_PERIOD_MS);
	}
}


void example_2_task(void *pvParameter) {
	while (1) {
	printf("hello from task 2\n");
	vTaskDelay(1132 / portTICK_PERIOD_MS);
	}
}

void example_3_task(void *pvParameter) {
	while (1) {
	printf("hello from task 3\n");
	vTaskDelay(1823 / portTICK_PERIOD_MS);
	}
}


void app_main(void) {
	char pcWriteBuffer[1024] = "";
	
	xTaskCreate(&example_3_task, "example_3_task", 2048, NULL, 5, NULL);
	xTaskCreate(&example_1_task, "example_1_task", 2048, NULL, 5, NULL);
	xTaskCreate(&example_2_task, "example_2_task", 2048, NULL, 5, NULL);
	
	while(1) {
	
		// vTaskList((char *) pcWriteBuffer);
	       vTaskGetRunTimeStats(( char *)pcWriteBuffer);
		   printf("Run Times:\n%s\n",pcWriteBuffer);
		   vTaskDelay(1000 / portTICK_PERIOD_MS);
	}
	
}



but i allways get this undefined for the task func
freertos/task.h is included in the code
where is my thinking mistake to this ?
must i have to change in component.mk that compiler find my archive in freertos ?
$ make all
CC hello_world_main.o
AR libmain.a
LD hello-world.elf
C:/eMbeddedHome2017/CLK_erzeuger/hello_world/build/main\libmain.a(hello_world_main.o):(.literal.app_main+0x1c): undefined reference to `vTaskGetRunTimeStats'
C:/eMbeddedHome2017/CLK_erzeuger/hello_world/build/main\libmain.a(hello_world_main.o): In function `app_main':
C:/eMbeddedHome2017/CLK_erzeuger/hello_world/main/hello_world_main.c:80: undefined reference to `vTaskGetRunTimeStats'
collect2.exe: error: ld returned 1 exit status
miss i other doing ?
in the build there is freertos created as folder
and there are tasks.o created..

best wishes
rudi ;-)

btw: if you test
you must change FreeRTOSconfig.h
to 1
https://github.com/espressif/esp-idf/bl ... fig.h#L191
to 1
https://github.com/espressif/esp-idf/bl ... fig.h#L192

edit:
@hans
read_task_info

edit:
added extern
and void *pvParameter
Last edited by rudi ;-) on Thu Mar 09, 2017 10:27 pm, edited 1 time in total.
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: Processor utilization in percent

Postby Hans Dorn » Thu Mar 09, 2017 10:11 pm

Hi Rudi.


Your task function should have a (void *) argument:

Code: Select all

void idleTask(void *arg)
{
  
  uint32_t t00, t01;
  for(;;)
  {
    
//...
  }

}

Cheers

P.S:
I managed to put my loop into an idle priority task, and now it reports 50% load
Guess it's competing with the system idle task, needs some fixing, lol

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: Processor utilization in percent

Postby rudi ;-) » Thu Mar 09, 2017 10:25 pm

Hans Dorn wrote: Your task function should have a (void *) argument:

Code: Select all

void idleTask(void *arg)
{
  
  uint32_t t00, t01;
  for(;;)
  {
    
//...
  }

}

Cheers

P.S:
I managed to put my loop into an idle priority task, and now it reports 50% load
Guess it's competing with the system idle task, needs some fixing, lol
50% ;-)

thank you usually used this (void *pvParameter) in task funcs
do you know why i get undefined reference to `vTaskGetRunTimeStats' ?

Code: Select all

..
extern void vTaskGetRunTimeStats( char *pcWriteBuffer );
..
helps not

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: Processor utilization in percent

Postby Hans Dorn » Thu Mar 09, 2017 10:49 pm

Hmmm.

Maybe your config changes didn't take.

What OS are you on, can you search the contents of your generated libraries to see if "vTaskGetRunTimeStats" is contained in one of your libs.


My timer loop seems to work on CPU1 if I double the expected number of cycles to account for the system idle task.
On CPU0, depending on system load, sometimes I see the system idle task, sometimes I don't, so no dice...


Cheers

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: Processor utilization in percent

Postby rudi ;-) » Thu Mar 09, 2017 10:58 pm

Hans Dorn wrote:Hmmm.

Maybe your config changes didn't take.

What OS are you on, can you search the contents of your generated libraries to see if "vTaskGetRunTimeStats" is contained in one of your libs.


My timer loop seems to work on CPU1 if I double the expected number of cycles to account for the system idle task.
On CPU0, depending on system load, sometimes I see the system idle taks, sometimes I don't, so no dice...


Cheers
thank you Hans,
in this example, i used windows.
build folder is created in the project folder
there is freertos folder with
libfreertos.a
text file: no vTaskGetRunTimeStats :o


seems we missing a part ;-)

xtensa_overlay_os_hook.o xt_overlay_init_os
xtensa_overlay_os_hook.o xt_overlay_lock
xtensa_overlay_os_hook.o xt_overlay_unlock
FreeRTOS-openocd.o uxTopUsedPriority
timers.o xTimerMux
timers.o xTimerCreateTimerTask
timers.o xTimerCreate
timers.o xTimerGenericCommand
timers.o pcTimerGetTimerName
timers.o xTimerIsTimerActive
timers.o pvTimerGetTimerID
timers.o xTimerPendFunctionCallFromISR
timers.o xTimerPendFunctionCall
tasks.o pxCurrentTCB
tasks.o taskYIELD_OTHER_CORE
tasks.o vTaskDelayUntil
tasks.o uxTaskPriorityGet
tasks.o vTaskSuspend
tasks.o vTaskResume
tasks.o vTaskEndScheduler
tasks.o vTaskSuspendAll
tasks.o xTaskGetTickCountFromISR
tasks.o uxTaskGetNumberOfTasks
tasks.o vTaskSwitchContext
tasks.o xTaskRemoveFromEventList
tasks.o vTaskSetTimeOutState
tasks.o vTaskMissedYield
tasks.o vTaskAllocateMPURegions
tasks.o uxTaskGetStackHighWaterMark
tasks.o xTaskGetCurrentTaskHandle
tasks.o eTaskGetState
tasks.o uxTaskPriorityGetFromISR
tasks.o __getreent
tasks.o pcTaskGetTaskName
tasks.o pvTaskGetThreadLocalStoragePointer
tasks.o xTaskGetAffinity
tasks.o xTaskGetCurrentTaskHandleForCPU
tasks.o xTaskGetSchedulerState
tasks.o vTaskEnterCritical
tasks.o vTaskExitCritical
tasks.o xTaskCreateRestricted
tasks.o xTaskCreatePinnedToCore
tasks.o vTaskStartScheduler
tasks.o vTaskDelete
tasks.o vTaskDelay
tasks.o vTaskPrioritySet
tasks.o xTaskResumeFromISR
tasks.o xTaskGetTickCount
tasks.o xTaskIncrementTick
tasks.o xTaskResumeAll
tasks.o vTaskPlaceOnEventList
tasks.o vTaskPlaceOnUnorderedEventList
tasks.o vTaskPlaceOnEventListRestricted
tasks.o xTaskRemoveFromUnorderedEventList
tasks.o xTaskCheckForTimeOut
tasks.o vTaskSetThreadLocalStoragePointerAndDelCallback
tasks.o vTaskSetThreadLocalStoragePointer
tasks.o vTaskPriorityInherit
tasks.o xTaskPriorityDisinherit
tasks.o uxTaskResetEventItemValue
tasks.o pvTaskIncrementMutexHeldCount
tasks.o ulTaskNotifyTake
tasks.o xTaskNotifyWait
tasks.o xTaskNotify
tasks.o xTaskNotifyFromISR
tasks.o vTaskNotifyGiveFromISR
event_groups.o xEventGroupCreate
event_groups.o xEventGroupWaitBits
event_groups.o xEventGroupClearBits
event_groups.o xEventGroupGetBitsFromISR
event_groups.o xEventGroupSetBits
event_groups.o xEventGroupSync
event_groups.o vEventGroupDelete
event_groups.o vEventGroupSetBitsCallback
event_groups.o vEventGroupClearBitsCallback
heap_regions.o pvPortMallocTagged
heap_regions.o vPortFreeTagged
heap_regions.o xPortGetFreeHeapSizeTagged
heap_regions.o xPortGetMinimumEverFreeHeapSizeTagged
heap_regions.o vPortDefineHeapRegionsTagged
port.o pxPortInitialiseStack
port.o vPortEndScheduler
port.o port_xSchedulerRunning
port.o xPortStartScheduler
port.o xPortSysTickHandler
port.o vPortYieldOtherCore
port.o vPortStoreTaskMPUSettings
port.o port_interruptNesting
port.o xPortInIsrContext
port.o vPortAssertIfInISR
port.o vPortCPUInitializeMutex
port.o vPortCPUAcquireMutex
port.o vPortCPUReleaseMutex
port.o vPortFirstTaskHook
port.o vPortSetStackWatchpoint
port.o xPortGetTickRateHz
xtensa_init.o _xt_tick_divisor
xtensa_init.o _xt_tick_divisor_init
list.o vListInitialise
list.o vListInitialiseItem
list.o vListInsertEnd
list.o vListInsert
list.o uxListRemove
croutine.o xCoRoutineCreate
croutine.o pxCurrentCoRoutine
croutine.o vCoRoutineAddToDelayedList
croutine.o vCoRoutineSchedule
croutine.o xCoRoutineRemoveFromEventList
queue.o xQueueGenericReset
queue.o xQueueGenericCreate
queue.o xQueueGetMutexHolder
queue.o xQueueCreateCountingSemaphore
queue.o xQueueGenericSend
queue.o xQueueCreateMutex
queue.o xQueueGiveMutexRecursive
queue.o xQueueGenericSendFromISR
queue.o xQueueGiveFromISR
queue.o xQueueGenericReceive
queue.o xQueueTakeMutexRecursive
queue.o xQueueReceiveFromISR
queue.o xQueuePeekFromISR
queue.o uxQueueMessagesWaiting
queue.o uxQueueSpacesAvailable
queue.o uxQueueMessagesWaitingFromISR
queue.o vQueueDelete
queue.o xQueueIsQueueEmptyFromISR
queue.o xQueueIsQueueFullFromISR
queue.o vQueueWaitForMessageRestricted
queue.o xQueueCreateSet
queue.o xQueueAddToSet
queue.o xQueueRemoveFromSet
queue.o xQueueSelectFromSet
queue.o xQueueSelectFromSetFromISR
xtensa_intr.o xt_unhandled_interrupt
xtensa_intr.o xt_set_exception_handler
xtensa_intr.o xt_set_interrupt_handler
ringbuf.o xRingbufferPrintInfo
ringbuf.o xRingbufferCreate
ringbuf.o vRingbufferDelete
ringbuf.o xRingbufferGetMaxItemSize
ringbuf.o xRingbufferSend
ringbuf.o xRingbufferSendFromISR
ringbuf.o xRingbufferReceive
ringbuf.o xRingbufferReceiveFromISR
ringbuf.o xRingbufferReceiveUpTo
ringbuf.o xRingbufferReceiveUpToFromISR
ringbuf.o vRingbufferReturnItem
ringbuf.o vRingbufferReturnItemFromISR
ringbuf.o xRingbufferAddToQueueSetRead
ringbuf.o xRingbufferAddToQueueSetWrite
ringbuf.o xRingbufferRemoveFromQueueSetRead
ringbuf.o xRingbufferRemoveFromQueueSetWrite
portasm.o port_IntStack
portasm.o port_IntStackTop
portasm.o _frxt_setup_switch
portasm.o _frxt_int_enter
portasm.o _frxt_int_exit
portasm.o vPortYieldFromInt
portasm.o _frxt_dispatch
portasm.o _frxt_timer_int
portasm.o _frxt_tick_timer_init
portasm.o vPortYield
portasm.o _frxt_task_coproc_state
xtensa_vectors.o _xt_panic
xtensa_vectors.o _DebugExceptionVector
xtensa_vectors.o _DoubleExceptionVector
xtensa_vectors.o _KernelExceptionVector
xtensa_vectors.o _UserExceptionVector
xtensa_vectors.o _xt_alloca_exc
xtensa_vectors.o _xt_user_exit
xtensa_vectors.o _xt_coproc_sa_offset
xtensa_vectors.o _xt_coproc_owner_sa
xtensa_vectors.o _Level2Vector
xtensa_vectors.o _xt_medint2_exit
xtensa_vectors.o _Level3Vector
xtensa_vectors.o _xt_medint3_exit
xtensa_vectors.o _Level4Vector
xtensa_vectors.o _Level5Vector
xtensa_vectors.o _NMIExceptionVector
xtensa_vectors.o _WindowOverflow4
xtensa_vectors.o _WindowUnderflow4
xtensa_vectors.o _WindowUnderflow8
xtensa_vectors.o _WindowUnderflow12
xtensa_vectors.o _WindowOverflow8
xtensa_vectors.o _WindowOverflow12
xtensa_context.o _xt_context_save
xtensa_context.o _xt_context_restore
xtensa_context.o _xt_coproc_init
xtensa_context.o _xt_coproc_release
xtensa_context.o _xt_coproc_savecs
xtensa_context.o _xt_coproc_restorecs
xtensa_intr_asm.o _xt_interrupt_table
xtensa_intr_asm.o _xt_exception_table
xtensa_intr_asm.o xt_ints_on
xtensa_intr_asm.o xt_ints_off

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: Processor utilization in percent

Postby Hans Dorn » Thu Mar 09, 2017 11:14 pm

Try doing a make menuconfig first to trigger a complete rebuild.
Just toggle an option on and off, save config and build.

Who is online

Users browsing this forum: No registered users and 79 guests