summaryrefslogtreecommitdiff
path: root/app/include/mrapp.h
blob: a81285e56f99bf111227246879b2d297df399983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#pragma once
#include <common.h>
#include <ldbc.h>
#include <marsio.h>
#include <mr_rte_msg.h>
#include <pcap/pcap.h>
#include <rte_epoll.h>
#include <tap.h>
#include <vdev_define.h>

struct mr_instance;
struct dp_trace_process;

struct mrapp_stat
{
    uint64_t mbuf_alloc_count;
    uint64_t mbuf_free_count;

    uint64_t packet_recv_count;
    uint64_t packet_recv_length;
    uint64_t packet_send_count;
    uint64_t packet_send_length;

    uint64_t packet_recv_drop;
    uint64_t packet_send_drop;

    uint64_t poll_wake_up_by_ev;
    uint64_t poll_wake_up_timeout;
} __rte_cache_aligned;

struct mr_vdev_counters
{
    unsigned int rx_burst_call_counters;
    unsigned int rx_burst_zero_counters;
    unsigned int rx_burst_non_zero_counters;
} __rte_cache_aligned;

struct mr_vdev_rx_buffer
{
    unsigned int curser;
    unsigned int length;
    unsigned int size;
    struct rte_mbuf * mbufs[];
};

struct mr_vdev_tx_buffer
{
    unsigned int size;
    unsigned int length;
    struct rte_mbuf * mbufs[];
};

/* 用户设备描述符 */
struct mr_vdev
{
    char devsym[MR_SYMBOL_MAX];
    unsigned int nr_rxstream;
    unsigned int nr_txstream;

    struct mr_instance * instance;
    struct vdev_instance * vdi;
    struct tap_device * tap_representor;

    int rx_notify_fds[MR_SID_MAX];
    struct rte_epoll_event rx_notify_epoll_events[MR_SID_MAX];
    unsigned int nr_rx_notify_fds;

    struct mr_vdev_counters counters[MR_SID_MAX];
    struct mr_vdev_rx_buffer * rx_buffer[MR_SID_MAX];
    struct mr_vdev_tx_buffer * tx_buffer[MR_SID_MAX];
};

struct mr_thread_info
{
    struct mr_instance * instance;
    unsigned int is_dataplane_thread;

    cpu_id_t cpu_id;
    thread_id_t thread_id;
    socket_id_t socket_id;
};

/* 静态邻居表项 */
struct mr_static_neigh_entry
{
    TAILQ_ENTRY(mr_static_neigh_entry) next;
    struct in_addr in_addr;
    struct rte_ether_addr ether_addr;
    char devsym[MR_SYMBOL_MAX];
    char str_in_addr[MR_SYMBOL_MAX];
    char str_ether_addr[MR_SYMBOL_MAX];
};

TAILQ_HEAD(mr_static_neigh_list, mr_static_neigh_entry);

struct mp_cache_map
{
    struct rte_mempool * mp;
    struct rte_mempool_cache * mp_cache[MR_SID_MAX];
};

struct mr_instance
{
    /* ==== 运行句柄 ==== */

    /* 应用名称 */
    char appsym[MR_SYMBOL_MAX];
    /* 状态监测输出路径 */
    char monit_file_path[MR_STRING_MAX];
    /* 全局配置文件路径 */
    char g_cfgfile_path[MR_STRING_MAX];
    /* 应用配置文件路径 */
    char app_cfgfile_path[MR_STRING_MAX];
    /* 虚设备实例列表 */
    struct mr_vdev vdevs[MR_VDEV_MAX];
    /* 虚设备实例数量 */
    unsigned int nr_vdevs;
    /* 负载均衡器 */
    struct distributer * dist_object;
    /* 静态邻居表 */
    struct mr_static_neigh_list static_neigh_list;
    /* 统计 */
    struct mrapp_stat stat[MR_SID_MAX];
    /* 监控marsio是否存活的句柄*/
    int marsio_fd;

    /* =====  运行选项  ===== */

    /* 遇到错误,是否自动退出 */
    unsigned int is_exit_when_err_raise;
    /* 线程数 */
    unsigned int nr_dataplane_thread;
    /* 是否发送免费ARP */
    unsigned int nr_gratuitous_arp_send;
    /* 核心掩码 */
    cpu_set_t cpu_set;
    /* 线程初始化锁 */
    pthread_mutex_t lock_thread_init;
    /* 当前待分配的线程ID */
    thread_id_t to_suppose_tid;
    /* RECV ALL的状态暂存 */
    unsigned int recv_all_state[MR_SID_MAX];
    /* 基于ASAN的内存保护模式 */
    unsigned int memory_protect_with_asan;

    /* tap resp handles */
    struct tap_device * tap_resp_devices[MR_DEVICE_MAX];
    unsigned int nr_tap_resp_devices;

    /* tap resp epoll fd */
    int tap_resp_epfd;
    pthread_t pid_tap_resp_poll;

    /* rx epoll fd */
    int rx_notify_epfd[MR_SID_MAX];
    unsigned int stat_notify_wake_up_from_ev[MR_SID_MAX];
    unsigned int stat_notify_wake_up_from_timeout[MR_SID_MAX];
    unsigned int busy_loop_counter[MR_SID_MAX];

    /* threshold */
    unsigned int zero_recv_usleep_threshold;
    unsigned int zero_recv_usleep_period;
    unsigned int zero_recv_notify_threshold;
    unsigned int en_notify;

    /* mempool cache map */
    struct mp_cache_map * mp_cache_map[MR_MEMPOOL_COUNT_MAX];
    unsigned int nr_mp_cache_map;
    unsigned int sz_mp_cache;

    /* vdev buffer size */
    unsigned int sz_vdev_buffer;

    /* data path trace */
    struct dp_trace_process * trace;
};

/* EAL环境是否初始化 */
extern unsigned int g_eal_inited;
extern __thread struct mr_thread_info thread_info;

/* 状态监测入口 */
int mrapp_monit_loop(struct mr_instance * instance);

int mrapp_packet_send_burst(struct vdev_instance * vdi, queue_id_t qid, struct rte_mbuf * mbufs[], int nr_mbufs);

int mrapp_packet_fast_send_burst(struct mr_instance * instance,
                                 struct vdev_instance * vdi, queue_id_t qid, struct rte_mbuf * mbufs[], int nr_mbufs);