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.
44 #include <sys/queue.h>
47 #include <rte_memory.h>
48 #include <rte_memzone.h>
49 #include <rte_tailq.h>
51 #include <rte_string_fns.h>
54 /* some functions used for printing out the memory segments and memory zones information */
56 #define PRINT_STR_FIELD(structname, field) do{ \
57 count+= rte_snprintf(buf + count, len-count, " %s='%s',", \
58 #field, (const char *)structname->field);\
61 #define PRINT_PTR_FIELD(structname, field) do{ \
62 count+= rte_snprintf(buf + count, len-count, " %s=%p,", \
63 #field, (void *)structname->field);\
66 #define PRINT_UINT_FIELD(structname, field) do{ \
67 count+= rte_snprintf(buf + count, len-count, " %s=%llu,", \
68 #field, (unsigned long long)structname->field);\
71 #define PRINT_INT_FIELD(structname, field) do{ \
72 count+= rte_snprintf(buf + count, len-count, " %s=%lld,", \
73 #field, (long long)structname->field);\
76 #define PRINT_CUSTOM_FIELD(structname, field, print_fn) do{ \
78 count+= rte_snprintf(buf + count, len-count, " %s=%s,", \
79 #field, print_fn(structname->field, buf2, sizeof(buf2)));\
82 static inline const char *
83 memseg_to_str(const struct rte_memseg *seg, char *buf, size_t len)
86 count += rte_snprintf(buf + count, len - count, "{");
87 PRINT_UINT_FIELD(seg, phys_addr);
88 PRINT_PTR_FIELD(seg, addr);
89 PRINT_UINT_FIELD(seg, len);
90 PRINT_INT_FIELD(seg, socket_id);
91 PRINT_UINT_FIELD(seg, hugepage_sz);
92 PRINT_UINT_FIELD(seg, nchannel);
93 PRINT_UINT_FIELD(seg, nrank);
94 rte_snprintf(buf + count - 1, len - count + 1, " }");
98 static inline const char *
99 memzone_to_str(const struct rte_memzone *zone, char *buf, size_t len)
102 count += rte_snprintf(buf + count, len - count, "{");
103 PRINT_STR_FIELD(zone, name);
104 PRINT_UINT_FIELD(zone, phys_addr);
105 PRINT_PTR_FIELD(zone, addr);
106 PRINT_UINT_FIELD(zone, len);
107 PRINT_INT_FIELD(zone, socket_id);
108 PRINT_UINT_FIELD(zone, flags);
109 rte_snprintf(buf + count - 1, len - count + 1, " }");
113 static inline const char *
114 tailq_to_str(const struct rte_tailq_head *tailq, char *buf, size_t len)
117 count += rte_snprintf(buf + count, len - count, "{");
118 PRINT_STR_FIELD(tailq, qname);
119 const struct rte_dummy_head *head = &tailq->tailq_head;
120 PRINT_PTR_FIELD(head, tqh_first);
121 PRINT_PTR_FIELD(head, tqh_last);
122 rte_snprintf(buf + count - 1, len - count + 1, " }");
126 #define PREFIX "prefix"
127 static const char *directory = "/var/run";
128 static const char *pre = "rte";
131 usage(const char *prgname)
133 printf("%s --prefix <prefix>\n\n"
134 "dump_config option list:\n"
135 "\t--"PREFIX": filename prefix\n",
140 dmp_cfg_parse_args(int argc, char **argv)
142 const char *prgname = argv[0];
143 const char *home_dir = getenv("HOME");
146 static struct option lgopts[] = {
151 if (getuid() != 0 && home_dir != NULL)
152 directory = home_dir;
154 while ((opt = getopt_long(argc, argv, "",
155 lgopts, &option_index)) != EOF) {
158 if (!strcmp(lgopts[option_index].name, PREFIX))
175 main(int argc, char **argv)
182 dmp_cfg_parse_args(argc, argv);
183 rte_snprintf(path, sizeof(path), "%s/.%s_config", directory, pre);
184 printf("Path to mem_config: %s\n\n", path);
186 fd = open(path, O_RDWR);
188 printf("Error with config open\n");
191 struct rte_mem_config *cfg = mmap(NULL, sizeof(*cfg), PROT_READ, \
194 printf("Error with config mmap\n");
200 printf("----------- MEMORY_SEGMENTS -------------\n");
201 for (i = 0; i < RTE_MAX_MEMSEG; i++){
202 if (cfg->memseg[i].addr == NULL) break;
203 printf("Segment %d: ", i);
204 printf("%s\n", memseg_to_str(&cfg->memseg[i], buffer, sizeof(buffer)));
206 printf("--------- END_MEMORY_SEGMENTS -----------\n");
208 printf("------------ MEMORY_ZONES ---------------\n");
209 for (i = 0; i < RTE_MAX_MEMZONE; i++){
210 if (cfg->memzone[i].addr == NULL) break;
211 printf("Zone %d: ", i);
212 printf("%s\n", memzone_to_str(&cfg->memzone[i], buffer, sizeof(buffer)));
215 printf("---------- END_MEMORY_ZONES -------------\n");
217 printf("------------- TAIL_QUEUES ---------------\n");
218 for (i = 0; i < RTE_MAX_TAILQ; i++){
219 if (cfg->tailq_head[i].qname[0] == '\0') break;
220 printf("Tailq %d: ", i);
221 printf("%s\n", tailq_to_str(&cfg->tailq_head[i], buffer, sizeof(buffer)));
224 printf("----------- END_TAIL_QUEUES -------------\n");