Commit Graph

321 Commits

Author SHA1 Message Date
Gregory Nutt 717bb04cb7 Increase the number of real time signals. Two is not enough.
Refer to issue #8867 for details and rational.

Convert sigset_t to an array type so that more than 32 signals can be supported.

Why not use a uin64_t?
- Using a uin32_t is more flexible if we decide to increase the number of signals beyound 64.
- 64-bit accesses are not atomic, at least not on 32-bit ARMv7-M and similar
- Keeping the base type as uint32_t does not introduce additional overhead due to padding to achieve 64-bit alignment of uin64_t
- Some architectures still supported by NuttX do not support uin64_t
  types,

Increased the number of signals to 64. This matches Linux. This will support all xsignals defined by Linux and also 32 real time signals (also like Linux).

This is is a work in progress; a draft PR that you are encouraged to comment on.
2023-03-27 16:59:04 +03:00
Petro Karashchenko 5651715486 signal: remove unused SIGCONDTIMEDOUT
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-23 17:17:25 -06:00
Ville Juven df1d7dd480 libc/exit: Purge calls to userspace API exit() from kernel
Remove calls to the userspace API exit() from the kernel. The problem
with doing such calls is that the exit functions are called with kernel
mode privileges which is a big security no-no.
2023-02-17 23:07:17 +08:00
zhangyuan21 a20bc77010 sched/pthread: change the wrong type cast
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-02-13 23:17:29 +08:00
zhangyuan21 9017f70561 sched/pthread: check pthread group after find joininfo
Need check tcb or group info after find joininfo,
otherwise the wrong value will be returned.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-02-12 16:47:28 +08:00
Ville Juven 09e7987121 sched/addrenv: Fix system crash when process group has been deleted
There is currently a big problem in the address environment handling which
is that the address environment is released too soon when the process is
exiting. The current MMU mappings will always be the exiting process's, which means
the system needs them AT LEAST until the next context switch happens. If
the next thread is a kernel thread, the address environment is needed for
longer.

Kernel threads "lend" the address environment of the previous user process.
This is beneficial in two ways:
- The kernel processes do not need an allocated address environment
- When a context switch happens from user -> kernel or kernel -> kernel,
  the TLB does not need to be flushed. This must be done only when
  changing to a different user address environment.

Another issue is when a new process is created; the address environment
of the new process must be temporarily instantiated by up_addrenv_select().
However, the system scheduler does not know that the process has a different
address environment to its own and when / if a context restore happens, the
wrong MMU page directory is restored and the process will either crash or
do something horribly wrong.

The following changes are needed to fix the issues:
- Add mm_curr which is the current address environment of the process
- Add a reference counter to safeguard the address environment
- Whenever an address environment is mapped to MMU, its reference counter
  is incremented
- Whenever and address environment is unmapped from MMU, its reference
  counter is decremented, and tested. If no more references -> drop the
  address environment and release the memory as well
- To limit the context switch delay, the address environment is freed in
  a separate low priority clean-up thread (LPWORK)
- When a process temporarily instantiates another process's address
  environment, the scheduler will now know of this and will restore the
  correct mappings to MMU

Why is this not causing more noticeable issues ? The problem only happens
under the aforementioned special conditions, and if a context switch or
IRQ occurs during this time.
2023-02-08 02:51:23 +08:00
Ville Juven 5713d85df0 group/group_addrenv: Move address environment from group -> tcb
Detach the address environment handling from the group structure to the
tcb. This is preparation to fix rare cases where the system (MMU) is left
without a valid page directory, e.g. when a process exits.
2023-02-08 02:51:23 +08:00
chao an 4c8d244fae sched/getpid: replace syscall getpid/tid/ppid() to kernel version
NuttX kernel should not use the syscall functions, especially after
enabling CONFIG_SCHED_INSTRUMENTATION_SYSCALL, all system functions
will be traced to backend, which will impact system performance.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
Xiang Xiao 631a8da1e2 sched: Map SCHED_OTHER to SCHED_FIFO or SCHED_RR
this behaviour is explicitly specified here:
https://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_08.html
and map SCHED_NORMAL to SCHED_OTHER like Linux:
https://man7.org/linux/man-pages/man7/sched.7.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-30 03:01:03 +02:00
chao an 2ad0a02182 sched/pthread: set default pthread name to parent's name
Align ps behavior with linux:

linux:

  $ ps -e -T | grep hello
  3758130 3758130 pts/10   00:00:00 hello
  3758130 3758131 pts/10   00:00:00 hello

nuttx:

  nsh> ps
    PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK   STACK COMMAND
  ...
      4     4 100 FIFO     Task    --- Waiting  Signal    00000000 067504 hello
      5     4 100 FIFO     pthread --- Waiting  Signal    00000000 067536 hello 0x561cef0dfc53 0x1

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-30 02:59:17 +02:00
Xiang Xiao 819fbd22cc sched: Implement tkill/tgkill
https://linux.die.net/man/2/tgkill

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-26 08:11:56 +02:00
Petro Karashchenko 5f55290e41 sched/pthread: restore C89 compliance in pthread_create
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-01-26 01:26:11 +08:00
zhangyuan21 9fd30c7f63 sched/pthread: check pthread group and flags before join
Prevent users from using the wrong pid and causing system crash.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-18 11:57:40 +08:00
ligd c821088734 pthread: fix pthread exit error when set DETACHED
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:09:36 +08:00
Ville Juven 3be81e649f libc/stdio: Flush streams in userspace when process exits
This fixes a long standing issue, where the kernel does flushing of file
streams, although it should not handle such streams at all.
2022-12-22 20:16:11 +08:00
zhangyuan21 0113865bb0 sched/pthread: Delay pjoininfo allocation time
Create pjoininfo until pthread_exit/pthread_canel/pthread_join get called.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-20 10:26:02 +08:00
zhangyuan21 3d2ffed8ae Revert "pthread: Change the default name from <pthread> to <0xyyyyyyyy>"
This reverts commit 092d23b25d.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-17 14:53:59 +08:00
Marco Casaroli 7ee8d38fda Remove `intr` param from `pthread_mutex_take` 2022-12-08 03:13:44 +08:00
Marco Casaroli 4cc7f3747c Remove `intr` param from `pthread_sem_take` 2022-12-08 03:13:44 +08:00
Marco Casaroli 11cc232de5 `pthread_mutex_timedlock` never returns `EINTR`
According to posix spec, this function should never return `EINTR`.

This fixes the call to `pthread_mutex_take` so it keeps retrying the
lock and doesn't return `EINTR`
2022-12-07 21:08:23 +08:00
qinwei1 8021dfece6 sched/task/task_getpid: getpid should return process id not thread id
Summary:
   implement the right semantics:
1. getpid should return the main thread id
2. gettid should return the current thread id

Refer to:
 https://github.com/apache/incubator-nuttx/issues/2499
 https://github.com/apache/incubator-nuttx/pull/2518

Signed-off-by: qinwei1 <qinwei1@xiaomi.com>
2022-11-17 17:58:08 +08:00
Xiang Xiao 3f12b4f1e3 sched: Remove the unnecessary (FAR sem_t *) cast
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-29 21:12:40 +02:00
anjiahao 5724c6b2e4 sem:remove sem default protocl
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
Xiang Xiao 40ef5bc6db libc: Move queue.h from include to include/nuttx
to avoid the conflict with libuv's queue.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-26 08:04:58 +02:00
Juha Niskanen fb852440af pthread: fix typo with CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2022-09-05 15:36:23 +02:00
Xiang Xiao 2a981cec95 sched: Remove the unnecessary "FAR dq_queue_t *" cast
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-31 08:50:57 +09:00
chao.an 6e5908cc92 sched: fix visual studio Compiler Warning (level 4) C4189
D:\code\incubator-nuttx\sched\pthread\pthread_create.c(154,22):
  warning C4189: “pjoin”: local variable is initialized but not referenced
  [D:\code\incubator-nuttx\vs20221\sched\sched.vcxproj]

D:\code\incubator-nuttx\sched\group\group_setupidlefiles.c(61,28):
  warning C4189: “group”: local variable is initialized but not referenced
  [D:\code\incubator-nuttx\vs20221\sched\sched.vcxproj]

Reference:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4189?view=msvc-170

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-17 10:00:20 +03:00
Gustavo Henrique Nihei 1416afc6b6 sched: Remove "0x" prefix preceding "%p" specifier on format string
The "p" format specifier already prepends the pointer address with
"0x" when printing.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-06-30 22:08:58 +03:00
Xiang Xiao 11c8f3125d sched/tls: Wrap up_info_size into tls_info_size
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-08 19:07:33 +09:00
Xiang Xiao 47b707bbf8 sched/tls: Add tls_init_info and tls_dup_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao 3e32b605fe libc/tls: Make tls_get_info as the pulibc function instead up_tls_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao 33a6aa2f48 sched/tls: Don't compensate the tls size to the stack size
it isn't good to change the stack size passed by caller

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao 3b136771ff sched: Move the call of pthread_mutex_inconsistent to nxtask_recover
to avoid it spread around all possible exit path

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-27 09:39:09 +03:00
Xiang Xiao feb54fc272 sched/pthread: Should call up_exit in pthread_exit
since _exit may kill all sibling thread when
HAVE_GROUP_MEMBERS equal true. Regressed by:
commit 622677d4a1
Author: Ville Juven <ville.juven@unikie.com>
Date:   Mon May 2 15:15:06 2022 +0300

    libc: Implement exit, atexit, on_exit and cxa_exit on the user side

    For CONFIG_BUILD_KERNEL using the sched/task/task_exithook implementation
    will just not work. It calls user code with kernel privileges which is
    a bit of a security issue.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-26 08:16:46 +03:00
jihandong 89338a6914 sched/pthread/pthread_condclockwait.c: follow POSIX.
pthread_condclockwait() can not distinguish between interrupt and timeout,
which cause these API not follow POSIX:
	pthread_rwlock_timedrdlock()
	pthread_rwlock_timedwrlock()
	pthread_condtimedwait()
POSIX:
	Upon return from the signal handler the thread resumes waiting for
	the condition variable as if it wasnot interrupted
	These functions shall not return an error code of [EINTR].

Replacing nxsem_wait() with nxsem_clockwait_uninterruptible() can solve it.

Signed-off-by: jihandong <jihandong@xiaomi.com>
2022-05-19 14:57:33 +08:00
zhuyanlin 1c977e97d2 pthread_mutexinit: fix deadcode in pthread_mutexinit
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-05-16 10:20:52 +03:00
Xiang Xiao 08002a0a38 sched: Replace pthread_sem_take with nxsem_wait_uninterruptible
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-14 20:47:34 +03:00
anjiahao a191d9bc3c sched/pthread_create:fix bug,delete data_sem
if a pthread set attr is detach,and when call pthread_create,
new thread exit quikly,new thread's tcb be free,then pthread_create
use new thread's tcb will crash.
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-14 01:42:16 +08:00
anjiahao 47304e7254 sched/pthread:need check pthread is DETACHED
pthread_join need check thread is DETACHED,
Whether to wait according to the result.And,
if a thread is DETACHED,it will not set a new
attr.
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-08 01:41:06 +08:00
Petro Karashchenko 68902d8732 pid_t: unify usage of special task IDs
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-03-22 21:22:32 +08:00
Huang Qi f452dd7ab4 sched: Mark pthread as non-cancelable to avoid additional calls to pthread_exit()
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-20 15:36:07 +01:00
Oki Minabe 682984e9ba add the kernel stack allocation in pthread create. 2022-02-19 19:32:21 +08:00
Huang Qi 8bf7f94d39 pthread: Call cleanup callback while asyncrhonous cancel
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-09 21:21:43 +08:00
Huang Qi c0a0de97ce Revert "libc: Call pthread_exit in user-space by up_pthread_exit"
This reverts commit f4a0b7aedd.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-09 21:21:43 +08:00
Huang Qi 6814b1416f Revert "pthread: Avoid recursive pthread_exit call"
This reverts commit a2941532bd.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-09 21:21:43 +08:00
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
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
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
Huang Qi 58e0781e2e arch/arm: Implement TLS support
Signed-off-by: Huang Qi <no1wudi@qq.com>
2021-12-07 23:31:41 -06: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
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 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
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 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
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
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
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
Gustavo Henrique Nihei 76acb32e29 Fix typos reported by codespell 2021-02-25 11:31:49 -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
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 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
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
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
Masayuki Ishikawa d1f82ced26 Revert "sched: Call up_[use|create]_stack after nxtask_setup_scheduler"
This reverts commit 6eba1ad90a.
2020-10-22 18:31:31 +09:00
Xiang Xiao 6eba1ad90a sched: Call up_[use|create]_stack after nxtask_setup_scheduler
to ensure the basic info(e.g. pid) setup correctly before call arch API

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I851cb0fdf22f45844938dafc5981b3f576100dba
2020-10-22 15:30:01 +09:00
Yoshinori Sugino 296eff3d40 Fix typos 2020-10-17 09:04:37 +01: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 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 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 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
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 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 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 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
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
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 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
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
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
Gregory Nutt 00933cfece sched/sched: Add sched_get_stackinfo()
The new OS interface, sched_get_stackinfo() combines two pthread-specific interfaces into a single generic interface.  The existing pthread_get_stackaddr_np() and pthread_get_stacksize_np() are moved from sched/pthread to libs/libc/pthread.

There are two motivations for this change:  First, it reduces the number of system calls.  Secondly, it adds a common hook that is going to used for a future implementation of TLS.
2020-05-03 23:33:44 +01:00
Xiang Xiao 5c748cea2a sched: Don't need call get_errno after task_activate
since task_activate don't save the error code into errno

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-03 12:15:54 -06:00
Xiang Xiao eca7059785 Refine __KERNEL__ and CONFIG_BUILD_xxx usage in the code base
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-01 10:43:47 -03:00
Gregory Nutt 621151a523 Fix some macOS sim warnings.
These warnings fix a class of warnings that I saw during CI checks for macOS sim builds.  For example:

    devif/devif_callback.c:111:49: warning: for loop has empty body [-Wempty-body]
                   prev = curr, curr = curr->nxtdev);
                                                    ^
    devif/devif_callback.c:111:49: note: put the semicolon on a separate line to silence this warning

I did not put the semi-colon on a separate line, but used braces.
2020-04-11 22:27:42 +01:00
Gregory Nutt 67ec3d7926 Remove CONFIG_CAN_PASS_STRUCT
This commit resolves issue #620:

Remove CONFIG_CAN_PASS_STRUCTS #620

The configuration option CONFIG_CAN_PASS_STRUCTS was added many years ago to support an old version of the SDCC compiler. That compiler is currently used only with the Z80 and Z180 targets. The limitation of that old compiler was that it could not pass structures or unions as either inputs or outputs. For example:

    #ifdef CONFIG_CAN_PASS_STRUCTS
    struct mallinfo mallinfo(void);
    #else
    int      mallinfo(FAR struct mallinfo *info);
    #endif

And even leads to violation of a few POSIX interfaces like:

    #ifdef CONFIG_CAN_PASS_STRUCTS
    int  sigqueue(int pid, int signo, union sigval value);
    #else
    int  sigqueue(int pid, int signo, FAR void *sival_ptr);
    #endif

This breaks the 1st INVIOLABLES rule:

Strict POSIX compliance
-----------------------

  o Strict conformance to the portable standard OS interface as defined at
    OpenGroup.org.
  o A deeply embedded system requires some special support.  Special
    support must be minimized.
  o The portable interface must never be compromised only for the sake of
    expediency.
  o Expediency or even improved performance are not justifications for
   violation of the strict POSIX interface

Also, it appears that the current SDCC compilers have resolve this issue and so, perhaps, this is no longer a problem: z88dk/z88dk#1132

NOTE:  This commit cannot pass the PR checks because it depends on matching changes to the apps/ directory.
2020-04-11 21:19:47 +01:00