Skip to content

Commit

Permalink
sched/signal: There is no need to use sched_[un]lock
Browse files Browse the repository at this point in the history
purpose:
1 sched_lock is very time-consuming, and reducing its invocations can improve performance.
2 sched_lock is prone to misuse, and narrowing its scope of use is to prevent people from referencing incorrect code and using it

test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx

We have also tested this patch on other ARM hardware platforms.
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed May 7, 2024
1 parent 8ef7238 commit 01f7fc3
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 28 deletions.
10 changes: 1 addition & 9 deletions sched/signal/sig_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ int nxsig_kill(pid_t pid, int signo)
FAR struct tcb_s *rtcb = this_task();
#endif
siginfo_t info;
int ret;

/* We do not support sending signals to process groups */

Expand All @@ -95,10 +94,6 @@ int nxsig_kill(pid_t pid, int signo)
return -EINVAL;
}

/* Keep things stationary through the following */

sched_lock();

/* Create the siginfo structure */

info.si_signo = signo;
Expand All @@ -112,10 +107,7 @@ int nxsig_kill(pid_t pid, int signo)

/* Send the signal */

ret = nxsig_dispatch(pid, &info);

sched_unlock();
return ret;
return nxsig_dispatch(pid, &info);
}

/****************************************************************************
Expand Down
3 changes: 0 additions & 3 deletions sched/signal/sig_procmask.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
irqstate_t flags;
int ret = OK;

sched_lock();

/* Return the old signal mask if requested */

if (oset != NULL)
Expand Down Expand Up @@ -148,7 +146,6 @@ int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
nxsig_unmask_pendingsignal();
}

sched_unlock();
return ret;
}

Expand Down
7 changes: 1 addition & 6 deletions sched/signal/sig_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ int nxsig_queue(int pid, int signo, union sigval value)
FAR struct tcb_s *rtcb = this_task();
#endif
siginfo_t info;
int ret;

sinfo("pid=0x%08x signo=%d value=%d\n", pid, signo, value.sival_int);

Expand All @@ -105,11 +104,7 @@ int nxsig_queue(int pid, int signo, union sigval value)

/* Send the signal */

sched_lock();
ret = nxsig_dispatch(pid, &info);
sched_unlock();

return ret;
return nxsig_dispatch(pid, &info);
}

/****************************************************************************
Expand Down
2 changes: 0 additions & 2 deletions sched/signal/sig_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ int sigsuspend(FAR const sigset_t *set)
* can only be eliminated by disabling interrupts!
*/

sched_lock(); /* Not necessary */
flags = enter_critical_section();

/* Save a copy of the old sigprocmask and install
Expand Down Expand Up @@ -154,7 +153,6 @@ int sigsuspend(FAR const sigset_t *set)
nxsig_unmask_pendingsignal();
}

sched_unlock();
leave_cancellation_point();
set_errno(EINTR);
return ERROR;
Expand Down
9 changes: 1 addition & 8 deletions sched/signal/sig_tgkill.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ int tgkill(pid_t pid, pid_t tid, int signo)
goto errout;
}

/* Keep things stationary through the following */

sched_lock();

/* Create the siginfo structure */

info.si_signo = signo;
Expand All @@ -110,15 +106,14 @@ int tgkill(pid_t pid, pid_t tid, int signo)
if (!stcb)
{
ret = -ESRCH;
goto errout_with_lock;
goto errout;
}

/* Dispatch the signal to thread, bypassing normal task group thread
* dispatch rules.
*/

ret = nxsig_tcbdispatch(stcb, &info);
sched_unlock();

if (ret < 0)
{
Expand All @@ -127,8 +122,6 @@ int tgkill(pid_t pid, pid_t tid, int signo)

return OK;

errout_with_lock:
sched_unlock();
errout:
set_errno(-ret);
return ERROR;
Expand Down

0 comments on commit 01f7fc3

Please sign in to comment.