Commit Graph

2663 Commits

Author SHA1 Message Date
yinshengkai
5d8cdeaea8 note: print without relying on format strings
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-25 19:04:02 +08:00
yinshengkai
57a385a994 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-25 19:04:02 +08:00
xuxingliang
46b1c8605a sched/note: add note for wdog module
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-25 19:04:02 +08:00
xuxingliang
dceb26c7b2 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-25 19:04:02 +08:00
xuxingliang
c2bcc56546 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-25 19:04:02 +08:00
yinshengkai
2c0e2ac36b 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-25 19:04:02 +08:00
xuxingliang
17cbaadce8 task: use get_task_name where possible
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-25 19:04:02 +08:00
hujun5
33e30239f1 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-17 12:51:14 +02:00
zhangyuan29
cdb5a7c6d4 sched: Disable the scheduling when send SIGCHLD signal
Disable the scheduling to prevent other tasks from being
deleted after they are awakened

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-10-17 12:51:14 +02:00
hujun5
b52ad53cc1 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-17 12:51:14 +02:00
hujun5
28cfadb4b0 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-17 12:51:14 +02:00
wangmingrong1
0b98e9e680 board_reset: flush cache before reset
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-11 01:30:51 +08:00
xuxingliang
8074812517 assert: dump all CPU registers and stack
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-11 01:30:51 +08:00
xuxingliang
e65b03edd2 assert: cleanup assert handler
1. extract dump from assert main flow
2. use OSINIT_PANIC for fatal error.
3. fix the method to judge kernel thread.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-11 01:30:51 +08:00
Xu Xingliang
9da6761453 assert: disable kasan in assert
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2024-10-11 01:30:51 +08:00
hujun5
f51c5452b2 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-11 01:30:51 +08:00
hujun5
c35e25b7e5 arch: rename xxxx_pause.c to xxxx_smpcall.c
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-11 01:30:51 +08:00
hujun5
d54bc8a9f8 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-11 01:30:51 +08:00
xuxingliang
5e2d205e1b sched: handle sched lock in interrupt
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-11 01:30:51 +08:00
dulibo1
755bef6c56 sched_smp:adjust the unlock order
1.nxsem_post wake up  nxsched_smp_call;
2.stack smp_call_data_s may return;
3.nxsched_smp_call_handler access call_data->lock is not safety;
so adjust the unlock order

Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
2024-10-11 01:30:51 +08:00
hujun5
4fd92edee7 sched: replace sync pause with async pause for nxsig_process
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-11 01:30:51 +08:00
hujun5
487fcb3bce signal: adjust the signal processing logic to remove the judgment
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-11 01:30:51 +08:00
hujun5
f791311138 sched/sched: next pointer value is definitely not null
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-10 17:57:30 +08:00
hujun5
508c5889d7 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-10 17:57:30 +08:00
dulibo1
1237e9fcea smp:fix sim build error under config CONFIG_SMP
CC:  sim/sim_smpsignal.c init/nx_smpstart.c: In function ‘nx_idle_trampoline’:
init/nx_smpstart.c:68:21: warning: unused variable ‘tcb’ [-Wunused-variable]
   68 |   FAR struct tcb_s *tcb = this_task_inirq();
      |                     ^~~
sim/sim_smpsignal.c: In function ‘host_cpu_started’:
sim/sim_smpsignal.c:271:17: warning: unused variable ‘tcb’ [-Wunused-variable]
  271 |   struct tcb_s *tcb = this_task();

sim/sim_smpsignal.c:249:33: error: ‘cpu’ undeclared (first use in this function)
  249 |   restore_critical_section(tcb, cpu);
      |                                 ^~~

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-10 17:55:47 +08:00
dulibo1
f1f38b6e16 sched_smp:adjust the critical section to protect refcount from multi cores access
Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-10 17:55:47 +08:00
dulibo1
6fd1ca64a1 sched_smp:sync refcount before enqueue smp call queue
Signed-off-by: dulibo1 <dulibo1@xiaomi.com>

1.call_data->refcount is not remote_cpus;
2.nxsched_smp_call_add enqueue  the call_data;
3.maybe nxsched_smp_call_handler is just doing;
4.dequeue the call_data but call_data->refcount is not corret;
5.unpredictability case will occur;
2024-10-10 17:55:47 +08:00
hujun5
ed998c08c4 sched: change the SMP scheduling policy from synchronous to asynchronous
reason:
Currently, if we need to schedule a task to another CPU, we have to completely halt the other CPU,
manipulate the scheduling linked list, and then resume the operation of that CPU. This process is both time-consuming and unnecessary.

During this process, both the current CPU and the target CPU are inevitably subjected to busyloop.

The improved strategy is to simply send a cross-core interrupt to the target CPU.
The current CPU continues to run while the target CPU responds to the interrupt, eliminating the certainty of a busyloop occurring.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-09 23:32:31 +08:00
hujun5
5f6eb292a8 sched: add nxsched_remove_self
reason:
1In the scenario of active waiting, context switching is inevitable, and we can eliminate redundant judgments.

code size
before
hujun5@hujun5-OptiPlex-7070:~/downloads1/vela_sim/nuttx$ size nuttx
   text    data     bss     dec     hex filename
 262848   49985   63893  376726   5bf96 nuttx

after
hujun5@hujun5-OptiPlex-7070:~/downloads1/vela_sim/nuttx$ size nuttx
   text    data     bss     dec     hex filename
 263324   49985   63893  377202   5c172 nuttx

reduce code size by  -476

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-09 18:19:13 +08:00
chao an
9dbde04327 Revert "toolchain/ghs: Fix CONFIG_SCHED_CRITMONITOR_MAXTIME_XXX "zero used for undefined preprocessing identifier" warnings"
move private define to public

This reverts commit 236678d730.

Signed-off-by: chao an <anchao@lixiang.com>
2024-10-09 18:16:56 +08:00
anjiahao
9403bc126b modlib/dlfcn:unify same code
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-08 23:51:33 +08:00
dongjiuzhu1
79b4b39994 libc/modlib: free memory resource when rmmod elf
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-08 23:51:33 +08:00
dongjiuzhu1
3b0e2be058 binfmt/modlib: support loading each sections to different memory for Relocate object
The feature depends on ARCH_USE_SEPARATED_SECTION
the different memory area has different access speed and cache
capability, so the arch can custom allocate them based on
section names to achieve performance optimization

test:
sim:elf
sim:sotest

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-08 23:51:33 +08:00
ouyangxiangzhen
db88754822 sched/signal: Simplify the implementation of SIGEV_THREAD_TID.
This commit simplified thread ID dispatching logic by integrating it into the `nxsig_dispatch` function.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-23 12:29:36 +08:00
ouyangxiangzhen
0373ba0fab sched/signal: Simplified Implementation for SIGEV_THREAD_TID.
This commit simplified the implementation for SIGEV_THREAD_TID.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-23 12:29:36 +08:00
ouyangxiangzhen
9f36509c0b signal: Add siginfo initializer
This patch is to make Coverity happy.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-23 12:29:36 +08:00
anjiahao
112cc083d3 pthread_mutex:add deadlock assert
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-20 22:05:29 +08:00
yinshengkai
f326f15b40 sched: move DUMP_ON_EXIT to sched
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:49:12 +08:00
buxiasen
b33e20a586 critmon: fix context switch critmon pause err.
Elapsed time statistic up to now when sched happen

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-09-19 03:16:14 +08:00
ligd
90dcd5edd3 critmonitor: add caller support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-19 03:16:14 +08:00
yinshengkai
e28b311b78 Make each function of SCHED_CRITMONITOR independent
There will be a large performance loss after SCHED_CRITMONITOR is enabled.
By isolating thread running time-related functions, CPU load can be run with less overhead.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-09-19 03:16:14 +08:00
yinshengkai
6b07284c61 sched/cpuload: fix SMP situation CPULOAD statistics are inaccurate
When statistics when sched_cpuload_critMonitor, thread switching only
calculates the current CPU's running time. Other CPU running threads
are updated for updates

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:16:14 +08:00
chao an
3cce16dd0c fs/dump: correct SCHED_DUMP_ON_EXIT to DUMP_ON_EXIT
1. correct SCHED_DUMP_ON_EXIT to DUMP_ON_EXIT
2. dump file list only if DUMP_ON_EXIT enabled

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-18 23:48:31 +08:00
simbit18
583f025422 Fix Kconfig style
Remove spaces from Kconfig files
Add TABs
Replace help => ---help---
2024-09-17 22:16:41 +08:00
hujun5
a2c704a84a Revert "irq: add [enter|leave]_critical_section_nonirq"
This reverts commit 1c5a0bf6cc.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-17 20:12:59 +08:00
ouyangxiangzhen
5a01f0f7f6 POSIX timer: Optimize overrun check by replacing loop with division.
Converted the timer overrun check from a loop-based approach to a division-based method. This change ensures a deterministic worst-case execution time (WCET), even if it might not outperform the loop in average scenarios.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-17 12:15:14 +08:00
ligd
578ecef975 wdog: add new API wd_start_realtime() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 12:15:14 +08:00
ligd
9c423ee5fa wdog: rename wd_start_absolute() to wd_start_abstick()
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 12:15:14 +08:00
yangguangcai
81b97b676b timer_settime:fix set time when flag is TIMER_ABSTIME.
Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
2024-09-17 12:15:14 +08:00
ouyangxiangzhen
213d5538fc signal: Add support for SIGEV_THREAD_ID and sigev_notify_thread_id
This patch added support for SIGEV_THREAD_ID and sigev_notify_thread_id.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 12:15:14 +08:00