Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
sched_priq.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_SCHED_PRIQ_H_
7#define ZEPHYR_INCLUDE_SCHED_PRIQ_H_
8
9#include <sys/util.h>
10#include <sys/dlist.h>
11#include <sys/rb.h>
12
13/* Two abstractions are defined here for "thread priority queues".
14 *
15 * One is a "dumb" list implementation appropriate for systems with
16 * small numbers of threads and sensitive to code size. It is stored
17 * in sorted order, taking an O(N) cost every time a thread is added
18 * to the list. This corresponds to the way the original _wait_q_t
19 * abstraction worked and is very fast as long as the number of
20 * threads is small.
21 *
22 * The other is a balanced tree "fast" implementation with rather
23 * larger code size (due to the data structure itself, the code here
24 * is just stubs) and higher constant-factor performance overhead, but
25 * much better O(logN) scaling in the presence of large number of
26 * threads.
27 *
28 * Each can be used for either the wait_q or system ready queue,
29 * configurable at build time.
30 */
31
32struct k_thread;
33
34struct k_thread *z_priq_dumb_best(sys_dlist_t *pq);
35void z_priq_dumb_remove(sys_dlist_t *pq, struct k_thread *thread);
36void z_priq_dumb_add(sys_dlist_t *pq, struct k_thread *thread);
37
38struct _priq_rb {
39 struct rbtree tree;
40 int next_order_key;
41};
42
43void z_priq_rb_add(struct _priq_rb *pq, struct k_thread *thread);
44void z_priq_rb_remove(struct _priq_rb *pq, struct k_thread *thread);
45struct k_thread *z_priq_rb_best(struct _priq_rb *pq);
46
47/* Traditional/textbook "multi-queue" structure. Separate lists for a
48 * small number (max 32 here) of fixed priorities. This corresponds
49 * to the original Zephyr scheduler. RAM requirements are
50 * comparatively high, but performance is very fast. Won't work with
51 * features like deadline scheduling which need large priority spaces
52 * to represent their requirements.
53 */
54struct _priq_mq {
55 sys_dlist_t queues[32];
56 unsigned int bitmask; /* bit 1<<i set if queues[i] is non-empty */
57};
58
59void z_priq_mq_add(struct _priq_mq *pq, struct k_thread *thread);
60void z_priq_mq_remove(struct _priq_mq *pq, struct k_thread *thread);
61struct k_thread *z_priq_mq_best(struct _priq_mq *pq);
62
63#endif /* ZEPHYR_INCLUDE_SCHED_PRIQ_H_ */
static struct k_thread thread[2]
Definition: atomic.c:22
Doubly-linked list implementation.
struct _dnode sys_dlist_t
Definition: dlist.h:48
Red/Black balanced tree data structure.
Definition: thread.h:201
Definition: rb.h:83
Misc utilities.