Skip to content

Commit 9308564

Browse files
Tm-C-mTRbb666
authored andcommitted
[utest]: Modify the utest logic for thread allocation of idle harts
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. Signed-off-by: Mengchen Teng <[email protected]>
1 parent 45f2246 commit 9308564

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/utest/smp/smp_assigned_idle_cores_tc.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,21 @@
2121

2222
#define THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
2323
#define THREAD_PRIORITY 20
24-
static rt_thread_t threads[RT_CPUS_NR];
25-
static int tick = 0, finsh_flag = 0;
24+
static rt_thread_t threads[RT_CPUS_NR - 1];
25+
static int tick = 0, finish_flag = 0;
2626
static int num = 0;
2727
/* thread entry function */
2828
static void thread_entry(void *parameter)
2929
{
30+
int value = *(int *)parameter;
3031
while (1)
3132
{
3233
tick++;
33-
if (tick == 100)
34+
if (tick >= 100 && (finish_flag & (1 << value)) == 0)
3435
{
35-
/* Output the current core running threads */
36-
extern long list_thread(void);
37-
list_thread();
38-
finsh_flag = 0xA55A;
36+
rt_atomic_or((volatile rt_atomic_t *)&finish_flag, (1 << value));
3937
uassert_true(1);
4038
}
41-
rt_thread_delay(5);
4239
}
4340
}
4441

@@ -54,8 +51,8 @@ static void thread_on_idle_core_tc(void)
5451
params[i] = i;
5552
}
5653

57-
/* Create RT_CPUS_NR threads and pass the entry parameters for each thread */
58-
for (i = 0; i < RT_CPUS_NR; i++)
54+
/* Create RT_CPUS_NR-1 threads and pass the entry parameters for each thread */
55+
for (i = 0; i < RT_CPUS_NR - 1; i++)
5956
{
6057
rt_snprintf(thread_name, sizeof(thread_name), "T%d", i);
6158
threads[i] = rt_thread_create(thread_name, thread_entry, &params[i], THREAD_STACK_SIZE, THREAD_PRIORITY, 20);
@@ -66,18 +63,23 @@ static void thread_on_idle_core_tc(void)
6663
}
6764
}
6865
/* Waiting for test cases to finish */
69-
while (finsh_flag != 0xA55A);
66+
while (finish_flag != (1<<(RT_CPUS_NR-1))-1);
67+
/* Output the current core running threads */
68+
extern long list_thread(void);
69+
list_thread();
7070
}
7171

7272
static rt_err_t utest_tc_init(void)
7373
{
74+
finish_flag = 0;
75+
tick = 0;
7476
rt_kprintf("[Test case]: created threads are automatically assigned to run on idle cores\r\n");
7577
return RT_EOK;
7678
}
7779

7880
static rt_err_t utest_tc_cleanup(void)
7981
{
80-
for (num = 0; num < RT_CPUS_NR; num++)
82+
for (num = 0; num < RT_CPUS_NR - 1; num++)
8183
{
8284
rt_thread_delete(threads[num]);
8385
}
@@ -89,3 +91,4 @@ static void testcase(void)
8991
UTEST_UNIT_RUN(thread_on_idle_core_tc);
9092
}
9193
UTEST_TC_EXPORT(testcase, "core.smp_assigned_idle_cores", utest_tc_init, utest_tc_cleanup, 10);
94+

0 commit comments

Comments
 (0)