From d3ef2166e1e9a960bdc43677ef496ff9fbe2b3f7 Mon Sep 17 00:00:00 2001 From: "LAPTOP-I8QJ9AF6\\Lenovo" <2358216566@qq.com> Date: Thu, 9 Jul 2026 21:27:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=9C=A8context=5Fswitch=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E5=8A=A0=E4=BA=86=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utest/perf/context_switch_tc.c | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/utest/perf/context_switch_tc.c b/src/utest/perf/context_switch_tc.c index c095edec216..3d47ff0e496 100644 --- a/src/utest/perf/context_switch_tc.c +++ b/src/utest/perf/context_switch_tc.c @@ -136,4 +136,45 @@ rt_err_t context_switch_test(rt_perf_t *perf) return RT_EOK; } +/* + * Copyright (c) 2006-2025, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-07-03 rcitach test case for context_switch + * 2025-11-30 westcity-YOLO Add standardized utest documentation block + */ +/* + * Test Case Name: Kernel Core Context Switch Performance Test + * + * Test Objectives: + * - Measures thread context switch overhead using semaphore synchronization + * - Validates interrupt-to-thread response time in switch scenarios + * - Provides quantitative results in microseconds (us) + * + * Test Scenarios: + * - **Thread Switch Simulation**: Two threads alternate using semaphores + * - **High-Resolution Timing**: Hardware timer measures switch duration + * - **Stress Cycles**: Repeated switch operations (RT_UTEST_SYS_PERF_TC_COUNT times) + * - **Priority Handling**: Higher-priority thread execution (THREAD_PRIORITY+1) + * + * Verification Metrics: + * - Switch time within reasonable limits (< 100 us) + * - Consistent results across multiple test cycles + * - No memory leaks during test execution + * - Correct thread priority handling + * + * Dependencies: + * - RT_USING_PERF_TEST must be enabled + * - RT_USING_UTEST framework must be enabled + * - Hardware timer support (for high-resolution timing) + * + * Expected Results: + * [ PASSED ] [ result ] testcase (core.context_switch) + * - Performance data printed in structured table format + * - Final line: "=== Context Switch Test Results End ===" + * - Test executed via: `utest_run core.context_switch` in msh + */ From 3757674d43eb324c1f5fe51bf329a8862be8b6c8 Mon Sep 17 00:00:00 2001 From: "LAPTOP-I8QJ9AF6\\Lenovo" <2358216566@qq.com> Date: Sat, 11 Jul 2026 08:51:19 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BB=8Enew-tes?= =?UTF-8?q?t=E5=88=B0master=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utest/perf/context_switch_tc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utest/perf/context_switch_tc.c b/src/utest/perf/context_switch_tc.c index 3d47ff0e496..ba8676b19c5 100644 --- a/src/utest/perf/context_switch_tc.c +++ b/src/utest/perf/context_switch_tc.c @@ -65,7 +65,14 @@ static void perf_thread_event1(void *parameter) rt_sem_release(sem2); } } - +static void perf_thread_event1(void *parameter) +{ + while (1) + { + rt_sem_take(sem1, RT_WAITING_FOREVER); + rt_sem_release(sem2); + } +} static void perf_thread_event2(void *parameter) { rt_perf_t *perf = (rt_perf_t *)parameter; From 71ae74857b781bd07a5bd8490568d13c89812054 Mon Sep 17 00:00:00 2001 From: "LAPTOP-I8QJ9AF6\\Lenovo" <2358216566@qq.com> Date: Sat, 11 Jul 2026 08:59:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E5=88=87=E6=8D=A2=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E7=9A=84=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utest/perf/context_switch_tc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utest/perf/context_switch_tc.c b/src/utest/perf/context_switch_tc.c index ba8676b19c5..1ce4f3bf197 100644 --- a/src/utest/perf/context_switch_tc.c +++ b/src/utest/perf/context_switch_tc.c @@ -57,6 +57,14 @@ static void local_modify_time(rt_perf_t *perf) perf->real_time = perf->real_time - perf->tmp_time; } +//我的改动---------------------------------- +static void local_modify_time(rt_perf_t *perf) +{ + if(perf) + perf->real_time = perf->real_time - perf->tmp_time; +} +//我的改动---------------------------------- + static void perf_thread_event1(void *parameter) { while (1)