Commit Graph

2090 Commits

Author SHA1 Message Date
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
Petro Karashchenko
d247e8d1d2 sched/semaphore: fix priority boost restoration for priority inheritance
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-10-03 15:14:24 -03:00
Xiang Xiao
e38248ee08 Return -EINVAL for the internal API
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-30 17:54:56 +02: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
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
764540267e sched/clock: Rename g_system_timer to g_system_ticks
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-27 17:45:44 -03:00
yinshengkai
ae38e3eb10 sched: Optimize sched_note_begin/end
Optimize sched_note_begin/end, replace note_printf with note_string
sched_note_begin/end optimized from 50us to 1us per consumption

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-09-27 21:32:35 +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
zhangyuan21
40366f4153 sched: clear waitsem and msgwaitq after remove blocked 2022-09-22 16:32:44 +08:00
zhangyuan21
af72a528f1 sched: merge waitsem and msgwaitq 2022-09-22 16:32:44 +08:00
Xiang Xiao
af12a552fe sched/Kconfig: let PREALLOC_TIMERS depends on !DISABLE_POSIX_TIMERS
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-19 11:39:22 -03:00
Xiang Xiao
8a265e274d Kconfig: Remove EXPERIMENTAL for features which is been around a long time
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-19 11:39:22 -03: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
615bc9f0e2 SMP: fix assert failed when one task set to 255
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-17 17:37:47 +09:00
chao an
e586f86918 sched/mqueue: fix resource leak in mq_timedsend()
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-15 01:56:35 +08:00
ligd
bc17563a8f wqueue: fix race-condition on work_queue
CPU0                     CPU1

work_queue(a)            work_queue(a)
                         -> work_cancel(a)
-> work_cancel(a)
-> enter_critical()
-> sq_addlast(a)
-> leave_critical()
                         -> enter_critical()
                         -> sq_addlast(a) // double add, wrong
                         -> leave_critical()

Also, this happens in mulit-threads in one CPU.

Fix:

work_cancel() should in critical section.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-09 21:52:21 +02: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
ligd
4a87578bdb wqueue: change single queue to double queue to improve speed
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-08 15:03:54 +02:00
ligd
3b04450808 sched: fix corner case wd_cancel assert crash
There one ways can caused this:
mq_timedreceive
   TIMER IRQ do wd_timer -> wd_func1 mq_send
                         -> wd_func2 nxmq_rcvtimeout -> crash

Resolve:
Stop the watchdog when mq_send

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-07 10:50:28 +08:00
Juha Niskanen
fb852440af pthread: fix typo with CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2022-09-05 15:36:23 +02:00
chao an
1b9c013dad sched/wqueue: fix visual studio Compiler Error C2059
Designated initializers are a C99 (or newer) feature, and Visual Studio doesn't (part) support C99 (or newer).

D:\code\incubator-nuttx\sched\wqueue\kwork_thread.c(94,50): error C2059: syntax error : ','

Reference:
https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-160#c-standard-library-features-1
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2059?view=msvc-170

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-03 23:31:04 +08:00
zhangyuan21
eb22ee0e21 sched/semaphore: add sem_count temporary variable to improve performance 2022-08-31 20:34:30 +08:00
Xiang Xiao
2a981cec95 sched: Remove the unnecessary "FAR dq_queue_t *" cast
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-31 08:50:57 +09: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
ligd
51d31cc4a2 cpuload: fix cpuload error
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-08-27 20:39:41 +08:00
Huang Qi
e4e3208180 Replace all strncpy with strlcpy for safety
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-25 13:38:36 +08:00
Huang Qi
1ba443aab2 prctl: Replace strncpy with strlcpy for safety
strlcpy ensure the destination is NUL-terminated, and also fix warning:
```c
task/task_prctl.c:138:15: warning: 'strncpy' output may be truncated copying 30 bytes from a string of length 31 [-Wstringop-truncation]
  138 |               strncpy(name, tcb->name, CONFIG_TASK_NAME_SIZE - 1);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-24 01:54:53 +08:00
Xiang Xiao
27e8d058e7 sched: Simplify the cpuload process
1.Forward nxsched_process_cpuload to nxsched_process_cpuload_ticks directly
2.Define the dummy nxsched_process_cpuload_ticks when CPULOAD isn't enabled
3.Remove the weak attribute from nxsched_process_cpuload_ticks

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-18 22:11:29 +03:00
chao.an
704b03f833 sched: fix visual studio Compiler Warning (level 4) C4706
D:\code\incubator-nuttx\sched\environ\env_dup.c(81):
  warning C4706: assignment within conditional expression
  [D:\code\nuttx\incubator-nuttx\vs20221\sched\sched.vcxproj]

Reference:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4706?view=msvc-170

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-17 18:33:44 +08:00
chao.an
6e5908cc92 sched: fix visual studio Compiler Warning (level 4) C4189
D:\code\incubator-nuttx\sched\pthread\pthread_create.c(154,22):
  warning C4189: “pjoin”: local variable is initialized but not referenced
  [D:\code\incubator-nuttx\vs20221\sched\sched.vcxproj]

D:\code\incubator-nuttx\sched\group\group_setupidlefiles.c(61,28):
  warning C4189: “group”: local variable is initialized but not referenced
  [D:\code\incubator-nuttx\vs20221\sched\sched.vcxproj]

Reference:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4189?view=msvc-170

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-17 10:00:20 +03:00
Nathan Hartman
dd718e78f7 Fix typos 2022-08-07 23:33:19 +08: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
chao.an
7032739efe sched/Makefile: move task_reparent.c to appropriate Makefile
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-07-27 23:22:37 +08:00
Xiang Xiao
579934e709 sched: Remove the not really used cmptime
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-26 12:03:16 +03:00
ligd
fe723f0715 sched_critmonitor: remove check zero in sched_critmonitor
Cause of up_perf_gettime() may return 0

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-22 10:15:06 +03:00
ligd
db08f3a723 sched: handle nxtask_setup_arguments return values
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-22 10:54:07 +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
larry
2721e01fc2 sched/timer: timer_settime not fully satisfy IEEE 1003.1
If the specified time has already passed, the function
shall succeed and the expiration notification shall be made.
2022-07-18 12:30:28 +08:00
Gustavo Henrique Nihei
6f0334140f sched: Convert DEBUGASSERT(false) into more intuitive DEBUGPANIC()
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-07-14 12:08:45 +08:00
Xiang Xiao
b1c72c023c libc/stdio: enable long long formating by CONFIG_HAVE_LONG_LONG
and remove CONFIG_LIBC_LONG_LONG option to simplify the usage.
note: the size will increase 668
before change:
   text    data     bss     dec     hex filename
 168440     348    4480  173268   2a4d4 nuttx

after change:
   text    data     bss     dec     hex filename
 169108     348    4480  173936   2a770 nuttx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-13 09:50:38 -03: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
chao.an
e5b3d52486 clock/settime: minor fix compile warning
clock/clock_settime.c: In function ‘clock_settime’:
clock/clock_settime.c:120:45: warning: passing argument 1 of ‘clock_timekeeping_set_wall_time’
                              discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  120 |       ret = clock_timekeeping_set_wall_time(tp);
      |                                             ^~
In file included from clock/clock_settime.c:37:
sched/clock/clock_timekeeping.h:40:58: note: expected ‘struct timespec *’
                                       but argument is of type ‘const struct timespec *’
   40 | int clock_timekeeping_set_wall_time(FAR struct timespec *ts);
      |

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-07-10 20:44:21 +03:00
Nathan Hartman
849f760b77 Fix various typos 2022-07-08 02:15:54 +08:00
Gustavo Henrique Nihei
1416afc6b6 sched: Remove "0x" prefix preceding "%p" specifier on format string
The "p" format specifier already prepends the pointer address with
"0x" when printing.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-06-30 22:08:58 +03:00
Xiang Xiao
abc72ad128 net: Ensure sendmsg and sendfile return -EAGAIN in case of timeout
instead of -ETIMEOUT, as specify here:
https://pubs.opengroup.org/onlinepubs/009604599/functions/sendmsg.html
https://man7.org/linux/man-pages/man2/sendfile.2.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-28 06:19:13 +03:00
Ville Juven
dc2b2dcb3f sched/env: Check for incoming parameter validity in unsetenv()
Something the function did not do, check the incoming parameter is vlaid
2022-06-14 10:39:52 +03:00
Ville Juven
1b32fc1642 sched/env: Fix the return value of unsetenv()
If the environment variable does not exist, the function succeeds, as
defined by POSIX.
2022-06-14 10:39:52 +03:00
chao.an
7c12e5281e sched/mqueue: replace inline linklist to improve performance
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-12 00:34:05 +08:00