dpif_netdev_run && pmd_thread_main (没有启动虚拟机去连接 -chardev socket,id=char1,path=$VHOST_SOCK_DIR/vhost-user1,不会有pmd_thread_main)
执行ovs-vsctl add-port br0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuser 会触发pmd_thread_main
[root@localhost ovs]# ovs-vsctl show c013fe69-c1a7-40dd-833b-bef8cd04d43e Bridge br0 datapath_type: netdev Port br0 Interface br0 type: internal Port dpdk1 Interface dpdk1 type: dpdk options: {dpdk-devargs="0000:05:00.0"} [root@localhost ovs]#
删除端口
if (!netdev_is_pmd(port->netdev))
Breakpoint 1, dpif_netdev_run (dpif=0x204f78a0) at lib/dpif-netdev.c:5438 5438 { (gdb) bt #0 dpif_netdev_run (dpif=0x204f78a0) at lib/dpif-netdev.c:5438 #1 0x000000000097d290 in dpif_run (dpif=<optimized out>) at lib/dpif.c:463 #2 0x0000000000934c68 in type_run (type=type@entry=0x202dd910 "netdev") at ofproto/ofproto-dpif.c:370 #3 0x000000000091eb18 in ofproto_type_run (datapath_type=<optimized out>, datapath_type@entry=0x202dd910 "netdev") at ofproto/ofproto.c:1772 #4 0x000000000090d94c in bridge_run__ () at vswitchd/bridge.c:3242 #5 0x0000000000913480 in bridge_run () at vswitchd/bridge.c:3307 #6 0x000000000042469c in main (argc=11, argv=0xffffe2250958) at vswitchd/ovs-vswitchd.c:127 (gdb) b dp_netdev_process_rxq_port Breakpoint 2 at 0x97851c: file lib/dpif-netdev.c, line 4441. (gdb) b pmd_thread_main Breakpoint 3 at 0x97880c: file lib/dpif-netdev.c, line 5658. (gdb)
(gdb) c Continuing. [New Thread 0xffff7c29f910 (LWP 18234)] Breakpoint 1, dpif_netdev_run (dpif=0x204f78a0) at lib/dpif-netdev.c:5438 5438 { (gdb) bt #0 dpif_netdev_run (dpif=0x204f78a0) at lib/dpif-netdev.c:5438 #1 0x000000000097d290 in dpif_run (dpif=<optimized out>) at lib/dpif.c:463 #2 0x0000000000934c68 in type_run (type=type@entry=0x202dd910 "netdev") at ofproto/ofproto-dpif.c:370 #3 0x000000000091eb18 in ofproto_type_run (datapath_type=<optimized out>, datapath_type@entry=0x202dd910 "netdev") at ofproto/ofproto.c:1772 #4 0x000000000090d94c in bridge_run__ () at vswitchd/bridge.c:3242 #5 0x0000000000913480 in bridge_run () at vswitchd/bridge.c:3307 #6 0x000000000042469c in main (argc=11, argv=0xffffe2250958) at vswitchd/ovs-vswitchd.c:127 (gdb) b dp_netdev_process_rxq_port Breakpoint 2 at 0x97851c: file lib/dpif-netdev.c, line 4441. (gdb) b pmd_thread_main Breakpoint 3 at 0x97880c: file lib/dpif-netdev.c, line 5658. (gdb) c Continuing. Breakpoint 2, dp_netdev_process_rxq_port (pmd=pmd@entry=0xffff75f00010, rxq=0x204f7230, port_no=0) at lib/dpif-netdev.c:4441 4441 { (gdb) bt #0 dp_netdev_process_rxq_port (pmd=pmd@entry=0xffff75f00010, rxq=0x204f7230, port_no=0) at lib/dpif-netdev.c:4441 #1 0x000000000097911c in dpif_netdev_run (dpif=<optimized out>) at lib/dpif-netdev.c:5469 #2 0x000000000097d290 in dpif_run (dpif=<optimized out>) at lib/dpif.c:463 #3 0x0000000000934c68 in type_run (type=type@entry=0x202dd910 "netdev") at ofproto/ofproto-dpif.c:370 #4 0x000000000091eb18 in ofproto_type_run (datapath_type=<optimized out>, datapath_type@entry=0x202dd910 "netdev") at ofproto/ofproto.c:1772 #5 0x000000000090d94c in bridge_run__ () at vswitchd/bridge.c:3242 #6 0x0000000000913480 in bridge_run () at vswitchd/bridge.c:3307 #7 0x000000000042469c in main (argc=11, argv=0xffffe2250958) at vswitchd/ovs-vswitchd.c:127 (gdb) c Continuing. Breakpoint 2, dp_netdev_process_rxq_port (pmd=pmd@entry=0xffff75f00010, rxq=0x2052ec80, port_no=2) at lib/dpif-netdev.c:4441 4441 { (gdb) bt #0 dp_netdev_process_rxq_port (pmd=pmd@entry=0xffff75f00010, rxq=0x2052ec80, port_no=2) at lib/dpif-netdev.c:4441 #1 0x000000000097911c in dpif_netdev_run (dpif=<optimized out>) at lib/dpif-netdev.c:5469 #2 0x000000000097d290 in dpif_run (dpif=<optimized out>) at lib/dpif.c:463 #3 0x0000000000934c68 in type_run (type=type@entry=0x202dd910 "netdev") at ofproto/ofproto-dpif.c:370 #4 0x000000000091eb18 in ofproto_type_run (datapath_type=<optimized out>, datapath_type@entry=0x202dd910 "netdev") at ofproto/ofproto.c:1772 ----执行了 #5 0x000000000090d94c in bridge_run__ () at vswitchd/bridge.c:3242 #6 0x0000000000913480 in bridge_run () at vswitchd/bridge.c:3307 #7 0x000000000042469c in main (argc=11, argv=0xffffe2250958) at vswitchd/ovs-vswitchd.c:127 (gdb)
(gdb) n 4451 cycle_timer_start(&pmd->perf_stats, &timer); (gdb) n 4441 { (gdb) n 4447 int rem_qlen = 0, *qlen_p = NULL; (gdb) n 4451 cycle_timer_start(&pmd->perf_stats, &timer); (gdb) n 4441 { (gdb) n 4447 int rem_qlen = 0, *qlen_p = NULL; (gdb) n 4451 cycle_timer_start(&pmd->perf_stats, &timer); (gdb) n 4453 pmd->ctx.last_rxq = rxq; (gdb) n 4457 if (pmd_perf_metrics_enabled(pmd) && rxq->is_vhost) { (gdb) n 4451 cycle_timer_start(&pmd->perf_stats, &timer); (gdb) n 4457 if (pmd_perf_metrics_enabled(pmd) && rxq->is_vhost) { (gdb) n 4451 cycle_timer_start(&pmd->perf_stats, &timer); (gdb) n 4454 dp_packet_batch_init(&batch); (gdb) set print pretty on (gdb) p *batch Structure has no component named operator*. (gdb) p batch $1 = { count = 0, trunc = false, do_not_steal = false, packets = {0xffff00000000, 0xa3505c <format_log_message+768>, 0x0, 0x0, 0x20, 0x1, 0xbfe3da, 0x980414 <ds_put_cstr+48>, 0xffffe22505a0, 0xffffe22505a0, 0xffffe2250570, 0xffffff80ffffffd8, 0xffffe22505a0, 0xffffe22505a0, 0xffffe22502a0, 0xa28468 <xclock_gettime+12>, 0xffffe22502b0, 0xa28560 <time_timespec__+212>, 0xffffe2250300, 0xa28638 <time_msec+28>, 0x202dd910, 0x204f2150, 0xffffe2250300, 0x9fb848 <ovs_mutex_lock_at+32>, 0xffff7c330f58, 0xbd4308, 0xffff00000000, 0xffff7e2a0c64 <malloc+88>, 0xffffe2250320, 0x978f74 <dpif_netdev_run+128>, 0xffffe2250320, 0x979100 <dpif_netdev_run+524>} } (gdb)
dp_netdev_process_rxq_port
(gdb) bt
#0 dp_netdev_process_rxq_port (pmd=pmd@entry=0xfffd546d0010, rxq=0x11c8c5d0, port_no=2) at lib/dpif-netdev.c:4480
#1 0x0000000000978a24 in pmd_thread_main (f_=0xfffd546d0010) at lib/dpif-netdev.c:5731
#2 0x00000000009fc5dc in ovsthread_wrapper (aux_=<optimized out>) at lib/ovs-thread.c:383
#3 0x0000ffff95e37d38 in start_thread (arg=0xfffd4fffd510) at pthread_create.c:309
#4 0x0000ffff95b1f690 in thread_start () from /lib64/libc.so.6
(gdb) c
Continuing.
Breakpoint 1, dp_netdev_process_rxq_port (pmd=pmd@entry=0xfffd546d0010, rxq=0x11c8c5d0, port_no=2) at lib/dpif-netdev.c:4480
4480 dp_netdev_input(pmd, &batch, port_no);
(gdb)
dp_netdev_process_rxq_port(struct dp_netdev_pmd_thread *pmd,
struct netdev_rxq *rx,
odp_port_t port_no)
{
struct dp_packet_batch batch;
int error;
dp_packet_batch_init(&batch);
cycles_count_start(pmd);
/*通过调用netdev_class->rxq_recv从rx中收包存入batch中*/
error = netdev_rxq_recv(rx, &batch);
cycles_count_end(pmd, PMD_CYCLES_POLLING);
if (!error) {
*recirc_depth_get() = 0;
cycles_count_start(pmd);
/*将batch中的包转入datapath中进行处理*/
dp_netdev_input(pmd, &batch, port_no);
cycles_count_end(pmd, PMD_CYCLES_PROCESSING);
}
...
}
netdev_class的实例有NETDEV_DPDK_CLASS,NETDEV_DUMMY_CLASS,NETDEV_BSD_CLASS,NETDEV_LINUX_CLASS.
netdev_rxq_recv &netdev_class ----->netdev_dpdk_vhost_rxq_recv
netdev_rxq_recv(struct netdev_rxq *rx, struct dp_packet_batch *batch,
int *qfill)
{
int retval;
retval = rx->netdev->netdev_class->rxq_recv(rx, batch, qfill);
if (!retval) {
COVERAGE_INC(netdev_received);
} else {
batch->count = 0;
}
return retval;
}
ovs-vsctl add-port br0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuser
static const struct netdev_class dpdk_vhost_class = {
.type = "dpdkvhostuser",
NETDEV_DPDK_CLASS_COMMON,
.construct = netdev_dpdk_vhost_construct,
.destruct = netdev_dpdk_vhost_destruct,
.send = netdev_dpdk_vhost_send,
.get_carrier = netdev_dpdk_vhost_get_carrier,
.get_stats = netdev_dpdk_vhost_get_stats,
.get_custom_stats = netdev_dpdk_get_sw_custom_stats,
.get_status = netdev_dpdk_vhost_user_get_status,
.reconfigure = netdev_dpdk_vhost_reconfigure,
.rxq_recv = netdev_dpdk_vhost_rxq_recv,
.rxq_enabled = netdev_dpdk_vhost_rxq_enabled,
};
dp_netdev_input
用户态Datapath处理packet流程:
pmd_thread_main dpif_netdev_run
/
/
dp_netdev_process_rxq_port
|
dp_netdev_input
|
fast_path_processing
|
handle_packet_upcall
/
(2) / (1)
/
dp_netdev_execute_actions dp_netdev_upcall
| |
odp_execute_actions upcall_cb(调用注册的回调函数)
|
dp_execute_cb
|
netdev_send
netdev_dpdk_rxq_recv
> >> #1 0x00000000007d2252 in rte_eth_rx_burst (nb_pkts=32,
> >>
> >> rx_pkts=0x7f3e4bffe7b0, queue_id=0, port_id=0 '