ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

dpdk rte_memzone_reserve

2020-09-01 16:01:09  阅读:348  来源: 互联网

标签:rte addr socket net reserve id memzone EAL


 

/* 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

 

标签:rte,addr,socket,net,reserve,id,memzone,EAL
来源: https://www.cnblogs.com/dream397/p/13596697.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有