X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Flinuxapp%2Feal%2Feal_xen_memory.c;h=19db1cb5fde56a43c4f4fd8bbb9c6af228535041;hb=31850d26850e59cb20cdb84a8048d9f501f3cb22;hp=c7d709c08e079eec82f52b98beacaff432ed6244;hpb=c738c6a644e5a07fa98ede668775c08ec5321273;p=dpdk.git diff --git a/lib/librte_eal/linuxapp/eal/eal_xen_memory.c b/lib/librte_eal/linuxapp/eal/eal_xen_memory.c index c7d709c08e..19db1cb5fd 100644 --- a/lib/librte_eal/linuxapp/eal/eal_xen_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_xen_memory.c @@ -1,13 +1,13 @@ /*- * BSD LICENSE - * + * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -46,7 +45,6 @@ #include #include #include -#include #include #include @@ -54,7 +52,6 @@ #include #include #include -#include #include #include #include @@ -68,7 +65,7 @@ #include #define PAGE_SIZE RTE_PGSIZE_4K -#define DEFAUL_DOM0_NAME "dom0-mem" +#define DEFAUL_DOM0_NAME "dom0-mem" static int xen_fd = -1; static const char sys_dir_path[] = "/sys/kernel/mm/dom0-mm/memsize-mB"; @@ -87,7 +84,7 @@ xen_get_virtual_area(size_t *size, size_t mem_size) int fd; long aligned_addr; - RTE_LOG(INFO, EAL, "Ask a virtual area of 0x%zu bytes\n", *size); + RTE_LOG(DEBUG, EAL, "Ask a virtual area of 0x%zu bytes\n", *size); fd = open("/dev/zero", O_RDONLY); if (fd < 0){ @@ -103,7 +100,7 @@ xen_get_virtual_area(size_t *size, size_t mem_size) if (addr == MAP_FAILED) { close(fd); - RTE_LOG(INFO, EAL, "Cannot get a virtual area\n"); + RTE_LOG(ERR, EAL, "Cannot get a virtual area\n"); return NULL; } @@ -115,7 +112,7 @@ xen_get_virtual_area(size_t *size, size_t mem_size) aligned_addr = RTE_ALIGN_CEIL(aligned_addr, mem_size); addr = (void *)(aligned_addr); - RTE_LOG(INFO, EAL, "Virtual area found at %p (size = 0x%zx)\n", + RTE_LOG(DEBUG, EAL, "Virtual area found at %p (size = 0x%zx)\n", addr, *size); return addr; @@ -133,13 +130,13 @@ get_xen_memory_size(void) static const char *file_name; file_name = "memsize"; - rte_snprintf(path, sizeof(path), "%s/%s", + snprintf(path, sizeof(path), "%s/%s", sys_dir_path, file_name); if (eal_parse_sysfs_value(path, &mem_size) < 0) return -1; - if (mem_size == 0) + if (mem_size == 0) rte_exit(EXIT_FAILURE,"XEN-DOM0:the %s/%s was not" " configured.\n",sys_dir_path, file_name); if (mem_size % 2) @@ -149,7 +146,7 @@ get_xen_memory_size(void) if (mem_size > DOM0_CONFIG_MEMSIZE) rte_exit(EXIT_FAILURE,"XEN-DOM0:the %s/%s should not be larger" " than %d mB\n",sys_dir_path, file_name, DOM0_CONFIG_MEMSIZE); - + return mem_size; } @@ -157,25 +154,39 @@ get_xen_memory_size(void) * Based on physical address to caculate MFN in Xen Dom0. */ phys_addr_t -rte_mem_phy2mch(uint32_t memseg_id, const phys_addr_t phy_addr) +rte_xen_mem_phy2mch(int32_t memseg_id, const phys_addr_t phy_addr) { - int mfn_id; + int mfn_id, i; uint64_t mfn, mfn_offset; struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; struct rte_memseg *memseg = mcfg->memseg; + /* find the memory segment owning the physical address */ + if (memseg_id == -1) { + for (i = 0; i < RTE_MAX_MEMSEG; i++) { + if ((phy_addr >= memseg[i].phys_addr) && + (phy_addr < memseg[i].phys_addr + + memseg[i].len)) { + memseg_id = i; + break; + } + } + if (memseg_id == -1) + return RTE_BAD_PHYS_ADDR; + } + mfn_id = (phy_addr - memseg[memseg_id].phys_addr) / RTE_PGSIZE_2M; /*the MFN is contiguous in 2M */ - mfn_offset = (phy_addr - memseg[memseg_id].phys_addr) % + mfn_offset = (phy_addr - memseg[memseg_id].phys_addr) % RTE_PGSIZE_2M / PAGE_SIZE; - mfn = mfn_offset + memseg[memseg_id].mfn[mfn_id]; - + mfn = mfn_offset + memseg[memseg_id].mfn[mfn_id]; + /** return mechine address */ - return (mfn * PAGE_SIZE + phy_addr % PAGE_SIZE); + return mfn * PAGE_SIZE + phy_addr % PAGE_SIZE; } -int +int rte_xen_dom0_memory_init(void) { void *vir_addr, *vma_addr = NULL; @@ -198,8 +209,8 @@ rte_xen_dom0_memory_init(void) /* if we didn't satisfy total memory requirements */ rte_exit(EXIT_FAILURE,"Not enough memory available! Requested: %uMB," " available: %uMB\n", requested, mem_size); - else if (total_mem != 0) - mem_size = requested; + else if (total_mem != 0) + mem_size = requested; /* Check FD and open once */ if (xen_fd < 0) { @@ -213,7 +224,7 @@ rte_xen_dom0_memory_init(void) meminfo.size = mem_size; /* construct memory mangement name for Dom0 */ - rte_snprintf(meminfo.name, DOM0_NAME_MAX, "%s-%s", + snprintf(meminfo.name, DOM0_NAME_MAX, "%s-%s", internal_config.hugefile_prefix, DEFAUL_DOM0_NAME); /* Notify kernel driver to allocate memory */ @@ -239,7 +250,7 @@ rte_xen_dom0_memory_init(void) goto fail; } - /* get all memory segements information */ + /* get all memory segements information */ ret = ioctl(xen_fd, RTE_DOM0_IOCTL_GET_MEMSEG_INFO, seginfo); if (ret < 0) { RTE_LOG(ERR, EAL, "XEN DOM0:failed to get memseg info.\n"); @@ -251,11 +262,11 @@ rte_xen_dom0_memory_init(void) for (memseg_idx = 0; memseg_idx < num_memseg; memseg_idx++) { vma_len = seginfo[memseg_idx].size; - - /** - * get the biggest virtual memory area up to vma_len. If it fails, - * vma_addr is NULL, so let the kernel provide the address. - */ + + /** + * get the biggest virtual memory area up to vma_len. If it fails, + * vma_addr is NULL, so let the kernel provide the address. + */ vma_addr = xen_get_virtual_area(&vma_len, RTE_PGSIZE_2M); if (vma_addr == NULL) { flags = MAP_SHARED; @@ -265,7 +276,7 @@ rte_xen_dom0_memory_init(void) seginfo[memseg_idx].size = vma_len; vir_addr = mmap(vma_addr, seginfo[memseg_idx].size, - PROT_READ|PROT_WRITE, flags, xen_fd, + PROT_READ|PROT_WRITE, flags, xen_fd, memseg_idx * page_size); if (vir_addr == MAP_FAILED) { RTE_LOG(ERR, EAL, "XEN DOM0:Could not mmap %s\n", @@ -275,10 +286,10 @@ rte_xen_dom0_memory_init(void) } memseg[memseg_idx].addr = vir_addr; - memseg[memseg_idx].phys_addr = page_size * + memseg[memseg_idx].phys_addr = page_size * seginfo[memseg_idx].pfn ; memseg[memseg_idx].len = seginfo[memseg_idx].size; - for ( i = 0; i < seginfo[memseg_idx].size / RTE_PGSIZE_2M; i++) + for ( i = 0; i < seginfo[memseg_idx].size / RTE_PGSIZE_2M; i++) memseg[memseg_idx].mfn[i] = seginfo[memseg_idx].mfn[i]; /* MFNs are continuous in 2M, so assume that page size is 2M */ @@ -295,7 +306,7 @@ rte_xen_dom0_memory_init(void) fail: if (xen_fd > 0) { close(xen_fd); - xen_fd = -1; + xen_fd = -1; } return err; } @@ -303,7 +314,7 @@ fail: /* * This creates the memory mappings in the secondary process to match that of * the server process. It goes through each memory segment in the DPDK runtime - * configuration, mapping them in order to form a contiguous block in the + * configuration, mapping them in order to form a contiguous block in the * virtual memory space */ int @@ -311,7 +322,7 @@ rte_xen_dom0_memory_attach(void) { const struct rte_mem_config *mcfg; unsigned s = 0; /* s used to track the segment number */ - int xen_fd = -1; + int xen_fd = -1; int ret = -1; void *vir_addr; char name[DOM0_NAME_MAX] = {0}; @@ -327,9 +338,9 @@ rte_xen_dom0_memory_attach(void) goto error; } } - + /* construct memory mangement name for Dom0 */ - rte_snprintf(name, DOM0_NAME_MAX, "%s-%s", + snprintf(name, DOM0_NAME_MAX, "%s-%s", internal_config.hugefile_prefix, DEFAUL_DOM0_NAME); /* attach to memory segments of primary process */ ret = ioctl(xen_fd, RTE_DOM0_IOCTL_ATTACH_TO_MEMSEG, name); @@ -356,7 +367,7 @@ rte_xen_dom0_memory_attach(void) "in %s to requested address [%p]\n", (unsigned long long)mcfg->memseg[s].len, DOM0_MM_DEV, mcfg->memseg[s].addr); - goto error; + goto error; } } return 0;