Commit Graph

2058 Commits

Author SHA1 Message Date
Petro Karashchenko
2447b7bd9a pthread: restore pthread mutex default protocol POSIX compatibility
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-01-11 01:55:12 +08:00
Xiang Xiao
964f4b7ed7 sched/Kconfig: Remove CONFIG_ prefix from SCHED_HPWORK
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-01-06 18:45:13 -03:00
Zeng Zhaoxiu
fb43fd73ed signal: signal handler may cause task's state error
For example, task is blocked by nxsem_wait(sem1), use nxsem_wait(sem2)
in signal handler, and take sem2 successfully, after exit from signal
handler to task, nxsem_wait(sem1) returns OK, but the correct result
should be -EINTR.

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
2022-01-05 21:36:44 +09:00
walker.zeng
76b2f7199d sched: fix the bug of task's tmeslice
The BUG is as follow:
 1. Suppose there are two ready tasks t1 and t2 have the same priority, and t1 is the running.
 2. A new, higher priority task t0 (such as hpwork) is ready, then switch to t0.
 3. After t0 is suspended, then switch to t1 and reset the t1's timeslice.
 4. goto 2
The t2 will have no chance to run.

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
2021-12-30 18:01:56 +08:00
Xiang Xiao
dd942f0b04 sched/backtrace: Dump the complete stack regardless the depth
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-29 12:09:54 +08:00
ligd
0bb32f27c0 init: use exec_spawn instead of exec
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-24 08:23:30 -06:00
ligd
10ccba6671 init: move USERMAIN_XX out of INIT_ENTRYPOINT
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-24 08:23:30 -06:00
ligd
e5420c8eee wqueue: fix NO leave_critical_section() when only CONFIG_SCHED_HPWORK
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-23 02:27:34 -06:00
Nathan Hartman
878c347bb6 sched: Fix typos in comments
sched/pthread/pthread_mutextimedlock.c:
sched/pthread/pthread_mutextrylock.c:

    * Fix typos in comments. No functional change.
2021-12-21 11:07:23 -06:00
Juha Niskanen
422ceec99b Fix typos in comments and Kconfig files
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2021-12-21 03:26:16 -06:00
anjiahao
9a53601ba9 sched:add holder in sem_trywait
Avoid priority rollover

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2021-12-17 11:28:27 -06:00
raiden00pl
e2c9f612c9 sched/init/nx_start.c: fix compile break when CONIFG_TASK_NAME_SIZE=0 2021-12-17 10:29:00 +01:00
zhanghu6
f56aefaa41 sched_note: change uint32_t nbi_module into uint8_t array, because variables keep the same style that use uint8_t array
sched_note: add note dump module tag definitions

NOTE_MODULE(a, b, c, d)

example:
define TEST_MODULE NOTE_MODULE('t', 'e', 's', 't')
sched_note_dump(TEST_MODULE, event, data, len);

define AUDIO_MODULE NOTE_MODULE('a', 'u', 'd', 'i')
sched_note_dump(AUDIO_MODULE, event, data, len);
2021-12-16 04:18:17 -06:00
zhanghu6
d05b9a9c79 note dump: add CONFIG_SCHED_INSTRUMENTATION_SWITCH
1. If CONFIG_SCHED_INSTRUMENTATION_SWITCH is enabled, then these additional interfaces are expected:
        sched_note_suspend
        sched_note_resume
at the same time,If CONFIG_SMP is enabled,then expected:
        sched_note_cpu_pause
        sched_note_cpu_paused
        sched_note_cpu_resume
        sched_note_cpu_resumed
2. other board if enable SCHED_INSTRUMENTATION,SCHED_INSTRUMENTATION_SWITCH to defconfig.
2021-12-15 07:07:00 -06:00
zhanghu6
a32d14cb9c sched note trace: and note dump
note_type NOTE_DUMP_STRING API:
sched_note_string
sched_note_vprintf
sched_note_printf

note_type NOTE_DUMP_BINARY API:
sched_note_dump
sched_note_vbprintf
sched_note_bprintf
2021-12-13 21:21:22 -06:00
ligd
166a9210ca wqueue: update wqueue to support using wqueue before wqueue start
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 21:16:25 -06:00
Jiuzhu Dong
6b5a7a73ba sim: add CONFIG_SIM_STACKSIZE_ADJUSTMENT to reduce variability
between sim and other different platform stack size setting

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-12-13 21:15:30 -06:00
chao.an
4703ef93cc sched/semaphore: remove redundant goto case
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-13 14:38:44 +09:00
chao.an
102a6357ca Revert "sched: Remove a redundant critical section"
There is a potential problem that can lead to deadlock at
condition wait, if the timeout of watchdog is a very small value
(1 tick ?), the timer interrupt will come before the nxsem_wait()

Revert "sched: pthread: Remove a redundant critical section in pthread_condclockwsait.c"
Revert "sched: semaphore: Remove a redundant critical section in nxsem_clockwait()"
Revert "sched: semaphore: Remove a redundant critical section in nxsem_tickwait()"

This reverts commit 7758f3dcb1.
This reverts commit 2976bb212e.
This reverts commit 65dec5d10a.

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-13 14:38:44 +09:00
Xiang Xiao
1af8cd4de8 sched: Move argv from tcb_s to task_info_s
argv is allocated from stack and then belong to userspace,
so task_info_s is a best location to hold this information.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-11 10:08:53 -06:00
Masayuki Ishikawa
83edd2fbba sched: signal: Introduce a private spinlock in sig_action.c
Summary:
- This commit introduces a private spinlock in sig_action.c

Impact:
- None

Testing:
- Tested with spresense:wifi_smp and spresense:wifi

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-12-09 00:13:31 -06:00
ligd
2f55807acb sched/signal: add spinlock to g_sigfreeaction
To avoid nxsig_alloc_action() & nxsig_release_action() competition

Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-09 11:55:24 +09:00
Huang Qi
58e0781e2e arch/arm: Implement TLS support
Signed-off-by: Huang Qi <no1wudi@qq.com>
2021-12-07 23:31:41 -06:00
anjiahao
9f4d236531 sched_waitpid:delete debugassert
If a task registers SIGCHLD, uses waitpid(-1)
in the handler, and the task also calls waitpid,
it will fail to delete the child function

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2021-12-03 01:17:15 -06:00
Abdelatif Guettouche
7776c6ad0e sched_note.c: Condition g_note_disabled_irq_nest with
INSTRUMENTATION_IRQHANDLER to avoid warnings.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-11-27 06:16:23 -06:00
zhuyanlin
060b99d67c sched:watchdog: remove tick check in wd_timer
In scene with CONFIG_SCHED_TICKLESS but no CONFIG_SCHED_TICKLESS_ALARM
The system may crash by assert
`up_assert: Assertion failed at file:wdog/wd_start.c line: 379 task: rptun`

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2021-11-20 02:28:06 -06:00
Abdelatif Guettouche
bdc157f443 sched/sched: Fix some typos in comments.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-11-18 19:27:40 -06:00
ligd
b5d1ec28de mm: do kmm_checkcorruption in IRQ when TCB_FLAG_DEBUG_CHECK set
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-17 09:55:19 -06:00
ligd
7c547b3ebd sem: remove limitation of irq context when do sem_trywait
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-17 02:20:08 -06:00
Abdelatif Guettouche
9b1d4de3be drivers/note: Fix typos.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-11-12 16:50:41 -03:00
Xiang Xiao
e57203eca4 sched: Disable message queue by default when DEFAULT_SMALL equals y
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-10 09:16:35 +01:00
Xiang Xiao
086b09cc84 sched: Reduce the default preallocated buffer when DEFAULT_SMALL=y
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-09 13:09:40 +01:00
Jukka Laitinen
c79d2067c7 Move timespec calculations from sched into libc/sched
Allow using these functions also outside sched, where systick
related calculations are performed

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2021-11-04 13:19:01 -05:00
Xiang Xiao
b1879d5d24 sched/vfork: allocate tls_info_s instead task_info_s from stack
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-01 20:53:07 -03:00
Xiang Xiao
aec01e96fa libc: Remove the empty lib_initialize
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-01 11:03:02 -03:00
Xiang Xiao
86fc19ff3f Fix error: 'struct tcb_s' has no member named 'low_priority'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-10-31 06:30:57 -03:00
anjiahao
0aa14f832d mq_open: add long file name check and parameter check
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2021-10-21 11:01:45 -03:00
Jiuzhu Dong
7e59a6a31e cpuload: fix crash because of the member of g_pidhash is NULL
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-10-18 15:13:52 +02:00
Xiang Xiao
4a7915e72b sched: Check g_pidhash[hash_ndx] isn't NULL before access pid field in nxsched_get_tcb
Fix the regression by commit:
commit 8b67944c75
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Thu Oct 14 11:03:07 2021 +0800

    sched: Remove pidhash_s and move ticks to tcb_s

    simplify the code logic and reduce memory a little bit

    Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-10-17 17:28:57 +09:00
Xiang Xiao
8b67944c75 sched: Remove pidhash_s and move ticks to tcb_s
simplify the code logic and reduce memory a little bit

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-10-16 06:19:17 -03:00
chao.an
13741c9017 sched/pidhash: init g_pidhash to NULL to avoid wild pointer
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-10-16 06:19:17 -03:00
Jiuzhu Dong
9bc913abef wd_start: use sclock_t type replace int
when enable SYSTEM_TIME64, tick may exceed the int32 range
example:
pthread_cond_clockwait
        ---->clock_abstime2ticks
                    ---->wd_start

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-10-10 19:59:57 -07:00
chenhonglin
dfc08a0b66 sched/sched/remove_readytorun.c: Fix CPU affinity issues in SMP
the logical may choose the head of g_readytorun(the greatest priority)
task as the next while ignoring the cpu affinity of it.

Signed-off-by: chenhonglin <chenhonglin@xiaomi.com>
2021-09-29 16:23:17 +09:00
chenhonglin
cb38060db2 sched/sched_setpriority.c: Fix CPU affinity issues in SMP
In "nxsched_nexttcb": the task may not running on this_cpu,
and rtrtcb->affinity(the affinity of the task in g_readytorun)
may not include the current cpu which should be the tcb->cpu.

Signed-off-by: chenhonglin <chenhonglin@xiaomi.com>
2021-09-29 16:23:17 +09:00
Huang Qi
e72680bb46 sched/signal: Correct kill with cancellation
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-09-27 18:17:40 -07:00
Abdelatif Guettouche
3b2aea204c sched/irq/irq_csection.c: Fix typos and correct some comments.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-09-16 10:53:51 -05:00
Abdelatif Guettouche
20d34cce98 sched/irq_section.c: irq_waitlock is a private function; remove its
prototype from irq.h and define it as static.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-09-15 06:20:59 +09:00
Michal Lenc
cdfe7b5a54 sched/wdog/wd_start.c: prevent accessing watch-dog lag if head is NULL
If statement in line 103 could acces wdactivelist.head->lag when head was
NULL which could result in hard fault. The statement was also redundant
as the same condition is checked in the while loop below. This change
remove the if statement to prevent hard fault to occur.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2021-09-06 09:29:21 -07:00
ligd
35379403f8 sched/wdog: move SMP enter_critical_section to sched_timerexpiration.c
Change-Id: Id654e6d2151e3b807ed2df4ab8169b90ab07b015
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-08-27 16:59:20 +09:00
ligd
9116ed9247 sched/wdog: fix switch_context caused error in wd_start()
Thead A:                     Thread B:
wd_start(wdogX)
wd_cancel
nxsched_cancel_timer  -->    wd_start(wdogX)
                             wd_cancel
                             add wdogX to g_wdactivelist
                      <--
add wdogX to g_wdactivelist

then, you will find wdogX add twice.

Change-Id: Icbf3b2badff20908e115c9134e2400cdcb32b1e0
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-08-27 16:59:20 +09:00
chao.an
904348302a sched/backtrace: simplify the assign of tcb in case of negative pid
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-08-20 13:11:45 -03:00
Jiuzhu Dong
35b3898ce1 task_spawn: release g_spawn_parmsem and sched_unlock at the ending
Change-Id: Ifcb5b9921e82fc495c4457fdb5f0607f40b07fc0
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-08-19 20:43:54 -07:00
Masayuki Ishikawa
cb167c3f7d sched: Allow CONFIG_SMP_NCPUS=1 without CONFIG_DEBUG_FEATURES
Summary:
- This commit allows CONFIG_SMP_NCPUS=1 without CONFIG_DEBUG_FEATURES

Impact:
- None

Testing:
- Tested with sim:smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-08-19 19:17:56 -07:00
chao.an
1060953567 sched/backtrace: add sched_backtrace support
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-08-19 01:30:50 -07:00
chao.an
83964231a5 libs/libc: move the backtrace implement to sched
1. move the backtrace implement to sched
2. rename CONFIG_UNWINDER to CONFIG_SCHED_BACKTRACE

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-08-19 01:30:50 -07:00
Abdelatif Guettouche
9859ceb8fd sched/: Fix some typos.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-08-14 11:19:34 -07:00
Gustavo Henrique Nihei
b145ad82b7 sched: Fix crash on early syslog message with prepended process name
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-08-06 21:09:08 -07:00
Xiang Xiao
5025fbef8d Rename LIB_ to LIBC_ for all libc Kconfig
follow other libc component naming convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-08-05 19:45:24 +02:00
Xiang Xiao
4bb50cdd37 signal: Allow SIG_EVTHREAD selectable in protected mode
since we can delivery signal through libs/libc/wqueue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-08-05 09:52:06 -03:00
Jiuzhu Dong
855c78bb9d work_queue: schedule the work queue using the timer mechanism
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-27 21:01:38 -07:00
Jiuzhu Dong
a0c3a0923a sched/wqueue: merge kwork_lpthread.c and kwork_hpthread.c to kwork_thread.c
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-27 21:01:38 -07:00
Jiuzhu Dong
11faf0cb20 fs/inode: add sanity check for inode to avoid nullpointer
Change-Id: Ib2c74ba308b8f15756fac4e69632c296243eb4ab
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-25 23:01:37 -07:00
Abdelatif Guettouche
de68507f84 sched/*/*spinlock.c: Fix some typos.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-07-24 09:00:41 -07:00
jordi
b87333bae8 Kconfig: remove empty help sections
To avoid the setconfig warning: "has 'help' but empty help text"
2021-07-23 02:32:19 -07:00
SPRESENSE
5db4d2a83b sched/task: Fix wrong return value from nxspawn_open()
nxspawn_open() is expected to return "OK" when it success, but
it doesn't return it in case of executing dup2.
Because of this, the "Command as parameter" couldn't work with
Builtin Apps.
2021-07-20 09:26:01 -03:00
Nathan Hartman
af1fd49fb0 wqueue: Fix typos
include/nuttx/wqueue.h:
libs/libc/wqueue/work_cancel.c:
libs/libc/wqueue/work_queue.c:
sched/wqueue/kwork_cancel.c:
sched/wqueue/kwork_queue.c:

    * Fix spelling, grammar, and typos.
    * Improve wording in a few areas.
    * These changes affect comments only. No functional changes.
2021-07-16 19:54:08 -03:00
Jiuzhu Dong
9e4352ad64 group/child_status: Dynamically expand group child_status
Change-Id: I4033e93b6adceb01eebe1c2a12ffe8737042b1a6
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-15 20:14:57 -07:00
Xiang Xiao
cee43ce280 arch/sim: Initialize the idle thread stack info correctly
and change the default value of IDLETHREAD_STACKSIZE to 65536

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ia54efbbca4b69706150bc4178844b316688a104e
2021-07-16 08:37:53 +09:00
Xiang Xiao
a5ac4463c2 sched/init: initialize all idle thread's tl_task
since this patch forget to initialize the idle tls info:
commit 50c08bf45b
Author: Huang Qi <huangqi3@xiaomi.com>
Date:   Tue Jun 29 16:01:02 2021 +0800

    libc: Move pthread_key_destructor to task_info_s

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: If7d0c0118323fa3dcf44081d675cd57b14eba75a
2021-07-16 08:37:53 +09:00
Xiang Xiao
bd74dc2b88 sched/init: Remove the unnessary CONFIG_SMP check
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I2afaf310b411993e37140b3d7977968a7fda5c3b
2021-07-16 08:37:53 +09:00
Xiang Xiao
0148e1d501 fs: Support the root file system attributes(mode, uid, gid and time)
Note: all attributes is guarded by PSEUDOFS_ATTRIBUTES to save the space

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I664d60382e356068fd920f08aca5b4a49d8d92a9
2021-07-14 10:35:15 -03:00
Jiuzhu Dong
9b1f554429 sched: Dynamically extend the pid hash table
Change-Id: I3a719bc575cd408cd530a39efa203f507b44fa9c
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-11 19:42:30 -07:00
Jiuzhu Dong
bb867a38fc nx_start: Simplify and unify the partial initialization process
for both SMP and non-SMP

Change-Id: I0fea8b4f59fc27d253a2ef9b7503acbb7410cc14
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-11 19:42:30 -07:00
Peter Bee
8a47dd95c9 sched/clock: add nsec range check in clock_settime
MIRTOS-109

Return error when tv_nsec <0 or >=1000 million.

Change-Id: Iddbbcda163cb402551f619efb7486f6798859d57
Signed-off-by: Peter Bee <bijunda1@xiaomi.com>
2021-07-09 14:19:03 -03:00
Huang Qi
50c08bf45b libc: Move pthread_key_destructor to task_info_s
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-07-04 07:36:44 -05:00
ligd
ece224a7e3 sched/waitpid: handle waitpid waitting tcb->group is NULL
Fail case:
exit -> nxtask_terminate -> nxtask_exithook -> nxsched_release_tcb
                            group_leave     || nxsched_releasepid & group_leave
                                            /\
                                           /  \
                                       switch out & waitpid()

Thread A group_leave in nxtask_exithook, switch out,
Thread B do waitpid(thread A) then meet traget thread A group is NULL, error.

Change-Id: Ia181d7a13aa645ec1c3141a45839fbf79db35b17
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-04 06:23:59 -05:00
ligd
8d2615f78d sched: add STACK_USAGE_SAFE_PERCENT for stack overflow check
Change-Id: Ia70e243b36401e28c31fcd7e1b480b79374c27ef
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-03 12:56:40 -05:00
ligd
940c80f7b3 sched: fix stack check crash in idle thread
Change-Id: Iea7c096ffcab181f318edcc1bfe1717785831b7a
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-03 12:56:40 -05:00
ligd
68d66148ad mm: idle check heap use mm_trysemaphore
Change-Id: I92e1df572fa6cd801b10e5b06e7b04d450b3e3fb
Signed-off-by: ligd <liguiding1@xiaomi.com>
(cherry picked from commit bc9a5d1ca9656f6effd3a419cc2488586dfb1489)
2021-07-03 12:56:40 -05:00
ligd
646b229f74 sched/init/nx_start.c: enter_critical_section when check heap & stack in idle
Change-Id: I2ef95ee8e1dc1ba3e74c1d6c8c6af20f53be85c7
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-03 12:56:40 -05:00
ligd
a96cab58ad sched: add depends on ARCH_INTERRUPTSTACK to SMP
Change-Id: I7edbbcf314045c5567e30b39b0693672e5d10e9a
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-03 07:02:33 -05:00
Huang Qi
65fa11634b sched: Refine tls_info_s and task_info_s
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-07-02 10:33:34 -05:00
ligd
adfaa140cc sched: add CONFIG_SCHED_CRITMONITOR_XX for debugging system lantency
Change-Id: Id2a75db28caf1a89552e33391bd90f85cde08dbd
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-02 08:25:02 -05:00
ligd
2d32a52353 sched_critmon: add thread run time to critmonitor
Change-Id: Ib44e45f0f9a1b249b4067db324c9dbdf0cf3f288
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-02 08:25:02 -05:00
Jiuzhu Dong
198b85d233 sched/idle: disable sched when idle call nx_bringup
Because idle task will call mm_malloc to create some task
and will take sem of mm. But if smp enable, the sem of mm may be
taken by other cpu, so idle may be block because take this sem and crash.

Change-Id: I22f0233ef6c59a1b81607d4389e68f8646c89395
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-02 04:51:15 -05:00
Xiang Xiao
d7d3177668 sched/wdog: Remove flags field from wdog_s to save memory
since WDOG_ISACTIVE can check func field instead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I21d7f9cfe6195c8ccb6cc5925ff66f3c89822f9d
2021-07-01 19:27:10 -03:00
Nathan Hartman
a8cbcd084f signal: Fix docs and comments related to SIGWORK and its config
Documentation/reference/os/wqueue.rst:

    * CONFIG_SIG_SIGWORK: Fix sentence that was cut off in the
      middle.

include/signal.h:

    * SIGWORK: Fix grammar in comment.

sched/Kconfig:

    * config SIG_SIGWORK: Fix ---help--- text to indicate that
      this user-configured signal number may be used by various
      internal worker threads.
2021-06-30 21:22:49 -05:00
Xiang Xiao
13780dada3 sched: Add kthread_create_with_stack
let caller customize the stack buffer

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I878818ec1ce5650165dbbe2d72a4618cb2e6a094
2021-06-27 12:35:13 -03:00
Abdelatif Guettouche
0a4982a80e Introduce ARCH_HAVE_EXTRA_HEAPS, this config is going to be used for
chips that have multiple separate heaps.
For now it's used to enable APIs to initialize the different heaps
during the start sequence but can be extended for other purposes that
manage those heaps.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-06-26 09:52:43 -05:00
Xiang Xiao
ae9b5fd306 Replace mktime with timegm in rtc and fs driver
since kernel component should use UTC instead local time

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Icf939e1ab0af8e577105f539d2553bc67b3b3d10
2021-06-23 13:43:32 -03:00
Juha Niskanen
ea1144630d sched/task/task_spawn.c: initialize variables explicitly
'pid' cannot really be used uninitialized, but Clang analyzer does not
see it.  Add initializer to silence it and also make debugging slightly
easier.

Explicitly set pid's address to NULL to fix this complaint:

  "Address of stack memory associated with local variable 'pid' is still
   referred to by the global variable 'g_spawn_parms' upon returning to
   the caller."

No functional change.

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2021-06-22 03:44:02 -05:00
Abdelatif Guettouche
af5e0c620f Rename MODULE_TEXT to TEXT_HEAP as the latter is more generic.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-06-18 07:14:17 -05:00
Xiang Xiao
bec68ad8ea sched/posix_spawn: Don't insert name at the begin of argv
since the standard require the caller pass the name explicitly
https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html:
The argument argv is an array of character pointers to null-terminated strings.
The last member of this array shall be a null pointer and is not counted in argc.
These strings constitute the argument list available to the new process image.
The value in argv[0] should point to a filename that is associated with the
process image being started by the posix_spawn() or posix_spawnp() function.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-15 07:32:33 -06:00
Xiang Xiao
90f71bd017 Revert "sched/posix_spawn: Don't insert name at the begin of argv"
This reverts commit 032086870d.
2021-06-15 07:32:33 -06:00
Xiang Xiao
032086870d sched/posix_spawn: Don't insert name at the begin of argv
since the standard require the caller pass the name explicitly
https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html:
The argument argv is an array of character pointers to null-terminated strings.
The last member of this array shall be a null pointer and is not counted in argc.
These strings constitute the argument list available to the new process image.
The value in argv[0] should point to a filename that is associated with the
process image being started by the posix_spawn() or posix_spawnp() function.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Id79ffcc501ae9552dc4e908418ff555f498be7f1
2021-06-14 07:11:53 -06:00
chao.an
6e6eecaa73 arch: adjust idle stack offset to reserve space of stack info
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-06-09 13:30:13 -05:00
YAMAMOTO Takashi
b3e8535ad6 Revert "tls: Move pthread key destructor to libc"
This reverts commit cc514d7791.

* It introduced a regression.
  https://github.com/apache/incubator-nuttx/issues/3868

* It seems conceptually wrong to have per-process data in
  the main thread's stack.
2021-06-09 07:59:44 -05:00
Xiang Xiao
5b2a17b892 Include assert.h in necessary place
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-08 13:06:08 -07:00
Huang Qi
cc514d7791 tls: Move pthread key destructor to libc
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-06-06 15:25:56 -06:00
Xiang Xiao
2e54df0f35 Don't include assert.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-03 08:36:03 -07:00
Xiang Xiao
ae216cf9e9 sched/task: Simplify the syscall handling of task_spawn
It's better to save one argument by returning pid directly.
This change also follow the convention of task_create.
BTW, it is reasonable to adjust the function prototype a
little bit from both implementation and consistency since
task_spawn is NuttX specific API.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-01 12:45:10 +09:00
Xiang Xiao
d7f96003cf Don't include debug.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-01 06:42:02 +09:00
Alin Jerpelea
c0ed011874 sched: update licenses to Apache
Gregory Nutt is the copyright holder for those files and he has submitted the
SGA as a result we can migrate the licenses to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-05-25 08:46:53 -05:00
Nathan Hartman
f61214cc0d mqueue, btqueue: Fix some typos (e.g., essage -> message)
include/nuttx/mqueue.h:
sched/mqueue/mq_msgqfree.c:
wireless/bluetooth/bt_queue.c:

    * Fix typos in comments only. No functional changes.
2021-05-25 07:39:24 +09:00
Xiang Xiao
001e7c3e76 sched: Don't include nuttx/sched.h inside sched.h
But let nuttx/sched.h include sched.h instead to
avoid expose nuttx kernel API to userspace.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-05-24 12:11:53 +09:00
Huang Qi
a2941532bd pthread: Avoid recursive pthread_exit call
pthread_exit will be called recursive when pthread_cancel
or other cleanup operation with syscalls that support
cancellation, to avoid this by mark current tcb flag as
TCB_FLAG_CANCEL_DOING instead of TCB_FLAG_CANCEL_PENDING.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-05-21 22:46:52 -06:00
Huang Qi
d374d55926 pthread: Implement destructor of pthread_key_create
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Change-Id: I6aafba9680257cba071bf1f72ae2ec2c475f5fb0
2021-05-21 22:46:52 -06:00
Huang Qi
f4a0b7aedd libc: Call pthread_exit in user-space by up_pthread_exit
Drop to user-space in kernel/protected build with up_pthread_exit,
now all pthread_cleanup functions executed in user mode.

* A new syscall SYS_pthread_exit added
* A new tcb flag TCB_FLAG_CANCEL_DOING added
* up_pthread_exit implemented for riscv/arm arch

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-05-21 22:46:52 -06:00
Huang Qi
81a01d089b libc/pthread: Fix comment and document issue
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-05-21 22:46:52 -06:00
Huang Qi
f1a92e9cbb libc: Move pthread_cleanup to user space
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-05-21 22:46:52 -06:00
Huang Qi
54eef9f639 libc: Move pthread_exit to userspace
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-05-21 22:46:52 -06:00
Gregory Nutt
bb9b58bdde libc: Move pthread_create to user space
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Change-Id: I5c447d94077debc79158686935f288e4c8e51e01
2021-05-21 22:46:52 -06:00
Xiang Xiao
8afb16ca55 Don't include errno.h from spawn.h
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-05-19 10:11:15 +02:00
Jiuzhu Dong
5ec3ef0e56 group/group_signal: cancel dispatch signal when
the number of members in the group is zero.

Repetition step:
If using waitpid() to wait a task has exited, the waitpid will use
nxsing_kill with signal number 0 to determine if that task is still
alive, and will call group_signal to dispatch signal for each member
of the group and perform signal handing checks, it will assert at
sched/group/group_signal.c:261.

Change-Id: I75ef015a261101277436d742897ce68fed44b5da
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-05-17 07:14:27 -05:00
Nathan Hartman
8af9d39667 Documentation, comments: Minor improvements and typos fixed 2021-05-09 19:12:13 -07:00
Masayuki Ishikawa
0ec5563a60 sched: group: Fix group_signal() for SMP
Summary:
- This commit fixes the signest_test issue with lc823450-xgevk

Impact:
- SMP with CONFIG_SCHED_CHILD_STATUS=y

Testing:
- Tested with ostest with lc82345-xgevk:rndis
- NOTE: need to revert the commit 65274d5fdf

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-04-23 03:25:14 -05:00
Masayuki Ishikawa
1b00e5d518 spinlock: Remove SP_SECTION
Summary:
- SP_SECTION was introduced to allocate spinlock in non-cachable
  region mainly for Cortex-A to stabilize the NuttX SMP kernel
- However, all spinlocks are now allocated in cachable area and
  works without any problems
- So SP_SECTION should be removed to simplify the kernel code

Impact:
- None

Testing:
- Build test only

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-04-20 22:41:44 -05:00
YAMAMOTO Takashi
418e11b8b3 modlib: Always use separate allocation for text and data
Pros:

* Reduce code differences
* Smaller allocations for !CONFIG_ARCH_USE_MODULE_TEXT

Cons:

* Likely to use more memory for !CONFIG_ARCH_USE_MODULE_TEXT in total

Tested with:

* sim:module on macOS
* esp32-devkit:nsh + CONFIG_MODULE on qemu
* lm3s6965-ek:qemu-protected + CONFIG_EXAMPLES_SOTEST on qemu
2021-04-19 22:20:20 -05:00
Masayuki Ishikawa
1a9e7efde5 smp: Remove CONFIG_SMP_IDLETHREAD_STACKSIZE
Summary:
- The CONFIG_SMP_IDLETHREAD_STACKSIZE was introduced to optimize
  the idle stack size for other than CPU0
- However, there are no big differences between the idle stacks.
- This commit removes the config to simplify the kernel code

Impact:
- All SMP configurations

Testing:
- Tested with ostest with the following configs
- spresense:smp, spresense:rndis_smp
- esp32-devkitc:smp (QEMU), maix-bit:smp (QEMU)
- sabre-6quad:smp (QEMU), sabre-6quad:netnsh_smp (QEMU)
- raspberrypi-pico:smp, sim:smp (x86_64)

Signed-off-by: Masayuki Ishikawa <asayuki.Ishikawa@jp.sony.com>
2021-04-19 21:46:39 -05:00
Xiang Xiao
2335b69120 arch: Allocate the space from the beginning in up_stack_frame
arch: Allocate the space from the beginning in up_stack_frame

and modify the affected portion:
1.Correct the stack dump and check
2.Allocate tls_info_s by up_stack_frame too
3.Move the stack fork allocation from arch to sched

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-04-16 12:41:41 +09:00
YAMAMOTO Takashi
51490bad55 modlib: Implement sh_addralign handling
I've seen a module with 16 bytes .rodata alignment for xmm operations.
It was getting SEGV on sim/Linux because of the alignment issue.
The same module binary seems working fine after applying this patch.

Also, tested on sim/macOS and esp32 on qemu,
using a module with an artificially large alignment. (64 bytes)
2021-04-14 21:17:07 -05:00
Anthony Merlino
9c8c2b0db2 Separate CLOCK_TIMEKEEPING and SCHED_TICKLESS. 2021-04-13 11:42:31 -05:00
Masayuki Ishikawa
a51a60d485 sched: task: Fix to initialize the task-specific data
Summary:
- I noticed that getopt() test in ostest wailed with
  esp32-devkitc:smp and spresense:smp
- Finally, I found that the task-specific data is not
  initialized.
- This commit fixes this issue

Impact:
- None

Testing:
- Tested with ostest esp32-devkitc:smp and spresense:smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-04-03 08:32:46 -06:00
Gregory Nutt
2ccc0da0c7 Move getopt() variables into TLS
getopt() in the FLAT build environment is not thread safe.  This is because global variables that are process-specific in Unix are truly global in the FLAT build.  Moving the getopt() variables into TLS resolves this issue.

No side-effects are expected other than to getopt()

Tested with sim:nsh
2021-03-31 21:13:01 -05:00
Xiang Xiao
bea6e0ddd7 sched/signal: Implement SA_NODEFER and SA_RESETHAND
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I9baa72b272c8877022cd94722824f393c7087721
2021-03-31 18:27:01 -03:00
Alan C. Assis
c172ced3ba sched: Move the default Task Stack size to Stack menu 2021-03-31 02:29:04 -05:00
YAMAMOTO Takashi
bf93b1d9d1 sched/module/mod_insmod.c: Fix ELF64-related printf formats 2021-03-23 02:48:42 -07:00
Xiang Xiao
e14c458747 mm/heap: Move semaphore related declaration to private header
since other subsystem doesn't need call these function anymore

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Idfb217c412db62d9f17f427310b75bb78785dc50
2021-03-22 15:35:32 +01:00
Gregory Nutt
2208aabbc6 Correct elapsed time calculation
Elapsed time calculation must always be be the current time minus a time in the past.  Not vice versa.

Also corrects and improves some comments.
2021-03-19 23:18:28 -07:00
Gregory Nutt
5b7dfa0213 Sporadic scheduler: Fix compile errors when assertions are enabled:
Fix missing semicolon at the end of a DEBUGASSERT statement:

sched/sched_sporadic.c: In function 'sporadic_budget_expire':
sched/sched_sporadic.c:512:15: error: expected ';' before 'period'
  512 |               period = (sporadic->repl_period >> 1) - unrealized;
      |               ^~~~~~
sched/sched_sporadic.c: In function 'nxsched_resume_sporadic':
sched/sched_sporadic.c:1078:19: error: expected ';' before 'period'
 1078 |                   period = (sporadic->repl_period >> 1) - unrealized;
      |                   ^~~~~~

Fix use of uninitialized variable in DEBUGASSERT statement:

sched/sched_sporadic.c:466:27: warning: 'sporadic' may be used uninitialized in this function [-Wmaybe-uninitialized]
  466 |                   sporadic->nrepls > 0);

Also fixes some typos.

There should be no unexpected side-effects of this changed.

Tested with the stm32f4discovery:sporadic configuration (see PR #3097
2021-03-19 23:18:28 -07:00
Masayuki Ishikawa
2976bb212e sched: pthread: Remove a redundant critical section in pthread_condclockwsait.c
Summary:
- This commit removes a redundant critical section in pthread_condclockwait.c

Impact:
- None

Testing:
- Tested with ostest with the following configs
  - maix-bit:smp, esp32-devkitc:smp, sabre-6quad:smp
  - spresense:smp, sim:smp
  - maix-bit:nsh, sabre-6quad:nsh
  - sprsesnse:wifi, sim:ostest
- Tested with nxplayer with the folowing configs
  - spresense:wifi_smp, spresense:rndis_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-03-19 23:01:20 -07:00
Jiuzhu Dong
e96c8b9283 fs: allocate file/socket dynamically
Change-Id: I8aea63eaf0275f47f21fc8d5482b51ffecd5c906
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-03-17 06:46:42 -07:00
Masayuki Ishikawa
7758f3dcb1 sched: semaphore: Remove a redundant critical section in nxsem_tickwait()
Summary:
- This commit removes a redundant critical section in nxsem_tickkwait()

Impact:
- None

Testing:
- Tested with ping with the following configs
- spresense:rndis, spresense:rndis_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-03-16 19:50:18 -07:00
Masayuki Ishikawa
65dec5d10a sched: semaphore: Remove a redundant critical section in nxsem_clockwait()
Summary:
- This commit removes a redundant critical section in nxsem_clockwait()

Impact:
- None

Testing:
- Tested with ostest with the following configurations
- maix-bit:smp (QEMU), sim:smp, esp32-devkitc:smp (QEMU)
- sabre-6quad:smp (QEMU), spresense:smp
- maix-bit:nsh (QEMU), sim:ostest, esp32-devkitc:ostest (QEMU)
- sabre-6quad:nsh (QEMU), spresense:wifi

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-03-16 19:50:18 -07:00
Gustavo Henrique Nihei
330eff36d7 sourcefiles: Fix relative path in file header 2021-03-09 23:18:28 +08:00
Xiang Xiao
90be95bb89 sched: Remove all group id related stuff
it is wrong to define a new grpid_t, but not reuse pid_t,
because it make getpid(parent) == getppid(child) impossible.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-03-05 20:35:22 +08:00
ligd
1d66d5c297 debug tools: add heap & stack check in idle thread
N/A

Change-Id: Iba6f5cdffb1336697096c71fca86c9ece584225f
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-03-04 18:38:05 -08:00
Xiang Xiao
d9cfeb0bc3 sched: Don't forward gettid to getpid directly
prepare to implement the right semantics:
getpid should return the main thread id
gettid should return the current thread id
2021-03-04 17:17:41 -06:00
ligd
48d49e5a7c mqueue: add poll support
Change-Id: I7e908f6a6c00158c0946587dd79ae3dc5d279d37
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-03-04 07:11:43 -08:00
Jiuzhu Dong
4d5a964f29 net: unify socket into file descriptor
Change-Id: I9bcd21564e6c97d3edbb38aed1748c114160ea36
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-03-03 19:01:41 -08:00
ligd
a27fe37120 signal/sig_kill.c: remove the limitation of kill(0, xx)
since there are situation which send singal to idle thread already,

CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y

Signo SIGCHLD will send to parent group, when child exit

Change-Id: Iceb2ac41948c1c3418839a3b5de70985d48c75d1
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-03-03 15:03:32 +00:00
Xiang Xiao
8d0fd4038b Remove the empty xxx_initialize functions
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I63cb6b37f78e910663724659e11f53e3335d419f
2021-03-03 08:21:04 +00:00
Masayuki Ishikawa
9d370fc363 sched: task: Call nxtask_flushstreams() without critical section
Summary:
- During investigating critical section with semaphores, I noticed
  that nxtask_flushstreams() is called with a critical section.
- The function calls lib_flushall() which handles a semaphore
  in userspace.
- So it should be done without a critical section

Impact:
- SMP only

Testing:
- Tested with ostest the following configs
- esp32-devkitc:smp (QEMU), sabre-6quad:smp (QEMU)
- maix-bit:smp (QEMU), sim:smp
- spresense:smp
- Tested with nxplayer and stress test with spresense:wifi_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-03-02 05:05:29 -08:00
Xiang Xiao
9473434587 Ensure the kernel component don't call userspace API
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-03-01 09:23:09 +09:00
Gustavo Henrique Nihei
76acb32e29 Fix typos reported by codespell 2021-02-25 11:31:49 -08:00
YAMAMOTO Takashi
bac6b11065 sched/module/mod_insmod.c: Fix a resource leak
Note: partially initialized loadinfo should be uninitialized.
It can contain an open file descriptor.
2021-02-24 23:42:06 -08:00
Xiang Xiao
092d23b25d pthread: Change the default name from <pthread> to <0xyyyyyyyy>
since it's very easy to identify thread through entry pointer

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-02-20 10:11:30 -08:00
YAMAMOTO Takashi
c3e27568de nxsig_tcbdispatch: unblock task in case of CONFIG_LIB_SYSCALL
Otherwise, long-sleeping system calls using nxsig_timedwait
are not actually interrupted.

Tested with "ntpcstop" using lm3s6965-ek:qemu-protected config.
2021-02-15 01:53:19 -08:00
Alin Jerpelea
dee641828f sched: nxstyle fixes
nxstyle fixes to pass CI

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-09 01:21:53 -08:00
Alin Jerpelea
8935ac4cc3 sched: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can mograte the licenses
to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-09 01:21:53 -08:00
Masayuki Ishikawa
d87f350831 arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
  g_irq_spin for backword compatibility (In this case, NULL must be specified)

Impact:
- None

Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-07 21:28:56 -08:00
Masayuki Ishikawa
ad2e85433a boards, include, sched: Remove CONFIG_SPINLOCK_IRQ
Summary:
- This commit removes CONFIG_SPINLOCK_IRQ to avoid complexity

Impact:
- None

Testing:
- Tested with the following configs
- spresense:wifi, spresense:smp
- esp32-devkitc:smp (QEMU), sabre-6quad:smp (QEMU)
- maix-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
2021-02-05 22:50:04 -08:00
Masayuki Ishikawa
82efbd5e6f sched: group: Fix group_kill_children() for SMP
Summary:
- During testing iperf -s with lc823450-xgevk:rndis,
  I noticed that hard fault happens
- Finally, I found that group_kill_children() is not
  not protected by a critical section
- This commit fixes this issue

Impact:
- SMP only

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

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-02 20:03:39 -08:00
chao.an
5cf794e42b sched/notifier: replace the unique key to freerun counter
replace the unique key to freerun counter to avoid traverse
of the notifier list.

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-01-30 05:13:26 -08:00
chao.an
003b360d12 sched/wqueue/notifier: protect the work notifier with critical section
replace the semaphore to avoid the notifier holding the lock in the interrupt context

ASSERT:

libs/libc/assert/lib_assert.c:36   :_assert
sched/semphore/sem_wait.c:113      :nxsem_wait
sched/semphore/sem_wait.c:222      :nxsem_wait_uniterruptible
sched/wqueue/kwork_notifier.c:371  :work_notifier_signal
mm/iob/iob_free.c:188              :iob_free
drivers/syslog/syslog_stream.c:272 :syslogstream_destroy
...
sched/irq/irq_dispatch.c:183       :irq_dispatch

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-01-30 05:13:26 -08:00
Masayuki Ishikawa
6f5793eefc sched: mqueue: Remove an unnecessary comment in mq_send.c
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-01-27 18:27:34 -08:00
Jiuzhu Dong
3e9b89f778 sched/timer: get the previous reload value correctly
Change-Id: I312d3ee74753441793f9505e168e449af3ab2c37
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-01-26 18:22:54 -08:00
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