CNDP 22.08.0
Loading...
Searching...
No Matches
cnet_stk.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016-2022 Intel Corporation
3 */
4
5#ifndef __CNET_STK_H
6#define __CNET_STK_H
7
12
13#include <sys/queue.h> // for TAILQ_HEAD
14#include <pthread.h> // for pthread_t, pthread_cond_t, pthread_mutex_t
15#include <cne_atomic.h> // for atomic_fetch_sub, atomic_load
16#include <stddef.h> // for NULL
17#include <stdint.h> // for uint32_t, uint16_t, uint64_t, uint8_t
18#include <sys/select.h> // for fd_set
19#include <unistd.h> // for usleep, pid_t
20#include <bsd/sys/bitstring.h>
21
22#include <cne_system.h> // for cne_get_timer_hz
23#include <cne_vec.h> // for vec_at_index, vec_len
24#include <hmap.h> // for hmap_t
25#include <cne_timer.h>
26
27#include "cne_common.h" // for __cne_cache_aligned
28#include "cne_per_thread.h" // for CNE_PER_THREAD, CNE_DECLARE_PER_THREAD
29#include "cnet.h" // for cnet, cnet_cfg (ptr only), per_thread_cnet
30#include "cnet_const.h" // for iofunc_t, PROTO_IO_MAX
31#include "mempool.h" // for mempool_t
32#include "pktmbuf.h" // for pktmbuf_alloc, pktmbuf_t
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38struct netlink_info;
39struct tcp_stats;
40
41typedef struct stk_s {
42 pthread_mutex_t mutex;
43 uint16_t idx;
44 uint16_t lid;
45 pid_t tid;
46 char name[32];
47 struct cne_graph *graph;
48 struct cne_node *tcp_tx_node;
49 bitstr_t *tcbs;
50 uint32_t tcp_now;
51 uint32_t gflags;
52 uint64_t ticks;
53 mempool_t *tcb_objs;
54 mempool_t *seg_objs;
55 mempool_t *pcb_objs;
56 mempool_t *chnl_objs;
57 struct protosw_entry **protosw_vec;
58 struct icmp_entry *icmp;
59 struct icmp6_entry *icmp6;
60 struct ipv4_entry *ipv4;
61 struct ipv6_entry *ipv6;
62 struct tcp_entry *tcp;
63 struct raw_entry *raw;
64 struct udp_entry *udp;
65 struct chnl_optsw **chnlopt;
66 struct cne_timer tcp_timer;
67 struct tcp_stats *tcp_stats;
69
70CNE_DECLARE_PER_THREAD(stk_t *, stk);
71#define this_stk CNE_PER_THREAD(stk)
72
73/* Flags values for stk_entry.gflags */
74enum {
75 TCP_TIMEOUT_ENABLED = 0x00000001,
77 RFC1323_SCALE_ENABLED = 0x00008000,
78};
79
80static inline uint64_t
81clks_to_ns(uint64_t clks)
82{
83 uint64_t ns = cne_get_timer_hz();
84
85 ns = 1000000000ULL / ((ns == 0) ? 1 : ns); /* nsecs per clk */
86 ns *= clks; /* nsec per clk times clks */
87
88 return ns;
89}
90
91static inline uint32_t
92stk_get_timer_ticks(void)
93{
94 return this_stk->tcp_now;
95}
96
97static inline void
98stk_set(stk_t *stk)
99{
100 CNE_PER_THREAD(stk) = stk;
101}
102
103static inline stk_t *
104stk_get(void)
105{
106 return CNE_PER_THREAD(stk);
107}
108
109static inline stk_t *
110cnet_stk_find_by_lcore(uint8_t lid)
111{
112 struct cnet *cnet = this_cnet;
113 stk_t *stk;
114
115 vec_foreach_ptr (stk, cnet->stks) {
116 if (stk->lid == lid)
117 return stk;
118 }
119 return NULL;
120}
121
122static inline int
123stk_lock(void)
124{
125 stk_t *stk = this_stk;
126
127 if (!stk)
128 CNE_ERR_RET_VAL(0, "Stack pointer is NULL\n");
129
130 if (pthread_mutex_lock(&stk->mutex) == 0)
131 return 1;
132
133 CNE_ERR_RET_VAL(0, "Unable to lock stk(%s) mutex\n", stk->name);
134}
135
136static inline void
137stk_unlock(void)
138{
139 stk_t *stk = this_stk;
140
141 if (!stk)
142 CNE_RET("Stack pointer is NULL\n");
143
144 if (pthread_mutex_unlock(&stk->mutex))
145 CNE_ERR("Unable to unlock (%s) mutex\n", stk->name);
146}
147
156CNDP_API int cnet_stk_initialize(struct cnet *cnet);
157
164CNDP_API int cnet_stk_stop(void);
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* __CNET_STK_H */
#define __cne_cache_aligned
Definition cne_common.h:379
#define CNE_ERR_RET_VAL(_val,...)
Definition cne_log.h:222
#define CNE_RET(...)
Definition cne_log.h:238
#define CNE_DECLARE_PER_THREAD(type, name)
#define CNE_PER_THREAD(name)
CNDP_API uint64_t cne_get_timer_hz(void)
@ TCP_TIMEOUT_ENABLED
Definition cnet_stk.h:75
@ RFC1323_TSTAMP_ENABLED
Definition cnet_stk.h:76
@ RFC1323_SCALE_ENABLED
Definition cnet_stk.h:77
CNDP_API int cnet_stk_initialize(struct cnet *cnet)
Initialize the stack instance.
CNDP_API int cnet_stk_stop(void)
Stop the stack instance and free resources.
void mempool_t
Definition mempool.h:45