Skip to content

Commit

Permalink
sched/sched: There is no need to use sched_[un]lock
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Apr 14, 2024
1 parent 3ce84d1 commit 19469e4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 83 deletions.
2 changes: 0 additions & 2 deletions sched/sched/sched_getaffinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ int nxsched_get_affinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask)

/* Verify that the PID corresponds to a real task */

sched_lock();
if (pid == 0)
{
tcb = this_task();
Expand All @@ -97,7 +96,6 @@ int nxsched_get_affinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask)
ret = OK;
}

sched_unlock();
return ret;
}

Expand Down
3 changes: 0 additions & 3 deletions sched/sched/sched_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ int nxsched_get_param(pid_t pid, FAR struct sched_param *param)
{
/* Get the TCB associated with this PID */

sched_lock();
tcb = nxsched_get_tcb(pid);
if (!tcb)
{
Expand Down Expand Up @@ -136,8 +135,6 @@ int nxsched_get_param(pid_t pid, FAR struct sched_param *param)
}
#endif
}

sched_unlock();
}

return ret;
Expand Down
24 changes: 5 additions & 19 deletions sched/sched/sched_setparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param)
{
FAR struct tcb_s *rtcb;
FAR struct tcb_s *tcb;
int ret;

/* Verify that the requested priority is in the valid range */

Expand All @@ -87,12 +86,6 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param)
return -EINVAL;
}

/* Prohibit modifications to the head of the ready-to-run task
* list while adjusting the priority
*/

sched_lock();

/* Check if the task to reprioritize is the calling task */

rtcb = this_task();
Expand All @@ -110,8 +103,7 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param)
{
/* No task with this PID was found */

ret = -ESRCH;
goto errout_with_lock;
return -ESRCH;
}
}

Expand All @@ -128,8 +120,7 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param)
if (param->sched_ss_max_repl < 1 ||
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)
{
ret = -EINVAL;
goto errout_with_lock;
return -EINVAL;
}

/* Convert timespec values to system clock ticks */
Expand Down Expand Up @@ -163,8 +154,7 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param)
if (repl_ticks < budget_ticks)
#endif
{
ret = -EINVAL;
goto errout_with_lock;
return -EINVAL;
}

/* Stop/reset current sporadic scheduling */
Expand Down Expand Up @@ -198,18 +188,14 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param)
leave_critical_section(flags);
if (ret < 0)
{
goto errout_with_lock;
return ret;
}
}
#endif

/* Then perform the reprioritization */

ret = nxsched_reprioritize(tcb, param->sched_priority);

errout_with_lock:
sched_unlock();
return ret;
return nxsched_reprioritize(tcb, param->sched_priority);
}

/****************************************************************************
Expand Down
12 changes: 1 addition & 11 deletions sched/sched/sched_setscheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ int nxsched_set_scheduler(pid_t pid, int policy,
{
FAR struct tcb_s *tcb;
irqstate_t flags;
int ret;

/* Check for supported scheduling policy */

Expand Down Expand Up @@ -120,12 +119,6 @@ int nxsched_set_scheduler(pid_t pid, int policy,
return -ESRCH;
}

/* Prohibit any context switches while we muck with priority and scheduler
* settings.
*/

sched_lock();

/* Further, disable timer interrupts while we set up scheduling policy. */

flags = enter_critical_section();
Expand Down Expand Up @@ -270,14 +263,11 @@ int nxsched_set_scheduler(pid_t pid, int policy,

/* Set the new priority */

ret = nxsched_reprioritize(tcb, param->sched_priority);
sched_unlock();
return ret;
return nxsched_reprioritize(tcb, param->sched_priority);

#ifdef CONFIG_SCHED_SPORADIC
errout_with_irq:
leave_critical_section(flags);
sched_unlock();
return ret;
#endif
}
Expand Down
22 changes: 2 additions & 20 deletions sched/sched/sched_waitid.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
FAR struct child_status_s *child;
bool retains;
#endif
irqstate_t flags;
sigset_t set;
int errcode;
int ret;
Expand Down Expand Up @@ -198,18 +199,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)

sigemptyset(&set);
nxsig_addset(&set, SIGCHLD);

/* NOTE: sched_lock() is not enough for SMP
* because the child task is running on another CPU
*/

#ifdef CONFIG_SMP
irqstate_t flags = enter_critical_section();
#else
/* Disable pre-emption so that nothing changes while the loop executes */

sched_lock();
#endif
flags = enter_critical_section();

/* Verify that this task actually has children and that the requested
* TCB is actually a child of this task.
Expand Down Expand Up @@ -464,20 +454,12 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
}
}

#ifdef CONFIG_SMP
leave_critical_section(flags);
#else
sched_unlock();
#endif
leave_cancellation_point();
return OK;

errout:
#ifdef CONFIG_SMP
leave_critical_section(flags);
#else
sched_unlock();
#endif
leave_cancellation_point();
set_errno(errcode);
return ERROR;
Expand Down
30 changes: 2 additions & 28 deletions sched/sched/sched_waitpid.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,7 @@ pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options)
* because the child task is running on another CPU
*/

#ifdef CONFIG_SMP
irqstate_t flags = enter_critical_section();
#else
/* Disable pre-emption so that nothing changes in the following tests */

sched_lock();
#endif

/* Get the TCB corresponding to this PID */

Expand Down Expand Up @@ -198,12 +192,7 @@ pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options)
ret = pid;

errout:
#ifdef CONFIG_SMP
leave_critical_section(flags);
#else
sched_unlock();
#endif

return ret;
}

Expand All @@ -230,25 +219,15 @@ pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options)
bool retains;
#endif
FAR struct siginfo info;
irqstate_t flags;
sigset_t set;
int ret;

/* Create a signal set that contains only SIGCHLD */

sigemptyset(&set);
nxsig_addset(&set, SIGCHLD);

/* NOTE: sched_lock() is not enough for SMP
* because the child task is running on another CPU
*/

#ifdef CONFIG_SMP
irqstate_t flags = enter_critical_section();
#else
/* Disable pre-emption so that nothing changes while the loop executes */

sched_lock();
#endif
flags = enter_critical_section();

/* Verify that this task actually has children and that the requested PID
* is actually a child of this task.
Expand Down Expand Up @@ -495,12 +474,7 @@ pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options)
ret = pid;

errout:
#ifdef CONFIG_SMP
leave_critical_section(flags);
#else
sched_unlock();
#endif

return ret;
}
#endif /* CONFIG_SCHED_HAVE_PARENT */
Expand Down

0 comments on commit 19469e4

Please sign in to comment.