4 * Copyright(c) 2010-2012 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.
33 * version: DPDK.L.1.2.3-3
45 #include <sys/queue.h>
48 #include <rte_memory.h>
49 #include <rte_memzone.h>
50 #include <rte_tailq.h>
52 #include <rte_string_fns.h>
55 /* some functions used for printing out the memory segments and memory zones information */
57 #define PRINT_STR_FIELD(structname, field) do{ \
58 count+= rte_snprintf(buf + count, len-count, " %s='%s',", \
59 #field, (const char *)structname->field);\
62 #define PRINT_PTR_FIELD(structname, field) do{ \
63 count+= rte_snprintf(buf + count, len-count, " %s=%p,", \
64 #field, (void *)structname->field);\
67 #define PRINT_UINT_FIELD(structname, field) do{ \
68 count+= rte_snprintf(buf + count, len-count, " %s=%llu,", \
69 #field, (unsigned long long)structname->field);\
72 #define PRINT_INT_FIELD(structname, field) do{ \
73 count+= rte_snprintf(buf + count, len-count, " %s=%lld,", \
74 #field, (long long)structname->field);\
77 #define PRINT_CUSTOM_FIELD(structname, field, print_fn) do{ \
79 count+= rte_snprintf(buf + count, len-count, " %s=%s,", \
80 #field, print_fn(structname->field, buf2, sizeof(buf2)));\
83 static inline const char *
84 memseg_to_str(const struct rte_memseg *seg, char *buf, size_t len)
87 count += rte_snprintf(buf + count, len - count, "{");
88 PRINT_UINT_FIELD(seg, phys_addr);
89 PRINT_PTR_FIELD(seg, addr);
90 PRINT_UINT_FIELD(seg, len);
91 PRINT_INT_FIELD(seg, socket_id);
92 PRINT_UINT_FIELD(seg, hugepage_sz);
93 PRINT_UINT_FIELD(seg, nchannel);
94 PRINT_UINT_FIELD(seg, nrank);
95 rte_snprintf(buf + count - 1, len - count + 1, " }");
99 static inline const char *
100 memzone_to_str(const struct rte_memzone *zone, char *buf, size_t len)
103 count += rte_snprintf(buf + count, len - count, "{");
104 PRINT_STR_FIELD(zone, name);
105 PRINT_UINT_FIELD(zone, phys_addr);
106 PRINT_PTR_FIELD(zone, addr);
107 PRINT_UINT_FIELD(zone, len);
108 PRINT_INT_FIELD(zone, socket_id);
109 PRINT_UINT_FIELD(zone, flags);
110 rte_snprintf(buf + count - 1, len - count + 1, " }");
114 static inline const char *
115 tailq_to_str(const struct rte_tailq_head *tailq, char *buf, size_t len)
118 count += rte_snprintf(buf + count, len - count, "{");
119 PRINT_STR_FIELD(tailq, qname);
120 const struct rte_dummy_head *head = &tailq->tailq_head;
121 PRINT_PTR_FIELD(head, tqh_first);
122 PRINT_PTR_FIELD(head, tqh_last);
123 rte_snprintf(buf + count - 1, len - count + 1, " }");
127 #define PREFIX "prefix"
128 static const char *directory = "/var/run";
129 static const char *pre = "rte";
132 usage(const char *prgname)
134 printf("%s --prefix <prefix>\n\n"
135 "dump_config option list:\n"
136 "\t--"PREFIX": filename prefix\n",
141 dmp_cfg_parse_args(int argc, char **argv)
143 const char *prgname = argv[0];
144 const char *home_dir = getenv("HOME");
147 static struct option lgopts[] = {
152 if (getuid() != 0 && home_dir != NULL)
153 directory = home_dir;
155 while ((opt = getopt_long(argc, argv, "",
156 lgopts, &option_index)) != EOF) {
159 if (!strcmp(lgopts[option_index].name, PREFIX))
176 main(int argc, char **argv)
183 dmp_cfg_parse_args(argc, argv);
184 rte_snprintf(path, sizeof(path), "%s/.%s_config", directory, pre);
185 printf("Path to mem_config: %s\n\n", path);
187 fd = open(path, O_RDWR);
189 printf("Error with config open\n");
192 struct rte_mem_config *cfg = mmap(NULL, sizeof(*cfg), PROT_READ, \
195 printf("Error with config mmap\n");
201 printf("----------- MEMORY_SEGMENTS -------------\n");
202 for (i = 0; i < RTE_MAX_MEMSEG; i++){
203 if (cfg->memseg[i].addr == NULL) break;
204 printf("Segment %d: ", i);
205 printf("%s\n", memseg_to_str(&cfg->memseg[i], buffer, sizeof(buffer)));
207 printf("--------- END_MEMORY_SEGMENTS -----------\n");
209 printf("------------ MEMORY_ZONES ---------------\n");
210 for (i = 0; i < RTE_MAX_MEMZONE; i++){
211 if (cfg->memzone[i].addr == NULL) break;
212 printf("Zone %d: ", i);
213 printf("%s\n", memzone_to_str(&cfg->memzone[i], buffer, sizeof(buffer)));
216 printf("---------- END_MEMORY_ZONES -------------\n");
218 printf("------------- TAIL_QUEUES ---------------\n");
219 for (i = 0; i < RTE_MAX_TAILQ; i++){
220 if (cfg->tailq_head[i].qname[0] == '\0') break;
221 printf("Tailq %d: ", i);
222 printf("%s\n", tailq_to_str(&cfg->tailq_head[i], buffer, sizeof(buffer)));
225 printf("----------- END_TAIL_QUEUES -------------\n");