Commit Graph

2079 Commits

Author SHA1 Message Date
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
chao.an
d09dc08eab sched/mqueue: do sanity check if DEBUG_FEATURES is enabled
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-11 12:42:47 -03:00
chao.an
be33d66c05 sched/mqueue: minor code tuning of message queue
1. remove unnecessary temporary variables
2. adjust the protection scope of the critical section

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-11 14:51:46 +08:00
chao.an
8da798926d sched/mqueue: configurable mqueue notification
Add a configuration to disable the mqueue notification mechanism

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-11 14:51:09 +08:00
chao.an
f5d4571abc sched/mqueue: remove sched_lock to improve performance
remove the sched_lock/unlock to improve the performance by 18%

mq_send Flow                        Cycle Count
mq_send                         Origin  Optimized
|
 ->nxmq_send                       24         24
   |
    ->file_mq_send                209        209
      |
      |->sched_lock               243        N/A  <-
      |->nxmq_do_send             391        348
      |  |
      |  |->sched_lock            434        N/A  <-
      |  |->up_unblock_task       545        459
      |   ->sched_unlock          675        N/A  <-
      |
       ->sched_unlock             684        N/A  <-
         |
          ->up_release_pending    701        N/A
            |
             ->arm_switchcontext  856        610

mq_receive
|
 ->arm_fullcontextrestore        1375       1133
   |
    ->up_block_task              1375       1133
      |
       ->nxmq_wait_receive       1530       1288
         |
          ->file_mq_receive      1606       1310
            |
             ->nxmq_receive      1616       1320
               |
                ->mq_receive     1628       1332  - 18%

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-10 07:23:42 +09:00
Xiang Xiao
11c8f3125d sched/tls: Wrap up_info_size into tls_info_size
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-08 19:07:33 +09: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
Xiang Xiao
01c8bebf58 sched/tls: Add task_init_info and task_uninit_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao
47b707bbf8 sched/tls: Add tls_init_info and tls_dup_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao
3e32b605fe libc/tls: Make tls_get_info as the pulibc function instead up_tls_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao
33a6aa2f48 sched/tls: Don't compensate the tls size to the stack size
it isn't good to change the stack size passed by caller

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
chao.an
5f46a21c25 signal: add define of SIGHUP/SIGTTIN
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-03 12:50:14 +08:00