Commit Graph

2766 Commits

Author SHA1 Message Date
hujun5 2c0e5e872b pthread_cond remove csection
reason:
We decouple semcount from business logic by using an independent counting variable,
which allows us to remove critical sections in many cases.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-11-02 09:40:19 -03:00
ouyangxiangzhen 17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
cuiziwei d1e5b38b9b nuttx/semaphore: Move define CONFIG_SEM_PREALLOCHOLDERS to include/semaphore.h.
Move CONFIG_SEM_PREALLOCHOLDERS to include/semaphore.h to avoid undefined issues from occurring in other places as well.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2024-10-31 18:37:53 +08:00
chenrun1 9a75519edc timer_create:Checks whether the signo provided by the user is valid
Summary:
  When the user sets an illegal signo, the error will only be known when timer_signotify is triggered during timeout.
By intercepting timer_create, we can directly locate the problem

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-10-31 17:16:12 +08:00
wangmingrong1 e3d7d23618 gcov: Fix typographical errors
1. CONFIG_ARCH_COVERAGE has been replaced by CONFIG_SCHED_GCOV
2. Delete the SIM-specific GCOV_ALL configuration and change it to a universal configuration for all architectures

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-30 14:45:23 +08:00
zhangyuan29 befe29801f sem: change sem wait to atomic operation
Add sem_wait fast operations, use atomic to ensure
atomicity of semcount operations, and do not depend
on critical section.

Test with robot:
before modify:
nxmutex_lock cost: 78 ns
nxmutex_unlock cost: 82 ns

after modify:
nxmutex_lock cost: 28 ns
nxmutex_unlock cost: 14 ns

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-10-30 01:38:45 +08:00
ligd 4541132035 Revert "shced:sem: replace mutex with spinlock"
Cause we can't do sem_post/wait within spinlock

This reverts commit 23d65cb97f.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-29 23:01:39 +08:00
chao an 9c97f7adaa sched/cpuload: move g_cpuload_wdog to private chapter
coding style

Signed-off-by: chao an <anchao@lixiang.com>
2024-10-25 13:28:51 +08:00
anjiahao b33226d76e coredump: coredump_add_memory_region need use flags
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-24 08:46:01 +08:00
Ville Juven 134ecf380b task_exit.c: Add missing sched_note_stop()
A regression from #13728 ; sched_note_stop() is never called for tasks
that exit normally via exit().
2024-10-23 12:08:18 -03:00
Ville Juven 112b8cf470 sched/task_exit.c: Refresh current CPU instead of relying on stale value
The comment about the CPU index remaining stable is incorrect. There is no
guarantee the task does not yield during the exit process, meaning the CPU
can most definitely change. Also, there is no reason why it should not be
allowed to change.

This fixes a full system crash during process exit when the CPU changes
and we query the current task from the old CPU.
2024-10-22 23:28:52 +08:00
ouyangxiangzhen 8ecca52b27 sched/timer: Simplify setitimer implementation.
This commit simplified setitmer implementation by eliminating a redundant conditional branch.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-10-18 23:58:07 +08:00
wanggang26 848b596a12 coredump: measure the system's running time in milliseconds unit
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-16 15:35:21 +08:00
anjiahao d347da10ca coredump:need close block device when finish coredump
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-16 15:35:21 +08:00
wanggang26 2414fc91ff coredump: fix issue that calculated dump region range is
smaller than it should be.

0x21000000    0x210105e8    0x210105f8      0x21044000
  |----------------|-------------|--------------|

If there is already a range of 0x210105e8 - 0x210105f8, adding another
range of 0x21000000 - 0x21044000 would result in an incorrect range of
0x210105e8 - 0x21044000.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-16 15:35:21 +08:00
yinshengkai 43d483efc0 sched: remove duplicate functions
nxsched_critmon_cpuload has two identical implementations

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-16 13:58:59 +08:00
hujun5 a46eb84334 sched: Use spinlock repalce sched_[un]lock in some place
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-16 13:53:51 +08:00
Xiang Xiao 5397a58731 libc/modlib: Make modlib selectable from defconfig
since bootloader may call modlib functions directly
to load elf firmware without binfmt, dlfcn or module.

BTW, this patch also remove the duplicated selecttion

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-16 10:11:20 +08:00
wangmingrong1 533c11eee2 coredump.c: Delete the judgment of continue
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-16 08:07:09 +08:00
wangmingrong1 2beef702cc coredump.c: del multiple behavior
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-16 08:07:09 +08:00
ligd f0e12a983d cpuload: add nxsched_update_critmon() to handle thread busyloop
Signed-off-by: ligd <liguiding1@xiaomi.com>
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
2024-10-15 21:11:15 +08:00
chenzhijia 10d0526f3f nuttx/sched:Modify the comment error in sched_resumescheduler.c
Signed-off-by: chenzhijia <chenzhijia@xiaomi.com>
2024-10-15 21:05:36 +08:00
hujun5 a567148888 sched: add up_this_task and up_change_task macro stub
reason:
We can utilize percpu storage to hold information about the
current running task. If we intend to implement this feature, we would
need to define two macros that help us manage this percpu information
effectively.

up_this_task: This macro is designed to read the contents of the percpu
              register to retrieve information about the current
              running task.This allows us to quickly access
              task-specific data without having to disable interrupts,
              access global variables and obtain the current cpu index.

up_update_task: This macro is responsible for updating the contents of
                the percpu register.It is typically called during
                initialization or when a context switch occurs to ensure
                that the percpu register reflects the information of the
                newly running task.

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-15 15:25:55 +08:00
yinshengkai ef62c70e5f sched: modify CONFIG_DUMP_ON_EXIT to CONFIG_SCHED_DUMP_ON_EXIT
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-15 01:50:55 +08:00
wanggang26 7a352d2b83 coredump: fix bug that memsegs got invalid value
for (; cinfo.regions[memsegs].start <
       cinfo.regions[memsegs].end; memsegs++);

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-15 01:07:45 +08:00
xuxingliang a8b7d26db5 Use BACKTRACE_BUFFER_SIZE to declare backtrace buffer
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-15 01:07:21 +08:00
chao an ce42a9affc Revert "sched/spinlock: remove nesting spinlock support"
This reverts commit 5aa13bc490.
2024-10-14 17:42:16 +08:00
hujun5 b964eeee18 Reapply "sched/spinlock: remove nesting spinlock support"
This reverts commit 9e81f5efac.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-13 18:31:35 +08:00
hujun5 fa8ccc0e85 sched: fix nxsched_suspend_scheduler regression
This commit fixes the regression from https://github.com/apache/nuttx/pull/13877

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-13 10:16:22 +08:00
chenrun1 9e81f5efac Revert "sched/spinlock: remove nesting spinlock support"
This reverts commit 5aa13bc490.
2024-10-13 09:41:59 +08:00
chenzhijia 505adfa277 nuttx:move "#define STRINGIFY(x)" to nuttx/macro.h
Franklin requirement, "#define STRINGIFY(x)" conflicts with https://github.com/mborgerding/kissfft define

Signed-off-by: chenzhijia <chenzhijia@xiaomi.com>
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
2024-10-13 03:16:25 +08:00
Xiang Xiao a074a572af sched/pthread: Remove unused pthread_sem_xxx functions
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-13 02:47:44 +08:00
xuxin19 351781d601 cmake:refine nuttx cmake build system fix CMake build missing part
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-10-13 02:25:06 +08:00
Xiang Xiao 17cb6ed63d sched/instrument: rename stack_record.c to stack_monitor.c
to align with gprof naming convention.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-13 02:10:41 +08:00
yinshengkai 0132d98e41 sched: delete the dump file list when the thread exits
Accessing the filelist of other tasks when the thread exits may cause a crash

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-13 02:06:38 +08:00
hujun5 7ab27ec1c8 sched: replace sync pause with async pause for sched_backtrace
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-13 01:54:14 +08:00
buxiasen 4b7493901e sched_backtrace: fix when dump running thread in other-core
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-13 01:54:14 +08:00
zhangyuan29 ed8007ac40 sched/signal: exit sig action when tcb group is null
nxsig_action will use tcb group when group release,
so check tcb group when do sig action.

[ap] dump_assert_info: Assertion failed : at file: signal/sig_action.c:205 task: ofonod process: Kernel 0xec89d5
[ap] sched_dumpstack: backtrace:
[ap] sched_dumpstack: [29] [<0x66e2e2>] backtrace_unwind+0x105/0x108
[ap] sched_dumpstack: [29] [<0x660272>] sched_backtrace+0x41/0x48
[ap] sched_dumpstack: [29] [<0x61c4dc>] sched_dumpstack+0x33/0x80
[ap] sched_dumpstack: [29] [<0x6023e4>] _assert+0x19b/0x39c
[ap] sched_dumpstack: [29] [<0x61b7e4>] __assert+0x7/0x10
[ap] sched_dumpstack: [29] [<0x6071a2>] nxsig_action+0x119/0x248
[ap] sched_dumpstack: [29] [<0x6072d8>] sigaction+0x7/0x24
[ap] sched_dumpstack: [29] [<0x66a072>] signal+0x4d/0x80
[ap] sched_dumpstack: [29] [<0x100fd36>] signalfd_file_close+0x35/0x60
[ap] sched_dumpstack: [29] [<0x64a7d8>] file_close+0x1b/0x44
[ap] sched_dumpstack: [29] [<0x649ac0>] files_putlist+0x2b/0x70
[ap] sched_dumpstack: [29] [<0x60491a>] group_leave+0x99/0xe4
[ap] sched_dumpstack: [29] [<0x605df8>] nxtask_exithook+0x4f/0xf4
[ap] sched_dumpstack: [29] [<0x603ca0>] _exit+0x33/0x3c
[ap] sched_dumpstack: [29] [<0x61ecf0>] abort+0x7/0xc

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-10-12 13:39:21 +08:00
hujun5 4c1c05164a sched/signal: There is no need to use sched_[un]lock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-12 13:28:23 +08:00
hujun5 794d362335 sched/pthread: There is no need to use sched_[un]lock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-12 13:28:23 +08:00
anjiahao 52126aede1 coredump:Move coredump to sched/misc
1. move coredump form libelf to sched/misc
2. rename core_dump to coredump

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-12 12:29:06 +08:00
anjiahao 9e868cadfb coredump:Move private functions to internal header files
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-12 12:29:06 +08:00
chao an 5aa13bc490 sched/spinlock: remove nesting spinlock support
developers must be careful to hold spinlocks and ensure all
of protected code is under control, so remove support for nested
spinlocks to improve performance.

Signed-off-by: chao an <anchao@lixiang.com>
2024-10-12 11:18:10 +08:00
buxiasen ca45ad69bd misc: flush syslog before possible long time cost coredump
When coredump to mtd, it maybe cost lots of time, do flush syslog can
make user access all log when coredump processing, should be better.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-12 09:32:44 +08:00
ligd dae2a39443 sched: fix warning
sched/sched_sysinfo.c:55:19: warning: unused variable 'minfo' [-Wunused-variable]
   55 |   struct mallinfo minfo;
      |                   ^~~~~

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-12 09:29:37 +08:00
ligd 6e68dde445 sem: fix assert failed when open CONFIG_PRIORITY_INHERITANCE
set CONFIG_PRIORITY_INHERITANCE=y
set CONFIG_SEM_PREALLOCHOLDERS=0 or CONFIG_SEM_PREALLOCHOLDERS=8

    #24 0x4dcab71 in __assert assert/lib_assert.c:37
    #25 0x4d6b0e9 in nxsem_destroyholder semaphore/sem_holder.c:602
    #26 0x4d80cf7 in nxsem_destroy semaphore/sem_destroy.c:80
    #27 0x4d80db9 in sem_destroy semaphore/sem_destroy.c:120
    #28 0x4dcb077 in nxmutex_destroy misc/lib_mutex.c:122
    #29 0x4dc6611 in pipecommon_freedev pipes/pipe_common.c:117
    #30 0x4dc7fdc in pipecommon_close pipes/pipe_common.c:397
    #31 0x4ed4f6d in file_close vfs/fs_close.c:78
    #32 0x6a91133 in local_free local/local_conn.c:184
    #33 0x6a92a9c in local_release local/local_release.c:129
    #34 0x6a91d1a in local_subref local/local_conn.c:271
    #35 0x6a75767 in local_close local/local_sockif.c:797
    #36 0x4e978f6 in psock_close socket/net_close.c:102
    #37 0x4eed1b9 in sock_file_close socket/socket.c:115
    #38 0x4ed4f6d in file_close vfs/fs_close.c:78
    #39 0x4ed1459 in nx_close_from_tcb inode/fs_files.c:754
    #40 0x4ed1501 in nx_close inode/fs_files.c:781
    #41 0x4ed154a in close inode/fs_files.c:819
    #42 0x6bcb9ce in property_get kvdb/client.c:307
    #43 0x6bcd465 in property_get_int32 kvdb/common.c:270
    #44 0x5106c9a in tz_offset_restore app/miwear_bluetooth.c:745
    #45 0x510893f in miwear_bluetooth_main app/miwear_bluetooth.c:1033
    #46 0x4dcf5c8 in nxtask_startup sched/task_startup.c:70
    #47 0x4d70873 in nxtask_start task/task_start.c:134
    #48 0x4e04a07 in pre_start sim/sim_initialstate.c:52

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-11 21:34:37 +08:00
ligd 4409db4a87 sem: fix NULL pointer when open CONFIG_PRIORITY_INHERITANCE
set CONFIG_PRIORITY_INHERITANCE=y
set CONFIG_SEM_PREALLOCHOLDERS=0

semaphore/sem_holder.c:320:34: runtime error: member access within null pointer of type 'struct tcb_s'
    #0 0xd8b540 in nxsem_boostholderprio semaphore/sem_holder.c:320
    #1 0xd8c1cf in nxsem_boost_priority semaphore/sem_holder.c:703
    #2 0xda5dfa in nxsem_wait semaphore/sem_wait.c:145
    #3 0xda61d9 in nxsem_wait_uninterruptible semaphore/sem_wait.c:248
    #4 0x12f2477 in media_service_thread0 /home/ligd/platform/dev/apps/examples/hello/hello_main.c:44
    #5 0x1204154 in pthread_startup pthread/pthread_create.c:59
    #6 0x1cd906f in pthread_start pthread/pthread_create.c:139
    #7 0xe72fcb in pre_start sim/sim_initialstate.c:52

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-11 21:34:37 +08:00
dongjiuzhu1 a041ebbaef Revert "sched/group/setuptask_file: duplicate idle task fd for kernel thread"
let's using shared group for kthreads, see pull/12320

This reverts commit 4e24eec7b6.
2024-10-11 16:53:19 +08:00
hujun5 1373957ea0 fix typo error
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-11 13:52:58 +08:00
yinshengkai 4685175617 sched: fix the inaccurate cpuload statistics issue
Non-fixed clock source will lead to inaccurate cpuload statistics

before:
5     5 253 RR       Task      - Waiting  Signal    0000000000000000 0002000 0000624  31.2%   2.5% cpuload -p 50
6     6 253 RR       Task      - Waiting  Signal    0000000000000000 0002000 0000624  31.2%   0.7% cpuload -p 10
7     7 253 RR       Task      - Waiting  Signal    0000000000000000 0002000 0000624  31.2%   2.2% cpuload -p 20
after:
5     5 253 RR       Task      - Waiting  Signal    0000000000000000 0002000 0000624  31.2%  50.8% cpuload -p 50
6     6 253 RR       Task      - Waiting  Signal    0000000000000000 0002000 0000624  31.2%  10.8% cpuload -p 10
7     7 253 RR       Task      - Waiting  Signal    0000000000000000 0002000 0000624  31.2%  20.0% cpuload -p 20
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-11 11:04:47 +08:00