Skip to content

Commit 0c3c3ea

Browse files
committed
[docs][utest]: Modification of the SMP Threads Auto Assign to Idle Cores Test
Currently, this utest cannot determine whether threads are evenly distributed across idle harts by observing the result of list_thread(). This is because the presence of rt_thread_delay(5); causes all other threads to be in the suspended state when thread information is printed. For example, if RT_CPUS_NR=4, T0 executes list_thread() to print information, while T1~T3 are in hibernation and thus it is impossible to observe which hart they are running on. Solution:Here, the completion judgment condition has been modified. For example, when RT_CPUS_NR=4, only RT_CPUS_NR-1 threads will be created (i.e., T0 to T2), because running the utest occupies one hart. The execution is judged as completed when finish_flag=0x0007, and the thread running the utest will call list_thread() to print the information. Observe whether T0 to T2 are running on different harts simultaneously. In addition, relevant explanations have been added to this modified utest. Signed-off-by: Mengchen Teng <[email protected]>
1 parent 30e1e5e commit 0c3c3ea

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/utest/smp/smp_assigned_idle_cores_tc.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,52 @@
1717
* @note Create multiple threads untied core threads, run them for a while on each core to see
1818
* if the threads are automatically distributed evenly, run for a while to output the threads
1919
* running on each core.
20+
*
21+
* Test Case Name: [smp_assigned_idle_cores]
22+
*
23+
* Test Objectives:
24+
* - Test whether ready threads unbound to cores can be automatically allocated
25+
* - to idle harts under the SMP architecture.
26+
*
27+
* Test Scenarios:
28+
* - Under the SMP architecture, each hart spends most of its time running the
29+
* - idle thread after the system starts. At this point, create RT_CPUS_NR-1 cyclic
30+
* - tasks and observe whether these tasks can be evenly distributed across all
31+
* - harts for execution. Since the thread running the utest occupies one hart, it
32+
* - is only necessary to observe whether the remaining (RT_CPUS_NR - 1) harts can
33+
* - be allocated the newly created threads and execute them.
34+
*
35+
* Verification Metrics:
36+
* - After running this test case, it is necessary to observe the printed thread
37+
* - list, where all threads created with names from T0 to T(RT_CPUS_NR-2) must
38+
* - be in the running state. RT_CPUS_NR must be greater than or equal to 2.
39+
*
40+
* Dependencies:
41+
* - RT_USING_SMP needs to be enabled.
42+
*
43+
* Expected Results:
44+
* - Print the thread list on the terminal, and observe that T0 to T(RT_CPUS_NR-2)
45+
* - are all in the running state, with the output "[ PASSED ] [ result ] testcase
46+
* - (core.smp_assigned_idle_cores)".
2047
*/
2148

2249
#define THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
2350
#define THREAD_PRIORITY 20
24-
static rt_thread_t threads[RT_CPUS_NR];
25-
static int tick = 0, finsh_flag = 0;
51+
static rt_thread_t threads[RT_CPUS_NR - 1];
52+
static int tick = 0, finish_flag = 0;
2653
static int num = 0;
2754
/* thread entry function */
2855
static void thread_entry(void *parameter)
2956
{
57+
int hartid = *(int *)parameter;
3058
while (1)
3159
{
3260
tick++;
33-
if (tick == 100)
61+
if (tick >= 100 && (finish_flag & (1 << hartid)) == 0)
3462
{
35-
/* Output the current core running threads */
36-
extern long list_thread(void);
37-
list_thread();
38-
finsh_flag = 0xA55A;
63+
finish_flag |= (1 << hartid);
3964
uassert_true(1);
4065
}
41-
rt_thread_delay(5);
4266
}
4367
}
4468

@@ -54,8 +78,8 @@ static void thread_on_idle_core_tc(void)
5478
params[i] = i;
5579
}
5680

57-
/* Create RT_CPUS_NR threads and pass the entry parameters for each thread */
58-
for (i = 0; i < RT_CPUS_NR; i++)
81+
/* Create RT_CPUS_NR-1 threads and pass the entry parameters for each thread */
82+
for (i = 0; i < RT_CPUS_NR - 1; i++)
5983
{
6084
rt_snprintf(thread_name, sizeof(thread_name), "T%d", i);
6185
threads[i] = rt_thread_create(thread_name, thread_entry, &params[i], THREAD_STACK_SIZE, THREAD_PRIORITY, 20);
@@ -66,18 +90,23 @@ static void thread_on_idle_core_tc(void)
6690
}
6791
}
6892
/* Waiting for test cases to finish */
69-
while (finsh_flag != 0xA55A);
93+
while (finish_flag != (1<<(RT_CPUS_NR-1))-1);
94+
/* Output the current core running threads */
95+
extern long list_thread(void);
96+
list_thread();
7097
}
7198

7299
static rt_err_t utest_tc_init(void)
73100
{
101+
finish_flag = 0;
102+
tick = 0;
74103
rt_kprintf("[Test case]: created threads are automatically assigned to run on idle cores\r\n");
75104
return RT_EOK;
76105
}
77106

78107
static rt_err_t utest_tc_cleanup(void)
79108
{
80-
for (num = 0; num < RT_CPUS_NR; num++)
109+
for (num = 0; num < RT_CPUS_NR - 1; num++)
81110
{
82111
rt_thread_delete(threads[num]);
83112
}
@@ -89,3 +118,4 @@ static void testcase(void)
89118
UTEST_UNIT_RUN(thread_on_idle_core_tc);
90119
}
91120
UTEST_TC_EXPORT(testcase, "core.smp_assigned_idle_cores", utest_tc_init, utest_tc_cleanup, 10);
121+

0 commit comments

Comments
 (0)