- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
- * 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
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- len = ms[memseg_idx].len;
- last_addr = ms[memseg_idx].addr;
+ /* align everything */
+ last_addr = RTE_PTR_ALIGN_CEIL(ms[memseg_idx].addr, CACHE_LINE_SIZE);
+ len = ms[memseg_idx].len - RTE_PTR_DIFF(last_addr, ms[memseg_idx].addr);
+ len &= ~((size_t) CACHE_LINE_MASK);
/* cycle through all memzones */
for (memzone_idx = 0; memzone_idx < RTE_MAX_MEMZONE; memzone_idx++) {
/* cycle through all memzones */
for (memzone_idx = 0; memzone_idx < RTE_MAX_MEMZONE; memzone_idx++) {
/* check if the memzone is in our memseg and subtract length */
if ((config->mem_config->memzone[memzone_idx].addr >=
ms[memseg_idx].addr) &&
/* check if the memzone is in our memseg and subtract length */
if ((config->mem_config->memzone[memzone_idx].addr >=
ms[memseg_idx].addr) &&
- (config->mem_config->memzone[memzone_idx].addr <=
- (RTE_PTR_ADD(ms[memseg_idx].addr,
- (size_t)ms[memseg_idx].len)))) {
+ (config->mem_config->memzone[memzone_idx].addr <
+ (RTE_PTR_ADD(ms[memseg_idx].addr, ms[memseg_idx].len)))) {
/* since the zones can now be aligned and occasionally skip
* some space, we should calculate the length based on
* reported length and start addresses difference. Addresses
* are allocated sequentially so we don't need to worry about
* them being in the right order.
*/
/* since the zones can now be aligned and occasionally skip
* some space, we should calculate the length based on
* reported length and start addresses difference. Addresses
* are allocated sequentially so we don't need to worry about
* them being in the right order.
*/
mz = rte_memzone_reserve("max_zone", 0, SOCKET_ID_ANY, 0);
if (mz == NULL){
printf("Failed to reserve a big chunk of memory\n");
mz = rte_memzone_reserve("max_zone", 0, SOCKET_ID_ANY, 0);
if (mz == NULL){
printf("Failed to reserve a big chunk of memory\n");
- len = ms[memseg_idx].len;
- last_addr = ms[memseg_idx].addr;
+ /* align everything */
+ last_addr = RTE_PTR_ALIGN_CEIL(ms[memseg_idx].addr, CACHE_LINE_SIZE);
+ len = ms[memseg_idx].len - RTE_PTR_DIFF(last_addr, ms[memseg_idx].addr);
+ len &= ~((size_t) CACHE_LINE_MASK);
/* cycle through all memzones */
for (memzone_idx = 0; memzone_idx < RTE_MAX_MEMZONE; memzone_idx++) {
/* cycle through all memzones */
for (memzone_idx = 0; memzone_idx < RTE_MAX_MEMZONE; memzone_idx++) {
/* check if the memzone is in our memseg and subtract length */
if ((config->mem_config->memzone[memzone_idx].addr >=
ms[memseg_idx].addr) &&
/* check if the memzone is in our memseg and subtract length */
if ((config->mem_config->memzone[memzone_idx].addr >=
ms[memseg_idx].addr) &&
- (config->mem_config->memzone[memzone_idx].addr <=
- (RTE_PTR_ADD(ms[memseg_idx].addr,
- (size_t) ms[memseg_idx].len)))) {
+ (config->mem_config->memzone[memzone_idx].addr <
+ (RTE_PTR_ADD(ms[memseg_idx].addr, ms[memseg_idx].len)))) {
/* since the zones can now be aligned and occasionally skip
* some space, we should calculate the length based on
* reported length and start addresses difference.
/* since the zones can now be aligned and occasionally skip
* some space, we should calculate the length based on
* reported length and start addresses difference.
- printf("Memzone reserve with 0 size and alignment 512 did not return"
- " bigest block\n");
- printf("Expected size = %" PRIu64 ", actual size = %" PRIu64 "\n",
+ printf("Memzone reserve with 0 size and alignment %u did not return"
+ " bigest block\n", align);
+ printf("Expected size = %zu, actual size = %zu\n",
if ((memzone_aligned_32->phys_addr & CACHE_LINE_MASK) != 0)
return -1;
if (((uintptr_t) memzone_aligned_32->addr & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_32->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_32->phys_addr & CACHE_LINE_MASK) != 0)
return -1;
if (((uintptr_t) memzone_aligned_32->addr & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_32->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_128->phys_addr & 127) != 0)
return -1;
if (((uintptr_t) memzone_aligned_128->addr & 127) != 0)
return -1;
if ((memzone_aligned_128->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_128->phys_addr & 127) != 0)
return -1;
if (((uintptr_t) memzone_aligned_128->addr & 127) != 0)
return -1;
if ((memzone_aligned_128->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_256->phys_addr & 255) != 0)
return -1;
if (((uintptr_t) memzone_aligned_256->addr & 255) != 0)
return -1;
if ((memzone_aligned_256->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_256->phys_addr & 255) != 0)
return -1;
if (((uintptr_t) memzone_aligned_256->addr & 255) != 0)
return -1;
if ((memzone_aligned_256->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_512->phys_addr & 511) != 0)
return -1;
if (((uintptr_t) memzone_aligned_512->addr & 511) != 0)
return -1;
if ((memzone_aligned_512->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_512->phys_addr & 511) != 0)
return -1;
if (((uintptr_t) memzone_aligned_512->addr & 511) != 0)
return -1;
if ((memzone_aligned_512->len & CACHE_LINE_MASK) != 0)
return -1;
if ((memzone_aligned_1024->phys_addr & 1023) != 0)
return -1;
if (((uintptr_t) memzone_aligned_1024->addr & 1023) != 0)
if ((memzone_aligned_1024->phys_addr & 1023) != 0)
return -1;
if (((uintptr_t) memzone_aligned_1024->addr & 1023) != 0)
/* check that zones don't overlap */
printf("check overlapping\n");
if (is_memory_overlap(memzone_aligned_32->phys_addr, memzone_aligned_32->len,
/* check that zones don't overlap */
printf("check overlapping\n");
if (is_memory_overlap(memzone_aligned_32->phys_addr, memzone_aligned_32->len,
printf("test reserving the largest size aligned memzone possible\n");
if (test_memzone_reserve_max_aligned() < 0)
return -1;
printf("test reserving the largest size aligned memzone possible\n");
if (test_memzone_reserve_max_aligned() < 0)
return -1;