Commit Graph

1643 Commits

Author SHA1 Message Date
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
Gregory Nutt
124e6ee53d sched/sched/sched_releasetcb.c: Handle custom stack allocations.
sched_releasetcb() will normally free the stack allocated for a task.  However, a task with a custom, user-managed stack may be created using nxtask_init() followed by nxtask_activer.  If such a custom stack is used then it must not be free in this many or a crash will most likely result.

This chagne addes a flag call TCB_FLAG_CUSTOM_STACK that may be passed in the the pre-allocted TCB to nxtask_init().  This flag is not used internally anywhere in the OS except that if set, it will prevent sched_releasetcb() from freeing that custom stack.
2020-05-27 20:00:14 +01:00
Gregory Nutt
b9042f5900 sched/task/task_init.c: Add nxtask_uninit()
Add trivial function nxtask_uninit().  This function will undo all operations on a TCB performed by task_init() and release the TCB by calling kmm_free().  This is intended primarily to support error recovery operations after a successful call to task_init() such was when a subsequent call to task_activate fails.

That error recovery is trivial but not obvious.  This helper function should eliminate confusion about what to do to recover after calling nxtask_init()
2020-05-27 17:53:46 +01:00
Gregory Nutt
d2f10e7386 sched/task/task_create.c: Correct logic in error handling
After nxtask_setup_arguments() is called, the task must be removed from the active task list in order to properly recover from any error condition.
2020-05-27 17:53:46 +01:00
Gregory Nutt
82debdc213 Make task_init() and task_activate() internal OS functions.
-Move task_init() and task_activate() prototypes from include/sched.h to include/nuttx/sched.h.  These are internal OS functions and should not be exposed to the user.
-Remove references to task_init() and task_activate() from the User Manual.
-Rename task_init() to nxtask_init() since since it is an OS internal function
-Rename task_activate() to nxtask_activate since it is an OS internal function
2020-05-25 23:54:45 +01:00
Xiang Xiao
7e5b0f81e9 build: Replace -I with INCDIR
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-24 20:20:12 +01:00
Xiang Xiao
23668a4b9b build: Remove the empty variable assignment
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-24 08:24:13 -06:00
Xiang Xiao
dd61d3d9f9 build: Remve the unnecessary .gitignore
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-23 18:00:40 +01:00
Gregory Nutt
154a87993f fs/vfs/fd_open.c: fs_fdopen() must not set errno
Functions within the OS must never set the errno value.  fs_fdopen() was setting the errno value.  Now, after some parameter changes, it reports errors via a negated errno integer return value as do most all other internal OS functions.
2020-05-23 15:22:09 +08:00
Xiang Xiao
1a95cce1a3 build: Move .config check to the top Makefile
remove the workaround to handle the inexistence of .config/Make.defs

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-20 17:57:34 +01:00
Gregory Nutt
57bc329aac Run nxstyle all .c and .h files modified by PR. 2020-05-17 14:01:00 -03:00
Gregory Nutt
a569006fd8 sched/: Make more naming consistent
Rename various functions per the quidelines of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions

    nxsem_setprotocol -> nxsem_set_protocol
    nxsem_getprotocol -> nxsem_get_protocol
    nxsem_getvalue -> nxsem_get_value
2020-05-17 14:01:00 -03:00
Gregory Nutt
54c643164b Fix some very minor spacing problems. 2020-05-16 18:53:25 +01:00
Gregory Nutt
00ed37b609 sched/: Run nxstyle on all .c/.h files modified by PR. 2020-05-16 13:39:03 -03:00
Gregory Nutt
d823a3ab3e sched/: Make more naming consistent
Rename various functions per the quidelines of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions
2020-05-16 13:39:03 -03:00
Xiang Xiao
517974787f Rename clock_systime[r|spec] to clock_systime_[ticks|timespec]
follow up the new naming convention:
https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions
2020-05-10 14:35:50 -06:00
Gregory Nutt
153eee6de2 Make more OS internal names consistent
1. Internal scheduler functions should begin with nxsched_, not sched_
2. Follow the consistent naming patter of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions

    # clock_systimer -> clock_systime_tick
    # clock_systimespec -> clock_systime_timespec
    sched_oneshot_extclk -> nxsched_oneshot_extclk
    sched_period_extclk -> nxsched_period_extclk
    # nxsem_setprotocol -> nxsem_set_protocol
    # nxsem_getprotocol -> nxsem_get_protocol
    # nxsem_getvalue -> nxsem_get_value
    nxsem_initholders -> nxsem_initialize_holders
    nxsem_addholder -> nxsem_add_holder
    nxsem_addholder_tcb -> nxsem_add_holder_tcb
    nxsem_boostpriority -> nxsem_boost_priority
    nxsem_releaseholder -> nxsem_release_holder
    nxsem_restorebaseprio -> nxsem_restore_baseprio

Some planned name changed were skipped for now because they effect too many files (and would require many hours of coding style fixups).
2020-05-10 22:47:07 +08:00
Gregory Nutt
fbbf1dffaf Fix minor spacing problems from 1017 and 1018 2020-05-09 22:09:12 +01:00
Gregory Nutt
3ac629bdfb Run all .c and .h files modifed by the PR though nxstyle. 2020-05-09 16:58:42 -03:00
Gregory Nutt
f92dba212d sched/sched/sched.h: Make naming of all internal names consistent:
1. Add internal scheduler functions should begin with nxsched_, not sched_
2. Follow the consistent naming patter of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions
2020-05-09 16:58:42 -03:00
Gregory Nutt
4b44b628ea Run nxstyle against all .c and .h files modified by this PR.
All complaints fixed except for those that were not possible to fix:

- Used of Mixed case identifier in ESP32 files.  These are references to Expressif ROM functions which are outside of the scope of NuttX.
2020-05-09 14:19:08 -03:00
Gregory Nutt
a4218e2144 include/nuttx/sched.h: Make naming of all internal names consistent:
1. Add internal scheduler functions should begin with nxsched_, not sched_
2. Follow the consistent naming patter of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions
2020-05-09 14:19:08 -03:00
chao.an
8b289023bf semaphore: do not assert if the count exceeds the limit
Linux Programmer's Manual:

SEM_POST(3)

NAME
       sem_post - unlock a semaphore
...

ERRORS
...
       EOVERFLOW
              The maximum allowable value for a semaphore would be exceeded.

Change-Id: I57c1a797a5510df4290a10aa2f3106fd01754b37
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-05-09 07:25:59 -06:00
Gregory Nutt
4301682fbc Fix up some problems/issues remaining from PR 1007
1. Add missing conditional logic in include/sys/syscall_lookup.h
2. CONFIG_NPTHREAD_KEYS removed from code but was still in sched/Kconfig
3. Refresh all configurations affected by PR 1007
4. syscall/syscall_funclookup.c needs to include nuttx/tls.h
2020-05-08 20:13:40 +01:00
Gregory Nutt
9ce03b1660 Move pthread-specific data into TLS
1. Move pthread-specific data files from sched/pthread/ to libs/libc/pthread.
2. Remove pthread-specific data functions from syscalls.
3. Implement tls_alloc() and tls_free() with system calls.
4. Reimplement pthread_key_create() and pthread_key_free() using tls_alloc() and tls_free().
5. Reimplement pthread_set_specific() and pthread_get_specicif() using tls_set_value() and tls_get_value()
2020-05-08 18:05:04 +01:00
Xiang Xiao
b7d922960f Fix nxstyle issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-08 07:20:49 -06:00