2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2015 Intel Corporation.
4 * Copyright 2012 Hasan Alayli <halayli@gmail.com>
7 #ifndef LTHREAD_SCHED_H_
8 #define LTHREAD_SCHED_H_
14 #include "lthread_int.h"
15 #include "lthread_queue.h"
16 #include "lthread_objcache.h"
17 #include "lthread_diag.h"
21 * insert an lthread into a queue
24 _ready_queue_insert(struct lthread_sched *sched, struct lthread *lt)
26 if (sched == THIS_SCHED)
27 _lthread_queue_insert_sp((THIS_SCHED)->ready, lt);
29 _lthread_queue_insert_mp(sched->pready, lt);
33 * remove an lthread from a queue
35 static inline struct lthread *_ready_queue_remove(struct lthread_queue *q)
37 return _lthread_queue_remove(q);
41 * Return true if the ready queue is empty
43 static inline int _ready_queue_empty(struct lthread_queue *q)
45 return _lthread_queue_empty(q);
48 static inline uint64_t _sched_now(void)
50 uint64_t now = rte_rdtsc();
52 if (now > (THIS_SCHED)->birth)
53 return now - (THIS_SCHED)->birth;
54 if (now < (THIS_SCHED)->birth)
55 return (THIS_SCHED)->birth - now;
56 /* never return 0 because this means sleep forever */
60 static __rte_always_inline void
65 struct lthread *lt = THIS_LTHREAD;
67 DIAG_EVENT(lt, LT_DIAG_LTHREAD_SUSPENDED, 0, 0);
68 ctx_switch(&(THIS_SCHED)->ctx, <->ctx);
71 static __rte_always_inline void
76 struct lthread *lt = THIS_LTHREAD;
78 (THIS_SCHED)->nb_blocked_threads++;
79 DIAG_EVENT(lt, LT_DIAG_LTHREAD_SUSPENDED, 0, 0);
80 ctx_switch(&(THIS_SCHED)->ctx, <->ctx);
81 (THIS_SCHED)->nb_blocked_threads--;
84 static __rte_always_inline void
89 struct lthread *lt = THIS_LTHREAD;
91 DIAG_EVENT(lt, LT_DIAG_LTHREAD_RESCHEDULED, 0, 0);
92 _ready_queue_insert(THIS_SCHED, lt);
93 ctx_switch(&(THIS_SCHED)->ctx, <->ctx);
96 extern struct lthread_sched *schedcore[];
97 void _sched_timer_cb(struct rte_timer *tim, void *arg);
98 void _sched_shutdown(__rte_unused void *arg);
104 #endif /* LTHREAD_SCHED_H_ */