Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for thread usage #8918

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
866 changes: 863 additions & 3 deletions bsp/stm32/stm32f427-robomaster-a/project.uvoptx

Large diffs are not rendered by default.

1,201 changes: 1,035 additions & 166 deletions bsp/stm32/stm32f427-robomaster-a/project.uvprojx

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions bsp/stm32/stm32f427-robomaster-a/rtconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

/* kservice optimization */


/* klibc optimization */

#define RT_USING_DEBUG
#define RT_DEBUGING_ASSERT
#define RT_DEBUGING_COLOR
#define RT_DEBUGING_CONTEXT

Expand All @@ -45,7 +49,7 @@
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart6"
#define RT_VER_NUM 0x50100
#define RT_VER_NUM 0x50200
#define RT_BACKTRACE_LEVEL_MAX_NR 32
#define RT_USING_HW_ATOMIC
#define RT_USING_CPU_FFS
Expand Down Expand Up @@ -184,20 +188,15 @@

/* peripheral libraries and drivers */

/* HAL & SDK Drivers */

/* STM32 HAL & SDK Drivers */


/* Kendryte SDK */


/* sensors drivers */


/* touch drivers */


/* Kendryte SDK */


/* AI packages */


Expand Down
41 changes: 41 additions & 0 deletions components/utilities/cpuusage/cpuusage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-05-9 Dyyt587 the first version
*/

#include "cpuusage.h"
//#ifdef RT_USING_CPU_USAGE
#if 1
static rt_tick_t pause_tick = 0;

/**
* @brief pause usage measure
*
* @note reduce scheduler time consuming
*/
void rt_usage_measure_pause(void)
{
pause_tick = rt_tick_get();
}
/**
* @brief start usage measure
*
* @param from wait to turn on
* @param to turn to be
*/
void rt_usage_measure_start(struct rt_thread *from, struct rt_thread *to)
{
/* to avoid scheduler time consuming */
from->duration_tick += pause_tick - from->last_start_tick;

to->last_start_tick = rt_tick_get();
}



#endif /* RT_USING_CPU_USAGE */
25 changes: 25 additions & 0 deletions components/utilities/cpuusage/cpuusage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-05-9 Dyyt587 the first version
*/

#ifndef CPU_USAGE_H
#define CPU_USAGE_H

#include <rtthread.h>
#include "ulog_def.h"

#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
}
#endif
#endif
6 changes: 6 additions & 0 deletions src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ config RT_USING_OVERFLOW_CHECK
Enable thread stack overflow checking. The stack overflow is checking when
each thread switch.

config RT_USING_CPU_USAGE
bool "thread usage measurement"
default y
help
Measure thread cpu usage.

config RT_USING_HOOK
bool "Enable system hook"
default y
Expand Down
27 changes: 26 additions & 1 deletion src/scheduler_mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);

/**@{*/

/**
* @brief pause usage measure
*/
#ifdef RT_USING_CPU_USAGE
rt_weak
#endif /* RT_USING_CPU_USAGE */
void rt_usage_measure_pause(void)
{
/* do nothing in it, implemented in another file */
}
/**
* @brief start usage measure
*
* @param from wait to turn on
* @param to turn to be
*/
#ifdef RT_USING_CPU_USAGE
rt_weak
#endif /* RT_USING_CPU_USAGE */
void rt_usage_measure_start(struct rt_thread *from, struct rt_thread *to)
{
/* do nothing in it, implemented in another file */
}

/**
* @brief This function will set a hook function, which will be invoked when thread
* switch happens.
Expand Down Expand Up @@ -857,7 +881,8 @@ void rt_schedule(void)
cpu_id, RT_SCHED_PRIV(to_thread).current_priority,
RT_NAME_MAX, to_thread->parent.name, to_thread->sp,
RT_NAME_MAX, current_thread->parent.name, current_thread->sp);

rt_usage_measure_pause();
rt_usage_measure_start(current_thread,to_thread);
rt_hw_context_switch((rt_ubase_t)&current_thread->sp,
(rt_ubase_t)&to_thread->sp, to_thread);
}
Expand Down
35 changes: 29 additions & 6 deletions src/scheduler_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);

/**@{*/

/**
* @brief pause usage measure
*/
#ifdef RT_USING_CPU_USAGE
rt_weak
#endif /* RT_USING_CPU_USAGE */
void rt_usage_measure_pause(void)
{
/* do nothing in it, implemented in another file */
}
/**
* @brief start usage measure
*
* @param from wait to turn on
* @param to turn to be
*/
#ifdef RT_USING_CPU_USAGE
rt_weak
#endif /* RT_USING_CPU_USAGE */
void rt_usage_measure_start(struct rt_thread *from, struct rt_thread *to)
{
/* do nothing in it, implemented in another file */
}

/**
* @brief This function will set a hook function, which will be invoked when thread
* switch happens.
Expand Down Expand Up @@ -207,6 +231,9 @@ void rt_schedule(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();

/*to avoid schedule interference*/
rt_usage_measure_pause();

/* check the scheduler is enabled or not */
if (rt_scheduler_lock_nest == 0)
{
Expand Down Expand Up @@ -276,9 +303,6 @@ void rt_schedule(void)
rt_hw_context_switch((rt_ubase_t)&from_thread->sp,
(rt_ubase_t)&to_thread->sp);

/* enable interrupt */
rt_hw_interrupt_enable(level);

#ifdef RT_USING_SIGNALS
/* check stat of thread for signal */
level = rt_hw_interrupt_disable();
Expand All @@ -295,7 +319,6 @@ void rt_schedule(void)
}
else
{
rt_hw_interrupt_enable(level);
}
#endif /* RT_USING_SIGNALS */
goto __exit;
Expand All @@ -316,10 +339,10 @@ void rt_schedule(void)
}
}

__exit:
rt_usage_measure_start(from_thread, to_thread);
/* enable interrupt */
rt_hw_interrupt_enable(level);

__exit:
return;
}

Expand Down
Loading