#pragma once #include #include #include #include #include #include #include #include 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);