【发布时间】:2021-08-16 18:59:52
【问题描述】:
我使用 dpdk 库编写了一个发送方应用程序。
struct my_message{
struct rte_ether_hdr eth_hdr; // the ethernet header
char payload[10];
};
*/ Sender Application */
void my_send(struct rte_mempool *mbuf_pool, uint16_t port, uint64_t max_packets)
{
int retval;
struct rte_mbuf *bufs[BURST_SIZE];
struct rte_ether_addr src_mac_addr;
retval = rte_eth_macaddr_get(0, &src_mac_addr); // gets MAC address of Port 0
struct rte_ether_addr dst_mac_addr = {{0xaa,0xbb,0xcc,0xdd,0xee,0xff}};
struct my_message *my_pkt;
int j=0;
uint16_t sent_packets = BURST_SIZE; //BURST_SIZE is 256
do{
for(int i = 0; i < sent_packets; i ++)
{
bufs[i] = rte_pktmbuf_alloc(mbuf_pool); //allocates a new mbuff from mempool
my_pkt = rte_pktmbuf_mtod(bufs[i], struct my_message*); //points (pointer is casted to struct my_message*) to start of data in mbuf
*my_pkt->payload = 'Hello2021';
int pkt_size = sizeof(struct my_message);
bufs[i]->pkt_len = bufs[i]->data_len = pkt_size;
rte_ether_addr_copy(&src_mac_addr, &my_pkt->eth_hdr.s_addr);
rte_ether_addr_copy(&dst_mac_addr, &my_pkt->eth_hdr.d_addr);
my_pkt->eth_hdr.ether_type = htons(PTP_PROTOCOL);
}
const uint16_t sent_packets = rte_eth_tx_burst(port, 0, bufs, BURST_SIZE);
printf("Number of packets tx %" PRIu16 "\n", sent_packets);
j = j + sent_packets;
}
while(j < max_packets);
/* Free any unsent packets. */
if (unlikely(sent_packets < BURST_SIZE)) {
uint16_t buf;
for (buf = sent_packets; buf < BURST_SIZE; buf++)
rte_pktmbuf_free(bufs[buf]);
}
}
我把这个函数称为
int main(int argc, char *argv[])
--
EAL initialization and port initialization
--
struct rte_mempool *mbuf_pool;
my_send(mbuf_pool, 0, 3000000);
该程序编译没有错误,但是,在运行该程序时,我遇到了分段错误。以下是输出:
我运行了 gdb,但无法从 gdb 输出进行调试
并收到以下消息
线程 1“app_tx_v2”收到信号 SIGSEGV,分段错误。 my_send()中的0x0000555555555567
【问题讨论】:
-
请提供minimal reproducible example 并将图片替换为文本输出。来自How do I ask a good question?:“请勿发布代码、数据、错误消息等的图片。 - 将文本复制或输入到问题中”
-
@stackinside,感谢您的提示。
rte_pktmbuf_alloc()返回一个 NULL 指针确实是对的。下一步是了解为什么会发生这种情况。以及如何避免这种情况。