Commit Graph

2393 Commits

Author SHA1 Message Date
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
yinshengkai
b99820744c timer: handle perf count overflow
clock_getcycle always returns an incremented cycle value
If the hardware does not support perf event it will use arch_alarm's up_perf_gettime

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-10-02 16:11:43 +02:00
Petteri Aimonen
0611f39cdc adjtime(): Improve configuration and math
1) Previously adjustments less than 1 microsecond per tick would be
   completely ignored. Now they are applied over a shorter period at
   a rate of 1 us per tick.

2) Previously CLOCK_ADJTIME_PERIOD was in units of 1/100th of second.
   Change to milliseconds to be more generally useful unit.
   Change setting name to CLOCK_ADJTIME_PERIOD_MS to make the unit change
   easier to notice.

3) Previously CLOCK_ADJTIME_SLEWLIMIT was in percentage.
   Most clock crystals have better accuracy than 1%, so the minimum slew
   rate was excessive. Change to CLOCK_ADJTIME_SLEWLIMIT_PPM with setting
   value in parts per million.

4) No need to use floating point math in clock_adjtime.c.
2023-09-29 13:03:10 +08:00
Petteri Aimonen
a2da12a67e Fix dependencies of CONFIG_SCHED_CPULOAD_ settings
CONFIG_SCHED_CPULOAD_EXTCLK doesn't actually require tickless mode.
As long as the platform provides external call to nxsched_process_cpuload(),
it will work in either tickless or ticking mode.
Removed Kconfig dependency.

Instead, CONFIG_SCHED_CPULOAD_SYSCLK does require ticking mode to work,
as documented in CONFIG_SCHED_CPULOAD help text.
Added the dependency to Kconfig also.
2023-09-26 22:13:37 +08:00
Xiang Xiao
2acd975435 assert: Skip to include arch/board/board.h if CONFIG_ARCH_LEDS=n
follow up the change: https://github.com/apache/nuttx/pull/10553

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-26 15:41:35 +08:00
zhuanglin
13ee3f8117 sched/clock Add special handling for TCB null pointer cases
Adding a judgment in the code that null return values are not referenced for dereference

Signed-off-by: zhuanglin <zhuanglin@xiaomi.com>
2023-09-22 08:46:50 +08:00
ThomasNS
a2c806027f fix led panic feature 2023-09-21 00:35:12 +08:00
Neale Ferguson
5d7f2fdf16 Fix loading of ET_DYN type of shared objects
* build-globals.sh
  - Only look in the nuttx for external symbols used when loading
    dynamic shared objects

* include/elf64.h
  - Correct the type of fields in the Elf64_Phdr structure

* libs/libc/dlfcn/lib_dlclose.c
  - Distinguish between ET_DYN and other objects as the former
    has both text and data in a single allocation to reserve
    GOT offsets

* libs/libc/dlfcn/lib_dlopen.c
  - Code formatting

* libs/libc/modlib/modlib_bind.c
  - Distinguish between relocation entry sizes by section type
  - Handle RELA style relocations

* libs/libc/modlib/modlib_globals.S
  - Formatting fixes
  - Symbols should not be weak - they exist or they don't

* include/nuttx/lib/modlib.h
  - Add an inidcator to module_s to distinguish between ET_DYN and other

* libs/libc/modlib/modlib_load.c
  - ET_DYN objects need to keep the relative displacement between the text
    and data sections due to GOT references from the former to the latter.
    This also implies that linking may require modification from the default
    for the shared objects being produced. For example, default alignment may
    mean nearly 64K of wasted space.

* libs/libc/modlib/modlib_unload.c
  sched/module/mod_rmmod.c
  - Distingusih between freeing of ET_DYN storage and other as the former
    is a single allocation.

* libs/libc/modlib/mod_insmod.c
  - Cater for ET_DYN objects having init and preinit sections
2023-09-20 09:35:28 -04:00
Xu Xingliang
3cd5e20f74 sched: return 0 from clock_systime_ticks if failed
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2023-09-19 16:17:08 +08:00
ligd
415fe60695 signal: use work_cancel_sync() to fix used after free
bug:

user thread:                             hpwork:
timer_create() with SIGEV_THREAD
timer_settime()
    irq -> work_queue()                  add nxsig_notification_worker to Q
timer_delete()
    nxsig_cancel_notification()
                                         call nxsig_notification_worker()
    work_cancel()
    timer_free()
                                         nxsig_notification_worker() used after free

root cause:
work_cancel() can't cancel work completely, the worker may alreay be running.

resolve:
use work_cancel_sync() API to cancel the work completely

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 15:52:48 +08:00
ligd
61ef7eb3dc wqueue: add work_cancel_sync() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 15:52:48 +08:00
yangguangcai
fe30f0fa82 sched/wdog:change g_wdtickbase update situation.
In the 'wd_timer',the callback function executed by 'wd_expiration' could call wd_start,and g_wdtickbase might be updated.Subsequently, g_wdtickbase is incremented by the value of ticks, causing g_wdtickbase to be greater than the actual passage of time.

Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
2023-09-19 11:41:50 +08:00
guoshichao
e0ec88e738 timer/timer_getoverrun: adjust the default errno from ENOSYS to EINVAL
modify the default errno from ENOSYS to EINVAL can pass the ltp
case: ltp_timer_getoverrun_speculative_6_1,
ltp_timer_getoverrun_speculative_6_2, ltp_timer_getoverrun_speculative_6_3

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-09-19 09:35:27 +08:00
Petro Karashchenko
440be65010 spinlock: use spinlock API instead of direct asignment/compare
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-16 14:17:47 +08:00
fangxinyong
a73f5f86dc sched: do not crash for priority multi-boost
aio client will queue asynchronous io requests to the worker threads.
if PRIORITY_INHERITANCE is enabled, client thread's priority will be
set to worker threads. There will be multi-boost/restore of worker
threads' priority and assert the system.

No need priority multi-boot/restore to worker thread because client
thread's priority is alway the same.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-09-12 23:02:10 +03: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
yangyalei
fd776e8cee fix wait after vfork return error
vfork use waitpid hang father process,
but waitpid release child processs information by default.
So when user call wait, it return errno 10.

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-09-08 00:53:56 +03:00
yangyalei
eba2f163ed Revert "fix wait after vfork return error"
This reverts commit 50428979d0.
2023-09-08 00:53:56 +03:00
Petro Karashchenko
47627c5fbd sched/misc: optimize collect_deadlock implementation
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-07 00:50:30 +08: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
chenxiaoyi
cc690f1d21 move task tls destruct to before _exit
Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2023-08-29 12:05:57 +08:00
anjiahao
48c153db25 vfs:add nxsched_foreach to sched_lock avoid crash
If scheduling occurs in file_fsync,
fl_lock may be released, and an error may
occur when calling nxmutex_unlock

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-29 10:36:21 +08:00
SPRESENSE
57d9083844 assert: Fix the printing alignment of interrupt stack during assert
Fix the printing alignment of interrupt stack during assert.
2023-08-29 02:59:38 +08:00
Xiang Xiao
47faeeb360 tls: Move task_tls_alloc and task_tls_destruct to libc
so task_tls_destruct can be called from usrspace, which is required by:
https://github.com/apache/nuttx/pull/10288

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-28 11:02:18 +03:00
Xiang Xiao
cb8df39207 binfmt/elf: Fix the minor style issue
and remove the unused macros and unnecessary cast

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-27 18:46:40 -03:00
xinhaiteng
dbefe37a3a sigqueue: add signal type judgment logic
To determine whether a signal is real-time signal or standard signal, the POSIX standard https://www.man7.org/linux/man-pages/man7/signal.7.html defines a real-time signal between SIGRTMIN  and SIGRTMAX , which can store multiple copies, otherwise only one can be retained.

Signed-off-by: xinhaiteng <xinhaiteng@xiaomi.com>
2023-08-21 15:35:45 +08:00
zhangyuan21
7737efd995 SMP: fix repeat entry timer_start
If we are running on a single CPU architecture, then we know interrupts
are disabled and there is no need to explicitly call enter_critical_section().
However, in the SMP case, enter_critical_section() is required prevent
multiple cpu to enter timer_start.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-21 13:20:56 +08: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
Tiago Medicci Serrano
98985f48dd sched/semaphore: Remove restriction to use nxsem_trywait from ISR
Considering that `nxsem_trywait` is non-blocking, although not
recommended, it could be called from the interrupt handler.
2023-08-14 23:47:41 +08:00
yangyalei
50428979d0 fix wait after vfork return error
Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-08-11 09:30:45 -06:00
ligd
e59f161fc2 pthread: remove unused temp change sched_priority
old:
pthread_create:

init_priority = prio;
if (sched_priority < parent_prio)
    sched_priority = parent_prio;    // don't need

pthread_start:

if (sched_priority > init_priority)
    sched_priority = init_priority

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-11 21:45:16 +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
fangxinyong
896f34fde9 sched: implement effective uid and gid interfaces
Implement 'effective' setuid, getuid, setgid, and getgid interfaces.
These will be inheritance by all child task groups. These definitons
are explicitly specified here:
https://pubs.opengroup.org/onlinepubs/000095399/functions/geteuid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/getegid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/seteuid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/setegid.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-09 17:07:58 +08:00
Petro Karashchenko
d113722eb2 style: fix indentation issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
Petro Karashchenko
1b0baa8337 nuttx: use lib_free for memory de-allocation after strdup or asprintf
The memory allocated with strdup and asprintf is done via lib_malloc
so we need to use lib_free to deallocate memory otherwise the assertion
"Free memory from the wrong heap" is hit with flat mode and user separated
heap enabled mode.

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03: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
cuiziwei
7c8bb8c293 nuttx/tls: Remove the max key limiatation in task_tls_alloc and pthread_key_create
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-05 06:33:49 -07:00
cuiziwei
5334c065b4 nuttx/tls:Setting the candidtate index to null prevents dangling pointers.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-05 06:33:49 -07:00
cuiziwei
8ffde7cf16 nuttx/tls:Setting the candidtate index to null prevents dangling pointers.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-05 06:33:49 -07:00
yinshengkai
996be8f2cf sched/cpuload: use perf to implement cpuload without relying on external timers
Need to enable CONFIG_SCHED_CRITMONITOR

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-04 10:58:54 -07:00
yinshengkai
e8bf910c3d sched: rename nxsched_cpu_process_cpuload
put nxsched_process_cpuload_ticks partial implementation into nxsched_task_process_cpuload

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-04 10:58:54 -07:00
yinshengkai
08c4ac133b sched/cpuload: add SCHED_CPULOAD_OSCLK option
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-04 10:58:54 -07:00
cuiziwei
5e3df24092 replace nxsched_gettid with nxsched_getpid.
When we find the exit status entry in this task, we need to use pid instead of tid.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-04 04:21:08 -07:00
yinshengkai
9dabcf9ad2 sched: add CRITMONITOR time out panic
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-03 10:08:12 -07:00
ligd
395fa73870 sched: group_killchildren send signo SIGQUIT before cancel it
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-03 08:06:33 -07:00
ligd
1552e52e14 signal: fix group signal can't dispatch some parent group twice
reproduce:

static void *pthread(void *arg)
{
  system(arg);
}

void test (int argc, char *argv[])
{
  pthread_create(&pthread0, &attr, pthread, argv[1]);
  pthread_create(&pthread1, &attr, pthread, argv[2]);
}

only one pthread system() returnd, othres hanged

rootcause:

As we known, system() will create a new task called:
system -c XX

The example:
parent group               child groups

pthread0 -> waitpid() -> system -c ps -> exit() -> nxtask_signalparent()
pthread1 -> waitpid() -> system -c ls -> exit() -> nxtask_signalparent()

Each child group exit with function nxtask_signalparent(),

As we expect:

system -c ps will signal pthread0
system -c ls will signal pthread1

But actually:

system -c ps will signal pthread0/1
system -c ls will signal pthread0/1

As the spec, we know, this behavior is normal:
https://man7.org/linux/man-pages/man2/sigwaitinfo.2.html

So for this situation, when the signo is SIGCHLD, we broadcast.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-03 03:35:59 -07:00
yangguangcai
f324d1d8dd SMP: fix repeat entry oneshot_tick_start
Situation:

Assume we have 2 cpus.

CPU0                                CPU1
1. -> nxsched_alarm_expiration
2. -> nxshced_timer_start
3. -> ONESHOT_TICK_START
4. now timer in IRQ
                                    5. in thread
                                    6. -> wd_start
                                    7. -> nxshced_timer_start
                                    8. -> ONESHOT_TICK_START
                                    9. reentry timer crash

Fix:
Enter critical section before nxsched_timer_start

Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
2023-08-03 03:20:40 -07:00
zhangyuan21
f2dc9402f6 assert: Remove unnecessary disable interrupts code
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-03 03:17:22 -07:00