nuttx/sched
Zhe Weng c9a38f42f7 sched/wqueue: Do as much work as possible in work_thread
Decouple the semcount and the work queue length.

Previous Problem:

If a work is queued and cancelled in high priority threads (or queued
by timer and cancelled by another high priority thread) before
work_thread runs, the queue operation will mark work_thread as ready to
run, but the cancel operation minus the semcount back to -1 and makes
wqueue->q empty. Then the work_thread still runs, found empty queue,
and wait sem again, then semcount becomes -2 (being minused by 1)

This can be done multiple times, then semcount can become very small
value. Test case to produce incorrect semcount:

high_priority_task()
{
  for (int i = 0; i < 10000; i++)
    {
      work_queue(LPWORK, &work, worker, NULL, 0);
      work_cancel(LPWORK, &work);
      usleep(1);
    }

  /* Now the g_lpwork.sem.semcount is a value near -10000 */
}

With incorrect semcount, any queue operation when the work_thread is
busy, will only increase semcount and push work into queue, but cannot
trigger work_thread (semcount is negative but work_thread is not
waiting), then there will be more and more works left in queue while
the work_thread is waiting sem and cannot call them.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-21 17:50:40 +02:00
..
addrenv sched/addrenv: Remove up_addrenv_restore 2023-02-08 02:51:23 +08:00
clock clock: adjust clock function to support tick 2022-11-01 21:54:20 +08:00
environ sched/env: add tg_envc in task_group_s to avoid some loops in code 2023-02-25 23:10:37 +02:00
group task/task_cancelpt: Kill the child if it is not in a cancel point 2023-02-17 22:57:36 +08:00
init Launch the initial task through task_spawn instead of nxtask_create 2023-01-25 23:34:52 +02:00
irq sched/irq: add spin_unlock_irqsave/irqrestore_wo_note 2023-01-02 22:29:01 +08:00
misc sync ps/assert output 2023-02-17 23:35:44 +08:00
module nuttx: Use MIN/MAX definitions from "sys/param.h" 2023-02-01 23:47:44 +08:00
mqueue sched/getpid: replace syscall getpid/tid/ppid() to kernel version 2023-02-02 10:33:01 +08:00
paging nuttx/sched: merge up_block_task and up_unblock_task 2022-11-22 22:59:08 +08:00
pthread libc/exit: Purge calls to userspace API exit() from kernel 2023-02-17 23:07:17 +08:00
sched nuttx: fix indentation issue 2023-03-09 16:27:07 -03:00
semaphore sched/semaphore: increase sem count when holder task exit 2023-02-12 16:49:45 +08:00
signal signal/sig_dispatch: Add signal action, if task is in system call 2023-03-14 11:16:52 +09:00
task sched: build error fix in task_exithook 2023-03-03 20:10:43 +08:00
timer sched/getpid: replace syscall getpid/tid/ppid() to kernel version 2023-02-02 10:33:01 +08:00
tls sched/group: fix task info heap-use-after-free 2023-01-11 01:53:59 +08:00
wdog nuttx: Use MIN/MAX definitions from "sys/param.h" 2023-02-01 23:47:44 +08:00
wqueue sched/wqueue: Do as much work as possible in work_thread 2023-03-21 17:50:40 +02:00
Kconfig sched: Disable stdio api by default when DEFAULT_SMALL equals y 2023-03-03 00:18:03 +02:00
Makefile group/group_addrenv: Move address environment from group -> tcb 2023-02-08 02:51:23 +08:00