dpdk Segmentation fault

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>

#include <rte_memory.h>
#include <rte_launch.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_debug.h>
//#include <rte_memzone.h>
//#include <rte_malloc.h>
#include <unistd.h>
//#include "eal_private.h"
struct node {
  int a;
  int b;
};

int
main(int argc, char **argv)
{
        int num = 0;
        if (argc > 1)
        {
           num = atoi(argv[1]); 
        }
        printf("socket id %d 
 ", num);
        int *arr;
        int ret;
        struct node *nodes;
        ret = rte_eal_init(argc, argv);
        if (ret < 0)
                rte_panic("Cannot init EAL
");
        arr = rte_malloc("arr", sizeof(int) * 1024, 0);
        if (arr == NULL)
                rte_exit(EXIT_FAILURE, "Cannot malloc memory 
");
        printf("arr addr %llx 
 ",(long long) arr);
        arr[0] = 1000;
        rte_free(arr);
         /*
        nodes = rte_malloc_socket(NULL, sizeof(struct node) * 2, 0, num);
        nodes = rte_malloc(NULL, sizeof(*nodes), 0);
        if (NULL == nodes)
                rte_exit(EXIT_FAILURE, "Cannot malloc memory 
");
        printf("nodes addr %llx 
 ",(long long) nodes);
        FILE * fp = fopen ("rte_malloc.txt", "w+");
        rte_malloc_dump_heaps(fp);
        fclose(fp);
        nodes[0].a = 18 ;
        nodes[0].b = 24 ;
        printf("start to   free 
");
        rte_free(nodes);
        */
        getchar();
        return 0;
}
[root@localhost memzone]# make clean all
  CC main.o
/data1/dpdk-19.11/demo/memzone/main.c: In function ‘main’:
/data1/dpdk-19.11/demo/memzone/main.c:41:9: warning: implicit declaration of function ‘rte_malloc’ [-Wimplicit-function-declaration]
         arr = rte_malloc("arr", sizeof(int) * 1024, 0);
         ^
/data1/dpdk-19.11/demo/memzone/main.c:41:9: warning: nested extern declaration of ‘rte_malloc’ [-Wnested-externs]
/data1/dpdk-19.11/demo/memzone/main.c:41:13: warning: assignment makes pointer from integer without a cast [enabled by default]
         arr = rte_malloc("arr", sizeof(int) * 1024, 0);
             ^
/data1/dpdk-19.11/demo/memzone/main.c:46:9: warning: implicit declaration of function ‘rte_free’ [-Wimplicit-function-declaration]
         rte_free(arr);
         ^
/data1/dpdk-19.11/demo/memzone/main.c:46:9: warning: nested extern declaration of ‘rte_free’ [-Wnested-externs]
/data1/dpdk-19.11/demo/memzone/main.c:37:22: warning: unused variable ‘nodes’ [-Wunused-variable]
         struct node *nodes;
                      ^
/data1/dpdk-19.11/demo/memzone/main.c: At top level:
cc1: warning: unrecognized command line option "-Wno-address-of-packed-member" [enabled by default]
  LD TestMalloc
  INSTALL-APP TestMalloc
  INSTALL-MAP TestMalloc.map
[root@localhost memzone]#  build/app/TestMalloc 3  -c 0xff  
socket id 3 
EAL: Detected 128 lcore(s)
EAL: Detected 4 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'PA'
EAL: No available hugepages reported in hugepages-2048kB
 EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: PCI device 0000:05:00.0 on NUMA socket 0
EAL:   probe driver: 19e5:200 net_hinic
EAL:   using IOMMU type 1 (Type 1)
net_hinic: Initializing pf hinic-0000:05:00.0 in primary process
net_hinic: Device 0000:05:00.0 hwif attribute:
net_hinic: func_idx:0, p2p_idx:0, pciintf_idx:0, vf_in_pf:0, ppf_idx:0, global_vf_id:15, func_type:2
net_hinic: num_aeqs:4, num_ceqs:4, num_irqs:32, dma_attr:2
net_hinic: Get public resource capability:
net_hinic: host_id: 0x0, ep_id: 0x0, intr_type: 0x0, max_cos_id: 0x7, er_id: 0x0, port_id: 0x0
net_hinic: host_total_function: 0xf2, host_oq_id_mask_val: 0x8, max_vf: 0x78
net_hinic: pf_num: 0x2, pf_id_start: 0x0, vf_num: 0xf0, vf_id_start: 0x10
net_hinic: Get share resource capability:
net_hinic: host_pctxs: 0x0, host_cctxs: 0x0, host_scqs: 0x0, host_srqs: 0x0, host_mpts: 0x0
net_hinic: Get l2nic resource capability:
net_hinic: max_sqs: 0x10, max_rqs: 0x10, vf_max_sqs: 0x4, vf_max_rqs: 0x4
net_hinic: Initialize 0000:05:00.0 in primary successfully
EAL: PCI device 0000:06:00.0 on NUMA socket 0
EAL:   probe driver: 19e5:200 net_hinic
EAL: PCI device 0000:7d:00.0 on NUMA socket 0
EAL:   probe driver: 19e5:a222 net_hns3
EAL: PCI device 0000:7d:00.1 on NUMA socket 0
EAL:   probe driver: 19e5:a221 net_hns3
EAL: PCI device 0000:7d:00.2 on NUMA socket 0
EAL:   probe driver: 19e5:a222 net_hns3
EAL: PCI device 0000:7d:00.3 on NUMA socket 0
EAL:   probe driver: 19e5:a221 net_hns3
arr addr 3febb800 
Segmentation fault
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>

#include <rte_memory.h>
#include <rte_launch.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_debug.h>
//#include <rte_memzone.h>
#include <rte_malloc.h>
#include <unistd.h>
//#include "eal_private.h"
struct node {
  int a;
  int b;
};

int
main(int argc, char **argv)
{
        int num = 0;
        if (argc > 1)
        {
           num = atoi(argv[1]); 
        }
        printf("socket id %d 
 ", num);
        int *arr;
        int ret;
        struct node *nodes;
        ret = rte_eal_init(argc, argv);
        if (ret < 0)
                rte_panic("Cannot init EAL
");
        arr = rte_malloc("arr", sizeof(int) * 1024, 0);
        if (arr == NULL)
                rte_exit(EXIT_FAILURE, "Cannot malloc memory 
");
        printf("arr addr %llx 
 ",(long long) arr);
        arr[0] = 1000;
        rte_free(arr);
         /*
        nodes = rte_malloc_socket(NULL, sizeof(struct node) * 2, 0, num);
        nodes = rte_malloc(NULL, sizeof(*nodes), 0);
        if (NULL == nodes)
                rte_exit(EXIT_FAILURE, "Cannot malloc memory 
");
        printf("nodes addr %llx 
 ",(long long) nodes);
        FILE * fp = fopen ("rte_malloc.txt", "w+");
        rte_malloc_dump_heaps(fp);
        fclose(fp);
        nodes[0].a = 18 ;
        nodes[0].b = 24 ;
        printf("start to   free 
");
        rte_free(nodes);
        */
        getchar();
        return 0;
}
[root@localhost memzone]# make clean all
  CC main.o
/data1/dpdk-19.11/demo/memzone/main.c: In function ‘main’:
/data1/dpdk-19.11/demo/memzone/main.c:37:22: warning: unused variable ‘nodes’ [-Wunused-variable]
         struct node *nodes;
                      ^
/data1/dpdk-19.11/demo/memzone/main.c: At top level:
cc1: warning: unrecognized command line option "-Wno-address-of-packed-member" [enabled by default]
  LD TestMalloc
  INSTALL-APP TestMalloc
  INSTALL-MAP TestMalloc.map
[root@localhost memzone]#
[root@localhost memzone]#  build/app/TestMalloc 3  -c 0xff  
socket id 3 
EAL: Detected 128 lcore(s)
EAL: Detected 4 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'PA'
EAL: No available hugepages reported in hugepages-2048kB
 EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: PCI device 0000:05:00.0 on NUMA socket 0
EAL:   probe driver: 19e5:200 net_hinic
EAL:   using IOMMU type 1 (Type 1)
net_hinic: Initializing pf hinic-0000:05:00.0 in primary process
net_hinic: Device 0000:05:00.0 hwif attribute:
net_hinic: func_idx:0, p2p_idx:0, pciintf_idx:0, vf_in_pf:0, ppf_idx:0, global_vf_id:15, func_type:2
net_hinic: num_aeqs:4, num_ceqs:4, num_irqs:32, dma_attr:2
net_hinic: Get public resource capability:
net_hinic: host_id: 0x0, ep_id: 0x0, intr_type: 0x0, max_cos_id: 0x7, er_id: 0x0, port_id: 0x0
net_hinic: host_total_function: 0xf2, host_oq_id_mask_val: 0x8, max_vf: 0x78
net_hinic: pf_num: 0x2, pf_id_start: 0x0, vf_num: 0xf0, vf_id_start: 0x10
net_hinic: Get share resource capability:
net_hinic: host_pctxs: 0x0, host_cctxs: 0x0, host_scqs: 0x0, host_srqs: 0x0, host_mpts: 0x0
net_hinic: Get l2nic resource capability:
net_hinic: max_sqs: 0x10, max_rqs: 0x10, vf_max_sqs: 0x4, vf_max_rqs: 0x4
net_hinic: Initialize 0000:05:00.0 in primary successfully
EAL: PCI device 0000:06:00.0 on NUMA socket 0
EAL:   probe driver: 19e5:200 net_hinic
EAL: PCI device 0000:7d:00.0 on NUMA socket 0
EAL:   probe driver: 19e5:a222 net_hns3
EAL: PCI device 0000:7d:00.1 on NUMA socket 0
EAL:   probe driver: 19e5:a221 net_hns3
EAL: PCI device 0000:7d:00.2 on NUMA socket 0
EAL:   probe driver: 19e5:a222 net_hns3
EAL: PCI device 0000:7d:00.3 on NUMA socket 0
EAL:   probe driver: 19e5:a221 net_hns3
arr addr 13febb800 
原文地址:https://www.cnblogs.com/dream397/p/13600875.html