Commit Graph

1739 Commits

Author SHA1 Message Date
Xiang Xiao
085619d395 libc: Implement getppid
as specified here:
https://pubs.opengroup.org/onlinepubs/009695399/functions/getppid.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-12-20 16:40:14 -03:00
Xiang Xiao
deef880dae sched/signal: Make the pre-allocated irq actions configurable
the action can't be dynamically allocated in any irq handler
so it's important to let the user extend the number as needed

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Id30c5d93003e63514c24f2ca0df2f634c4c63c5f
2020-12-20 19:31:59 +01:00
Xiang Xiao
c079760777 sched/mqueue: Make the pre-allocated irq messages configurable
the message can't be dynamically allocated in any irq handler
so it's important to let the user extend the number as needed

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ia26584c3815bac6cf24de4c88be0844ac8e8fba2
2020-12-20 19:31:59 +01:00
Masayuki Ishikawa
8ba67b7ec9 sched: pthread: Fix potential bugs in pthread_condclockwait.c
Summary:
- I found potential bugs in pthread_condclockwait.c
- Actually, sched_unlock() and wd_cancel() were misplaced.
- This commit fixes this issue

Impact:
- pthread_cond_clockwait() only

Testing:
- Tested with ostest with the following configs
- sabre-6quad:nsh, sabre-6quad:smp, sim:ostest

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-12-14 21:11:05 -06:00
Masayuki Ishikawa
6158b6b77b spinlock: Introduce SP_WFE() and SP_SEV()
Summary:
- This commit introduces SP_WFE() and SP_SEV() to be used for spinlock
- Also, use wfe/sev instructions for ARMV7-A to reduce power consumption

Impact:
- ARMV7-a SMP only

Testing:
- sabre-6quad:smp (QEMU, dev board)
- maix-bit:smp, esp32-devkitc:smp, spresense:smp sim:smp (compile only)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-12-11 05:58:35 -06:00
chao.an
8ac184633b clock/time: add CLOCK_BOOTTIME definition
Change-Id: I1adc0445dcdd8284d11aec44bd67b447b2b0490f
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-10 06:40:47 -06:00
Masayuki Ishikawa
409c65ce0b arch, sched: Fix global IRQ control logics for SMP
Summary:
- This commit fixes global IRQ control logic
- In previous implementation, g_cpu_irqset for a remote CPU was
  set in sched_add_readytorun(), sched_remove_readytorun() and
  up_schedule_sigaction()
- In this implementation, they are removed.
- Instead, in the pause handler, call enter_critical_setion()
  which will call up_cpu_paused() then acquire g_cpu_irqlock
- So if a new task with irqcount > 1 restarts on the remote CPU,
  the CPU will only hold a critical section. Thus, the issue such as
  'POSSIBLE FOR TWO CPUs TO HOLD A CRITICAL SECTION' could be resolved.
- Fix nxsched_resume_scheduler() so that it does not call spin_clrbit()
  if a CPU does not hold a g_cpu_irqset
- Fix nxtask_exit() so that it acquires g_cpu_irqlock
- Update TODO

Impact:
- All SMP implementations

Testing:
- Tested with smp, ostest with the following configurations
- Tested with spresense:wifi_smp (NCPUS=2,4)
- Tested with sabre-6quad:smp (QEMU, dev board)
- Tested with maix-bit:smp (QEMU)
- Tested with esp32-core:smp (QEMU)
- Tested with lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-12-10 08:33:42 +01:00
Masayuki Ishikawa
a24905059e sched: irq: Change irq_waitlock() from private to public
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-12-10 08:33:42 +01:00
Yoshinori Sugino
bce576c0bd sched/sched/sched_waitid.c: Discard the child entry
Summary:
 - Discard the child entry after receiving SIGCHLD.

Impact:
 - waitid

Testing:
hifive1-revb:nsh (CONFIG_SCHED_HAVE_PARENT=y, CONFIG_SCHED_CHILD_STATUS=y, CONFIG_SIG_DEFAULT=y)
on QEMU

static int task_main(int argc, char *argv[])
{
  sleep(1);
  return 0;
}

int main(int argc, FAR char *argv[])
{
  pid_t pid;
  siginfo_t info;
  int ret;

  pid = task_create("task1", 224, 1024, task_main, NULL);
  task_create("task2", 224, 1024, task_main, NULL);

  waitid(P_PID, pid, &info, WEXITED);
  waitid(P_ALL, 0, &info, WEXITED);
  ret = waitid(P_ALL, 0, &info, WEXITED | WNOHANG);

  assert(ret == -1);

  return 0;
}
2020-12-05 08:45:42 -06:00
Yoshinori Sugino
1a9a71f47c sched/sched/sched_waitid.c: Fix an error that occurs when a waiting task has already finished
Summary:
 - Fix an error that occurs when a waiting task has already finished.

Impact:
 - waitid

Testing:
hifive1-revb:nsh (CONFIG_SCHED_HAVE_PARENT=y, CONFIG_SCHED_CHILD_STATUS=y, CONFIG_SIG_DEFAULT=y)
on QEMU

static int task_main(int argc, char *argv[])
{
  return 0;
}

int main(int argc, FAR char *argv[])
{
  siginfo_t info;
  int pid;
  int ret;

  pid = task_create("task", 224, 1024, task_main, NULL);

  sleep(1);

  ret = waitid(P_PID, pid, &info, WEXITED);

  assert(ret == 0);

  return 0;
}
2020-12-05 08:45:42 -06:00
Yoshinori Sugino
bd79eaa5a6 sched/sched/sched_waitpid.c: Discard the correct child entry
Summary:
 - Discard the correct child entry after receiving SIGCHLD.

Impact:
 - waitpid, wait

Testing:
hifive1-revb:nsh (CONFIG_SCHED_HAVE_PARENT=y, CONFIG_SCHED_CHILD_STATUS=y, CONFIG_SIG_DEFAULT=y)
on QEMU

static int task_main(int argc, char *argv[])
{
  sleep(1);
  return 0;
}

int main(int argc, FAR char *argv[])
{
  pid_t pid1;
  pid_t pid2;
  int status;

  task_create("task1", 224, 1024, task_main, NULL);
  task_create("task2", 224, 1024, task_main, NULL);

  pid1 = waitpid(-1, &status, 0);
  pid2 = waitpid(-1, &status, 0);

  assert(pid1 != pid2);

  return 0;
}
2020-12-02 09:47:11 +09:00
Yoshinori Sugino
5dabb4c2d8 sched/sched/sched_waitpid.c: Fix return value
waitpid should return the process ID of the child whose state has changed even if pid is -1.
2020-11-29 01:02:15 -06:00
chao.an
c56785bd0d style/Makefile: remove unnecessary trailing whitespace
N/A

Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-28 12:20:30 +01:00
Yoshinori Sugino
8acff49a14 sched/signal: Remove redundant checks 2020-11-27 05:18:31 -06:00
YAMAMOTO Takashi
b1ecca08c1 sched/semaphore/sem_holder.c: Fix syslog formats 2020-11-22 19:01:05 -08:00
YAMAMOTO Takashi
09b7660795 sched/sched/sched_timerexpiration.c: Fix a syslog format 2020-11-22 19:01:05 -08:00
YAMAMOTO Takashi
fe4395f916 sched/pthread/pthread_getaffinity.c: Fix a syslog format 2020-11-22 19:01:05 -08:00
YAMAMOTO Takashi
e4c2494a74 sched/pthread/pthread_setaffinity.c: Fix a syslog format 2020-11-22 19:01:05 -08:00
Nathan Hartman
8e8ead3224 sched/signal/sig_timedwait.c: Fix typo in comment
sched/signal/sig_timedwait.c:

    * nxsig_timedwait(): Fix typo in comment:
      "is store din" -> "is stored in"

include/nuttx/signal.h:

    * Fix same typo in extern declaration of nxsig_timedwait().
2020-11-22 18:31:49 -08:00
Matias N
d5b6ec450f Parallelize depend file generation 2020-11-22 09:02:59 -03:00
YAMAMOTO Takashi
d2d48a1b9b sched/module/mod_modhandle.c: Fix a syslog format 2020-11-21 19:38:32 -08:00
YAMAMOTO Takashi
0c8aa190ca sched/signal/sig_dispatch.c: Fix a syslog format 2020-11-20 22:22:53 -08:00
YAMAMOTO Takashi
b83d658df2 sched/signal/sig_dispatch.c: Fix a syslog format error 2020-11-20 22:22:53 -08:00
YAMAMOTO Takashi
92397727ab sched/signal/sig_notification.c: Fix a syslog format error 2020-11-20 22:22:53 -08:00
Masayuki Ishikawa
12862c7b33 armv7-a: Fix comments on Cortex-A SGI
Summary:
- I noticed that Cortex-A SGI can be masked
- We thought the SGI is not maskable
- Although I can not remember how I tested it before
- It actually works as expected now
- Also, fixed the number of remaining bugs in TODO

Impact:
- No impact

Testing:
- Tested with sabre-6quad:smp (QEMU and dev board)
- Add the following code in up_idle() before calling asm("WFI");
+  if (0 != up_cpu_index())
+    {
+      up_irq_save();
+    }
- Run the hello app, you can see "Hello, World!!"
- But nsh will freeze soon because arm_pause_handler is not called.

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-19 18:01:30 -08:00
Masayuki Ishikawa
4cc38caba9 sched: Fix nx_waitid(), nx_waitpid(), nxtask_exithook() for SMP
Summary:
- I noticed waitpid_test stops with lc823450-xgevk:rndis
- The condition was CONFIG_DEBUG_ASSERTION=y
- Actually, the child task sent SIGCHILD but the parent couldn't catch the signal
- Then, I found that nx_waitid(), nx_waitpid() use sched_lock()
- However, a parent task and a child task are running on different CPUs
- So, sched_lock() is not enough and need to use a critical section
- Also, signal handling in nxtask_exithook() must be done in a critical section

Impact:
- SMP only

Testing:
- Tested with ostest with the following configurations
- lc823450-xgevk:rndis (CONFIG_DEBUG_ASSERTION=y and n)
- spresense:smp
- spresense:wifi_smp (NCPUS=2 and 4)
- sabre-6quad:smp (QEMU)
- esp32-core:smp (QEMU)
- maix-bit:smp (QEMU)
- sim:smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-14 16:31:49 -08:00
Masayuki Ishikawa
1dad55d4be sched: sched: Remove sched_tasklistlock.c for SMP
Summary:
- sched_tasklistlock.c was introduced to stabilize NuttX SMP
- However, the current SMP implementation is stable by recent fixes
- So I decided to remove the file finally

Impact:

- SMP only

Testing:
- Tested with ostest with the following configurations
- spresense:smp
- spresense:wifi_smp (NCPUS=2 and 4)
- sabre-6quad:smp (QEMU)
- esp32-core:smp (QEMU)
- maix-bit:smp (QEMU)
- sim:smp
- lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-10 23:18:08 -08:00
Masayuki Ishikawa
f0bf2143f6 sched: pthread: Fix pthread_join() for SMP
Summary:
- I noticed 'pthread_rwlock test' in ostest sometimes stops
- This issue happened with spresense:wifi_smp (NCPUS=4) and sim:smp
- Finally, I found an issue in pthread_join()
- In pthread_join(), sched_lock() is used to avoid pre-emption
- However, this is not enough for SMP
- Because another CPU would continue the pthread and exit sequences
- So we need to protect it with a critical section

Impact:
- Affect SMP only

Testing:
- Tested with ostest with the following configurations
- spresnese:smp
- spresense:wifi_smp (NCPUS=2, NCPUS=4)
- sabre-6quad:smp (QEMU)
- esp32-core:smp (QEMU)
- maix-bit:smp (QEMU)
- sim:smp
- lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-10 19:41:46 -08:00
chao.an
f6cd23e9d2 sched/init: init the default home directory to environment
Change-Id: Ib08a7702ce2256d48b210a70fa181591bbe8abe8
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-09 23:42:46 -08:00
chao.an
723698c787 sched/timer: add support of CLOCK_MONOTONIC
Reference here:
https://pubs.opengroup.org/onlinepubs/009695399/functions/timer_create.html

DESCRIPTION
...
  Each implementation shall define a set of clocks that can be
  used as timing bases for per-process timers. All implementations
  shall support a clock_id of CLOCK_REALTIME.

  *** If the Monotonic Clock option is supported, implementations shall
  support a clock_id of CLOCK_MONOTONIC. ***
...

Change-Id: Ia8e7302ed4a7e9ec11a0059bd68e9674ea942001
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-09 15:01:36 -03:00
Masayuki Ishikawa
2395ab7f6e sched: task: Fix nxtask_exit() for SMP
Summary:
- I noticed that nxsched_merge_pending() is called outside a critical section
- The issue happens if a new rtcb does not hold a critical section
- Actually, global IRQ control is done in nxsched_resume_scheduler() in nxtask_exit()
- However, nxsched_merge_pending() was called after calling nxsched_resume_scheduler()
- This commit fixes the issue by moving nxsched_merge_pending() before the function
- NOTE: the sequence was changed for SMP but works for non-SMP as well

Impact:
- This commit affects both SMP and non-SMP

Testing:
- Tested with ostest with the following configurations
- spresense:wifi_smp (NCPUS=2 and 4)
- spresense:wifi (non SMP)
- sabre-6quad:smp (QEMU)
- esp32-core:smp (QEMU)
- maix-bit:smp (QEMU)
- sim:smp
- lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-09 10:59:20 +01:00
Yoshinori Sugino
878dc33736 sched/task/task_exithook.c: Remove a redundant assignment 2020-11-07 11:14:43 +01:00
Yoshinori Sugino
d3700649c0 sched/sched/sched_waitid.c: Allow WNOHANG
In the current implementation of waitid, WEXITED is mandatory and WNOHANG is optional.
2020-11-06 00:44:55 -08:00
Yoshinori Sugino
51875ab039 sched/sched/sched_waitpid.c: Fix a typo 2020-11-05 23:06:51 -08:00
ligd
2dfd7a4e8f signal.h: fix compile failed when open TTY_SIGINT
In file included from string/lib_strsignal.c:40:0:
string/lib_strsignal.c: In function ‘strsignal’:
string/lib_strsignal.c:142:12: error: ‘CONFIG_SIG_STOP’ undeclared (first use in this function); did you mean ‘CONFIG_SIG_PIPE’?
       case SIGSTOP:
            ^
string/lib_strsignal.c:142:12: note: each undeclared identifier is reported only once for each function it appears in
string/lib_strsignal.c:147:12: error: ‘CONFIG_SIG_STP’ undeclared (first use in this function); did you mean ‘CONFIG_SIG_STOP’?
       case SIGSTP:

Esnure all standard signal number is always defined

Change-Id: I3abce86079ebeba7bab038d7c770efc90b9cffd7
Signed-off-by: ligd <liguiding1@xiaomi.com>
2020-11-05 08:28:53 +01:00
Yoshinori Sugino
5c6c0d2d57 sched/signal: Fix typos 2020-11-03 01:30:14 -08:00
Masayuki Ishikawa
6ec94082a1 sched: irq: Fix enter_critical_section() in an irq handler for SMP
Summary:
- I found a deadlock during Wi-Fi audio streaming test plus stress test
- The testing environment was spresense:wifi_smp (NCPUS=4)
- The deadlock happened because two CPUs called up_cpu_pause() almost simultaneously
- This situation should not happen, because up_cpu_pause() is called in a critical section
- Actually, the latter call was from nxsem_post() in an IRQ handler
- And when enter_critical_section() was called, irq_waitlock() detected a deadlock
- Then it called up_cpu_paused() to break the deadlock
- However, this resulted in setting g_cpu_irqset on the CPU
- Even though another CPU had held a g_cpu_irqlock
- This situation violates the critical section and should be avoided
- To avoid the situation, if a CPU sets g_cpu_irqset after calling up_cpu_paused()
- The CPU must release g_cpu_irqlock first
- Then retry irq_waitlock() to acquire g_cpu_irqlock

Impact:
- Affect SMP

Testing:
- Tested with spresense:wifi_smp (NCPUS=2 and 4)
- Tested with spresense:smp
- Tested with sim:smp
- Tested with sabre-6quad:smp (QEMU)
- Tested with maix-bit:smp (QEMU)
- Tested with esp32-core:smp (QEMU)
- Tested with lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-03 08:19:41 +01:00
Nakamura, Yuuichi
60bf4a4d8a Fix build break when CONFIG_TASK_NAME_SIZE == 0 2020-11-01 18:46:26 -08:00
Yoshinori Sugino
106b140319 sched/signal/sig_default.c: Fix a comment 2020-10-30 19:57:06 -07:00
Yoshinori Sugino
834b74c786 sched/signal/sig_default.c: Fix a typo 2020-10-30 19:56:37 -07:00
Yoshinori Sugino
c13f869432 Modify SIGSTP to SIGTSTP
Follow the POSIX description.
SIGTSTP should be sent when the Ctrl-Z characters is encountered, not SIGSTP.

Testing:
Built with hifive1-revb:nsh (CONFIG_SERIAL_TERMIOS=y, CONFIG_SIG_DEFAULT=y and CONFIG_TTY_SIGTSTP=y)
2020-10-29 01:12:43 -07:00
Yoshinori Sugino
04c0055355 Fix typos 2020-10-28 19:15:04 -07:00
chao.an
d0bde1114d sched/task: do not migrate the task state to INVALID
which still on used in task/nxmq_recover()

Change-Id: I31273aadd9e09c283cc3d0420dfc854ca8ae1899
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-10-28 11:15:22 -07:00
Juha Niskanen
8c464b0e7a sched: use nx_close instead of close
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2020-10-28 09:11:50 -07:00
Masayuki Ishikawa
46659d5a14 sched: Fix sched_lock() logic for SMP
Summary:
- I noticed sched_lock() logic is different from sched_unlock()
- I think sched_lock() should use critical section
- Also, the code should be simple like sched_unlock()
- This commit fixes these issues

Impact:
- Affects SMP only

Testing:
- Tested with spresense:wifi_smp (both NCPUS=2 and 3)
- Tested with lc823450-xgevk:rndis
- Tested with maix-bit:smp (QEMU)
- Tested with esp32-core:smp (QEMU)
- Tested with sabre-6quad:smp (QEMU)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-10-26 22:22:31 -07:00
Masayuki Ishikawa
0820549223 sched: Fix DEBUGASSERT() in sched_unlock() for SMP
Summary:
- I noticed DEBUGASSERT() happens in sched_unlock()
- The test was Wi-Fi audio streaming stress test with spresense 3cores
- Actually, g_cpu_schedlock was locked but g_cpu_lockset was incorrect
- Finally, I found that cpu was obtained before enter_critical_section()
- And the task was moved from one cpu to another cpu
- However, that call should be done within the critical section
- This commit fixes this issue

Impact:
- Affects SMP only

Testing:
- Tested with spresense:wifi_smp (both NCPUS=2 and 3)
- Tested with lc823450-xgevk:rndis
- Tested with maix-bit:smp (QEMU)
- Tested with esp32-core:smp (QEMU)
- Tested with sabre-6quad:smp (QEMU)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-10-26 22:22:31 -07:00
YAMAMOTO Takashi
6a2bd9a75b Change the default value of SIGPIPE
To avoid the conflicting default with SIGQUIT.
2020-10-25 20:35:41 -07:00
Yoshinori Sugino
fabfc9ab10 sched/signal/sig_procmask.c: Remove an unnecessary variable 2020-10-24 14:10:20 +01:00
Yoshinori Sugino
ea5ec14995 sched/signal/sig_procmask.c: Fix a typo 2020-10-24 09:36:46 +01:00
Masayuki Ishikawa
d1f82ced26 Revert "sched: Call up_[use|create]_stack after nxtask_setup_scheduler"
This reverts commit 6eba1ad90a.
2020-10-22 18:31:31 +09:00