Commit Graph

2663 Commits

Author SHA1 Message Date
ouyangxiangzhen
a483c884ce sched/timer: Fix timer accuracy problems
This commit fixed timer accuracy problems when repetitive timer is set.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-17 12:15:14 +08:00
Shoukui Zhang
43223124ec vfs/file: add reference counting to prevent accidental close during reading writing...
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
2024-09-17 12:01:53 +08:00
Zhe Weng
f8bd93575c sched/wqueue: Fix unexpected dq entry status
When we do not drop notifier from g_notifier_pending, we need an
isolated dq entry for this queue, otherwise the queued work_s's dq entry
may be modified by the work queue and breaks the chain of
g_notifier_pending.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-09-17 02:56:39 +08:00
ligd
4d6203d4c6 wqueue: teardown should cancel the work already in wqueue
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 02:56:39 +08:00
ligd
42b6dd0ff1 wqueue: extend the work_cancel_sync() return value
Return 1 to indicate the work was not cancelled.
Because it is currently being processed by work thread,
but wait for it to finish.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 02:56:39 +08:00
ligd
f3ada4b666 wqueue: workaound g_notifier_pending list unsafe
Situation:

thread1                             thread2
work_notifier_signal
enter_critical_section
dq_peek(&g_notifier_pending)
    dq_rem(&g_notifier_pending)
    work_queue()
      // switch -->                 work_notifier_teardown
                                    enter_critical_section
                                    dq_rem(&g_notifier_pending)
                                    leave_critical_section
                                    <--- switch back
    error occured
leave_critical_section

Workaound:
used sched_lock() to prevent the switch

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 02:56:39 +08:00
Masayuki Ishikawa
df298c186f Revert "build depend:Revert Make.dep intermediate ddc file"
This reverts commit ddc3119c4e.
2024-09-15 19:29:47 +08:00
ligd
fc50e57a26 pthread_mutx: remove unused critical_secton lock
Caused the 'nlocks' are remove from mutex, so
here don't need do critical_secton lock like nxmutex_lock

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-15 17:32:33 +08:00
wanggang26
f07a1868ce coredump: just save latest core file
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-15 17:31:40 +08:00
xuxin19
ddc3119c4e build depend:Revert Make.dep intermediate ddc file
Revert "Parallelize depend file generation"
This reverts commit d5b6ec450f.

parallel depend ddc does not significantly speed up compilation,
intermediately generated .ddc files can cause problems if compilation is interrupted unexpectedly

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-09-15 10:01:58 +08:00
ligd
ff1b54bff3 pthread_cleanup: move clenup down to tls
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-14 20:15:12 +08:00
hujun5
908df725ad arch: use up_current_regs/up_set_current_regs replace CURRENT_REGS
reason:
1 On different architectures, we can utilize more optimized strategies
  to implement up_current_regs/up_set_current_regs.
eg. use interrupt registersor percpu registers.

code size
before
    text    data     bss     dec     hex filename
 262848   49985   63893  376726   5bf96 nuttx

after
       text    data     bss     dec     hex filename
 262844   49985   63893  376722   5bf92 nuttx

size change -4

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-09-13 23:18:58 +08:00
ligd
f0d3c8ab2b usleep: use div_const to optimize the usleep
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd
fae6a00e02 clock: refactor clock_systime_timespec() & clock_systime_ticks()
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd
76e807560e clock: take clock_abstime2ticks() as MACRO
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd
07a4233d1d clock: refactor clock_gettime clock_settime
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd
6a2c03732f clock: Replace all ts and tick conversion functions
Using the ts/tick conversion functions provided in clock.h

Do this caused we want speed up the time calculation, so change:
clock_time2ticks, clock_ticks2time, clock_timespec_add,
clock_timespec_compare, clock_timespec_subtract... to MACRO

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd
a10c46d02e clock: use clock_timespec_add/subtract to optimize code
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
liaoao
45d6b5f8f2 clock: remove cast
Signed-off-by: liaoao <liaoao@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd
f2a77bbcea clock: take clock_timespec_compare/add/subtract() as MACRO
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
hujun5
3619e61c31 sched: adjust the scheduling strategy
1 Only the idle task can have the flag TCB_FLAG_CPU_LOCKED.
  According to the code logic, btcb cannot be an idle task, so this check can be removed.
2 Optimized the preemption logic check and removed the call to nxsched_add_prioritized.
3 Speed up the scheduling time while avoiding the potential for
  tasks to be moved multiple times between g_assignedtasks and g_readytorun.

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-09-12 01:34:56 +08:00
Alin Jerpelea
eb9030c891 sched: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:10:14 +08:00
hujun5
cd8db329de irq: simplify code by using OSINIT_TASK_READY
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-11 11:05:33 +08:00
ligd
7ff7f6ec21 wdog: optimize a bit speed in wd_start
After these wdog refactor:
We conducted a latency measurement using the rt-tests/cyclictest (commit cadd661) on an x86_64 NUC12 equipped with an i7-1255U processor and 16GB of LPDDR5 memory. The specific command used for this microbenchmark was cyclictest -q -l 100000 -h 30000, which is designed to assess the responsiveness of the cyclic timer.

The findings from our benchmark are summarized below, highlighting the minimum, median, and maximum latency values for each operating system tested:

Operating System	Minimum Latency (us)	Median Latency (us)	Maximum Latency (us)
Linux	            48	                    53	                410
PreemptRT	        6	                    57	                148
Xenomai	            53	                    53	                64
NuttX	            64	                    626	                1212
NuttX (refactor)	1	                    1	                3
In this table, "Min" indicates the shortest latency observed, "Median" represents the middle value of the latency distribution, and "Max" denotes the longest latency encountered.

The systems tested were as follows:

Linux: ACRN version 6.1.80 (commit f528146)
PreemptRT: Linux kernel 5.4.251 with the 5.4.254-rt85 patch applied
Xenomai: Linux kernel 5.4.251 patched with ipipe-core-5.4.239-x86-13
These results clearly demonstrate the varying performance of different operating systems in terms of timer latency, the refactored NuttX showing particularly low latency values.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
cb5bab34f1 wdog: always ticks++ when wd_start
Now we have CONFIG_USEC_PER_TICK, and for our timer system, all the calculation used 'tick'.
And all the timespec should change to 'tick' before use wd_start(), so USEC2TICK() can NOT be avoided.

Then there must be an 'less then one tick' loss.

One resolution:
ticks++ anyway when wd_start(). But this will caused time expired more a tick.

Another resolution:
Change the testcase, and allow the following logic:

t1 = current_time();
sleep(3);
t2 = current_time();

allow: t2 - t1 >= 3;
(original test must be: t2- t1 > 3)

The original test think the time must be elapse-ing, and the (t2 - t1) must bigger then 3,
but in our system, we use 'tick' as the minimal wdog unit, then there must a precision loss.

Now we choose first resolution.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
e334df6d9a wdog: add API wd_cancel_irq() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ouyangxiangzhen
b7cd0ab796 sched/sched: Correct the elapsed time calculation.
This patch addresses an issue where the elapsed time was uncorrectly calculated.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
bc1e1e1064 sched: add nxsched_get_next_expired() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
b010356b26 wdog: fix timer IRQ busy when timer list empty
when timer list empty, should return 0 to indicate
we are no longer set time

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
f23fb7ec09 sched: disable interrupt in non-SMP case
For the nested interrupt, one thing should decleared:
We are in ISR context, but no meaning we are disabled the interrupts.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ouyangxiangzhen
35fcd9331f sched/sched: Remove g_sched_time and fix CONFIG_SCHED_SPORADIC compilation error
This patch removes unused variable g_sched_time while fixes
 compilation error if CONFIG_SCHED_SPORADIC enabled.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ouyangxiangzhen
66871ced4d sched/wdog: move g_wdtimernested to wd_start.c
This patch moved the g_wdtimernested to wd_start.c

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ouyangxiangzhen
50f801dfaa sched/wdog: Fix list traversal problem in nested wdog process
If g_wdactivelist has been changed in the wdog callback, the list traversal with next pointer will cause problem.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ouyangxiangzhen
ebf7f5f748 sched/sched: Fix recursive watchdog handling
This commit fixed recursive watchdog handling caused by calling wd_start within watchdog timeout callback function.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ouyangxiangzhen
3b111c8b99 sched/wdog: Refactor wdog module
This commit refactors the wdog module to use absolute time representation internally. The main improvements include:
1. Fixed recursive watchdog handling caused by calling wd_start within watchdog timeout callback function.
2. Simplified timer processing to improve performance and enhance code readability.
3. Improved accuracy of timers.
4. Reduced critical section and interrupt disable time, improving real-time performance.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
7dabc6ff2f sched/wdog: Change sq to list
Before wdog module refactoring, we change the sq to double linked list.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
ligd
16df0dba4d wdog: wd_gettime() return 0 when wdog has already expired
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-10 23:32:30 +08:00
hujun5
8439296a50 irq: inline restore_critical_section
reason:
In the SMP, when a context switch occurs, restore_critical_section is executed.
In order to reduce the time taken for context switching,
we inline the restore_critical_section function.
Given that restore_critical_section is small in size
and is called from only one location, inlining it does not increase the size of the image.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-10 23:14:09 +08:00
dongjiuzhu1
00e878e848 fs/inode: add reference to protect filelist of group
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-10 15:16:19 +08:00
zhangyuan29
fbc8605b27 sem: add mutex protect in sem_trywait
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-09-10 01:26:31 +08:00
makejian
3240540952 pthread/realtime: export interfaces about pthread ceiling priority
pthread_mutex_setprioceiling and pthread_mutex_getprioceiling refers
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_setprioceiling.html
Signed-off-by: makejian <makejian@xiaomi.com>
2024-09-10 01:26:31 +08:00
makejian
85f8677e21 nxmutex: export priority ceiling interfaces with nxsem
Signed-off-by: makejian <makejian@xiaomi.com>
2024-09-10 01:26:31 +08:00
makejian
ee78219f9c semaphore: export priority ceiling interfaces in semaphore
Signed-off-by: makejian <makejian@xiaomi.com>
2024-09-10 01:26:31 +08:00
dongjiuzhu1
4e24eec7b6 sched/group/setuptask_file: duplicate idle task fd for kernel thread
The file descriptors of kernel threads should be clean and should
not be generated based on user threads. Instead, an idle thread
hould be chosen.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-09 19:45:29 +08:00
hujun5
1e57a5653c sched/sched: simplify the implementation of the function nxsched_readytorun_setpriority
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

reason:
If the type of tcb is TSTATE_TASK_ASSIGNED, removing it using nxsched_remove_not_running
and then putting it back into the queue may result in a context switch.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-08 17:53:59 +08:00
hujun5
1c5a0bf6cc irq: add [enter|leave]_critical_section_nonirq
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

reason:
In some non-irq scenarios, we can simplify
the implementation of critical sections to improve performance.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-08 17:50:51 +08:00
hujun5
427e5f18e8 irq: irq with the same priority share the same wqueue
reason:
1 We place interrupt handling functions of the same priority into the work queue corresponding
to that priority, allowing high-priority interrupts to preempt low-priority ones,
thus ensuring the real-time performance of high-priority interrupts.

2 The sole purpose of the interrupt handler is to wake
up the work queue of the corresponding priority and execute the interrupt handling function.

3 Compared to the functionality of isr threads, this
approach saves more memory, particularly when the number of interrupts is large.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-06 17:43:11 +08:00
hujun5
40ae660d30 init: add OSINIT_TASK_READY
reason:
simplifying some code writing

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-06 11:25:34 +08:00
yinshengkai
d7f02a8cb6 sched: change pthread_mutex implementation from sem to mutex
Since pthread_mutex is implemented by sem, it is impossible to see in ps who holds the lock and causes the wait.
Replace sem with mutex implementation to solve the above problems

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-06 09:42:53 +08:00
yinshengkai
2fd3981a8e pthread: remove pshared parameter from pthread_mutex_init
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-06 09:42:53 +08:00
yinshengkai
4feb418e36 pthread: remove the code which save and restore mutex state in pthread_condwait
type and flags are only initialized in mutex_init and should not change in the middle

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-06 09:42:53 +08:00
hujun5
608b59e401 smp: enable smp_call in all smp arch
reason:
In subsequent implementations, we will replace up_cpu_pause with smp_call.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-06 07:11:38 +09:00
hujun5
855060f353 sched: Make sure that affinity mask is valid
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-05 21:26:58 +08:00
hujun5
a65adcd9db smp: smp call handler add up_cpu_paused_[save|restore]
reason:
Since smp call handler may lead to context switching,
we need to update the context information by calling up_cpu_paused_[save|restore].

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-05 09:35:17 -03:00
hujun5
198630a809 sched: use this_task replace nxsched_self
reason:
We can reduce a function call to improve performance.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-05 09:33:50 -03:00
fangxinyong
7b05a550dc sched: replace up_cpu_index with this_cpu
Make this_cpu is arch independent and up_cpu_index do that.
In AMP mode, up_cpu_index() may return the index of the physical core.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-09-05 12:09:24 +08:00
hujun5
9e5d3dacd6 irq: dynaminc create g_irqmap
reason:
dynaminc create g_irqmap to reduce the use of data segments
CONFIG_ARCH_NUSER_INTERRUPTS should be one more than the number of IRQs actually used

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-03 19:22:28 -03:00
yinshengkai
baf79de7e5 task: assign_pid retry after malloc
Calling malloc in the critical section may cause thread switching.
Add a retry mechanism to handle the situation where other threads have been successfully expanded.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-03 09:45:33 -03:00
yinshengkai
8b13572d64 sched: update spinlock in nxsched_get_tcb to enter_critical_section
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-03 09:45:33 -03:00
chao an
f084685da8 sched/event: clear pending events before enable the scheduler
enable the scheduler may cause the context to switch to a high-priority task,
which will failure to clear pending events correctly.

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-02 18:24:28 +08:00
chao an
39e873f269 sched/policy: move g_policy from data to rodata
Signed-off-by: chao an <anchao@lixiang.com>
2024-09-02 18:23:57 +08:00
hujun5
b1884d2fa2 wqueue: add interface work_queue_priority_wq and work_queue_priority
reason:
These interfaces are used when we assign interrupt
handling of the same priority to the corresponding priority work queues.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-08-30 21:40:55 +08:00
ligd
ce2ad51b3a wqueue: expose wqueue API for customization
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-30 01:52:22 +08:00
ligd
f5095d781b wqueue: handle work_cancel() called in irq mode or idle thread
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-30 01:52:22 +08:00
ligd
04e746967a wqueue: remove unused work_foreach() API
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-30 01:52:22 +08:00
dulibo1
5e8ce0b9f0 work queue:fix work_cancel_sync can not cancel the work which call work_queue in handler
1.work_queue a work which call work_queue again
2.work_cancel_sync the work
3.the work is just calling in workthread
4.work_queue the work again,and post the work_cancel_sync wakeup
5.the work is not canceled

Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
2024-08-30 01:52:22 +08:00
YAMAMOTO Takashi
52baca0a89 Increase the chance for _assert to work early in the boot 2024-08-30 01:12:45 +08:00
pengyinjie
6b21bebcd1 [env]:Fixed spacing and typo issues in code comment descriptions
[Desc]: as title

Signed-off-by: pengyinjie <pengyinjie@xiaomi.com>
2024-08-27 21:52:56 +08:00
hujun5
572daf46c2 irq: add isr thread
purpose:
To improve the real-time performance of the system, we prefer to perform
as few operations as possible within the interrupt function.
We have designed an interrupt thread for each interrupt,
where all the operations that are not necessary to be handled
in the interrupt function are delegated to be processed by the interrupt thread.
Up_enable_irq will be invoked after isrthread started.

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-08-27 21:49:53 +08:00
yanghuatao
f6b3e92b6c toolchain/ghs: Fix tstate_t "enumerated type mixed with another type" warnings
"/mnt/yang/qixinwei_cmake/nuttx/sched/sched/sched_removeblocked.c", line 58: warning #188-D:
          enumerated type mixed with another type
    tstate_t task_state = btcb->task_state;
"/mnt/yang/qixinwei_cmake/nuttx/sched/sched/sched_setpriority.c", line 243: warning #188-D:
          enumerated type mixed with another type
    tstate_t task_state = tcb->task_state;

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2024-08-27 01:39:37 +08:00
Petro Karashchenko
d499ac9d58 nuttx: fix multiple 'FAR', 'CODE' and style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
yinshengkai
624fc5a9b8 sched: support dumping all file information during assert
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-23 16:12:31 -03:00
yinshengkai
20b357abde assert: pause all other CPUs when assert
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-23 16:12:31 -03:00
yinshengkai
b3794c8af7 assert: Avoid recursive calls of Assert
After the structure of the kernel core is wrong, dump_stack, dumpstack is easy to appear crash

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-23 16:12:31 -03:00
yinshengkai
7b02d788ef sched/signal: fix pthread_kill use after free
When a low-priority thread sends a kill signal to a high-priority thread,
the high-priority thread will exit and release tcb. When the thread returns
to the low-priority thread, it will access the released stcb.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-23 20:02:46 +08:00
chao an
75fac7dbc6 sched/nxevent: add support of kernel event group
Events groups are synchronization primitives that allow tasks to wait
for multiple conditions to be met before proceeding. They are particularly
useful in scenarios where a task needs to wait for several events to occur
simultaneously.

Signed-off-by: chao an <anchao@lixiang.com>
2024-08-23 17:00:35 +08:00
chao an
4c6f75d13c sched/irq: correct critical section to spin lock
Regression by:

| commit 2ee8aa6f2b
| Author: hujun5 <hujun5@xiaomi.com>
| Date:   Thu Jan 11 11:27:31 2024 +0800
|
|     sched: we use spin_lock_irqsave replace enter_critical_section to protect g_irqvector
|
|     enter_critical_section may be called before os initialized
|
|     Signed-off-by: hujun5 <hujun5@xiaomi.com>

Signed-off-by: chao an <anchao@lixiang.com>
2024-08-22 01:39:29 +08:00
Yanfeng Liu
51d4d336ab docs: fix typo in nx_smpstart.c
This fixes a typo in comments of `nx_idle_trampoline`

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-08-21 17:07:19 +08:00
hujun5
14d94ddd76 arch: inline this_task to improve performence
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-08-18 10:53:51 -03:00
wanggang26
c58bd521a3 coredump: refine coredump info analyse
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-08-18 19:34:36 +08:00
xuxin19
b3f1871bc3 sched:fix windows sim build error
nuttx\sched\signal\sig_timedwait.c(253,13): error C2059: syntax error:'<parameter-list>'
nuttx\sched\signal\sig_timedwait.c(321,44): error C2182: '$S1': illegal use of type 'void'
nuttx\sched\signal\sig_timedwait.c(321,50): error C2059: syntax error:':'

nuttx\sched\tls\tls_initinfo.c(68,39): error C2036: 'void *': unknown size
nuttx\sched\sched\sched_get_tls.c(76,44): error C2036: 'void *': unkown size

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-14 22:36:57 +08:00
chenxiaoyi
538582ede1 convert pointer string to number in base 16
Co-authored-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
Co-authored-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-14 22:36:57 +08:00
anjiahao
2ff2b82437 coredump:coredump_set_memory_region to set memory region
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-08-12 02:02:25 +08:00
anjiahao
8d0d1f7571 coredump:Add coredump success log printing to remind you to use coreudmp
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-08-12 02:02:25 +08:00
chao an
555dab3da3 spinlock: inline irqsaved spinlock
Reference pull request: #12599

Signed-off-by: chao an <anchao@lixiang.com>
2024-08-05 16:20:47 +08:00
chao an
500ebd6498 spinlock: fix unused parameter
fix unused parameter if unlock spinlock from different function

Signed-off-by: chao an <anchao@lixiang.com>
2024-08-05 16:20:47 +08:00
Ville Juven
6047a9fe14 task_fork.c: Fix vfork for BUILD_KERNEL
Two things need to be done when vfork'ing:
- Must attach to parent's address environment (the addrenv is shared)
- Must allocate a kernel stack (where would the register context go otherwise)

Note that this code assumes the address environment is shared, since we
don't support fork() which would _clone_ the address environment instead.
2024-08-01 10:58:25 -03:00
buxiasen
f5021021ae up_backtrace: fix maybe backtrace the exiting thread
when the thread to backtrace is exiting, get_tcb and up_backtrace in
different critical section may cause try to dump invalid pointer, have
to ensure the nxsched_get_tcb and up_backtrace inside same critical
section procedure.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-07-26 12:03:43 +08:00
Nathan Hartman
b8561558e7 sched: Improve Kconfig help of INIT_ENTRYPOINT
* sched/Kconfig
  (INIT_ENTRYPOINT): Document that the signature of "main" must take
   "argc" and "argv" or else compilation error results, as discussed in
   the email thread below [1].

References:

[1] dev@nuttx.apache.org email thread:
    "basically, I get an error when I do make" started 18 Jul 2024,
    archived:
    https://lists.apache.org/thread/9j2s3647ysdhy204g4ombn4o09bn11c1
    and elsewhere.
2024-07-21 19:53:27 -03:00
hujun5
a4fece3450 spin_lock: inline spin_lock
test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
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
2024-07-15 02:29:30 +08:00
xuxingliang
bbc31d70f4 drivers: add API for drivers early initialization
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-07-09 16:05:59 +08:00
hujun5
1bf4198556 irq: remove g_cpu_nestcount in restore_critical_section
because 'g_cpu_nestcount[me] > 0' will never happen, in this place

test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
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-07-02 03:02:32 +08:00
p-szafonimateusz
2192d83200 arch/x86_64: add support for XSAVE/XRSTOR
Add support for XSAVE/XRSTOR to handle x86_64 procesor extended states.
Support for these instructions is required to support AVX instruction set

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-07-01 13:27:33 +08:00
xuxingliang
c6d712df0e sched: move nxsched_dumponexit() to task_exithook
So the tcb->group still exists to dump files.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-06-30 17:30:42 +08:00
yinshengkai
5a31d52fd8 files: add files_dumplist api, replace dumponexit implementation
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-06-30 17:30:42 +08:00
hujun5
ddf1410312 sched/signal: There is no need to use sched_[un]lock
purpose:
1 sched_lock is very time-consuming, and reducing its invocations can improve performance.
2 sched_lock is prone to misuse, and narrowing its scope of use is to prevent people from referencing incorrect code and using it

test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
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

We have also tested this patch on other ARM hardware platforms.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-06-27 11:51:16 +08:00
Yanfeng Liu
c8f18767de sched/tcb: fix 12320 regression
This patch attempts to fix regressions reported for pull# 12320.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-26 00:20:26 +08:00
Yanfeng Liu
3b1f4562a0 sched/tls: drop ta_argv and g_idleargv
- replaces `ta_argv` with `stackargs`
- drops `ta_argv` from `task_info_s`
- drops `g_idleargv` and checks idle accordingly

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-23 22:24:19 +08:00
Yanfeng Liu
8a8c1f943e sched/tcb: use shared group for kthreads
Kthreads can share the group data so that to reduce overheads.
This implements shared kthread group via:

- use `tcb_s` instead of `task_tcb_s` for kthreads
- use `g_kthread_group` when creating kthreads
- use stackargs to start tasks and kthreads

see pull/12320 for test logs.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-23 22:24:19 +08:00
Yanfeng Liu
1d169fe325 sched/tls: add nxsched_get_stackargs
Thread args have already been saved to stack after the TLS section by
nxtask_setup_stackargs. This is to retrieve it for use.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-23 22:24:19 +08:00