Commit Graph

24 Commits

Author SHA1 Message Date
ligd 42b6dd0ff1 wqueue: extend the work_cancel_sync() return value
Return 1 to indicate the work was not cancelled.
Because it is currently being processed by work thread,
but wait for it to finish.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 02:56:39 +08:00
Alin Jerpelea eb9030c891 sched: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:10:14 +08:00
ligd ce2ad51b3a wqueue: expose wqueue API for customization
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-30 01:52:22 +08:00
ligd f5095d781b wqueue: handle work_cancel() called in irq mode or idle thread
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-30 01:52:22 +08:00
chao an e456c88c09 Revert "sched: replace some global variables to macro"
sched implementation not depends on macro abstraction, so revert below commit:

This reverts commit 4e62d0005a
This reverts commit 0f0c370520
This reverts commit ad0efd04ee

Signed-off-by: chao an <anchao@lixiang.com>
2024-06-06 22:00:25 +08:00
chao an ad0efd04ee sched/wqueue: replace some global variables to macro
replace to macro will help to extend the scheduling implementation

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 11:22:41 +09:00
ligd 61ef7eb3dc wqueue: add work_cancel_sync() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 15:52:48 +08:00
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
chao an b9d70365a1 sched/wqueue: semaphore count should be consistent with the number of work entries.
The number of work entries will be inconsistent with semaphore count
if the work is canceled, in extreme case, semaphore count will overflow
and fallback to 0 the workqueue will stop scheduling the enqueue work.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-28 21:45:10 +09: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
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
Jiuzhu Dong 855c78bb9d work_queue: schedule the work queue using the timer mechanism
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-07-27 21:01:38 -07:00
Nathan Hartman af1fd49fb0 wqueue: Fix typos
include/nuttx/wqueue.h:
libs/libc/wqueue/work_cancel.c:
libs/libc/wqueue/work_queue.c:
sched/wqueue/kwork_cancel.c:
sched/wqueue/kwork_queue.c:

    * Fix spelling, grammar, and typos.
    * Improve wording in a few areas.
    * These changes affect comments only. No functional changes.
2021-07-16 19:54:08 -03:00
Gregory Nutt 45b8e3ce7f sched/wqueue: Update to Apache 2.0 headers.
Also run files through nxstyle to assurand coding standard compliance.
2020-03-11 18:39:53 -03:00
Gregory Nutt 7cf88d7dbd Make sure that labeling is used consistently in all function headers. 2018-02-01 10:00:02 -06:00
Gregory Nutt a20863f6c0 Remove some empty file section section header comments 2016-02-17 17:15:08 -06:00
Gregory Nutt 6e3107650d nuttx/sched: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() 2016-02-14 08:17:46 -06:00
Gregory Nutt cb9e27c3b0 Standardize naming used for public data and function groupings 2015-10-02 16:30:35 -06:00
Gregory Nutt a813baef0a User workqueue, cosmetic changes 2015-09-30 14:03:55 -06:00
Gregory Nutt 4cd57e1e4e Work queues: Logic that sets the queued indication and the logic that does the actual queuing must be atomic 2015-09-30 11:04:29 -06:00
Gregory Nutt 4a4b3ac537 Add support for multiple low-priority worker threads 2014-10-10 16:24:50 -06:00
Gregory Nutt cf59a195ba User-mode work queue logic should not disable interrupts 2014-10-10 14:52:04 -06:00
Gregory Nutt 2015fd76e2 Fix some conditional logic in last work queue repartitioning change 2014-10-10 08:47:41 -06:00
Gregory Nutt 1afc9773ac Decoupling work queue data structures. This is part of the preparation to support multiple low-priority worker threads 2014-10-10 08:35:58 -06:00