X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fcommon%2Feal_common_memzone.c;h=b5a5d7274f99f891e90427ff070f45030b063df9;hb=fdf20fa7bee9df9037116318a87080e1eb7e757e;hp=4d60f8c04ad61d5862abc1867c6b8bfbbd025b49;hpb=013615a784c18582d32e2a702049783c68801f6c;p=dpdk.git diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 4d60f8c04a..b5a5d7274f 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.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 @@ -70,7 +70,7 @@ memzone_lookup_thread_unsafe(const char *name) * zones and this function should be called at init only */ for (i = 0; i < RTE_MAX_MEMZONE && mcfg->memzone[i].addr != NULL; i++) { - if (!strncmp(name, mcfg->memzone[i].name, RTE_MEMZONE_NAMESIZE)) + if (!strncmp(name, mcfg->memzone[i].name, RTE_MEMZONE_NAMESIZE)) return &mcfg->memzone[i]; } @@ -86,7 +86,7 @@ rte_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags) { return rte_memzone_reserve_aligned(name, - len, socket_id, flags, CACHE_LINE_SIZE); + len, socket_id, flags, RTE_CACHE_LINE_SIZE); } /* @@ -164,21 +164,21 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, } /* alignment less than cache size is not allowed */ - if (align < CACHE_LINE_SIZE) - align = CACHE_LINE_SIZE; + if (align < RTE_CACHE_LINE_SIZE) + align = RTE_CACHE_LINE_SIZE; /* align length on cache boundary. Check for overflow before doing so */ - if (len > SIZE_MAX - CACHE_LINE_MASK) { + if (len > SIZE_MAX - RTE_CACHE_LINE_MASK) { rte_errno = EINVAL; /* requested size too big */ return NULL; } - len += CACHE_LINE_MASK; - len &= ~((size_t) CACHE_LINE_MASK); + len += RTE_CACHE_LINE_MASK; + len &= ~((size_t) RTE_CACHE_LINE_MASK); /* save minimal requested length */ - requested_len = RTE_MAX((size_t)CACHE_LINE_SIZE, len); + requested_len = RTE_MAX((size_t)RTE_CACHE_LINE_SIZE, len); /* check that boundary condition is valid */ if (bound != 0 && @@ -199,6 +199,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* bad socket ID */ if (socket_id != SOCKET_ID_ANY && + free_memseg[i].socket_id != SOCKET_ID_ANY && socket_id != free_memseg[i].socket_id) continue; @@ -215,10 +216,16 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* check flags for hugepage sizes */ if ((flags & RTE_MEMZONE_2MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_1G ) + free_memseg[i].hugepage_sz == RTE_PGSIZE_1G) continue; if ((flags & RTE_MEMZONE_1GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_2M ) + free_memseg[i].hugepage_sz == RTE_PGSIZE_2M) + continue; + if ((flags & RTE_MEMZONE_16MB) && + free_memseg[i].hugepage_sz == RTE_PGSIZE_16G) + continue; + if ((flags & RTE_MEMZONE_16GB) && + free_memseg[i].hugepage_sz == RTE_PGSIZE_16M) continue; /* this segment is the best until now */ @@ -255,13 +262,11 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, * try allocating again without the size parameter otherwise -fail. */ if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) && - ((flags & RTE_MEMZONE_1GB) || (flags & RTE_MEMZONE_2MB))) + ((flags & RTE_MEMZONE_1GB) || (flags & RTE_MEMZONE_2MB) + || (flags & RTE_MEMZONE_16MB) || (flags & RTE_MEMZONE_16GB))) return memzone_reserve_aligned_thread_unsafe(name, len, socket_id, 0, align, bound); - RTE_LOG(ERR, EAL, "%s(%s, %zu, %d): " - "No appropriate segment found\n", - __func__, name, requested_len, socket_id); rte_errno = ENOMEM; return NULL; } @@ -291,7 +296,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* fill the zone in config */ struct rte_memzone *mz = &mcfg->memzone[mcfg->memzone_idx++]; - rte_snprintf(mz->name, sizeof(mz->name), "%s", name); + snprintf(mz->name, sizeof(mz->name), "%s", name); mz->phys_addr = memseg_physaddr; mz->addr = memseg_addr; mz->len = requested_len; @@ -315,7 +320,8 @@ rte_memzone_reserve_aligned(const char *name, size_t len, const struct rte_memzone *mz = NULL; /* both sizes cannot be explicitly called for */ - if ((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) { + if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) + || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { rte_errno = EINVAL; return NULL; } @@ -346,7 +352,8 @@ rte_memzone_reserve_bounded(const char *name, size_t len, const struct rte_memzone *mz = NULL; /* both sizes cannot be explicitly called for */ - if ((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) { + if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) + || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { rte_errno = EINVAL; return NULL; } @@ -375,7 +382,7 @@ rte_memzone_lookup(const char *name) const struct rte_memzone *memzone = NULL; mcfg = rte_eal_get_configuration()->mem_config; - + rte_rwlock_read_lock(&mcfg->mlock); memzone = memzone_lookup_thread_unsafe(name); @@ -387,7 +394,7 @@ rte_memzone_lookup(const char *name) /* Dump all reserved memory zones on console */ void -rte_memzone_dump(void) +rte_memzone_dump(FILE *f) { struct rte_mem_config *mcfg; unsigned i = 0; @@ -400,7 +407,7 @@ rte_memzone_dump(void) for (i=0; imemzone[i].addr == NULL) break; - printf("Zone %u: name:<%s>, phys:0x%"PRIx64", len:0x%zx" + fprintf(f, "Zone %u: name:<%s>, phys:0x%"PRIx64", len:0x%zx" ", virt:%p, socket_id:%"PRId32", flags:%"PRIx32"\n", i, mcfg->memzone[i].name, mcfg->memzone[i].phys_addr, @@ -423,8 +430,8 @@ memseg_sanitize(struct rte_memseg *memseg) unsigned virt_align; unsigned off; - phys_align = memseg->phys_addr & CACHE_LINE_MASK; - virt_align = (unsigned long)memseg->addr & CACHE_LINE_MASK; + phys_align = memseg->phys_addr & RTE_CACHE_LINE_MASK; + virt_align = (unsigned long)memseg->addr & RTE_CACHE_LINE_MASK; /* * sanity check: phys_addr and addr must have the same @@ -434,19 +441,19 @@ memseg_sanitize(struct rte_memseg *memseg) return -1; /* memseg is really too small, don't bother with it */ - if (memseg->len < (2 * CACHE_LINE_SIZE)) { + if (memseg->len < (2 * RTE_CACHE_LINE_SIZE)) { memseg->len = 0; return 0; } /* align start address */ - off = (CACHE_LINE_SIZE - phys_align) & CACHE_LINE_MASK; + off = (RTE_CACHE_LINE_SIZE - phys_align) & RTE_CACHE_LINE_MASK; memseg->phys_addr += off; memseg->addr = (char *)memseg->addr + off; memseg->len -= off; /* align end address */ - memseg->len &= ~((uint64_t)CACHE_LINE_MASK); + memseg->len &= ~((uint64_t)RTE_CACHE_LINE_MASK); return 0; } @@ -466,7 +473,7 @@ rte_eal_memzone_init(void) /* mirror the runtime memsegs from config */ free_memseg = mcfg->free_memseg; - + /* secondary processes don't need to initialise anything */ if (rte_eal_process_type() == RTE_PROC_SECONDARY) return 0; @@ -479,11 +486,17 @@ rte_eal_memzone_init(void) rte_rwlock_write_lock(&mcfg->mlock); - /* duplicate the memsegs from config */ - memcpy(free_memseg, memseg, sizeof(struct rte_memseg) * RTE_MAX_MEMSEG); + /* fill in uninitialized free_memsegs */ + for (i = 0; i < RTE_MAX_MEMSEG; i++) { + if (memseg[i].addr == NULL) + break; + if (free_memseg[i].addr != NULL) + continue; + memcpy(&free_memseg[i], &memseg[i], sizeof(struct rte_memseg)); + } /* make all zones cache-aligned */ - for (i=0; imem_config; + + rte_rwlock_read_lock(&mcfg->mlock); + for (i=0; imemzone[i].addr != NULL) + (*func)(&mcfg->memzone[i], arg); + } + rte_rwlock_read_unlock(&mcfg->mlock); +}