Commit Graph

216 Commits

Author SHA1 Message Date
fangxinyong c479ccb8aa sched: move etc romfs mount from nsh to sched/init
Usually the startup script is placed under /etc. The contents of the etc directory
are compiled and linked with Nuttx binary in the form of romfs. After startup,
it will be  mounted by Nsh.

etc is generated by the different boards, that use genromfs and xxd tools to generate
and compile it into the Nuttx, for example: boards/arm/at32/at32f437-mini/tool/mkromfs.sh
The more common method is etc image generated from the content in the corresponding
board/arch/board/board/src/etc directory, and added by Makefile for example:
boards/sim/sim/sim/src/etc.

But in kernel/protected mode, Nuttx kernel and apps are run in different privileged/
non-privileged mode or the isolated binarys, so as that nsh should use syscall to
access Nuttx kernel by exported API. In this scenario, nsh can not mount the etc image
content, because that is generated in board and as a part of Nuttx kernel.

changes:

- move etc romfs mount from nsh to Nuttx, but keep the script to parse and execute.
- move and rename the related CONFIG, move customized nsh_romfsimg.h to etc_romfs.c
  in boards, and no need declaration for romfs_img/romfs_img_len.

This commit changes and updates all configurations in Nuttx arch/board as much as possible,
but if any missing, please refer to the following simple guide:

- rename CONFIG_NSH_ROMFSETC to CONFIG_ETC_ROMFS, and delete CONFIG_NSH_ARCHROMFS in defconfig
- rename the etc romfs mount configs, for example CONFIG_NSH_FATDEVNO to CONFIG_ETC_FATDEVNO
- move customized nsh_romfsimg.h to etc_romfs.c in board/arch/board/board/src and no need
  declaration for romfs_img/romfs_img_len.
- delete default nsh_romfsimg.h, if ROMFSETC is enabled, should generate and compile etc_romfs.c
  in board/arch/board/board/src.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-01-09 21:29:46 -03:00
anjiahao d932e0af2a sched/procfs:use instrument to statistics run time max stack
Usage:
1. CONFIG_FS_PROCFS_MAX_STACK_RECORD > 0, such as 32,
2. add '-finstrument-functions' to CFLAGS for What you want to check
   stack.
3. mount porcfs
4. cat /proc/<pid>/stack will print backtace & size

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-11 02:06:51 -08:00
anjiahao 35051dd715 coredump: support coredump save to block device when crash
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-10 07:02:03 -08:00
chao an 42427e9e29 sched/taskfiles: skip unnecessary file open/close operations to improve performance
The task files should consult the "spawn action" and "O_CLOEXEC flags"
to determine further whether the file should be duplicated.

This PR will further optimize file list duplicating to avoid the performance
regression caused by additional file operations.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-11-16 07:30:36 -08:00
Ville Juven 0dedbcd4ae task/pthread_cancelpt: Move cancel point handling to libc, data to TLS
This moves task / thread cancel point logic from the NuttX kernel into
libc, while the data needed by the cancel point logic is moved to TLS.

The change is an enabler to move user-space APIs to libc as well, for
a coherent user/kernel separation.
2023-11-15 08:52:04 -08:00
Xiang Xiao a34be7f7c2 sched: Remove the unused tcb argument from group_setupidlefiles
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 17:23:05 +03:00
zhangyuan21 fb12e7530d sched/smp: flush dcache before start other cpus
core0 may write the data used by other cpu, this will cause cache inconsistency.
so need fulsh dcache before start other cpus.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-21 12:02:45 +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 63252af054 sched: remove space in task name
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-11 13:27:17 +08:00
anjiahao 3a808bab19 support stm32f429i-disco run open flash loader
We can use the driver in nuttx to download
files with debugger

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-05 12:40:02 -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
tjwu1217 75d0312b4c sched/init/nx_start.c: Fix typo and format 2023-07-03 23:06:55 +03:00
Ville Juven 0476e30a6d mm/kmm_map: Add support to dynamically map pages into kernel virtual memory
This adds functionality to map pages dynamically into kernel virtual
memory. This allows implementing I/O remap for example, which is a useful
(future) feature.

Now, the first target is to support mapping user pages for the kernel.

Why? There are some userspace structures that might be needed when the
userspace process is not running. Semaphores are one such example. Signals
and the WDT timeout both need access to the user semaphore to work
properly. Even though for this only obtaining the kernel addressable
page pool virtual address is needed, for completeness a procedure is
provided to map several pages.
2023-06-02 10:50:26 +08:00
Xiang Xiao 7a8cf7ff70 Indent the include statement by two spaces
follow the coding style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-16 12:34:32 -03:00
zhangyuan21 f7cfcd4e95 sched: add the CPU bitset to initialize the non-exclusive CPU
Set the Default CPU bits. The way to use the unset CPU is to call the
sched_setaffinity function to bind a task to the CPU. bit0 means CPU0.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-05-04 20:30:35 +08:00
chao an 507c8145a9 sched/spawn: remove spawn proxy thread to simplify task/posix_spawn()
The spawn proxy thread is a special existence in NuttX, usually some developers
spend a lot of time on stack overflow of spawn proxy thread:

https://github.com/apache/nuttx/issues/9046
https://github.com/apache/nuttx/pull/9081

In order to avoid similar issues, this PR will remove spawn proxy thread to simplify
the process of task/posix_spawn().

1. Postpone the related processing of spawn file actions until after task_init()
2. Delete the temporary thread of spawn proxy and related global variables

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-27 17:35:58 +08:00
Xiang Xiao 1280a2a8f9 Launch the initial task through task_spawn instead of nxtask_create
to share the code with the code path of posix_spawn

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-25 23:34:52 +02:00
Ville Juven 864bcf556e sched/nx_bringup: Set the initial stack size in kernel build as well
After #7364 this now works, so use it for the init process. It makes sense
as the init process typically requires a big stack (due to init scripts).
2022-12-09 22:15:48 +08:00
zhangyuan21 f27065cb9e sched/mqueue: make mqueue and mqueue sysv can disable separately 2022-11-16 20:03:40 +08:00
Xiang Xiao 64e7833cbc sched/spawn: Support task_spawnattr_[set|get]stackaddr
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-31 12:46:58 +09:00
Xiang Xiao 677a907dc8 sched: Pass idle thread environment variables to the child task through copy
because if we pass predefined environment variables table explicitly,
the environment variables created by the board code will be lost.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-27 10:28:05 +09:00
chao an 205c8934a3 sched/msgq: add support of System V message queue
https://man.openbsd.org/msgget.2

Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-22 12:58:11 +08:00
chao an 96c3debe6a sched/mqueue: decoupling condition member to common prologue
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-22 12:58:11 +08:00
Xiang Xiao e2a18ad339 sched: Support envp argument of task_spawn and nxtask_create
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-19 08:22:56 +09:00
Xiang Xiao 6b31918b42 Remove the unnecessary cast for main_t, NULL and argv
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-18 08:51:45 +02:00
zhangyuan21 85d013f69a sched: mqueue wait list optimize 2022-09-28 18:08:37 +08:00
zhangyuan21 838309313e sched: semaphore wait list optimize 2022-09-28 18:08:37 +08:00
Xiang Xiao 40ef5bc6db libc: Move queue.h from include to include/nuttx
to avoid the conflict with libuv's queue.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-26 08:04:58 +02:00
Xiang Xiao a23b30d625 sched: Remove volatile from the task list
it inappropriate to apply volatile to the task list:
1.The code access task list is already protected by critical section
2.The queue is complex struct, it isn't enough to protect by volatile

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-31 08:50:57 +09: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
Nathan Hartman dd718e78f7 Fix typos 2022-08-07 23:33:19 +08:00
Xiang Xiao 8543df7e4c sched/init: Initialize the idle thread local storage by tls_init_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-08 19:07:33 +09:00
Ville Juven 4c1b66246d env_dup: Fix copying of env between address environments
If address environments are in use, it is not possible to simply
memcpy from from one process to another. The current implementation
of env_dup does precisely this and thus, it fails at once when it is
attempted between two user processes.

The solution is to use the kernel's heap as an intermediate buffer.
This is a simple, effective and common way to do a fork().

Obviously this is not needed for kernel processes.
2022-04-21 18:38:37 +08:00
chao.an a594a5d7a8 sched/init: drivers_initialize() should be late than up_initialize()
up_initialize
|
 ->up_serialinit
   |
    ->uart_register  /* ("/dev/console", &CONSOLE_DEV); */

drivers_initialize
|
 ->syslog_console_init
   |
    ->register_driver /* ("/dev/console", &g_consoleops, 0666, NULL); */

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-04-12 07:51:34 +09:00
Ville Juven 75afe491ad RISC-V: Prepare for CONFIG_BUILD_KERNEL
- Thread context prior to system call needs to be preserved
- Allocate a kernel heap
2022-03-18 18:20:12 +08:00
Ville Juven 50578dc501 Fix the initial idle tasks environment
- User mode allocator was used for setting up the environment. This
  works in flat mode and probably in protected mode as well, as there
  is always a a single user allocator present
- This does not work in kernel mode, where each user task has its own
  heap allocator. Also, when the idle tasks environment is being set,
  no allocator is ready and the system crashes at once.

Fix this by using the group allocators instead:
- Idle task is a kernel task, so its group is privileged
- Add group_realloc
- Use the group_malloc/realloc functions instead of kumm_malloc
2022-03-16 20:21:19 +08:00
Xiang Xiao c96c96a399 drivers: Merge the common driver initialization into one place
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-13 11:24:48 -03:00
Xiang Xiao 4cc28882f9 sched/init: Don't call sq_init/dq_init on global link list
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 15:06:39 -03:00
Xiang Xiao ab872b0199 sched/init: Move binfmt_initialize before hardware initialization
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 15:06:39 -03:00
Xiang Xiao b0786606fc sched/wdog: Remove wd_initialize which isn't really used anymore
since g_wdactivelist is already set to zero by the boot code

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 15:06:39 -03:00
Xiang Xiao cf2538c277 mm/shm: Initialize shm_info_s at the definition place
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 15:06:39 -03:00
Xiang Xiao 8fa26944f7 sched/init: Fix the compiler warning
/github/workspace/sources/nuttx/include/nuttx/init.h: In function 'nx_start':
Error: init/nx_start.c:439:7: error: 'strncpy' output truncated copying 8 bytes from a string of length 9 [-Werror=stringop-truncation]
  439 |       strncpy(g_idletcb[i].cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-10 19:46:01 +02:00
Xiang Xiao a50d87d5b7 sched/group: Simplify the allocation and deallocation logic
1.Move tg_membe allocation to group_alloc
2.Merge group_deallocate to group_release

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-03-04 12:11:24 +09:00
ligd fe6aa4a874 sim: add loop thread to handle dev loops
For some dev loops will call sem_wait/sem_trywait

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-03-02 20:29:52 +09:00
ligd 61a0453e6e os init_state: add new state OSINIT_IDLELOOP
This is for distinguish we are in init idle or idle loop.
Use for assertion for sem_trywait & sem_wait

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-02-23 22:05:37 +09:00
Masayuki Ishikawa fccdcf7011 Revert "os init_state: add new state OSINIT_IDLELOOP"
This reverts commit 051bb32010.
2022-02-22 10:56:14 +01:00
ligd 051bb32010 os init_state: add new state OSINIT_IDLELOOP
This is for distinguish we are in init idle or idle loop.
Use for assertion for sem_trywait & sem_wait

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-02-22 07:58:55 +01:00
ligd d8c2610157 idle: remove heap & stack check in idle thread
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-01-29 00:53:47 +08:00
Xiang Xiao 77792a1598 sched: Define CONFIG_SMP_NCPUS to 1 in no SMP case
to simplify the SMP related code logic

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-01-20 23:21:21 +08:00
Petro Karashchenko 08043fb5bc net: unify FAR keyword usage for all net buffer memory mapped buffers
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-01-20 01:42:56 +08:00