]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/examples/performance-thread/common/lthread_sched.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / examples / performance-thread / common / lthread_sched.h
CommitLineData
7c673cae 1/*
9f95a23c
TL
2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2015 Intel Corporation.
4 * Copyright 2012 Hasan Alayli <halayli@gmail.com>
7c673cae
FG
5 */
6
7#ifndef LTHREAD_SCHED_H_
8#define LTHREAD_SCHED_H_
9
11fdf7f2
TL
10#ifdef __cplusplus
11extern "C" {
12#endif
13
7c673cae
FG
14#include "lthread_int.h"
15#include "lthread_queue.h"
16#include "lthread_objcache.h"
17#include "lthread_diag.h"
18#include "ctx.h"
19
20/*
21 * insert an lthread into a queue
22 */
23static inline void
24_ready_queue_insert(struct lthread_sched *sched, struct lthread *lt)
25{
26 if (sched == THIS_SCHED)
27 _lthread_queue_insert_sp((THIS_SCHED)->ready, lt);
28 else
29 _lthread_queue_insert_mp(sched->pready, lt);
30}
31
32/*
33 * remove an lthread from a queue
34 */
35static inline struct lthread *_ready_queue_remove(struct lthread_queue *q)
36{
37 return _lthread_queue_remove(q);
38}
39
40/**
41 * Return true if the ready queue is empty
42 */
43static inline int _ready_queue_empty(struct lthread_queue *q)
44{
45 return _lthread_queue_empty(q);
46}
47
48static inline uint64_t _sched_now(void)
49{
50 uint64_t now = rte_rdtsc();
51
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 */
57 return 1;
58}
59
9f95a23c
TL
60static __rte_always_inline void
61_affinitize(void);
7c673cae
FG
62static inline void
63_affinitize(void)
64{
65 struct lthread *lt = THIS_LTHREAD;
66
67 DIAG_EVENT(lt, LT_DIAG_LTHREAD_SUSPENDED, 0, 0);
68 ctx_switch(&(THIS_SCHED)->ctx, &lt->ctx);
69}
70
9f95a23c
TL
71static __rte_always_inline void
72_suspend(void);
7c673cae
FG
73static inline void
74_suspend(void)
75{
76 struct lthread *lt = THIS_LTHREAD;
77
78 (THIS_SCHED)->nb_blocked_threads++;
79 DIAG_EVENT(lt, LT_DIAG_LTHREAD_SUSPENDED, 0, 0);
80 ctx_switch(&(THIS_SCHED)->ctx, &lt->ctx);
81 (THIS_SCHED)->nb_blocked_threads--;
82}
83
9f95a23c
TL
84static __rte_always_inline void
85_reschedule(void);
7c673cae
FG
86static inline void
87_reschedule(void)
88{
89 struct lthread *lt = THIS_LTHREAD;
90
91 DIAG_EVENT(lt, LT_DIAG_LTHREAD_RESCHEDULED, 0, 0);
92 _ready_queue_insert(THIS_SCHED, lt);
93 ctx_switch(&(THIS_SCHED)->ctx, &lt->ctx);
94}
95
96extern struct lthread_sched *schedcore[];
97void _sched_timer_cb(struct rte_timer *tim, void *arg);
98void _sched_shutdown(__rte_unused void *arg);
99
11fdf7f2
TL
100#ifdef __cplusplus
101}
102#endif
7c673cae
FG
103
104#endif /* LTHREAD_SCHED_H_ */