Commit Graph

2709 Commits

Author SHA1 Message Date
Neo Xu c3ed24aec6 Remove check for group to retriev argv string
Now the argument vector is stored in TLS, thus no need to check if group is valid

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-10 23:13:37 +08:00
yinshengkai 1b42a7bf84 sched: gprof SMP support
In the case of SMP, use smp_call to get other CPU data

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-10 18:46:51 +08:00
yinshengkai eb8449cb0c sched/gprof: add gprof support
gprof can analyze code hot spots based on scheduled sampling.
After adding the "-pg" parameter when compiling, you can view the code call graph.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-10 18:46:51 +08:00
Xiang Xiao 4944bfd56c sched: Implement profil function
which is very useful for performance analysis:
https://man7.org/linux/man-pages/man3/profil.3.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-10 18:46:51 +08:00
hujun5 d26c2380e4 sched: fix omitted merging the pending queue regression
This commit fixes the regression from https://github.com/apache/nuttx/pull/13995

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-10 17:59:35 +08:00
zhangyuan29 8acc3b4771 sched/pthread: save pid before task activate
When a high-priority pthread is created,
ptcb may be released after nxtask_activate.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-10-10 17:58:22 +08:00
dongjiuzhu1 2e3a6acaa2 sched/sem_rw: convert read-lock to write-lock when self already holds a write-lock
If the write lock is already held by oneself and sine the write
lock can be recursively held, so, this operation can be converted to a write
lock to avoid deadlock.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-10 16:42:15 +08:00
ouyangxiangzhen 93890321c5 sched/wdog: Fix code style
This commit fixed code style issue left by the previous patch.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-10-10 13:57:46 +08:00
hujun5 67c9a7aabd sched: remove param in nxsched_remove_readytorun
after
   text    data     bss     dec     hex filename
 269732   51065   63335  384132   5dc84 nuttx

before
   text    data     bss     dec     hex filename
269784   51065   63335  384184   5dcb8 nuttx

size -50

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-10 08:44:52 +08:00
ouyangxiangzhen 110ab50f50 sched/wdog: Revert wd_cancel semantics
In the original implementation, if wdog is not ACTIVE, -EINVAL will be returned. The rp2040 i2c driver relies on this semantics to correctly release the semaphore.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-10-09 16:18:27 -03:00
hujun5 e249dd2672 arch: support customized up_cpu_index() in AMP mode
Some app with same code runs on different cores in AMP mode,
need the physical core on which the function is called.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-10-10 02:38:40 +08:00
ligd 80079f35e4 signal: add sig_tgkill() kenrnel version support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-10 02:38:12 +08:00
yinshengkai 3271142b87 note: print without relying on format strings
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-09 22:23:29 +08:00
yinshengkai b5cf4310cb gote: implement asynchronous printf formatting
Do not format immediately when calling sched_note_printf, but delay formatting until dump trace.
After turning on SYSTEM_NOTE, similar asynchronous syslog functions can be achieved.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-09 22:23:29 +08:00
yinshengkai 034af29aab arch: adjust gcov configuration name
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-09 21:27:47 +08:00
anjiahao fa59adde40 Simplify BOARD_MEMORY_RANGE initialization logic
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-09 15:41:48 +08:00
anjiahao e0bcad3a1d gdbstub:support gdbstub memory access control
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-09 15:41:48 +08:00
fangxinyong 76508d42a9 sched: export sched_getcpu API in AMP mode
Some app with same code runs on different cores in AMP mode,
need known physical core id on which the function is called.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-10-09 15:21:25 +08:00
ligd 86869e96c9 sem: use wd_start_realtime/abstime to replace wd_start
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 13:54:29 +08:00
ligd 4196433888 nxsig_clockwait: fix time error when clockid is CLOCK_REALTIME
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 13:54:29 +08:00
yangguangcai 475bbfc165 nxsig_clockwait: add Parameter Check.
Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
2024-10-09 13:54:29 +08:00
ligd fc73dfd368 sleep: optimize sleep logic, to reduce the disable IRQ time
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 13:54:29 +08:00
hujun5 e01d6b26cc sched/group: There is no need to use sched_[un]lock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-09 13:46:33 +08:00
xuxingliang bc5a337a58 sched/note: add note for wdog module
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-09 08:39:58 +08:00
fangpeina b5145c528e misc/assert: add backtrace dump support for mutex hold task
Signed-off-by: fangpeina <fangpeina@xiaomi.com>
2024-10-09 08:37:01 +08:00
wangmingrong1 ba05a36eed board_reset: flush cache before reset
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-09 02:30:21 +08:00
ouyangxiangzhen c0ae6525c4 sched/signal: Fix compilation errors for MSVC.
This commit removed empty struct to fix compilation errors for the MSVC compiler.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-10-09 01:36:39 +08:00
xuxingliang b7824264f6 sched: optimize deadlock detection readability
Use meaningful variable names.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-08 23:35:01 +08:00
anjiahao 97425687cf deadlock:fix find deadlock bug
bug:
  thread 1: get mutexA
            wait a sem

  thread 2: wait mutexA

  This situation will be mistakenly judged as a deadlock.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-08 23:35:01 +08:00
anjiahao 3d69dbe1c8 deadlock:fix bug,When holder is -1 need stop search next
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-08 23:35:01 +08:00
Xu Xingliang 4ed506d6ab board/coredump: add option to use base64 stream
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2024-10-08 22:33:19 +08:00
zhangyuan29 651a5e6afa sched/signal: change pthread_exit to nx_pthread_exit
In protected build, kernel cannot call usersapce interface.

1. change pthread_exit to nx_pthread_exit.
2. add kernel tls cleanup.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-10-08 16:53:21 +08:00
buxiasen 0b3859521a arch: fix the sched parameter update when exiting
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 13:53:06 +08:00
ligd 07b27cd199 sched: swap setting for g_npidhash
in case of crash in kmm_zalloc, and crash dump use
nxsched_foreach()

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-08 08:59:39 +08:00
hujun5 31a3cea64a arch: rename xxxx_pause.c to xxxx_smpcall.c
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-08 08:13:22 +08:00
hujun5 d8cb7759b6 arch: remove up_cpu_pause up_cpu_resume up_cpu_paused up_cpu_pausereq
reason:
  To remove the "sync pause" and decouple the critical section from the dependency on enabling interrupts,
  after that we need to further implement "schedlock + spinlock".
changelist
  1 Modify the implementation of critical sections to no longer involve enabling interrupts or handling synchronous pause events.
  2 GIC_SMP_CPUCALL attach to pause handler to remove arch interface up_cpu_paused_restore up_cpu_paused_save
  3 Completely remove up_cpu_pause, up_cpu_resume, up_cpu_paused, and up_cpu_pausereq
  4 change up_cpu_pause_async to up_send_cpu_sgi

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-08 08:13:22 +08:00
zhangyuan29 82eca2607a mq: change mqueue msg mail to dynamic array
Change mqueue_msg_s to a dynamic array so that
mqueue msg can be malloc based on the msg size
of the current data when applied dynamically.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-10-07 20:20:13 +08:00
xuxingliang 18d5ae20f5 drivers/segger: add heap data plot
Add heap current used to note.
Plot it in segger sysview data plot.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
xuxingliang 0663ac1483 sched/note: specify note event for heap instrumentation
1. Add NOTE_HEAP_ prefix for heap note event.
2. Use note type as heap instrumentation parameter.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
yinshengkai 79eab8783f note: add memory tracing event support
Record all memory allocation and release, save to ram, used to analyze memory allocation rate and memory usage
Its absolute value is not trustworthy because the memory will be allocated in thread A and released in thread B

 netinit-5   [0]   0.105984392: tracing_mark_write: C|5|Heap Usage|96|free: heap: 0x606000000020 size:24, address: 0x603000000370
 netinit-5   [0]   0.105996874: tracing_mark_write: C|5|Heap Usage|24|free: heap: 0x606000000020 size:72, address: 0x6070000008e0
nsh_main-4   [0]   3.825169408: tracing_mark_write: C|4|Heap Usage|2177665|free: heap: 0x606000000020 size:424, address: 0x614000000840
nsh_main-4   [0]   3.825228525: tracing_mark_write: C|4|Heap Usage|14977|free: heap: 0x606000000020 size:2162688, address: 0x7f80a639f800
nsh_main-4   [0]   3.825298789: tracing_mark_write: C|4|Heap Usage|15189|malloc: heap: 0x606000000020 size:20, address: 0x6030000003a0

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
ligd 86a1cc30a5 task: merge nxtask_setup_name() before create_stack
After this patch up_create_stack() can do some
judgement with thread name

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-07 15:47:13 +08:00
hujun5 f12996c851 sched: replace sync pause with async pause for nxsig_process
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-07 13:32:57 +08:00
hujun5 f132ed2edb signal: adjust the signal processing logic to remove the judgment
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-07 13:32:57 +08:00
hujun5 eae57cb0e6 sched: replace sync pause with async pause for nxtask_terminate
reason:
In the kernel, we are planning to remove all occurrences of up_cpu_pause as one of the steps to
simplify the implementation of critical sections. The goal is to enable spin_lock_irqsave to encapsulate critical sections,
thereby facilitating the replacement of critical sections(big lock) with smaller spin_lock_irqsave(small lock)

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-06 09:26:56 +08:00
anjiahao a9cb28cd23 modlib:Standardized module loading method
1. use '__attribute__((constructor))' mark initialize function
2. use '__attribute__((destructor))' mark uninitialize function
3. compile module with -fvisibility=hidden. use `__attribute__((visibility("default")))`
mark is need export symbol.so not need module_initialize to initialize export symbol.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-05 15:22:02 +08:00
hujun5 5df3625b62 sched: replace sync pause with async pause for nxtask_restart
reason:
In the kernel, we are planning to remove all occurrences of up_cpu_pause as one of the steps to
simplify the implementation of critical sections. The goal is to enable spin_lock_irqsave to encapsulate critical sections,
thereby facilitating the replacement of critical sections(big lock) with smaller spin_lock_irqsave(small lock)

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-05 14:23:25 +08:00
hujun5 0b0f535c66 sched: replace sync pause with async pause for setpriority
reason:
In the kernel, we are planning to remove all occurrences of up_cpu_pause as one of the steps to
simplify the implementation of critical sections. The goal is to enable spin_lock_irqsave to encapsulate critical sections,
thereby facilitating the replacement of critical sections(big lock) with smaller spin_lock_irqsave(small lock)

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-05 14:00:59 +08:00
hujun5 8e89984360 sched: replace sync pause with async pause for nxsched_suspend
reason:
In the kernel, we are planning to remove all occurrences of up_cpu_pause as one of the steps to
simplify the implementation of critical sections. The goal is to enable spin_lock_irqsave to encapsulate critical sections,
thereby facilitating the replacement of critical sections(big lock) with smaller spin_lock_irqsave(small lock)

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-05 13:59:35 +08:00
hujun5 6a13e4a6f6 sched/sched: next pointer value is definitely not null
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-05 13:49:55 +08:00
hujun5 b4cc9fb11b sched: change nxsched_islocked_global to nxsched_islocked_tcb
reason:
1 To improve efficiency, we mimic Linux's behavior where preemption disabling is only applicable to the current CPU and does not affect other CPUs.
2 In the future, we will implement "spinlock+sched_lock", and use it extensively. Under such circumstances, if preemption is still globally disabled, it will seriously impact the scheduling efficiency.
3 We have removed g_cpu_lockset and used irqcount in order to eliminate the dependency of schedlock on critical sections in the future, simplify the logic, and further enhance the performance of sched_lock.
4 We set lockcount to 1 in order to lock scheduling on all CPUs during startup, without the need to provide additional functions to disable scheduling on other CPUs.
5 Cpu1~n must wait for cpu0 to enter the idle state before enabling scheduling because it prevents CPUs1~n from competing with cpu0 for the memory manager mutex, which could cause the cpu0 idle task to enter a wait state and trigger an assert.

size nuttx
before:
   text    data     bss     dec     hex filename
 265396   51057   63646  380099   5ccc3 nuttx
after:
   text    data     bss     dec     hex filename
 265184   51057   63642  379883   5cbeb nuttx

size -216

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-05 13:49:55 +08:00