4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/queue.h>
39 #include <rte_random.h>
40 #include <rte_cycles.h>
41 #include <rte_memory.h>
42 #include <rte_memzone.h>
44 #include <rte_eal_memconfig.h>
45 #include <rte_common.h>
46 #include <rte_string_fns.h>
47 #include <rte_errno.h>
48 #include <rte_malloc.h>
49 #include "../../lib/librte_eal/common/malloc_elem.h"
57 * - Search for three reserved zones or reserve them if they do not exist:
59 * - One is on any socket id.
60 * - The second is on socket 0.
61 * - The last one is on socket 1 (if socket 1 exists).
63 * - Check that the zones exist.
65 * - Check that the zones are cache-aligned.
67 * - Check that zones do not overlap.
69 * - Check that the zones are on the correct socket id.
71 * - Check that a lookup of the first zone returns the same pointer.
73 * - Check that it is not possible to create another zone with the
74 * same name as an existing zone.
76 * - Check flags for specific huge page size reservation
79 /* Test if memory overlaps: return 1 if true, or 0 if false. */
81 is_memory_overlap(phys_addr_t ptr1
, size_t len1
, phys_addr_t ptr2
, size_t len2
)
83 if (ptr2
>= ptr1
&& (ptr2
- ptr1
) < len1
)
85 else if (ptr2
< ptr1
&& (ptr1
- ptr2
) < len2
)
91 test_memzone_invalid_alignment(void)
93 const struct rte_memzone
* mz
;
95 mz
= rte_memzone_lookup("invalid_alignment");
97 printf("Zone with invalid alignment has been reserved\n");
101 mz
= rte_memzone_reserve_aligned("invalid_alignment", 100,
102 SOCKET_ID_ANY
, 0, 100);
104 printf("Zone with invalid alignment has been reserved\n");
111 test_memzone_reserving_zone_size_bigger_than_the_maximum(void)
113 const struct rte_memzone
* mz
;
115 mz
= rte_memzone_lookup("zone_size_bigger_than_the_maximum");
117 printf("zone_size_bigger_than_the_maximum has been reserved\n");
121 mz
= rte_memzone_reserve("zone_size_bigger_than_the_maximum", (size_t)-1,
124 printf("It is impossible to reserve such big a memzone\n");
132 test_memzone_reserve_flags(void)
134 const struct rte_memzone
*mz
;
135 const struct rte_memseg
*ms
;
136 int hugepage_2MB_avail
= 0;
137 int hugepage_1GB_avail
= 0;
138 int hugepage_16MB_avail
= 0;
139 int hugepage_16GB_avail
= 0;
140 const size_t size
= 100;
142 ms
= rte_eal_get_physmem_layout();
143 for (i
= 0; i
< RTE_MAX_MEMSEG
; i
++) {
144 if (ms
[i
].hugepage_sz
== RTE_PGSIZE_2M
)
145 hugepage_2MB_avail
= 1;
146 if (ms
[i
].hugepage_sz
== RTE_PGSIZE_1G
)
147 hugepage_1GB_avail
= 1;
148 if (ms
[i
].hugepage_sz
== RTE_PGSIZE_16M
)
149 hugepage_16MB_avail
= 1;
150 if (ms
[i
].hugepage_sz
== RTE_PGSIZE_16G
)
151 hugepage_16GB_avail
= 1;
153 /* Display the availability of 2MB ,1GB, 16MB, 16GB pages */
154 if (hugepage_2MB_avail
)
155 printf("2MB Huge pages available\n");
156 if (hugepage_1GB_avail
)
157 printf("1GB Huge pages available\n");
158 if (hugepage_16MB_avail
)
159 printf("16MB Huge pages available\n");
160 if (hugepage_16GB_avail
)
161 printf("16GB Huge pages available\n");
163 * If 2MB pages available, check that a small memzone is correctly
164 * reserved from 2MB huge pages when requested by the RTE_MEMZONE_2MB flag.
165 * Also check that RTE_MEMZONE_SIZE_HINT_ONLY flag only defaults to an
166 * available page size (i.e 1GB ) when 2MB pages are unavailable.
168 if (hugepage_2MB_avail
) {
169 mz
= rte_memzone_reserve("flag_zone_2M", size
, SOCKET_ID_ANY
,
172 printf("MEMZONE FLAG 2MB\n");
175 if (mz
->hugepage_sz
!= RTE_PGSIZE_2M
) {
176 printf("hugepage_sz not equal 2M\n");
180 mz
= rte_memzone_reserve("flag_zone_2M_HINT", size
, SOCKET_ID_ANY
,
181 RTE_MEMZONE_2MB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
183 printf("MEMZONE FLAG 2MB\n");
186 if (mz
->hugepage_sz
!= RTE_PGSIZE_2M
) {
187 printf("hugepage_sz not equal 2M\n");
191 /* Check if 1GB huge pages are unavailable, that function fails unless
192 * HINT flag is indicated
194 if (!hugepage_1GB_avail
) {
195 mz
= rte_memzone_reserve("flag_zone_1G_HINT", size
, SOCKET_ID_ANY
,
196 RTE_MEMZONE_1GB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
198 printf("MEMZONE FLAG 1GB & HINT\n");
201 if (mz
->hugepage_sz
!= RTE_PGSIZE_2M
) {
202 printf("hugepage_sz not equal 2M\n");
206 mz
= rte_memzone_reserve("flag_zone_1G", size
, SOCKET_ID_ANY
,
209 printf("MEMZONE FLAG 1GB\n");
215 /*As with 2MB tests above for 1GB huge page requests*/
216 if (hugepage_1GB_avail
) {
217 mz
= rte_memzone_reserve("flag_zone_1G", size
, SOCKET_ID_ANY
,
220 printf("MEMZONE FLAG 1GB\n");
223 if (mz
->hugepage_sz
!= RTE_PGSIZE_1G
) {
224 printf("hugepage_sz not equal 1G\n");
228 mz
= rte_memzone_reserve("flag_zone_1G_HINT", size
, SOCKET_ID_ANY
,
229 RTE_MEMZONE_1GB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
231 printf("MEMZONE FLAG 1GB\n");
234 if (mz
->hugepage_sz
!= RTE_PGSIZE_1G
) {
235 printf("hugepage_sz not equal 1G\n");
239 /* Check if 1GB huge pages are unavailable, that function fails unless
240 * HINT flag is indicated
242 if (!hugepage_2MB_avail
) {
243 mz
= rte_memzone_reserve("flag_zone_2M_HINT", size
, SOCKET_ID_ANY
,
244 RTE_MEMZONE_2MB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
246 printf("MEMZONE FLAG 2MB & HINT\n");
249 if (mz
->hugepage_sz
!= RTE_PGSIZE_1G
) {
250 printf("hugepage_sz not equal 1G\n");
253 mz
= rte_memzone_reserve("flag_zone_2M", size
, SOCKET_ID_ANY
,
256 printf("MEMZONE FLAG 2MB\n");
261 if (hugepage_2MB_avail
&& hugepage_1GB_avail
) {
262 mz
= rte_memzone_reserve("flag_zone_2M_HINT", size
, SOCKET_ID_ANY
,
263 RTE_MEMZONE_2MB
|RTE_MEMZONE_1GB
);
265 printf("BOTH SIZES SET\n");
271 * This option is for IBM Power. If 16MB pages available, check
272 * that a small memzone is correctly reserved from 16MB huge pages
273 * when requested by the RTE_MEMZONE_16MB flag. Also check that
274 * RTE_MEMZONE_SIZE_HINT_ONLY flag only defaults to an available
275 * page size (i.e 16GB ) when 16MB pages are unavailable.
277 if (hugepage_16MB_avail
) {
278 mz
= rte_memzone_reserve("flag_zone_16M", size
, SOCKET_ID_ANY
,
281 printf("MEMZONE FLAG 16MB\n");
284 if (mz
->hugepage_sz
!= RTE_PGSIZE_16M
) {
285 printf("hugepage_sz not equal 16M\n");
289 mz
= rte_memzone_reserve("flag_zone_16M_HINT", size
,
290 SOCKET_ID_ANY
, RTE_MEMZONE_16MB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
292 printf("MEMZONE FLAG 2MB\n");
295 if (mz
->hugepage_sz
!= RTE_PGSIZE_16M
) {
296 printf("hugepage_sz not equal 16M\n");
300 /* Check if 1GB huge pages are unavailable, that function fails
301 * unless HINT flag is indicated
303 if (!hugepage_16GB_avail
) {
304 mz
= rte_memzone_reserve("flag_zone_16G_HINT", size
,
306 RTE_MEMZONE_16GB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
308 printf("MEMZONE FLAG 16GB & HINT\n");
311 if (mz
->hugepage_sz
!= RTE_PGSIZE_16M
) {
312 printf("hugepage_sz not equal 16M\n");
316 mz
= rte_memzone_reserve("flag_zone_16G", size
,
317 SOCKET_ID_ANY
, RTE_MEMZONE_16GB
);
319 printf("MEMZONE FLAG 16GB\n");
324 /*As with 16MB tests above for 16GB huge page requests*/
325 if (hugepage_16GB_avail
) {
326 mz
= rte_memzone_reserve("flag_zone_16G", size
, SOCKET_ID_ANY
,
329 printf("MEMZONE FLAG 16GB\n");
332 if (mz
->hugepage_sz
!= RTE_PGSIZE_16G
) {
333 printf("hugepage_sz not equal 16G\n");
337 mz
= rte_memzone_reserve("flag_zone_16G_HINT", size
,
338 SOCKET_ID_ANY
, RTE_MEMZONE_16GB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
340 printf("MEMZONE FLAG 16GB\n");
343 if (mz
->hugepage_sz
!= RTE_PGSIZE_16G
) {
344 printf("hugepage_sz not equal 16G\n");
348 /* Check if 1GB huge pages are unavailable, that function fails
349 * unless HINT flag is indicated
351 if (!hugepage_16MB_avail
) {
352 mz
= rte_memzone_reserve("flag_zone_16M_HINT", size
,
354 RTE_MEMZONE_16MB
|RTE_MEMZONE_SIZE_HINT_ONLY
);
356 printf("MEMZONE FLAG 16MB & HINT\n");
359 if (mz
->hugepage_sz
!= RTE_PGSIZE_16G
) {
360 printf("hugepage_sz not equal 16G\n");
363 mz
= rte_memzone_reserve("flag_zone_16M", size
,
364 SOCKET_ID_ANY
, RTE_MEMZONE_16MB
);
366 printf("MEMZONE FLAG 16MB\n");
371 if (hugepage_16MB_avail
&& hugepage_16GB_avail
) {
372 mz
= rte_memzone_reserve("flag_zone_16M_HINT", size
,
374 RTE_MEMZONE_16MB
|RTE_MEMZONE_16GB
);
376 printf("BOTH SIZES SET\n");
385 /* Find the heap with the greatest free block size */
387 find_max_block_free_size(const unsigned _align
)
389 struct rte_malloc_socket_stats stats
;
390 unsigned i
, align
= _align
;
393 for (i
= 0; i
< RTE_MAX_NUMA_NODES
; i
++) {
394 rte_malloc_get_socket_stats(i
, &stats
);
395 if (stats
.greatest_free_size
> len
)
396 len
= stats
.greatest_free_size
;
399 if (align
< RTE_CACHE_LINE_SIZE
)
400 align
= RTE_CACHE_LINE_ROUNDUP(align
+1);
402 if (len
<= MALLOC_ELEM_OVERHEAD
+ align
)
405 return len
- MALLOC_ELEM_OVERHEAD
- align
;
409 test_memzone_reserve_max(void)
411 const struct rte_memzone
*mz
;
414 maxlen
= find_max_block_free_size(0);
417 printf("There is no space left!\n");
421 mz
= rte_memzone_reserve("max_zone", 0, SOCKET_ID_ANY
, 0);
423 printf("Failed to reserve a big chunk of memory - %s\n",
424 rte_strerror(rte_errno
));
425 rte_dump_physmem_layout(stdout
);
426 rte_memzone_dump(stdout
);
430 if (mz
->len
!= maxlen
) {
431 printf("Memzone reserve with 0 size did not return bigest block\n");
432 printf("Expected size = %zu, actual size = %zu\n", maxlen
, mz
->len
);
433 rte_dump_physmem_layout(stdout
);
434 rte_memzone_dump(stdout
);
441 test_memzone_reserve_max_aligned(void)
443 const struct rte_memzone
*mz
;
446 /* random alignment */
447 rte_srand((unsigned)rte_rdtsc());
448 const unsigned align
= 1 << ((rte_rand() % 8) + 5); /* from 128 up to 4k alignment */
450 maxlen
= find_max_block_free_size(align
);
453 printf("There is no space left for biggest %u-aligned memzone!\n", align
);
457 mz
= rte_memzone_reserve_aligned("max_zone_aligned", 0,
458 SOCKET_ID_ANY
, 0, align
);
460 printf("Failed to reserve a big chunk of memory - %s\n",
461 rte_strerror(rte_errno
));
462 rte_dump_physmem_layout(stdout
);
463 rte_memzone_dump(stdout
);
467 if (mz
->len
!= maxlen
) {
468 printf("Memzone reserve with 0 size and alignment %u did not return"
469 " bigest block\n", align
);
470 printf("Expected size = %zu, actual size = %zu\n",
472 rte_dump_physmem_layout(stdout
);
473 rte_memzone_dump(stdout
);
480 test_memzone_aligned(void)
482 const struct rte_memzone
*memzone_aligned_32
;
483 const struct rte_memzone
*memzone_aligned_128
;
484 const struct rte_memzone
*memzone_aligned_256
;
485 const struct rte_memzone
*memzone_aligned_512
;
486 const struct rte_memzone
*memzone_aligned_1024
;
488 /* memzone that should automatically be adjusted to align on 64 bytes */
489 memzone_aligned_32
= rte_memzone_reserve_aligned("aligned_32", 100,
490 SOCKET_ID_ANY
, 0, 32);
492 /* memzone that is supposed to be aligned on a 128 byte boundary */
493 memzone_aligned_128
= rte_memzone_reserve_aligned("aligned_128", 100,
494 SOCKET_ID_ANY
, 0, 128);
496 /* memzone that is supposed to be aligned on a 256 byte boundary */
497 memzone_aligned_256
= rte_memzone_reserve_aligned("aligned_256", 100,
498 SOCKET_ID_ANY
, 0, 256);
500 /* memzone that is supposed to be aligned on a 512 byte boundary */
501 memzone_aligned_512
= rte_memzone_reserve_aligned("aligned_512", 100,
502 SOCKET_ID_ANY
, 0, 512);
504 /* memzone that is supposed to be aligned on a 1024 byte boundary */
505 memzone_aligned_1024
= rte_memzone_reserve_aligned("aligned_1024", 100,
506 SOCKET_ID_ANY
, 0, 1024);
508 printf("check alignments and lengths\n");
509 if (memzone_aligned_32
== NULL
) {
510 printf("Unable to reserve 64-byte aligned memzone!\n");
513 if ((memzone_aligned_32
->phys_addr
& RTE_CACHE_LINE_MASK
) != 0)
515 if (((uintptr_t) memzone_aligned_32
->addr
& RTE_CACHE_LINE_MASK
) != 0)
517 if ((memzone_aligned_32
->len
& RTE_CACHE_LINE_MASK
) != 0)
520 if (memzone_aligned_128
== NULL
) {
521 printf("Unable to reserve 128-byte aligned memzone!\n");
524 if ((memzone_aligned_128
->phys_addr
& 127) != 0)
526 if (((uintptr_t) memzone_aligned_128
->addr
& 127) != 0)
528 if ((memzone_aligned_128
->len
& RTE_CACHE_LINE_MASK
) != 0)
531 if (memzone_aligned_256
== NULL
) {
532 printf("Unable to reserve 256-byte aligned memzone!\n");
535 if ((memzone_aligned_256
->phys_addr
& 255) != 0)
537 if (((uintptr_t) memzone_aligned_256
->addr
& 255) != 0)
539 if ((memzone_aligned_256
->len
& RTE_CACHE_LINE_MASK
) != 0)
542 if (memzone_aligned_512
== NULL
) {
543 printf("Unable to reserve 512-byte aligned memzone!\n");
546 if ((memzone_aligned_512
->phys_addr
& 511) != 0)
548 if (((uintptr_t) memzone_aligned_512
->addr
& 511) != 0)
550 if ((memzone_aligned_512
->len
& RTE_CACHE_LINE_MASK
) != 0)
553 if (memzone_aligned_1024
== NULL
) {
554 printf("Unable to reserve 1024-byte aligned memzone!\n");
557 if ((memzone_aligned_1024
->phys_addr
& 1023) != 0)
559 if (((uintptr_t) memzone_aligned_1024
->addr
& 1023) != 0)
561 if ((memzone_aligned_1024
->len
& RTE_CACHE_LINE_MASK
) != 0)
564 /* check that zones don't overlap */
565 printf("check overlapping\n");
566 if (is_memory_overlap(memzone_aligned_32
->phys_addr
, memzone_aligned_32
->len
,
567 memzone_aligned_128
->phys_addr
, memzone_aligned_128
->len
))
569 if (is_memory_overlap(memzone_aligned_32
->phys_addr
, memzone_aligned_32
->len
,
570 memzone_aligned_256
->phys_addr
, memzone_aligned_256
->len
))
572 if (is_memory_overlap(memzone_aligned_32
->phys_addr
, memzone_aligned_32
->len
,
573 memzone_aligned_512
->phys_addr
, memzone_aligned_512
->len
))
575 if (is_memory_overlap(memzone_aligned_32
->phys_addr
, memzone_aligned_32
->len
,
576 memzone_aligned_1024
->phys_addr
, memzone_aligned_1024
->len
))
578 if (is_memory_overlap(memzone_aligned_128
->phys_addr
, memzone_aligned_128
->len
,
579 memzone_aligned_256
->phys_addr
, memzone_aligned_256
->len
))
581 if (is_memory_overlap(memzone_aligned_128
->phys_addr
, memzone_aligned_128
->len
,
582 memzone_aligned_512
->phys_addr
, memzone_aligned_512
->len
))
584 if (is_memory_overlap(memzone_aligned_128
->phys_addr
, memzone_aligned_128
->len
,
585 memzone_aligned_1024
->phys_addr
, memzone_aligned_1024
->len
))
587 if (is_memory_overlap(memzone_aligned_256
->phys_addr
, memzone_aligned_256
->len
,
588 memzone_aligned_512
->phys_addr
, memzone_aligned_512
->len
))
590 if (is_memory_overlap(memzone_aligned_256
->phys_addr
, memzone_aligned_256
->len
,
591 memzone_aligned_1024
->phys_addr
, memzone_aligned_1024
->len
))
593 if (is_memory_overlap(memzone_aligned_512
->phys_addr
, memzone_aligned_512
->len
,
594 memzone_aligned_1024
->phys_addr
, memzone_aligned_1024
->len
))
600 check_memzone_bounded(const char *name
, uint32_t len
, uint32_t align
,
603 const struct rte_memzone
*mz
;
606 bmask
= ~((phys_addr_t
)bound
- 1);
608 if ((mz
= rte_memzone_reserve_bounded(name
, len
, SOCKET_ID_ANY
, 0,
609 align
, bound
)) == NULL
) {
610 printf("%s(%s): memzone creation failed\n",
615 if ((mz
->phys_addr
& ((phys_addr_t
)align
- 1)) != 0) {
616 printf("%s(%s): invalid phys addr alignment\n",
621 if (((uintptr_t) mz
->addr
& ((uintptr_t)align
- 1)) != 0) {
622 printf("%s(%s): invalid virtual addr alignment\n",
627 if ((mz
->len
& RTE_CACHE_LINE_MASK
) != 0 || mz
->len
< len
||
628 mz
->len
< RTE_CACHE_LINE_SIZE
) {
629 printf("%s(%s): invalid length\n",
634 if ((mz
->phys_addr
& bmask
) !=
635 ((mz
->phys_addr
+ mz
->len
- 1) & bmask
)) {
636 printf("%s(%s): invalid memzone boundary %u crossed\n",
637 __func__
, mz
->name
, bound
);
645 test_memzone_bounded(void)
647 const struct rte_memzone
*memzone_err
;
651 /* should fail as boundary is not power of two */
652 name
= "bounded_error_31";
653 if ((memzone_err
= rte_memzone_reserve_bounded(name
,
654 100, SOCKET_ID_ANY
, 0, 32, UINT32_MAX
)) != NULL
) {
655 printf("%s(%s)created a memzone with invalid boundary "
656 "conditions\n", __func__
, memzone_err
->name
);
660 /* should fail as len is greater then boundary */
661 name
= "bounded_error_32";
662 if ((memzone_err
= rte_memzone_reserve_bounded(name
,
663 100, SOCKET_ID_ANY
, 0, 32, 32)) != NULL
) {
664 printf("%s(%s)created a memzone with invalid boundary "
665 "conditions\n", __func__
, memzone_err
->name
);
669 if ((rc
= check_memzone_bounded("bounded_128", 100, 128, 128)) != 0)
672 if ((rc
= check_memzone_bounded("bounded_256", 100, 256, 128)) != 0)
675 if ((rc
= check_memzone_bounded("bounded_1K", 100, 64, 1024)) != 0)
678 if ((rc
= check_memzone_bounded("bounded_1K_MAX", 0, 64, 1024)) != 0)
685 test_memzone_free(void)
687 const struct rte_memzone
*mz
[RTE_MAX_MEMZONE
];
691 mz
[0] = rte_memzone_reserve("tempzone0", 2000, SOCKET_ID_ANY
, 0);
692 mz
[1] = rte_memzone_reserve("tempzone1", 4000, SOCKET_ID_ANY
, 0);
696 if (!rte_memzone_lookup("tempzone0"))
698 if (!rte_memzone_lookup("tempzone1"))
701 if (rte_memzone_free(mz
[0])) {
702 printf("Fail memzone free - tempzone0\n");
705 if (rte_memzone_lookup("tempzone0")) {
706 printf("Found previously free memzone - tempzone0\n");
709 mz
[2] = rte_memzone_reserve("tempzone2", 2000, SOCKET_ID_ANY
, 0);
712 printf("tempzone2 should have gotten the free entry from tempzone0\n");
715 if (rte_memzone_free(mz
[2])) {
716 printf("Fail memzone free - tempzone2\n");
719 if (rte_memzone_lookup("tempzone2")) {
720 printf("Found previously free memzone - tempzone2\n");
723 if (rte_memzone_free(mz
[1])) {
724 printf("Fail memzone free - tempzone1\n");
727 if (rte_memzone_lookup("tempzone1")) {
728 printf("Found previously free memzone - tempzone1\n");
734 snprintf(name
, sizeof(name
), "tempzone%u", i
);
735 mz
[i
] = rte_memzone_reserve(name
, 1, SOCKET_ID_ANY
, 0);
736 } while (mz
[i
++] != NULL
);
738 if (rte_memzone_free(mz
[0])) {
739 printf("Fail memzone free - tempzone0\n");
742 mz
[0] = rte_memzone_reserve("tempzone0new", 0, SOCKET_ID_ANY
, 0);
745 printf("Fail to create memzone - tempzone0new - when MAX memzones were "
746 "created and one was free\n");
750 for (i
= i
- 2; i
>= 0; i
--) {
751 if (rte_memzone_free(mz
[i
])) {
752 printf("Fail memzone free - tempzone%d\n", i
);
763 const struct rte_memzone
*memzone1
;
764 const struct rte_memzone
*memzone2
;
765 const struct rte_memzone
*memzone3
;
766 const struct rte_memzone
*memzone4
;
767 const struct rte_memzone
*mz
;
769 memzone1
= rte_memzone_reserve("testzone1", 100,
772 memzone2
= rte_memzone_reserve("testzone2", 1000,
775 memzone3
= rte_memzone_reserve("testzone3", 1000,
778 memzone4
= rte_memzone_reserve("testzone4", 1024,
781 /* memzone3 may be NULL if we don't have NUMA */
782 if (memzone1
== NULL
|| memzone2
== NULL
|| memzone4
== NULL
)
785 rte_memzone_dump(stdout
);
787 /* check cache-line alignments */
788 printf("check alignments and lengths\n");
790 if ((memzone1
->phys_addr
& RTE_CACHE_LINE_MASK
) != 0)
792 if ((memzone2
->phys_addr
& RTE_CACHE_LINE_MASK
) != 0)
794 if (memzone3
!= NULL
&& (memzone3
->phys_addr
& RTE_CACHE_LINE_MASK
) != 0)
796 if ((memzone1
->len
& RTE_CACHE_LINE_MASK
) != 0 || memzone1
->len
== 0)
798 if ((memzone2
->len
& RTE_CACHE_LINE_MASK
) != 0 || memzone2
->len
== 0)
800 if (memzone3
!= NULL
&& ((memzone3
->len
& RTE_CACHE_LINE_MASK
) != 0 ||
803 if (memzone4
->len
!= 1024)
806 /* check that zones don't overlap */
807 printf("check overlapping\n");
809 if (is_memory_overlap(memzone1
->phys_addr
, memzone1
->len
,
810 memzone2
->phys_addr
, memzone2
->len
))
812 if (memzone3
!= NULL
&&
813 is_memory_overlap(memzone1
->phys_addr
, memzone1
->len
,
814 memzone3
->phys_addr
, memzone3
->len
))
816 if (memzone3
!= NULL
&&
817 is_memory_overlap(memzone2
->phys_addr
, memzone2
->len
,
818 memzone3
->phys_addr
, memzone3
->len
))
821 printf("check socket ID\n");
823 /* memzone2 must be on socket id 0 and memzone3 on socket 1 */
824 if (memzone2
->socket_id
!= 0)
826 if (memzone3
!= NULL
&& memzone3
->socket_id
!= 1)
829 printf("test zone lookup\n");
830 mz
= rte_memzone_lookup("testzone1");
834 printf("test duplcate zone name\n");
835 mz
= rte_memzone_reserve("testzone1", 100,
840 printf("test free memzone\n");
841 if (test_memzone_free() < 0)
844 printf("test reserving memzone with bigger size than the maximum\n");
845 if (test_memzone_reserving_zone_size_bigger_than_the_maximum() < 0)
848 printf("test memzone_reserve flags\n");
849 if (test_memzone_reserve_flags() < 0)
852 printf("test alignment for memzone_reserve\n");
853 if (test_memzone_aligned() < 0)
856 printf("test boundary alignment for memzone_reserve\n");
857 if (test_memzone_bounded() < 0)
860 printf("test invalid alignment for memzone_reserve\n");
861 if (test_memzone_invalid_alignment() < 0)
864 printf("test reserving the largest size memzone possible\n");
865 if (test_memzone_reserve_max() < 0)
868 printf("test reserving the largest size aligned memzone possible\n");
869 if (test_memzone_reserve_max_aligned() < 0)
875 REGISTER_TEST_COMMAND(memzone_autotest
, test_memzone
);