Skip to content
Closed
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();
Copy link
Contributor

Choose a reason for hiding this comment

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

建议参考 FMT 的算法设计,用更高精度的时间戳去计算时间间隔

https://github.com/Firmament-Autopilot/FMT-Firmware/blob/9de2ddb736ceaea09b4ecc36a6b5bb151436404a/src/module/system/statistic.c#L65

rt-thread 最新添加的 ktme 就挺合适的。

/**
* @brief Get boottime with us precision
*
* @param tv: timeval
* @return rt_err_t
*/
rt_err_t rt_ktime_boottime_get_us(struct timeval *tv);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

感谢提供的建议,我会采纳并修改

Copy link
Member

Choose a reason for hiding this comment

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

@Dyyt587 这个PR还在跟进吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

目前没有更进了

}



#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