Commit Graph

1751 Commits

Author SHA1 Message Date
Masayuki Ishikawa
e981a5c8bc sched: task: Fix comments and label in nxtask_assign_pid()
Summary:
- This commit fixes comments and label in nxtask_assign_pid()

Impact:
- None

Testing:
- Built with spresense:wifi

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-01-24 22:07:16 -08:00
Masayuki Ishikawa
e277ac7a7f sched: task: Fix a potential bug in nxtask_assign_pid()
Summary:
- During reviewing sched_lock() in nxtask_assign_pid(),
  I noticed that g_pidhash is not protected by a critical section
- Because g_pidhash is accessed in an interrupt context,
  it should be protected by a critical section.
- Actually, nxsched_foreach(), nxsched_get_tcb() and so on
  use a critical section.

Impact:
- No impact

Testing:
- Tested with spresense:wifi (non-SMP) and spresense:wifi_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-01-24 20:02:58 -08:00
Masayuki Ishikawa
cb6d78c9d1 sched: sched: Remove sched_lock/unlock from nxsched_set_affinity()
Summary:
- Because this_task() and nxsched_get_tcb() are protected inside the funtcions
- Also, enter_critical_section() is used in nxsched_set_affinity()

Impact:
- No impact

Testing:
- Tested with spresense:wifi_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-01-20 21:52:58 -08:00
chao.an
23b28766c3 sched/task: setup the scheduling policy to task
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-01-19 09:24:55 -03:00
Xiang Xiao
e49bae1300 fs: Remove fs_dupfd and fs_dupfd2 internal functions
let's call either nx_dup/nx_dup2 or file_dup/file_dup2
instead just like other fs api: xxx->nx_xxx->file_xxx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I1aacfb9e25dc7b3fcb0345ff7b269b1953a01e5b
2021-01-13 16:39:45 +08:00
Xiang Xiao
0536953ded Kernel module should prefer functions with nx/kmm prefix
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-01-13 08:57:58 +01:00
ligd
f63db66382 mqueue: add file_mq_xx for kernel use
Change-Id: Ida12f5938388cca2f233a4cde90277a218033645
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-01-05 02:40:43 -06:00
ligd
3bc33572e3 mqueue: simplify the mqueue reailize
1. remove descript management in mqueue, save code size
2. use i_ops instead of i_mqueue to remove the dup logic

Change-Id: Ie88960e50ddcae9c87977c9ad65a45297c663291
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-01-05 02:40:43 -06:00
Masayuki Ishikawa
89406462cc sched: sched: Don't call sched_lock()/unlock() in nx_waitid()/waitpid() for SMP
Summary:
- Calling sched_lock()/unlock() is unnecessary for SMP
  because we've been using the critical section API

Impact:
- SMP only

Testing:
- Tested with smp and ostest with the following configurations
- sabre-6quad:smp (QEMU, dev board)
- spresense:smp, spresense:wifi_smp
- sim:smp, sim:ostest
- maix-bit:smp (QEMU)
- esp32-devkitc:smp (QEMU)
- lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-01-04 20:15:36 -06:00
chao.an
1241f910ce arch/spinlock: implement the default test-and-set semantics
use the default testset implement on single core platform
that does not support test-and-set, more flexibility for
SMP drivers(using spinlock) if configured in a single-core mode.

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-01-01 15:03:55 -06:00
Masayuki Ishikawa
ec73a4e69c arch & sched: task: Fix up_exit() and nxtask_exit() for SMP
Summary:
- During repeating ostest with sabre-6quad:smp (QEMU),
  I noticed that pthread_rwlock_test sometimes stops
- Finally, I found that nxtask_exit() released a critical
  section too early before context switching which resulted in
  selecting inappropriate TCB
- This commit fixes this issue by moving nxsched_resume_scheduler()
  from nxtask_exit() to up_exit() and also removing
  spin_setbit() and spin_clrbit() from nxtask_exit()
  because the caller holds a critical section
- To be consistent with non-SMP cases, the above changes
  were done for all CPU architectures

Impact:
- This commit affects all CPU architectures regardless of SMP

Testing:
- Tested with ostest with the following configs
- sabre-6quad:smp (QEMU, dev board), sabre-6quad:nsh (QEMU)
- spresense:wifi_smp
- sim:smp, sim:ostest
- maix-bit:smp (QEMU)
- esp32-devkitc:smp (QEMU)
- lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-12-21 23:29:56 -06:00
Nathan Hartman
93b9ad0237 sched/Kconfig: Minor grammar fixes in help text
sched/Kconfig:

    * SCHED_CRITMONITOR, SCHED_CPULOAD: Minor grammar fixes in help
      text.
2020-12-21 20:04:45 -06:00
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