dpdk rte_memzone_reserve

 

/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2014 Intel Corporation
 */

#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 <unistd.h>
#include "eal_private.h"
static int
lcore_hello(__attribute__((unused)) void *arg)
{
        unsigned lcore_id,  socket_id;
        lcore_id = rte_lcore_id();
        socket_id = rte_socket_id();
        printf("hello from core %u\n", lcore_id);
        printf("socket id  %u\n", socket_id);
        sleep(60); 
        return 0;
}

int
main(int argc, char **argv)
{
        int ret;
        unsigned lcore_id;
        const struct rte_memzone *mz;
        int *arr;
        ret = rte_eal_init(argc, argv);
        if (ret < 0)
                rte_panic("Cannot init EAL\n");
        
        if (rte_eal_process_type() == RTE_PROC_PRIMARY){
             mz = rte_memzone_reserve("memzone", sizeof(int)*2,
                                SOCKET_ID_ANY, 0);
        }
        else {
             mz = rte_memzone_lookup("memzone"); 
        }
        if (mz == NULL)
                rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n");

        printf("mz addr: %llx, mz->addr :%llx , mz->addr_64 : %llx\n", (long long)mz, (long long)(mz->addr), mz->addr_64);
        printf("arr addr: %llx \n", (unsigned long long)(&arr));
        arr = (int *)rte_malloc("arr", sizeof(int) * 1024, 0);
        //arr = (int *)rte_malloc(NULL, sizeof(int) * 1024, 0);
        if (arr == NULL)
                rte_exit(EXIT_FAILURE, "Cannot malloc memory \n");
        printf("arr addr: %llx \n", (unsigned long long)arr);
        /* call lcore_hello() on every slave lcore */
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
                rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
        }
        if (rte_eal_process_type() == RTE_PROC_PRIMARY){

            ((int *)(mz->addr))[0] =9999;
        }
        else {
             printf("(mz->addr)[0] : %d \n", ((int*)(mz->addr))[0]);
        }
        //arr[0]=4;
        /* call it on master lcore too */
        lcore_hello(NULL);
        struct rte_config *tmp_config;
        tmp_config=rte_eal_get_configuration();
        printf("rte_config addr : %llx \n", (unsigned long long )tmp_config);
        rte_eal_mp_wait_lcore();
        //rte_free(arr);
        return 0;
}

 

[root@localhost memzone]# build/app/helloworld -c 0xf -n 4 --proc-type=primary
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: 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
mz addr: 100012838, mz->addr :42002bc780 , mz->addr_64 : 42002bc780
arr addr: ffffe08a5768 
arr addr: 2bb700 
hello from core 1
socket id  0
hello from core 2
socket id  0
hello from core 0
socket id  0
hello from core 3
socket id  0
rte_config addr : affea8 

 

[root@localhost memzone]# build/app/helloworld -c 0xf -n 4 --proc-type=secondary
EAL: Detected 128 lcore(s)
EAL: Detected 4 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_62051_36199956461d
EAL: Selected IOVA mode 'PA'
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 secondary process
net_hinic: Initialize 0000:05:00.0 in secondary process
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
mz addr: 100012838, mz->addr :42002bc780 , mz->addr_64 : 42002bc780
arr addr: ffffdb1b7d98 
arr addr: 290580 
hello from core 1
socket id  0
hello from core 2
socket id  0
(mz->addr)[0] : 9999 
hello from core 0
socket id  0
hello from core 3
socket id  0
rte_config addr : affea8

 

posted on 2020-09-01 16:00  tycoon3  阅读(407)  评论(0编辑  收藏  举报

导航