Commit Graph

194 Commits

Author SHA1 Message Date
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
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
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 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
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
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
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
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
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
hujun5 7db6632ab3 sched: irq: Change this_task to current_task(me) in restore_critical_section()
this_task() is a function call that involves disabling interrupts and this_cpu().
Since restore_critical_section is always called in an interrupt-disabled context,
there's no need to disable interrupts again. Therefore, to save time and achieve
the same effect, I directly call tcb = current_task(me) instead of tcb = this_task().

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-06-21 11:11:07 +09:00
hujun5 f7843e2198 sched:remove g_cpu_schedlock g_cpu_irqsetlock g_cpu_locksetlock
we can use g_cpu_lockset to determine whether we are currently in the scheduling lock,
and all accesses and modifications to g_cpu_lockset, g_cpu_irqlock, g_cpu_irqset
are in the critical section, so we can directly operate on 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

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-06-21 11:11:07 +09:00
hujun5 9a36b8b823 csection: We can save execution time by removing judgments.
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

or
compiling
make distclean -j20; ./tools/configure.sh -l sabre-6quad:smp ;make -j20
running
qemu-system-arm  -semihosting -M sabrelite -m 1024 -smp 4 -kernel nuttx/nuttx -nographic

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-05-09 13:45:02 +08:00
hujun5 2ee8aa6f2b 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>
2024-05-09 13:45:02 +08:00
hujun5 82acf6e6a7 irq: All irq_cpu_locked is called in the critical_section, and the parameter is the current cpu id.
so it must return false, We can safely delete.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-04-12 17:40:23 +08:00
hujun5 1b068b0d4b sched/irq: remove scheduling check in csection
1. The critical section does not prevent task scheduling
2. If the critical section is in sched_lock, there is no need to check,
   scheduling is not going to happen
3. If sched_lock is in the critical section, sched_unlock will also
   trigger scheduling without waiting for the exit of the critical section
4. After exiting the critical section, if there is an interrupt,
   the scheduling will be automatically triggered

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-04-12 16:15:42 +08:00
chao an 25339b0a17 sched/irq: spinlock should not depends on SMP
spinlock should work independently without CONFIG_SMP

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-26 15:21:52 +08:00
chao an b9a74f30c6 sched/init: refine init state interface
N/A, refine init state interface

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-23 01:04:15 +08:00
chao an feb6ede434 sched/cpu: replace up_cpu_index() to this_cpu()
In SMP mode, up_cpu_index()/this_cpu() are the same, both return the index of the physical core.
In AMP mode, up_cpu_index() will return the index of the physical core, and this_cpu() will always return 0

| #ifdef CONFIG_SMP
| #  define this_cpu()             up_cpu_index()
| #elif defined(CONFIG_AMP)
| #  define this_cpu()             (0)
| #else
| #  define this_cpu()             (0)
| #endif

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 18:52:35 +08:00
chao an 4e62d0005a sched: replace some global variables to macro
replace to macro will help to extend the scheduling implementation

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 18:51:25 +08:00
chao an 306c1c0b7d sched/tasklist: replace task status list with macro definition
replace to macro will help to extend the scheduling implementation

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 11:23:46 +09:00
ligd 2241969e5a SMP: fix crash when switch to new task which is still running
cpu0 thread0:                        cpu1:
sched_yield()
nxsched_set_priority()
nxsched_running_setpriority()
nxsched_reprioritize_rtr()
nxsched_add_readytorun()
up_cpu_pause()
                                     IRQ enter
                                     arm64_pause_handler()
                                     enter_critical_section() begin
                                     up_cpu_paused() pick thread0
                                     arm64_restorestate() set thread0 tcb->xcp.regs to CURRENT_REGS
up_switch_context()
  thread0 -> thread1
arm64_syscall()
    case SYS_switch_context
     change thread0 tcb->xcp.regs
    restore_critical_section()
                                     enter_critical_section() done
                                     leave_critical_section()
                                     IRQ leave with restore CURRENT_REGS
                                     ERROR !!!

Reason:
As descript above, cpu0 swith task: thread0 -> thread1, and the
syscall() execute slowly, this time cpu1 pick thread0 to run at
up_cpu_paused(). Then cpu0 syscall execute, cpu1 IRQ leave error.

Resolve:
Move arm64_restorestate() after enter_critical_section() done

This is a continued fix with:
https://github.com/apache/nuttx/pull/6833

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-03-01 21:05:00 +09:00
yinshengkai 9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
TaiJu Wu 68a4d3df7e spinlock: implement read writer spinlock
spinlock.c:
Implement read write spinlock.
Readers can take lock simultaneously but only one writer can take lock.

irq_spinlock.c:
Align g_irq_spin_count.
If the lock is NULL, the caller will get global lock (e.g. g_irq_spin) and spin_lock_irqsave() support nest on the same CPU.
If the CPU can write lock, it can call write_lock_irqsave() again (e.g. support nest).

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>

Co-authored-by: David Sidrane <David.Sidrane@Nscdg.com>
2023-10-16 08:55:01 +08:00
Xiang Xiao dfa0283d83 spinlock: Rename spin_islocked to spin_is_locked
align with Linux naming style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-06 20:03:19 -04:00
TaiJu Wu ffba0d15a5 Feature: implement ticket spinlock
test config: ./tools/configure.sh -l qemu-armv8a:nsh_smp

Pass ostest

No matter big-endian or little-endian, ticket spinlock only check the
next and the owner is equal or not.

If they are equal, it means there is a task hold the lock or lock is
free.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>

Co-authored-by: Xiang Xiao <xiaoxiang781216@gmail.com>
2023-10-07 01:38:37 +08:00
yinshengkai ddb87d3b86 clock: replace all up_perf_xx with perf_xx
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-02 16:11:43 +02:00
xuxin19 d93d377257 cmake:complete missing changes during cmake reforming for sched
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
chao an 664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
yinshengkai 8fa4f2d61d add the startup process tracepoint
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-19 21:50:08 +08:00
yinshengkai 9dabcf9ad2 sched: add CRITMONITOR time out panic
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-03 10:08:12 -07:00
zhangyuan21 8f39ba6ae4 arch: update g_running_tasks when context switch occurred
When supporting high-priority interrupts, updating the
g_running_tasks within a high-priority interrupt may be
cause problems. The g_running_tasks should only be updated
when it is determined that a task context switch has occurred.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-01 09:35:18 -07:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
yinshengkai 20c5c4f47d sched/irq: optimizing IRQMONITOR, move up_perf_convert to irq_procfs
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-04-25 09:58:43 +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
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 81448b5021 sched/irq: add spin_unlock_irqsave/irqrestore_wo_note
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-01-02 22:29:01 +08:00
zhangyuan21 632d87ee71 arch: remove up_release_pending function
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-16 21:29:57 +08:00
yinshengkai 552cf4b549 merge sched_note_spinxx into sched_note_spincommon
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-12-16 17:03:53 +08:00
Xiang Xiao 6f33dd6ea0 mm/heap: Change TCB_FLAG_HEAPCHECK to TCB_FLAG_HEAP_CHECK
align with other flags naming convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-12 09:39:01 +01:00
Masayuki Ishikawa d071d6869f sched: irq: Refactor irq_spinlock.c
Summary:
- Call this_cpu() properly in spin_unlock_irqrestore()

Impact:
- None

Testing:
- Tested with spresense:wifi_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-10-04 23:41:04 +08:00
Xiang Xiao bdeaea3742 Remove the unnessary empty line after label
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-30 17:54:56 +02:00
ligd e2df52390a SMP: fix crash when switch to new task which is still running
Situation:

Assume we have 2 cpus, and busy run task0.

CPU0                                CPU1
task0 -> task1                      task2 -> task0
1. remove task0 form runninglist
2. take task1 as new tcb
3. add task0 to blocklist
4. clear spinlock
                                    4.1 remove task2 form runninglist
                                    4.2 take task0 as new tcb
                                    4.3 add task2 to blocklist
                                    4.4 use svc ISR swith to task0
                                    4.5 crash
5. use svc ISR swith to task1

Fix:
Move clear spinlock to the end of svc ISR

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-17 17:37:47 +09:00
ligd 10529c7d0a sched: fix kasan report error when open CONFIG_DEBUG_MM
reason:
1. g_running_tasks = thread A
2. thread A exit (free thread A's tcb) -> thread B
3. thread B interrupt by irq
4. check g_running_tasks->flags -> kasan report used after free

rootcause:
g_running_tasks has't set completely when syscall hanppened

Resolve:
Use rtcb (get at ISR begining) instead

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-09 19:00:05 +02:00
Xiang Xiao 1b04bfae20 sched: Remove the unnecessary weak_function
because not all compiler support the weak attribute, and
many features are either always used or guarded by config.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-30 09:42:24 +02:00
haopengxiang 4bb393a24e nuttx: change TCB_FLAG_MEM_CHECK to TCB_FLAG_HEAPCHECK
Signed-off-by: haopengxiang <haopengxiang@xiaomi.com>
2022-08-02 10:46:44 +08:00
ligd 3bc2131918 irq_procfs: fix divide 0 error
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-22 10:53:44 +08:00
Nathan Hartman 1867bc2210 Fix compiler warnings (-Wunused-parameter) in various functions
Fixes the -Wunused-parameter warning in:
* group/group_signal.c: group_signal()
* irq/irq_unexpectedisr.c: irq_unexpected_isr()
* task/task_spawn.c: nxtask_spawn_proxy()
* timer/timer_getoverrun.c: timer_getoverrun()
* misc/dev_null.c: devnull_read(), devnull_write(), devnull_poll()
* misc/dev_zero.c: devzero_read(), devzero_write(), devzero_poll()
* syslog/syslog_channel.c: syslog_default_write()
* syslog/syslog_device.c: syslog_dev_flush()
* grp/lib_initgroups.c: initgroups()
* misc/lib_mknod.c: mknod()
* misc/lib_glob.c: ignore_err()
* pthread/pthread_barrierinit.c: pthread_barrier_init()
* pthread/pthread_atfork.c: pthread_atfork()
* semaphore/sem_init.c: nxsem_init()
* stream/lib_nullinstream.c: nullinstream_getc()
* stream/lib_nulloutstream.c: nulloutstream_putc()
* stream/lib_libnoflush.c: lib_noflush()
* stream/lib_libsnoflush.c: lib_snoflush()
* string/lib_strerror.c: strerror()
* time/lib_gettimeofday.c: gettimeofday()
* time/lib_settimeofday.c: settimeofday()
* unistd/lib_pathconf.c: fpathconf(), pathconf()
* unistd/lib_getrusage.c: getrusage()
* unistd/lib_setrlimit.c: setrlimit()
* unistd/lib_getrlimit.c: getrlimit()
* unistd/lib_setpriority.c: setpriority()
2022-07-12 11:42:34 +08:00