rte_fbarray_init
rte_fbarray_init
eal_get_fbarray_path(path, sizeof(path), name); /* * Each fbarray is unique to process namespace, i.e. the * filename depends on process prefix. Try to take out a lock * and see if we succeed. If we don't, someone else is using it * already. */ fd = open(path, O_CREAT | O_RDWR, 0600);
rte_fbarray_init data = eal_get_virtual_area(NULL, &mmap_len, page_sz, 0, 0); eal_get_fbarray_path(path, sizeof(path), name); fd = open(path, O_CREAT | O_RDWR, 0600); resize_and_map(fd, data, mmap_len) arr->data = data;
void * eal_get_virtual_area(void *requested_addr, size_t *size, size_t page_sz, int flags, int mmap_flags) { /* ... */ /* 映射虚拟地址 */ mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ, mmap_flags, -1, 0); /* 经过了简化,去除了地址对齐 */ aligned_addr = mapped_addr : /* 如果 `requested_addr` 和 `aligned_addr` 不匹配。则提示出错 */ if (requested_addr != NULL && aligned_addr != requested_addr) { RTE_LOG(ERR, EAL, "Cannot get a virtual area at requested address: %p (got %p)\n", requested_addr, aligned_addr); munmap(mapped_addr, map_sz); rte_errno = EADDRNOTAVAIL; return NULL; } return aligned_addr; }
[root@localhost memzone]# gdb build/app/TestMalloc GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "aarch64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /data1/dpdk-19.11/demo/memzone/build/app/TestMalloc...done. (gdb) b /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:713 Breakpoint 1 at 0x5afeac: file /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c, line 713. (gdb) set args 3 -c 0xf (gdb) r Starting program: /data1/dpdk-19.11/demo/memzone/build/app/TestMalloc 3 -c 0xf [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". EAL: Detected 128 lcore(s) EAL: Detected 4 NUMA nodes [New Thread 0xffffbe43d910 (LWP 129851)] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [New Thread 0xffffbdc2d910 (LWP 129852)] EAL: Selected IOVA mode 'PA' EAL: No available hugepages reported in hugepages-2048kB EAL: Probing VFIO support... EAL: VFIO support initialized Breakpoint 1, rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) bt #0 rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 #1 0x000000000059f2c8 in rte_eal_memzone_init () at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_memzone.c:376 #2 0x000000000058a5a8 in rte_eal_init (argc=4, argv=0xfffffffff518) at /data1/dpdk-19.11/lib/librte_eal/linux/eal/eal.c:1170 #3 0x0000000000464d24 in main (argc=4, argv=0xfffffffff518) at /data1/dpdk-19.11/demo/memzone/main.c:40 (gdb)
rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, unsigned int elt_sz)
Breakpoint 1, rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) bt #0 rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 #1 0x000000000059f2c8 in rte_eal_memzone_init () at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_memzone.c:376 #2 0x000000000058a5a8 in rte_eal_init (argc=4, argv=0xfffffffff518) at /data1/dpdk-19.11/lib/librte_eal/linux/eal/eal.c:1170 #3 0x0000000000464d24 in main (argc=4, argv=0xfffffffff518) at /data1/dpdk-19.11/demo/memzone/main.c:40 (gdb) list 714 unsigned int elt_sz) 715 { 716 size_t page_sz, mmap_len; 717 char path[PATH_MAX]; 718 struct used_mask *msk; 719 struct mem_area *ma = NULL; 720 void *data = NULL; 721 int fd = -1; 722 723 if (arr == NULL) { (gdb) b /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:745 Breakpoint 2 at 0x5aff88: file /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c, line 745. (gdb) c Continuing. Breakpoint 2, rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:745 745 mmap_len = calc_data_size(page_sz, elt_sz, len); (gdb) Continuing. Breakpoint 1, rte_fbarray_init (arr=0x1000000b0, name=0xfffffffff090 "memseg-524288k-0-0", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) n 720 void *data = NULL; (gdb) n 721 int fd = -1; (gdb) n 723 if (arr == NULL) { (gdb) n 728 if (fully_validate(name, elt_sz, len)) (gdb) p *arr $1 = {name = '\000' <repeats 63 times>, count = 0, len = 0, elt_sz = 0, data = 0x0, rwlock = {cnt = 0}} (gdb) n 732 ma = malloc(sizeof(*ma)); (gdb) n 733 if (ma == NULL) { (gdb) n 738 page_sz = sysconf(_SC_PAGESIZE); (gdb) n 739 if (page_sz == (size_t)-1) { (gdb) n Breakpoint 2, rte_fbarray_init (arr=0x1000000b0, name=0xfffffffff090 "memseg-524288k-0-0", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:745 745 mmap_len = calc_data_size(page_sz, elt_sz, len); (gdb) n 747 data = eal_get_virtual_area(NULL, &mmap_len, page_sz, 0, 0); (gdb) s eal_get_virtual_area (requested_addr=0x0, size=0xfffffffff028, page_sz=65536, flags=0, mmap_flags=0) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_memory.c:51 51 uint8_t try = 0; (gdb) n 53 if (system_page_sz == 0) (gdb) n 56 mmap_flags |= MAP_PRIVATE | MAP_ANONYMOUS; (gdb) n 58 RTE_LOG(DEBUG, EAL, "Ask a virtual area of 0x%zx bytes\n", *size); (gdb) n 60 addr_is_hint = (flags & EAL_VIRTUAL_AREA_ADDR_IS_HINT) > 0; (gdb) n 61 allow_shrink = (flags & EAL_VIRTUAL_AREA_ALLOW_SHRINK) > 0; (gdb) n 62 unmap = (flags & EAL_VIRTUAL_AREA_UNMAP) > 0; (gdb) n 64 if (next_baseaddr == NULL && internal_config.base_virtaddr != 0 && (gdb) n 69 if (next_baseaddr == NULL && internal_config.base_virtaddr == 0 && (gdb) n 73 if (requested_addr == NULL && next_baseaddr != NULL) { (gdb) n 74 requested_addr = next_baseaddr; (gdb) n 75 requested_addr = RTE_PTR_ALIGN(requested_addr, page_sz); (gdb) n 76 addr_is_hint = true; (gdb) n 89 !addr_is_hint) || (gdb) n 88 requested_addr == RTE_PTR_ALIGN(requested_addr, page_sz) && (gdb) n 87 no_align = (requested_addr != NULL && (gdb) n 89 !addr_is_hint) || (gdb) n 88 requested_addr == RTE_PTR_ALIGN(requested_addr, page_sz) && (gdb) n 90 page_sz == system_page_sz; (gdb) n 89 !addr_is_hint) || (gdb) n 87 no_align = (requested_addr != NULL && (gdb) n 93 map_sz = no_align ? *size : *size + page_sz; (gdb) n 100 mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ, (gdb) n 102 if (mapped_addr == MAP_FAILED && allow_shrink) (gdb) n 105 if (mapped_addr != MAP_FAILED && addr_is_hint && (gdb) n 117 mapped_addr == MAP_FAILED && *size > 0); (gdb) n 116 } while ((allow_shrink || addr_is_hint) && (gdb) n 122 aligned_addr = no_align ? mapped_addr : (gdb) n 125 if (*size == 0) { (gdb) n 130 } else if (mapped_addr == MAP_FAILED) { (gdb) n 136 } else if (requested_addr != NULL && !addr_is_hint && (gdb) n 143 } else if (requested_addr != NULL && addr_is_hint && (gdb) n 148 } else if (next_baseaddr != NULL) { (gdb) n 149 next_baseaddr = RTE_PTR_ADD(aligned_addr, *size); (gdb) n 152 RTE_LOG(DEBUG, EAL, "Virtual area found at %p (size = 0x%zx)\n", (gdb) n 155 if (unmap) { (gdb) n 157 } else if (!no_align) { (gdb) n 182 return aligned_addr; (gdb) n 183 } (gdb) n rte_fbarray_init (arr=0x1000000b0, name=0xfffffffff090 "memseg-524288k-0-0", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:748 748 if (data == NULL) { (gdb) n 753 rte_spinlock_lock(&mem_area_lock); (gdb) n 755 fd = -1; (gdb) n 757 if (internal_config.no_shconf) { (gdb) n 767 eal_get_fbarray_path(path, sizeof(path), name); (gdb) p patch No symbol "patch" in current context. (gdb) p path $2 = "\000\000\000\000\b\000\000\000\000\341\377\377\377\377\000\000\020\341\377\377\377\377\000\000\020\341\377\377\377\377\000\000\340\340\377\377\377\377\000\000\330\377\377\377\200\377\377\377\000\000\000\000\000\000\000\000`\341\377\377\377\377\000\000\220\342Z\000\000\000\000\000`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377/var/run/dpdk/rt\324\037\242q\364%#D\324\037\242q\364%#D", '\000' <repeats 104 times>... (gdb) p *name $3 = 109 'm' (gdb) p *path $4 = 0 '\000' (gdb) s eal_get_fbarray_path (buffer=0xffffffffe028 "", buflen=4096, name=0xfffffffff090 "memseg-524288k-0-0") at /data1/dpdk-19.11/lib/librte_eal/common/eal_filesystem.h:61 61 snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(), (gdb) n 63 return buffer; (gdb) p buffer $5 = 0xffffffffe028 "/var/run/dpdk/rte/fbarray_memseg-524288k-0-0" (gdb) n 64 } (gdb) n rte_fbarray_init (arr=0x1000000b0, name=0xfffffffff090 "memseg-524288k-0-0", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 775 fd = open(path, O_CREAT | O_RDWR, 0600); (gdb) p path $6 = "/var/run/dpdk/rte/fbarray_memseg-524288k-0-0\000\377\377\377\000\000\000\000\000\000\000\000`\341\377\377\377\377\000\000\220\342Z\000\000\000\000\000`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377/var/run/dpdk/rt\324\037\242q\364%#D\324\037\242q\364%#D", '\000' <repeats 104 times>... (gdb) n 776 if (fd < 0) { (gdb) n 781 } else if (flock(fd, LOCK_EX | LOCK_NB)) { (gdb) n 792 if (flock(fd, LOCK_SH | LOCK_NB)) { (gdb) n 797 if (resize_and_map(fd, data, mmap_len)) (gdb) p data $7 = (void *) 0x100040000 (gdb) p *data Attempt to dereference a generic pointer. (gdb) n 800 ma->addr = data; (gdb) n 801 ma->len = mmap_len; (gdb) n 802 ma->fd = fd; (gdb) n 805 TAILQ_INSERT_TAIL(&mem_area_tailq, ma, next); (gdb) n 808 memset(data, 0, mmap_len); (gdb) n 811 strlcpy(arr->name, name, sizeof(arr->name)); (gdb) p arr $8 = (struct rte_fbarray *) 0x1000000b0 (gdb) p *arr $9 = {name = '\000' <repeats 63 times>, count = 0, len = 0, elt_sz = 0, data = 0x0, rwlock = {cnt = 0}} (gdb) set print pretty on (gdb) p *arr $10 = { name = '\000' <repeats 63 times>, count = 0, len = 0, elt_sz = 0, data = 0x0, rwlock = { cnt = 0 } } (gdb)
[root@localhost memzone]# gdb build/app/TestMalloc GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "aarch64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /data1/dpdk-19.11/demo/memzone/build/app/TestMalloc...done. (gdb) set args 3 -c 0xf (gdb) b /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:713 Breakpoint 1 at 0x5afeac: file /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c, line 713. (gdb) b /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 Breakpoint 2 at 0x5b008c: file /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c, line 775. (gdb) r Starting program: /data1/dpdk-19.11/demo/memzone/build/app/TestMalloc 3 -c 0xf [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". EAL: Detected 128 lcore(s) EAL: Detected 4 NUMA nodes [New Thread 0xffffbe43d910 (LWP 130823)] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [New Thread 0xffffbdc2d910 (LWP 130824)] EAL: Selected IOVA mode 'PA' EAL: No available hugepages reported in hugepages-2048kB EAL: Probing VFIO support... EAL: VFIO support initialized Breakpoint 1, rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) c Continuing. Breakpoint 2, rte_fbarray_init (arr=0x100000028, name=0xbc8488 "memzone", len=2560, elt_sz=72) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 775 fd = open(path, O_CREAT | O_RDWR, 0600); (gdb) p path $1 = "/var/run/dpdk/rte/fbarray_memzone\000.!\000\000\000\000\263xG_\000\000\000\000\240s.!\000\000\000\000\263xG_\000\000\000\000\240s.!", '\000' <repeats 12 times>, "/sys/module/rte_kni\000_socket_*", '\000' <repeats 667 times>... (gdb) set print pretty on (gdb) p *arr $2 = { name = '\000' <repeats 63 times>, count = 0, len = 0, elt_sz = 0, data = 0x0, rwlock = { cnt = 0 } } (gdb) c Continuing. Breakpoint 1, rte_fbarray_init (arr=0x1000000b0, name=0xfffffffff090 "memseg-524288k-0-0", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) c Continuing. Breakpoint 2, rte_fbarray_init (arr=0x1000000b0, name=0xfffffffff090 "memseg-524288k-0-0", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 775 fd = open(path, O_CREAT | O_RDWR, 0600); (gdb) p path $3 = "/var/run/dpdk/rte/fbarray_memseg-524288k-0-0\000\377\377\377\000\000\000\000\000\000\000\000`\341\377\377\377\377\000\000\220\342Z\000\000\000\000\000`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377/var/run/dpdk/rt\220\230\065\352)Zu\326\220\230\065\352)Zu\326", '\000' <repeats 104 times>... (gdb) p data $4 = (void *) 0x100040000 (gdb) c Continuing. Breakpoint 1, rte_fbarray_init (arr=0x100000138, name=0xfffffffff090 "memseg-524288k-0-1", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) c Continuing. Breakpoint 2, rte_fbarray_init (arr=0x100000138, name=0xfffffffff090 "memseg-524288k-0-1", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 775 fd = open(path, O_CREAT | O_RDWR, 0600); (gdb) p path $5 = "/var/run/dpdk/rte/fbarray_memseg-524288k-0-1\000\377\377\377\000\000\000\000\000\000\000\000`\341\377\377\377\377\000\000\220\342Z\000\000\000\000\000`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377/var/run/dpdk/rt\220\230\065\352)Zu\326\220\230\065\352)Zu\326", '\000' <repeats 104 times>... (gdb) p/x path $6 = {0x2f, 0x76, 0x61, 0x72, 0x2f, 0x72, 0x75, 0x6e, 0x2f, 0x64, 0x70, 0x64, 0x6b, 0x2f, 0x72, 0x74, 0x65, 0x2f, 0x66, 0x62, 0x61, 0x72, 0x72, 0x61, 0x79, 0x5f, 0x6d, 0x65, 0x6d, 0x73, 0x65, 0x67, 0x2d, 0x35, 0x32, 0x34, 0x32, 0x38, 0x38, 0x6b, 0x2d, 0x30, 0x2d, 0x31, 0x0, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x90, 0xe2, 0x5a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x60, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x30, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xd8, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0x60, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x60, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x30, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xd8, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x72, 0x75, 0x6e, 0x2f, 0x64, 0x70, 0x64, 0x6b, 0x2f, 0x72, 0x74, 0x90, 0x98, 0x35, 0xea, 0x29, 0x5a, 0x75, 0xd6, 0x90, 0x98, 0x35, 0xea, 0x29, 0x5a, 0x75, 0xd6, 0x0 <repeats 104 times>, 0x88, 0x84, 0xbc, 0x0 <repeats 15 times>, 0x4, 0x0, 0x1, 0x0 <repeats 12 times>...} (gdb) c Continuing. Breakpoint 1, rte_fbarray_init (arr=0x1000001c0, name=0xfffffffff090 "memseg-524288k-0-2", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:719 719 struct mem_area *ma = NULL; (gdb) c Continuing. Breakpoint 2, rte_fbarray_init (arr=0x1000001c0, name=0xfffffffff090 "memseg-524288k-0-2", len=64, elt_sz=48) at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 775 fd = open(path, O_CREAT | O_RDWR, 0600); (gdb) p path $7 = "/var/run/dpdk/rte/fbarray_memseg-524288k-0-2\000\377\377\377\000\000\000\000\000\000\000\000`\341\377\377\377\377\000\000\220\342Z\000\000\000\000\000`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377`\341\377\377\377\377\000\000`\341\377\377\377\377\000\000\060\341\377\377\377\377\000\000\330\377\377\377\200\377\377\377/var/run/dpdk/rt\220\230\065\352)Zu\326\220\230\065\352)Zu\326", '\000' <repeats 104 times>... (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0x00000000005afeac in rte_fbarray_init at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:713 breakpoint already hit 4 times 2 breakpoint keep y 0x00000000005b008c in rte_fbarray_init at /data1/dpdk-19.11/lib/librte_eal/common/eal_common_fbarray.c:775 breakpoint already hit 4 times (gdb) delete 1-2