@@ -97,28 +97,26 @@ static int cleanup_test(struct unit_test *test)
97
97
#endif
98
98
#define CPUHOLD_STACK_SZ (512 + CONFIG_TEST_EXTRA_STACK_SIZE)
99
99
100
- #if defined(CONFIG_SMP ) && (CONFIG_MP_NUM_CPUS > 1 )
101
- static struct k_thread cpuhold_threads [CONFIG_MP_NUM_CPUS ];
102
- K_KERNEL_STACK_ARRAY_DEFINE (cpuhold_stacks , CONFIG_MP_NUM_CPUS , CPUHOLD_STACK_SZ );
100
+ static struct k_thread cpuhold_threads [NUM_CPUHOLD ];
101
+ K_KERNEL_STACK_ARRAY_DEFINE (cpuhold_stacks , NUM_CPUHOLD , CPUHOLD_STACK_SZ );
103
102
static struct k_sem cpuhold_sem ;
104
- atomic_t cpuhold_holding ;
105
103
volatile int cpuhold_active ;
106
- #endif
107
104
108
105
/* "Holds" a CPU for use with the "1cpu" test cases. Note that we
109
106
* can't use tools like the cpumask feature because we have tests that
110
107
* may need to control that configuration themselves. We do this at
111
108
* the lowest level, but locking interrupts directly and spinning.
112
109
*/
113
- static inline void cpu_hold (void * arg1 , void * arg2 , void * arg3 )
110
+ static void cpu_hold (void * arg1 , void * arg2 , void * arg3 )
114
111
{
115
112
ARG_UNUSED (arg1 );
116
113
ARG_UNUSED (arg2 );
117
114
ARG_UNUSED (arg3 );
118
- #if defined(CONFIG_SMP ) && (CONFIG_MP_NUM_CPUS > 1 )
119
115
unsigned int key = arch_irq_lock ();
120
116
uint32_t dt , start_ms = k_uptime_get_32 ();
121
117
118
+ k_sem_give (& cpuhold_sem );
119
+
122
120
#if defined(CONFIG_ARM64 ) && defined(CONFIG_FPU_SHARING )
123
121
/*
124
122
* We'll be spinning with IRQs disabled. The flush-your-FPU request
@@ -130,26 +128,6 @@ static inline void cpu_hold(void *arg1, void *arg2, void *arg3)
130
128
z_arm64_flush_local_fpu ();
131
129
#endif
132
130
133
- /* One of these threads will end up on cpu 0. Its job is to
134
- * wait for the others to start holding their CPUs, then wake
135
- * up the main test thread and exit, so that the test starts
136
- * running on cpu 0. Note that the spinning here is a
137
- * CPU-local loop, not k_busy_wait(), which tends to involve
138
- * the timer driver and cause performance weirdness in SMP
139
- * situations.
140
- */
141
- if (arch_curr_cpu ()-> id == 0 ) {
142
- while (atomic_get (& cpuhold_holding ) < (CONFIG_MP_NUM_CPUS - 1 )) {
143
- for (volatile int i = 0 ; i < 10000 ; i ++ ) {
144
- }
145
- }
146
-
147
- k_sem_give (& cpuhold_sem );
148
- arch_irq_unlock (key );
149
- return ;
150
- }
151
-
152
- atomic_inc (& cpuhold_holding );
153
131
while (cpuhold_active ) {
154
132
k_busy_wait (1000 );
155
133
}
@@ -163,23 +141,24 @@ static inline void cpu_hold(void *arg1, void *arg2, void *arg3)
163
141
zassert_true (dt < 3000 ,
164
142
"1cpu test took too long (%d ms)" , dt );
165
143
arch_irq_unlock (key );
166
- #endif
167
144
}
168
145
169
146
void z_impl_z_test_1cpu_start (void )
170
147
{
171
- #if defined( CONFIG_SMP ) && ( CONFIG_MP_NUM_CPUS > 1 )
148
+ cpuhold_active = 1 ;
172
149
#ifdef CONFIG_THREAD_NAME
173
150
char tname [CONFIG_THREAD_MAX_NAME_LEN ];
174
151
#endif
175
- cpuhold_active = 1 ;
176
152
k_sem_init (& cpuhold_sem , 0 , 999 );
177
- atomic_set (& cpuhold_holding , 0 );
178
153
179
- /* Spawn threads to "hold" the other CPUs, waiting for each to
180
- * signal us that it's locked and spinning.
154
+ /* Spawn N-1 threads to "hold" the other CPUs, waiting for
155
+ * each to signal us that it's locked and spinning.
156
+ *
157
+ * Note that NUM_CPUHOLD can be a value that causes coverity
158
+ * to flag the following loop as DEADCODE so suppress the warning.
181
159
*/
182
- for (int i = 0 ; i < CONFIG_MP_NUM_CPUS ; i ++ ) {
160
+ /* coverity[DEADCODE] */
161
+ for (int i = 0 ; i < NUM_CPUHOLD ; i ++ ) {
183
162
k_thread_create (& cpuhold_threads [i ],
184
163
cpuhold_stacks [i ], CPUHOLD_STACK_SZ ,
185
164
(k_thread_entry_t ) cpu_hold , NULL , NULL , NULL ,
@@ -188,23 +167,21 @@ void z_impl_z_test_1cpu_start(void)
188
167
snprintk (tname , CONFIG_THREAD_MAX_NAME_LEN , "cpuhold%02d" , i );
189
168
k_thread_name_set (& cpuhold_threads [i ], tname );
190
169
#endif
170
+ k_sem_take (& cpuhold_sem , K_FOREVER );
191
171
}
192
-
193
- /* Sleep, waiting to be woken up on cpu0 */
194
- k_sem_take (& cpuhold_sem , K_FOREVER );
195
- __ASSERT (arch_curr_cpu ()-> id == 0 , "1cpu case running on wrong cpu" );
196
- #endif
197
172
}
198
173
199
174
void z_impl_z_test_1cpu_stop (void )
200
175
{
201
- #if defined(CONFIG_SMP ) && (CONFIG_MP_NUM_CPUS > 1 )
202
176
cpuhold_active = 0 ;
203
177
204
- for (int i = 0 ; i < CONFIG_MP_NUM_CPUS ; i ++ ) {
178
+ /* Note that NUM_CPUHOLD can be a value that causes coverity
179
+ * to flag the following loop as DEADCODE so suppress the warning.
180
+ */
181
+ /* coverity[DEADCODE] */
182
+ for (int i = 0 ; i < NUM_CPUHOLD ; i ++ ) {
205
183
k_thread_abort (& cpuhold_threads [i ]);
206
184
}
207
- #endif
208
185
}
209
186
210
187
#ifdef CONFIG_USERSPACE
0 commit comments