Skip to content

Commit 57e54b3

Browse files
hujun260xiaoxiang781216
authored andcommitted
sched: remove all spin_lock_irqsave(NULL)
Signed-off-by: hujun5 <hujun5@xiaomi.com>
1 parent 4e563e3 commit 57e54b3

24 files changed

+97
-60
lines changed

drivers/timers/rpmsg_rtc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,12 @@ static int rpmsg_rtc_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data,
308308
struct rpmsg_rtc_set_s *msg = data;
309309

310310
#ifdef CONFIG_RTC_RPMSG_SYNC_BASETIME
311+
irqstate_t flags;
312+
313+
flags = spin_lock_irqsave(&g_basetime_lock);
311314
g_basetime.tv_sec = msg->base_sec;
312315
g_basetime.tv_nsec = msg->base_nsec;
316+
spin_unlock_irqrestore(&g_basetime_lock, flags);
313317
#else
314318
struct timespec tp;
315319

@@ -480,6 +484,7 @@ static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower,
480484
FAR struct rpmsg_rtc_client_s *client;
481485
FAR struct list_node *node;
482486
struct rpmsg_rtc_set_s msg;
487+
irqstate_t flags;
483488
int ret;
484489

485490
ret = server->lower->ops->settime(server->lower, rtctime);
@@ -500,8 +505,10 @@ static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower,
500505
ret = 1; /* Request the upper half skip clock synchronize */
501506
}
502507

508+
flags = spin_lock_irqsave(&g_basetime_lock);
503509
msg.base_sec = g_basetime.tv_sec;
504510
msg.base_nsec = g_basetime.tv_nsec;
511+
spin_unlock_irqrestore(&g_basetime_lock, flags);
505512

506513
nxmutex_lock(&server->lock);
507514

@@ -730,6 +737,7 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev,
730737
FAR struct rpmsg_rtc_client_s *client;
731738
struct rpmsg_rtc_set_s msg;
732739
struct rtc_time rtctime;
740+
irqstate_t flags;
733741

734742
client = kmm_zalloc(sizeof(*client));
735743
if (client == NULL)
@@ -753,8 +761,11 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev,
753761
{
754762
msg.sec = timegm((FAR struct tm *)&rtctime);
755763
msg.nsec = rtctime.tm_nsec;
764+
765+
flags = spin_lock_irqsave(&g_basetime_lock);
756766
msg.base_sec = g_basetime.tv_sec;
757767
msg.base_nsec = g_basetime.tv_nsec;
768+
spin_unlock_irqrestore(&g_basetime_lock, flags);
758769

759770
msg.header.command = RPMSG_RTC_SYNC;
760771
rpmsg_send(&client->ept, &msg, sizeof(msg));

include/nuttx/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ struct task_group_s
571571
/* Virtual memory mapping info ********************************************/
572572

573573
struct mm_map_s tg_mm_map; /* Task group virtual memory mappings */
574+
575+
spinlock_t tg_lock; /* lock */
574576
};
575577

576578
/* struct tcb_s *************************************************************/

sched/clock/clock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <nuttx/clock.h>
3535
#include <nuttx/compiler.h>
36+
#include <nuttx/spinlock_type.h>
3637

3738
/****************************************************************************
3839
* Pre-processor Definitions
@@ -66,6 +67,7 @@ extern volatile clock_t g_system_ticks;
6667

6768
#ifndef CONFIG_CLOCK_TIMEKEEPING
6869
extern struct timespec g_basetime;
70+
extern spinlock_t g_basetime_lock;
6971
#endif
7072

7173
/****************************************************************************

sched/clock/clock_gettime.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ static clock_t clock_process_runtime(FAR struct tcb_s *tcb)
5858

5959
group = tcb->group;
6060

61-
flags = spin_lock_irqsave(NULL);
61+
flags = spin_lock_irqsave(&group->tg_lock);
6262
sq_for_every(&group->tg_members, curr)
6363
{
6464
tcb = container_of(curr, struct tcb_s, member);
6565

6666
runtime += tcb->run_time;
6767
}
6868

69-
spin_unlock_irqrestore(NULL, flags);
69+
spin_unlock_irqrestore(&group->tg_lock, flags);
7070
return runtime;
7171
# else /* HAVE_GROUP_MEMBERS */
7272
return tcb->run_time;
@@ -109,9 +109,9 @@ void nxclock_gettime(clockid_t clock_id, FAR struct timespec *tp)
109109
* was last set, this gives us the current time.
110110
*/
111111

112-
flags = spin_lock_irqsave(NULL);
112+
flags = spin_lock_irqsave(&g_basetime_lock);
113113
clock_timespec_add(&g_basetime, &ts, tp);
114-
spin_unlock_irqrestore(NULL, flags);
114+
spin_unlock_irqrestore(&g_basetime_lock, flags);
115115
#else
116116
clock_timekeeping_get_wall_time(tp);
117117
#endif

sched/clock/clock_initialize.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ volatile clock_t g_system_ticks = INITIAL_SYSTEM_TIMER_TICKS;
5656

5757
#ifndef CONFIG_CLOCK_TIMEKEEPING
5858
struct timespec g_basetime;
59+
spinlock_t g_basetime_lock = SP_UNLOCKED;
5960
#endif
6061

6162
/****************************************************************************
@@ -160,7 +161,9 @@ static void clock_inittime(FAR const struct timespec *tp)
160161

161162
#ifndef CONFIG_CLOCK_TIMEKEEPING
162163
struct timespec ts;
164+
irqstate_t flags;
163165

166+
flags = spin_lock_irqsave(&g_basetime_lock);
164167
if (tp)
165168
{
166169
memcpy(&g_basetime, tp, sizeof(struct timespec));
@@ -170,8 +173,12 @@ static void clock_inittime(FAR const struct timespec *tp)
170173
clock_basetime(&g_basetime);
171174
}
172175

176+
spin_unlock_irqrestore(&g_basetime_lock, flags);
177+
173178
clock_systime_timespec(&ts);
174179

180+
flags = spin_lock_irqsave(&g_basetime_lock);
181+
175182
/* Adjust base time to hide initial timer ticks. */
176183

177184
g_basetime.tv_sec -= ts.tv_sec;
@@ -181,6 +188,8 @@ static void clock_inittime(FAR const struct timespec *tp)
181188
g_basetime.tv_nsec += NSEC_PER_SEC;
182189
g_basetime.tv_sec--;
183190
}
191+
192+
spin_unlock_irqrestore(&g_basetime_lock, flags);
184193
#else
185194
clock_inittimekeeping(tp);
186195
#endif
@@ -266,13 +275,9 @@ void clock_initialize(void)
266275
#ifdef CONFIG_RTC
267276
void clock_synchronize(FAR const struct timespec *tp)
268277
{
269-
irqstate_t flags;
270-
271278
/* Re-initialize the time value to match the RTC */
272279

273-
flags = enter_critical_section();
274280
clock_inittime(tp);
275-
leave_critical_section(flags);
276281
}
277282
#endif
278283

@@ -319,10 +324,6 @@ void clock_resynchronize(FAR struct timespec *rtc_diff)
319324
rtc_diff = &rtc_diff_tmp;
320325
}
321326

322-
/* Set the time value to match the RTC */
323-
324-
flags = enter_critical_section();
325-
326327
/* Get RTC time */
327328

328329
ret = clock_basetime(&rtc_time);
@@ -334,9 +335,11 @@ void clock_resynchronize(FAR struct timespec *rtc_diff)
334335

335336
rtc_diff->tv_sec = 0;
336337
rtc_diff->tv_nsec = 0;
337-
goto skip;
338+
return;
338339
}
339340

341+
/* Set the time value to match the RTC */
342+
340343
/* Get the elapsed time since power up (in milliseconds). This is a
341344
* bias value that we need to use to correct the base time.
342345
*/
@@ -348,7 +351,9 @@ void clock_resynchronize(FAR struct timespec *rtc_diff)
348351
* was last set, this gives us the current time.
349352
*/
350353

354+
flags = spin_lock_irqsave(&g_basetime_lock);
351355
clock_timespec_add(&bias, &g_basetime, &curr_ts);
356+
spin_unlock_irqrestore(&g_basetime_lock, flags);
352357

353358
/* Check if RTC has advanced past system time. */
354359

@@ -382,9 +387,6 @@ void clock_resynchronize(FAR struct timespec *rtc_diff)
382387
atomic_fetch_add((FAR atomic_t *)&g_system_ticks, diff_ticks);
383388
#endif
384389
}
385-
386-
skip:
387-
leave_critical_section(flags);
388390
}
389391
#endif
390392

sched/clock/clock_settime.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <nuttx/arch.h>
3535
#include <nuttx/irq.h>
36+
#include <nuttx/spinlock.h>
3637
#include <sys/time.h>
3738

3839
#include "clock/clock.h"
@@ -71,16 +72,17 @@ void nxclock_settime(clockid_t clock_id, FAR const struct timespec *tp)
7172
* possible.
7273
*/
7374

74-
flags = enter_critical_section();
75-
7675
/* Get the elapsed time since power up (in milliseconds). This is a
7776
* bias value that we need to use to correct the base time.
7877
*/
7978

8079
clock_systime_timespec(&bias);
80+
81+
flags = spin_lock_irqsave(&g_basetime_lock);
82+
8183
clock_timespec_subtract(tp, &bias, &g_basetime);
8284

83-
leave_critical_section(flags);
85+
spin_unlock_irqrestore(&g_basetime_lock, flags);
8486

8587
/* Setup the RTC (lo- or high-res) */
8688

sched/clock/clock_systime_timespec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ int clock_systime_timespec(FAR struct timespec *ts)
6868

6969
up_rtc_gettime(ts);
7070

71-
flags = spin_lock_irqsave(NULL);
71+
flags = spin_lock_irqsave(&g_basetime_lock);
7272
clock_timespec_subtract(ts, &g_basetime, ts);
73-
spin_unlock_irqrestore(NULL, flags);
73+
spin_unlock_irqrestore(&g_basetime_lock, flags);
7474
}
7575
else
7676
{

sched/group/group_create.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void group_postinitialize(FAR struct task_tcb_s *tcb)
222222

223223
DEBUGASSERT(tcb && tcb->cmn.group);
224224
group = tcb->cmn.group;
225+
spin_lock_init(&group->tg_lock);
225226

226227
/* Allocate mm_map list if required */
227228

sched/group/group_exitinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo)
7070
irqstate_t flags;
7171

7272
DEBUGASSERT(bininfo != NULL);
73-
flags = spin_lock_irqsave(NULL);
73+
flags = enter_critical_section();
7474

7575
/* Get the TCB associated with the PID */
7676

7777
tcb = nxsched_get_tcb(pid);
7878
if (tcb == NULL)
7979
{
80-
spin_unlock_irqrestore(NULL, flags);
80+
leave_critical_section(flags);
8181
return -ESRCH;
8282
}
8383

@@ -90,7 +90,7 @@ int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo)
9090

9191
group->tg_bininfo = bininfo;
9292

93-
spin_unlock_irqrestore(NULL, flags);
93+
leave_critical_section(flags);
9494
return OK;
9595
}
9696

sched/group/group_join.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ void group_join(FAR struct pthread_tcb_s *tcb)
102102

103103
/* Add the member to the group */
104104

105-
flags = spin_lock_irqsave(NULL);
105+
flags = spin_lock_irqsave(&group->tg_lock);
106106
sq_addfirst(&tcb->cmn.member, &group->tg_members);
107-
spin_unlock_irqrestore(NULL, flags);
107+
spin_unlock_irqrestore(&group->tg_lock, flags);
108108
}
109109

110110
#endif /* !CONFIG_DISABLE_PTHREAD */

0 commit comments

Comments
 (0)