net/enic: avoid error message when no advanced filtering
[dpdk.git] / examples / performance-thread / common / lthread_int.h
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright 2015 Intel Corporation.
4  * Copyright 2012 Hasan Alayli <halayli@gmail.com>
5  */
6 #ifndef LTHREAD_INT_H
7 #define LTHREAD_INT_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 #include <stdint.h>
14 #include <sys/time.h>
15 #include <sys/types.h>
16 #include <errno.h>
17 #include <pthread.h>
18 #include <time.h>
19
20 #include <rte_memory.h>
21 #include <rte_cycles.h>
22 #include <rte_per_lcore.h>
23 #include <rte_timer.h>
24 #include <rte_spinlock.h>
25 #include <ctx.h>
26
27 #include <lthread_api.h>
28 #include "lthread.h"
29 #include "lthread_diag.h"
30 #include "lthread_tls.h"
31
32 struct lthread;
33 struct lthread_sched;
34 struct lthread_cond;
35 struct lthread_mutex;
36 struct lthread_key;
37
38 struct key_pool;
39 struct qnode;
40 struct qnode_pool;
41 struct lthread_sched;
42 struct lthread_tls;
43
44
45 #define BIT(x) (1 << (x))
46 #define CLEARBIT(x) ~(1 << (x))
47
48 #define POSIX_ERRNO(x)  (x)
49
50 #define MAX_LTHREAD_NAME_SIZE 64
51
52 #define RTE_LOGTYPE_LTHREAD RTE_LOGTYPE_USER1
53
54
55 /* define some shorthand for current scheduler and current thread */
56 #define THIS_SCHED RTE_PER_LCORE(this_sched)
57 #define THIS_LTHREAD RTE_PER_LCORE(this_sched)->current_lthread
58
59 /*
60  * Definition of an scheduler struct
61  */
62 struct lthread_sched {
63         struct ctx ctx;                                 /* cpu context */
64         uint64_t birth;                                 /* time created */
65         struct lthread *current_lthread;                /* running thread */
66         unsigned lcore_id;                              /* this sched lcore */
67         int run_flag;                                   /* sched shutdown */
68         uint64_t nb_blocked_threads;    /* blocked threads */
69         struct lthread_queue *ready;                    /* local ready queue */
70         struct lthread_queue *pready;                   /* peer ready queue */
71         struct lthread_objcache *lthread_cache;         /* free lthreads */
72         struct lthread_objcache *stack_cache;           /* free stacks */
73         struct lthread_objcache *per_lthread_cache;     /* free per lthread */
74         struct lthread_objcache *tls_cache;             /* free TLS */
75         struct lthread_objcache *cond_cache;            /* free cond vars */
76         struct lthread_objcache *mutex_cache;           /* free mutexes */
77         struct qnode_pool *qnode_pool;          /* pool of queue nodes */
78         struct key_pool *key_pool;              /* pool of free TLS keys */
79         size_t stack_size;
80         uint64_t diag_ref;                              /* diag ref */
81 } __rte_cache_aligned;
82
83 RTE_DECLARE_PER_LCORE(struct lthread_sched *, this_sched);
84
85
86 /*
87  * State for an lthread
88  */
89 enum lthread_st {
90         ST_LT_INIT,             /* initial state */
91         ST_LT_READY,            /* lthread is ready to run */
92         ST_LT_SLEEPING,         /* lthread is sleeping */
93         ST_LT_EXPIRED,          /* lthread timeout has expired  */
94         ST_LT_EXITED,           /* lthread has exited and needs cleanup */
95         ST_LT_DETACH,           /* lthread frees on exit*/
96         ST_LT_CANCELLED,        /* lthread has been cancelled */
97 };
98
99 /*
100  * lthread sub states for exit/join
101  */
102 enum join_st {
103         LT_JOIN_INITIAL,        /* initial state */
104         LT_JOIN_EXITING,        /* thread is exiting */
105         LT_JOIN_THREAD_SET,     /* joining thread has been set */
106         LT_JOIN_EXIT_VAL_SET,   /* exiting thread has set ret val */
107         LT_JOIN_EXIT_VAL_READ,  /* joining thread has collected ret val */
108 };
109
110 /* defnition of an lthread stack object */
111 struct lthread_stack {
112         uint8_t stack[LTHREAD_MAX_STACK_SIZE];
113         size_t stack_size;
114         struct lthread_sched *root_sched;
115 } __rte_cache_aligned;
116
117 /*
118  * Definition of an lthread
119  */
120 struct lthread {
121         struct ctx ctx;                         /* cpu context */
122
123         uint64_t state;                         /* current lthread state */
124
125         struct lthread_sched *sched;            /* current scheduler */
126         void *stack;                            /* ptr to actual stack */
127         size_t stack_size;                      /* current stack_size */
128         size_t last_stack_size;                 /* last yield  stack_size */
129         lthread_func_t fun;                     /* func ctx is running */
130         void *arg;                              /* func args passed to func */
131         void *per_lthread_data;                 /* per lthread user data */
132         lthread_exit_func exit_handler;         /* called when thread exits */
133         uint64_t birth;                         /* time lthread was born */
134         struct lthread_queue *pending_wr_queue; /* deferred  queue to write */
135         struct lthread *lt_join;                /* lthread to join on */
136         uint64_t join;                          /* state for joining */
137         void **lt_exit_ptr;                     /* exit ptr for lthread_join */
138         struct lthread_sched *root_sched;       /* thread was created here*/
139         struct queue_node *qnode;               /* node when in a queue */
140         struct rte_timer tim;                   /* sleep timer */
141         struct lthread_tls *tls;                /* keys in use by the thread */
142         struct lthread_stack *stack_container;  /* stack */
143         char funcname[MAX_LTHREAD_NAME_SIZE];   /* thread func name */
144         uint64_t diag_ref;                      /* ref to user diag data */
145 } __rte_cache_aligned;
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif                          /* LTHREAD_INT_H */