Commit Graph

1668 Commits

Author SHA1 Message Date
Xiang Xiao
952af92690 sched/note: Move the circle buffer code to driver
so the format code can be shared by different transport

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-09-07 11:54:10 +08:00
Masayuki Ishikawa
08c4376606 arch, include, sched : Refactor ARCH_GLOBAL_IRQDISABLE related code
Summary:
- ARCH_GLOBAL_IRQDISABLE was initially introduced for LC823450 SMP
- At that time, i.MX6 (quad Cortex-A9) did not use this config
- However, this option is now used for all CPUs which support SMP
- So it's good timing for refactoring the code

Impact:
- Should have no impact because the logic is the same for SMP

Testing:
- Tested with board: spresense:smp, spresense:wifi_smp
- Tested with qemu: esp32-core:smp, maix-bit:smp, sabre-6quad:smp
- Build only: lc823450-xgevk:rndis, sam4cmp-db:nsh

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-09-03 10:20:20 +08:00
Xiang Xiao
b5f429c88b Fix nxstyle warning
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-08-22 17:37:21 -06:00
Xiang Xiao
ae356001cf Change all files come from Xiaomi/Pinecone to Apache License 2.0
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-08-22 17:37:21 -06:00
Xiang Xiao
beb745ef92 sched/pthread: Implement pthread_attr_[get|set]detachstate
specified here:
https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getdetachstate.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I84ec2d14f14cb7118aac3f7f356f83a5f9af4e18
2020-08-20 10:46:14 +01:00
Xiang Xiao
d43bf7717e sched: Support config the argument passed to init
it is useful to pass the nonempty argument to change the init task behaviour

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I684e9c76b9eac54404d0e4e63ab78e51e039c9a8
2020-08-17 12:52:28 -06:00
Xiang Xiao
acca9fcc3b sched/wdog: Remove MAX_WDOGPARMS and related stuff
since the variable arguments are error prone and seldom used.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-08-14 08:19:50 -06:00
Xiang Xiao
a0ce81d659 sched/wdog: Don't dynamically allocate wdog_s
to save the preserved space(1KB) and also avoid the heap overhead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I694073f68e1bd63960cedeea1ddec441437be025
2020-08-11 12:28:55 -06:00
Xiang Xiao
00c662bbd7 sched/group: Fix the typo error
build will fail with debug assert

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-08-11 11:19:37 +01:00
Xiang Xiao
154852acb5 sched/mqueue: Reduce the initial memory consumption
Change the preallocated message and descriptor from 32/24 to 4.
The total size is reduce from 1892 to 532

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I79d199465daef678986868f773876289859f42fc
2020-08-10 08:07:50 +02:00
Xiang Xiao
854276285c sched/signal: Reduce the initial memory consumption
1.Don't preallocate sigaction list since it's used only in the task context
2.Reduce the preserved item which is used only in the task context from 16 to 4
The total memory decrease from 1280B to 480B

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ib5d5a7365c7d443fc0e99c0d3ea943e85f67ca8c
2020-08-10 08:07:50 +02:00
Xiang Xiao
f618de9c97 Fix nxstyle warning
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-08-08 17:30:26 -03:00
Xiang Xiao
4c706771c3 sched/wdog: Replace all callback argument from uint32_t to wdparm_t
and alwasy cast the argument of wd_start to wdparm_t

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-08-08 17:30:26 -03:00
Xiang Xiao
e1d3627bb1 sched/wdog: Change the default value of MAX_WDOGPARMS from 4 to 2
since the maximum number of argument pass to wd_start in the whole
code base is 2 and change CONFIG_MAX_WDOGPARMS in some defconfig
from 1 to 2 oherwise pthread_condclockwait will fail

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ib6cb28b8c0722058849e7be916e164513431d21c
2020-08-06 10:36:22 -06:00
YAMAMOTO Takashi
8b0d42275e sched/sched/sched_waitpid.c: Remove a redundant assignment
Found by clang-check:

sched/sched_waitpid.c:380:33: warning: Although the value stored to 'ret' is used in the enclosing expression, the value is never actually read from 'ret'
          (pid != (pid_t)-1 && (ret = nxsig_kill(pid, 0)) < 0))
                                ^     ~~~~~~~~~~~~~~~~~~
1 warning generated.
2020-07-30 16:16:21 +02:00
Xiang Xiao
28eed285c8 sched: The secondary idle threads should call nx_idle_trampoline
because nx_task_idle doesn't call sched_note_start. To avoid the
same error happen again in the furture, nx_task_idle is removed.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-07-29 16:03:13 +09:00
SPRESENSE
e249a2f82f Makefile: Fix Make.dep not updated by config changes
Make.dep file should be updated by .config changed after first make.
There are 2 cases affected for this problem:

 1) Add source files by config symbol
 2) Include header files in #ifdef directive

These 2 cases may not be included in Make.dep and this may prevent the
differential build from working correctly.
2020-07-28 03:59:45 -05:00
Masayuki Ishikawa
996e93da0c sched: Replace license header with Apache License 2.0
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-07-28 00:47:39 -05:00
Xiang Xiao
33ec242caf Implement proposed POSIX _clockwait variants of existing _timedwait functions
Here is the related glibc patchset:
https://patchwork.ozlabs.org/project/glibc/cover/cover.b0c66849a87ca79889a49f2f1f2563b1a8a15d8b.1551291557.git-series.mac@mcrowe.com/

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I0095cb34cef3d0d88a100255053da79266b73ff2
2020-07-27 20:39:59 -03:00
Nakamura, Yuuichi
02718f0827 Syscall instrumentation build system support for Arm and RISC-V 2020-07-22 12:01:40 -05:00
Nakamura, Yuuichi
2b4d2cd4a3 Fix note structure members types 2020-07-22 11:55:21 -05:00
Nakamura, Yuuichi
53c84c7b60 Fix note type id for syscall enter/leave 2020-07-13 00:45:16 -05:00
Xiang Xiao
3472de3500 Revert "sched/sched/sched_releasetcb.c: Handle custom stack allocations."
Since up_release_stack auto detect whether the memory come from builtin heap
if (ttype == TCB_FLAG_TTYPE_KERNEL)
  {
    if (kmm_heapmember(dtcb->stack_alloc_ptr))
      {
        kmm_free(dtcb->stack_alloc_ptr);
      }
  }
else
  {
    /* Use the user-space allocator if this is a task or pthread */
    if (umm_heapmember(dtcb->stack_alloc_ptr))
      {
        kumm_free(dtcb->stack_alloc_ptr);
      }
  }

This reverts commit 124e6ee53d.
2020-07-07 00:21:46 +01:00
chao.an
3fbdc213b7 syscall/prctl: fix PR_SET_NAME failure if without <pid> arg
add PR_SET_NAME_EXT/PR_GET_NAME_EXT extension to avoid semantic
conflicts, use extened version for pthread_setname_np/pthread_getname_np

Change-Id: I40404c737977a623130dcd37feb4061b5526e466
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-07-01 21:52:18 -05:00
Xiang Xiao
8153e31753 sched: Call c++ global variables constructor inside nxtask_startup
to avoid the similar code spread around each application

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I8967d647eaf2ecae47f29f83e7fa322ef1b42a02
2020-07-01 07:55:33 -06:00
Xiang Xiao
14ecb8723a sched: Change tcb_s to task_tcb_s for nxtask_[un]init
since these functions can just work with task not thread

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-06-30 10:54:42 -06:00
chao.an
2fc02ec4a4 sched/task_init: change the stack pointer type to (void *)
change the stack pointer type from (uint32_t *) to (void *)

Change-Id: I90bb7d6a9cb0184c133578a1a2ae9a19c233ad30
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-06-30 08:26:38 +02:00
chao.an
62b777b1cd sched/task: unify task initialization
1. nxthread_create() Reduce code duplication
2. nxtask_init(): support stack allocation from internal

Change-Id: Ib495a6efb032d9caa9b03113a0763b71486d14ea
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-06-30 08:26:38 +02:00
Xiang Xiao
d8376efdc1 nxsched_release_tcb: Should release stack in kernel build too
otherwise the memory can't be reused util the process exit

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-06-29 17:07:50 -06:00
YAMAMOTO Takashi
91611de0ff waitid: implement WNOHANG
If there's no child status available immediately,
return 0 without blocking as specified by the standards.

I checked the following version of the standard.
I believe it has always been this way though.

    The Open Group Base Specifications Issue 7, 2018 edition
    IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
2020-06-26 05:19:59 -05:00
YAMAMOTO Takashi
6661f56add waitpid: implement WNOHANG for CONFIG_SCHED_HAVE_PARENT=y
If there's no child status available immediately,
return 0 without blocking as specified by the standards.

The implementation for non CONFIG_SCHED_HAVE_PARENT case
seems ok in this regard.

I checked the following version of the standard.
I believe it has always been this way though.

    The Open Group Base Specifications Issue 7, 2018 edition
    IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
2020-06-26 05:19:59 -05:00
Gregory Nutt
ebeeb0d3e8 sched/pthread/pthread_cleanup.c: Exclude kernel threads.
Prohibit use of pthread_cleanup API's by kernel threads.  The pthread pthread_cleanup functions MUST run in user mode, making them unusable for kernel threads.

See Issue #1263
2020-06-17 13:18:30 -03:00
Xiang Xiao
56fa98f3ea sched: Avoid call up_initial_state for idle thread twice
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Iaf5d4bcc915fbe842e9356ea6416f0af869ab116
2020-06-16 17:05:05 -06:00
Gregory Nutt
69e97c19ea sched/sched/sched_note.c: Implement interrupt/syscall support
A previous PR added interrupt and system call scheduler notes.  This addess buffering support for those notes.
2020-06-16 20:42:22 +01:00
Gregory Nutt
ed9532e31f CONFIG_SCHED_INSTRUMENTATION_SYSCALL should not available if the architecture does not support the required system hook note hooks. 2020-06-16 14:04:53 -03:00
Yuuichi Nakamura
df2bc1e4c3 Add syscall and irqhandler hooks in sched_note.h 2020-06-16 14:04:53 -03:00
Xiang Xiao
4d634b9006 sched: Consolidate the cancellation notification logic
to avoid the code duplication

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ie2ba55c382eb3eb7c8d9f04bba1b9e294aaf6196
2020-06-15 21:21:14 +01:00
Xiang Xiao
2160a65030 sched: Don't call nxnotify_cancellation in task_setcancelstate
since it is impossible that the current running thread is
in the waiting state and then need to wake up self.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ie2ba55c382eb3eb7c8d9f04bba1b9e294aaf6196
2020-06-15 21:21:14 +01:00
Xiang Xiao
6982eb35fe sched: Remove SCHED_EXIT_KILL_CHILDREN option
All standard indicate exit should terminate the whole process/task:
https://pubs.opengroup.org/onlinepubs/007904975/functions/exit.html
https://en.cppreference.com/w/c/program/exit
https://linux.die.net/man/2/exit
so let's remove the option and trust the caller know the difference:
1.exit terminate all threads belong the current process/task
2.pthread_exit only terminate the current(main/pthread) thread

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I2950ddee3d471272bb9570782f1cd4af33513d57
2020-06-15 07:17:43 -06:00
Xiang Xiao
f70981c179 sched: Make task_delete(getpid()) equal exit(EXIT_SUCCESS)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I63b2a372ccf0e9ac4e6a7fc9b1b160d71eeeb40f
2020-06-15 07:17:11 -06:00
Xiang Xiao
fd5fc2ab07 sched: Check the mutex consistent in main thread too
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I2d91154572805699237cfc028202021c8f8eee40
2020-06-15 07:16:21 -06:00
Xiang Xiao
309dda3ef8 sched: pthread_cleanup_[push|pop] should be callable from main thread
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ifefccda6cb7e2335e11976dcec74e308d64c7f5e
2020-06-15 07:16:21 -06:00
Xiang Xiao
5785340e04 sched/group: Change group_kill_children's argument from task_tcb_s to tcb_s
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I8fee46e75bd192bbaa6b03db8fc4d5dd60c58b10
2020-06-15 07:09:51 -06:00
Xiang Xiao
09f64dd0ac sched/task: Avoid the cast in atexit when CONFIG_SCHED_ONEXIT is defined
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ic3360555fa8bb24d5dae52e7ae5bb5fb5c24de0c
2020-06-05 13:29:22 +01:00
Xiang Xiao
3409c989bd sched/task: Simplify atexit and onexit implementation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I3028b74fe4872ae5cb376fa160e3cff79d5ad449
2020-06-05 13:29:22 +01:00
Xiang Xiao
a69678810d sched: Change the return type of nxtask_activate to void
to simplify the error handling logic

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I00fedd4d69620a7cc7b9f9e8bf4ba7f7989dc2b2
2020-06-04 22:20:45 +01:00
Xiang Xiao
b4bd9427f7 arch: Rename _exit to up_exit to follow the naming convention
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I2779a2a3ccb5426fe78714fdcc629b8dfbb7aaf6
2020-06-04 22:20:45 +01:00
Xiang Xiao
85b859fb8d arch: _exit should't call nxsched_resume_scheduler twice in SMP mode
utilize the call inside nxtask_exit instead, also move
nxsched_suspend_scheduler to nxtask_exit for symmetry

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I219fc15faf0026e452b0db3906aa40b40ac677f3
2020-06-04 22:20:45 +01:00
Gregory Nutt
1041100948 sched/task/task_spawn.c: Fix duplicate task_spawn()
In the FLAT build if CONFIG_LIB_SYSCALL=y, then the function task_spawn() will be duplicated.:  One version in libs/libc/spawn and one version in sched/task.

The version of task_spawn in lib/libc/spawn exists only if CONFIG_LIB_SYSCALL is selected.  In that case, the one in sched/task/task_spawn.c should be static, at least in the FLAT build.

The version of task_spawn.c in libs/libc/spawn simply marshals the parameters into a structure and calls nx_task_spawn().  If CONFIG_LIB_SYSCALL is defined then nx_task_spawn() will un-marshal the data can call the real task spawn.  This nonsense is only necessary because task_spawn has 8 parameters and the maximum number of parameters in a system call is only 6.

Without syscalls:  Application should call directly in task_spawn() in sched/task/task_spawn.c and, hence, it must not be static

With syscalls:  Application should call the marshalling task_spawn() in libs/libc/spawn/lib_task_spawn.c -> That will call the autogenerated nx_task_spawn() proxy -> And generate a system call -> The system call will the unmarshalling nx_task_spawn() in sched/task/task_spawn.c -> Which will, finally, call the real task_spawn().

The side-effect of making task_spawn() static is that it then cannot be used within the OS.  But as far as I can tell, nothing in the OS itself currently uses task_spawn() so I think it is safe to make it conditionally static.  But that only protects from duplicate symbols in the useless case mentioned above.
2020-06-01 16:40:06 +01:00
Gregory Nutt
1c002e1049 fs/vfs/fs_fstat: Correct fstat() for proxied block and MTD drivers.
Block and MTD drivers may be opened and managed as though they were character drivers.  But this is really sleight of hand; there is a hidden character driver proxy that mediates the interface to the block and MTD drivers in this case.

fstat(), however, did not account for this.  It would report the characteristics of the proxy character driver, not of the underlying block or MTD driver.

This change corrects that.  fstat now checks if the character driver is such a proxy and, if so, reports the characteristics of the underlying block or MTD driver, not the proxy character driver.
2020-05-28 17:34:09 +01:00