Commit Graph

2259 Commits

Author SHA1 Message Date
yinshengkai
c418d147fe procfs: add total time running time of task
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-04-24 19:38:29 +08:00
hujun5
0477fb116a pthread: pthread_cond_wait dead lock
pthread_cond_wait is preempted after releasing the lock, sched_lock cannot lock threads from other CPUs, use enter_critical_section

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-04-24 12:53:56 +03:00
yinshengkai
a40a802f9b sched/pthread: repalce sched_lock to enter_critical_section
After RR is enabled, an interrupt occurs during this period and the task cannot be switched

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-04-24 01:54:44 +08:00
Xiang Xiao
149cafe450 procfs: Add g_ prefix to all procfs_operations
to conform the coding style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-22 03:33:50 -04:00
Ville Juven
64d8249895 sched/addrenv, binfmt: Always allocate address environment from heap
Instead of using a volatile storage for the address environment in the
binfmt / loadinfo structures, always allocate the address environment
from kheap.

This serves two purposes:
- If the task creation fails, any kernel thread that depends on the
  address environment created during task creation will not lose their
  mappings (because they hold a reference to it)
- The current address environment variable (g_addrenv) will NEVER contain
  a stale / incorrect value
- Releasing the address environment is simplified as any pointer given
  to addrenv_drop() can be assumed to be heap memory
- Makes the kludge function addrenv_clear_current irrelevant, as the
  system will NEVER have invalid mappings any more
2023-04-22 00:43:30 +08:00
dongjiuzhu1
1f665e3498 sched/wqueue: fix issue about worker can't wake up thread before work_thread running
Problem:
AppBringup task in default priority 240 ->
board_late_initialize() ->
   some driver called work_queue() ->
      nxsem_post(&(wqueue).sem) failed because sem_count is 0

hp work_thread in default priority 224 ->
      nxsem_wait_uninterruptible(&wqueue->sem);

so hp_work_thread can't wake up, worker can't run immediately.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-04-19 02:50:04 +08:00
Petro Karashchenko
fcd6ec7809 sched/sched: fix scheduler lock/unlock operation for non-SMP case
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-04-19 02:43:55 +08:00
Ville Juven
b982c1747b sched/addrenv: Miscellaneous clean-up and fixes
- Remove the temporary "saved" variable when temporarily changing MMU
  mappings to access another process's memory. The fact that it has an
  address environment is enough to make the choice
- Restore nxflat_addrenv_restore-macro. It was accidentally lost when
  the address environment handling was re-factored.
2023-04-15 13:21:48 +09:00
Petro Karashchenko
e9b5c25baf sched/semaphore: rework semaphore holder check for priority inheritance
- The code will detect an error condition described in
  https://cwiki.apache.org/confluence/display/NUTTX/Signaling+Semaphores+and+Priority+Inheritance
- The kernel will go to PANIC if semaphore holder can't be allocated even
  if CONFIG_DEBUG_ASSERTIONS is disabled
- Clean-up code that handled posing of semaphore with priority inheritance
  enabled from the interrupt context (remove nxsem_restore_baseprio_irq())
2023-04-11 17:01:14 +09:00
Petro Karashchenko
2864e8c4b4 Revert "Assert if a thread attempts to post a semaphore incorrectly."
This reverts commit 758e88672b.
2023-04-11 17:01:14 +09:00
zhangyuan21
c239d19df0 nuttx: add more dependent header file
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-04-11 09:13:32 +03:00
wangming9
a7fc26124d arch/arm64: the arm64 perf interface supports pmu
Summary:
- Support arm64 pmu api, Currently only the cycle counter function is supported.
- Using ARM64 PMU hardware capability to implement perf interface, modify all
  perf interface related code.
- Support for pmu init under smp.

Signed-off-by: wangming9 <wangming9@xiaomi.com>
2023-04-10 16:23:49 -03:00
yinshengkai
b3e1004658 sched_note: add function auto-tracing
After enabling this option, you can automatically trace the function instrumentation without adding tracepoint manually.
This is similar to the Function Trace effect of the linux kernel

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-04-10 11:04:24 -03:00
Fotis Panagiotopoulos
95af4b35cf Fixed improper access of g_pidhash. 2023-04-04 18:00:36 -06:00
Xiang Xiao
84ddfb5455 sched/assert: Simplify the fatal detection logic
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-04 11:29:10 -04:00
Gregory Nutt
758e88672b Assert if a thread attempts to post a semaphore incorrectly.
Assert in nxsem_post if:

- Priority inheritance is enabled on a semaphore
- A thread that does not hold the semaphore attempts to post it

This will detect an error condition described in https://cwiki.apache.org/confluence/display/NUTTX/Signaling+Semaphores+and+Priority+Inheritance

None.  The debug instrumentation is only enabled if CONFIG_DEBUG_ASSERTIONS is enabled.

Use sim:ostest.  Verify that no assertions occur.
2023-04-03 09:03:15 +02:00
yinshengkai
700fd265ee sched: fix compile error when SCHED_CRITMONITOR is enabled
Compilation error occurs after SCHED_CRITMONITOR is enabled
sched/sched_critmonitor.c:315: undefined reference to `serr'

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-03-30 09:29:37 -03:00
Ville Juven
f468371332 sched/sem_waitirq: Swap user mappings to MMU when releasing semaphore
sem_t is user memory and the correct mappings are needed to perform
the semaphore wait interruption.

Otherwise either a page fault, or access to the WRONG address environment
happens.
2023-03-29 10:53:09 -03:00
Petro Karashchenko
a8f4a89221 signal: add SIGSYS
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-28 11:24:35 -06:00
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
c7326717ca sched/paging: add FAR in paging worker
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-26 09:23:50 -06:00
Xiang Xiao
beb38917d1 signal: Replace NuttX special SIGWORK with SIGPAGING(SIGRTMIN)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-26 08:31:36 -06:00
Xiang Xiao
5ce5d01d75 signal: Remove configurable assignment of signal numbers
please reference the issue here for more information:
https://github.com/apache/nuttx/issues/8898

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-26 08:31:36 -06:00
chenrun1
d60dee4a65 sched/clock_gettime:Remove output log
Calling syslog to print logs in clock_gettime will cause the system to have recursive output, i.e., clock_gettime->sinfo->syslog->clock_gettime, with the consequences of stack overflow or non-stop log output.
2023-03-25 01:43:01 +02: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
Zhe Weng
c9a38f42f7 sched/wqueue: Do as much work as possible in work_thread
Decouple the semcount and the work queue length.

Previous Problem:

If a work is queued and cancelled in high priority threads (or queued
by timer and cancelled by another high priority thread) before
work_thread runs, the queue operation will mark work_thread as ready to
run, but the cancel operation minus the semcount back to -1 and makes
wqueue->q empty. Then the work_thread still runs, found empty queue,
and wait sem again, then semcount becomes -2 (being minused by 1)

This can be done multiple times, then semcount can become very small
value. Test case to produce incorrect semcount:

high_priority_task()
{
  for (int i = 0; i < 10000; i++)
    {
      work_queue(LPWORK, &work, worker, NULL, 0);
      work_cancel(LPWORK, &work);
      usleep(1);
    }

  /* Now the g_lpwork.sem.semcount is a value near -10000 */
}

With incorrect semcount, any queue operation when the work_thread is
busy, will only increase semcount and push work into queue, but cannot
trigger work_thread (semcount is negative but work_thread is not
waiting), then there will be more and more works left in queue while
the work_thread is waiting sem and cannot call them.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-21 17:50:40 +02:00
Ville Juven
776e2d774f signal/sig_dispatch: Add signal action, if task is in system call
The _unmasked_ signal action was never added if the task is in system call
and waiting for (a different) signal.

This fixes deliver especially for default signal actions / unmaskable
signals, like SIGTERM.
2023-03-14 11:16:52 +09:00
Petro Karashchenko
4581a84064 nuttx: fix indentation issue
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-09 16:27:07 -03:00
Ville Juven
47ce89f757 Revert "signal/sig_dispatch: Signal action was not performed if TCB_FLAG_SYSCALL is set"
This reverts commit 0e44666828.
2023-03-08 10:13:26 +01:00
Ville Juven
3f529b4882 Revert "signal/sig_dispatch: Fix case where signal action is sent twice"
This reverts commit be0cb4cbe3.
2023-03-08 10:13:26 +01:00
wangbowen6
14ba7a7dd1 sched: build error fix in task_exithook
CC:  task/task_recover.c task/task_exithook.c: In function 'nxtask_exithook':
task/task_exithook.c:464:11: error: 'struct tcb_s' has no member named 'cmn'
  464 |   if ((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
      |           ^~
CC:  opus/silk/shell_coder.c make[1]: *** [Makefile:60: task_exithook.o] Error 1

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-03-03 20:10:43 +08:00
Xiang Xiao
66c5f86018 sched: Disable stdio api by default when DEFAULT_SMALL equals y
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-03 00:18:03 +02:00
wangbowen6
51c30289ae sched: add critical section in nxsched_get_stateinfo
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-03-02 01:12:53 +08:00
wangbowen6
d77b53957c sched/env: add tg_envc in task_group_s to avoid some loops in code
this commit optimize the env api speed

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-02-25 23:10:37 +02:00
Junbo Zheng
468a0f0991 sched: fix kconfig warning
warning: SIG_ABRT (defined at sched/Kconfig:1481) has 'help' but empty help text

Reference: https://dsa.cs.tsinghua.edu.cn/oj/static/unix_signal.html

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2023-02-24 15:49:33 +08:00
lilei19
38f64f559d change strcpy to strlcpy
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-02-24 12:15:40 +08:00
chenrun1
e6227e1943 include/signal.h:Expanding SIGNAL to be consistent with Linux 2023-02-24 04:07:10 +08:00
yinshengkai
29a7d267fb note: correct systime with perf count
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-02-23 22:30:07 +08:00
yinshengkai
55ce5d0511 note: remove SCHED_INSTRUMENTATION_HIRES
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-02-23 22:30:07 +08:00
Ville Juven
be0cb4cbe3 signal/sig_dispatch: Fix case where signal action is sent twice
As far as I can interpret how signal delivery should work when the signal
is blocked, it should still be sent to the pending queue even if the signal
is masked. When the sigmask changes it will be delivered.

The original implementation did not add the pending signal action, if
stcb->task_state == TSTATE_WAIT_SIG is true.

An attempt to patch this was made in #8563 but it is insufficient as it
creates an issue when the task is not waiting for a signal, but is in
syscall, in this case the signal is incorrectly queued twice.
2023-02-22 01:29:06 +08:00
Xiang Xiao
6b14ad9337 driver/note: Restore SCHED_INSTRUMENTATION config to sched/Konfig
since the chip/board vendor could disable dirvers/note and
provide the implementation of sched_note_xxx by self

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-20 14:30:59 +08:00
lilei19
77f6319268 sync ps/assert output 2023-02-17 23:35:44 +08: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
Ville Juven
2cdba4a0a2 task/task_cancelpt: Kill the child if it is not in a cancel point
Do not allow a deferred cancellation if the group is exiting, it is too
dangerous to allow the threads to execute any user space code after the
exit has started.

If the cancelled thread is not inside a cancellation point, just kill it
immediately via asynchronous cancellation. This will create far less
problems than allowing it to continue running user code.
2023-02-17 22:57:36 +08:00
Ville Juven
0e44666828 signal/sig_dispatch: Signal action was not performed if TCB_FLAG_SYSCALL is set
For some reason the signal action was never performed if the receiveing
task was within a system call, the pending queue inser was simply missing.

This fixes the issue.
2023-02-17 22:54:55 +08:00
Ville Juven
905cba3ee3 group/tg_info/argv: Make utility function to read argv as string
This creates a generic and safe way to read a process argument vector
as string from any context.
2023-02-17 01:27:16 +08:00
Ville Juven
40800823c6 sched/nxtask_sigchild: Set exit code when CONFIG_SCHED_CHILD_STATUS=y
This is a follow-up to https://github.com/apache/nuttx/pull/8486
2023-02-14 10:27:46 +09: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
01741a0b65 sched/semaphore: increase sem count when holder task exit
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-02-12 16:49:45 +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