upgrade rtt 5.2.2
This commit is contained in:
@@ -192,10 +192,12 @@ endif
|
||||
config RT_USING_CPU_USAGE_TRACER
|
||||
select RT_USING_HOOK
|
||||
bool "Enable cpu usage tracing"
|
||||
help
|
||||
Enable cpu usage tracer for application like top.
|
||||
default y if RT_USING_SMART
|
||||
default n
|
||||
help
|
||||
Enable thread CPU usage statistics and monitoring.
|
||||
This feature tracks CPU usage for each thread and provides
|
||||
percentage information through the list thread command.
|
||||
It will automatically integrate with the scheduler to track thread execution time.
|
||||
|
||||
menu "kservice options"
|
||||
config RT_USING_TINY_FFS
|
||||
|
||||
@@ -59,6 +59,8 @@ RTM_EXPORT(rt_spin_lock)
|
||||
/**
|
||||
* @brief This function will unlock the spinlock, will unlock the thread scheduler.
|
||||
*
|
||||
* @note If the scheduling function is called before unlocking, it will be scheduled in this function.
|
||||
*
|
||||
* @param lock is a pointer to the spinlock.
|
||||
*/
|
||||
void rt_spin_unlock(struct rt_spinlock *lock)
|
||||
@@ -95,6 +97,8 @@ RTM_EXPORT(rt_spin_lock_irqsave)
|
||||
/**
|
||||
* @brief This function will unlock the spinlock and then restore current cpu interrupt status, will unlock the thread scheduler.
|
||||
*
|
||||
* @note If the scheduling function is called before unlocking, it will be scheduled in this function.
|
||||
*
|
||||
* @param lock is a pointer to the spinlock.
|
||||
*
|
||||
* @param level is interrupt status returned by rt_spin_lock_irqsave().
|
||||
|
||||
@@ -40,7 +40,8 @@ void rt_spin_lock(struct rt_spinlock *lock)
|
||||
|
||||
/**
|
||||
* @brief This function will unlock the spinlock, will unlock the thread scheduler.
|
||||
* If the scheduling function is called before unlocking, it will be scheduled in this function.
|
||||
*
|
||||
* @note If the scheduling function is called before unlocking, it will be scheduled in this function.
|
||||
*
|
||||
* @param lock is a pointer to the spinlock.
|
||||
*/
|
||||
@@ -73,7 +74,8 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
|
||||
|
||||
/**
|
||||
* @brief This function will unlock the spinlock and then restore current cpu interrupt status, will unlock the thread scheduler.
|
||||
* If the scheduling function is called before unlocking, it will be scheduled in this function.
|
||||
*
|
||||
* @note If the scheduling function is called before unlocking, it will be scheduled in this function.
|
||||
*
|
||||
* @param lock is a pointer to the spinlock.
|
||||
*
|
||||
|
||||
@@ -250,9 +250,4 @@ menu "klibc options"
|
||||
default n
|
||||
endmenu # rt_strnlen options
|
||||
|
||||
config RT_UTEST_TC_USING_KLIBC
|
||||
bool "Enable klibc utest cases"
|
||||
select RT_USING_UTEST
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
config RT_UTEST_TC_USING_KLIBC
|
||||
bool "Enable klibc utest cases"
|
||||
select RT_USING_UTEST
|
||||
default n
|
||||
@@ -539,6 +539,53 @@ rt_err_t rt_backtrace_thread(rt_thread_t thread)
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_CPU_USAGE_TRACER
|
||||
/**
|
||||
* @brief Get thread usage percentage relative to total system CPU time
|
||||
*
|
||||
* This function calculates the CPU usage percentage of a specific thread
|
||||
* relative to the total CPU time consumed by all threads in the system.
|
||||
*
|
||||
* @param thread Pointer to the thread object. Must not be NULL.
|
||||
*
|
||||
* @return The CPU usage percentage as an integer value (0-100).
|
||||
* Returns 0 if total system time is 0 or if CPU usage tracing is not enabled.
|
||||
*
|
||||
* @note This function requires RT_USING_CPU_USAGE_TRACER to be enabled.
|
||||
* @note The percentage is calculated as: (thread_time * 100) / total_system_time
|
||||
* @note Due to integer arithmetic, the result is truncated and may not sum
|
||||
* to exactly 100% across all threads due to rounding.
|
||||
* @note If thread is NULL, an assertion will be triggered in debug builds.
|
||||
*/
|
||||
rt_uint8_t rt_thread_get_usage(rt_thread_t thread)
|
||||
{
|
||||
rt_ubase_t thread_time;
|
||||
rt_ubase_t total_time = 0U;
|
||||
int i;
|
||||
rt_cpu_t pcpu;
|
||||
|
||||
RT_ASSERT(thread != RT_NULL);
|
||||
|
||||
thread_time = thread->user_time + thread->system_time;
|
||||
|
||||
/* Calculate total system time by summing all CPUs' time */
|
||||
for (i = 0; i < RT_CPUS_NR; i++)
|
||||
{
|
||||
pcpu = rt_cpu_index(i);
|
||||
total_time += pcpu->cpu_stat.user + pcpu->cpu_stat.system + pcpu->cpu_stat.idle;
|
||||
}
|
||||
|
||||
if (total_time > 0U)
|
||||
{
|
||||
/* Calculate thread usage percentage: (thread_time * 100) / total_time */
|
||||
rt_ubase_t usage = (thread_time * 100U) / total_time;
|
||||
return (rt_uint8_t)(usage > 100U ? 100U : usage);
|
||||
}
|
||||
|
||||
return 0U;
|
||||
}
|
||||
#endif /* RT_USING_CPU_USAGE_TRACER */
|
||||
|
||||
#if defined(RT_USING_LIBC) && defined(RT_USING_FINSH)
|
||||
#include <stdlib.h> /* for string service */
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
|
||||
obj_name_len = rt_strlen(name);
|
||||
if(obj_name_len > RT_NAME_MAX - 1)
|
||||
{
|
||||
LOG_E("Object name '%s' exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
|
||||
LOG_E("Object name %s exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
|
||||
RT_ASSERT(obj_name_len <= RT_NAME_MAX - 1);
|
||||
}
|
||||
rt_memcpy(object->name, name, obj_name_len);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
* 2023-03-27 rose_man Split into scheduler upc and scheduler_mp.c
|
||||
* 2023-10-17 ChuShicheng Modify the timing of clearing RT_THREAD_STAT_YIELD flag bits
|
||||
* 2025-08-04 Pillar Add rt_scheduler_critical_switch_flag
|
||||
* 2025-08-20 RyanCW rt_scheduler_lock_nest use atomic operations
|
||||
*/
|
||||
|
||||
#define __RT_IPC_SOURCE__
|
||||
@@ -49,7 +50,7 @@ rt_uint8_t rt_thread_ready_table[32];
|
||||
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
|
||||
|
||||
extern volatile rt_atomic_t rt_interrupt_nest;
|
||||
static rt_int16_t rt_scheduler_lock_nest;
|
||||
static rt_atomic_t rt_scheduler_lock_nest;
|
||||
rt_uint8_t rt_current_priority;
|
||||
|
||||
static rt_int8_t rt_scheduler_critical_switch_flag;
|
||||
@@ -649,22 +650,9 @@ RTM_EXPORT(rt_exit_critical_safe);
|
||||
*/
|
||||
rt_base_t rt_enter_critical(void)
|
||||
{
|
||||
rt_base_t level;
|
||||
rt_base_t critical_level;
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
/*
|
||||
* the maximal number of nest is RT_UINT16_MAX, which is big
|
||||
* enough and does not check here
|
||||
*/
|
||||
rt_scheduler_lock_nest ++;
|
||||
critical_level = rt_scheduler_lock_nest;
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
critical_level = rt_atomic_add(&rt_scheduler_lock_nest, 1) + 1;
|
||||
return critical_level;
|
||||
}
|
||||
RTM_EXPORT(rt_enter_critical);
|
||||
@@ -722,7 +710,7 @@ RTM_EXPORT(rt_exit_critical);
|
||||
*/
|
||||
rt_uint16_t rt_critical_level(void)
|
||||
{
|
||||
return rt_scheduler_lock_nest;
|
||||
return (rt_uint16_t)rt_atomic_load(&rt_scheduler_lock_nest);
|
||||
}
|
||||
RTM_EXPORT(rt_critical_level);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user