summaryrefslogtreecommitdiff
path: root/app/dump_cfg
diff options
context:
space:
mode:
authorIntel <intel.com>2012-12-20 00:00:00 +0100
committerThomas Monjalon <thomas.monjalon@6wind.com>2013-07-25 15:52:59 +0200
commita25904dbbbde02246addc0df71b35c2ebd59b89a (patch)
tree223b464cc180f1b167946ca2e24d51d77aae56ef /app/dump_cfg
parent1b938bb9dfb650b386caad8a89689068488acf4e (diff)
downloaddpdk-a25904dbbbde02246addc0df71b35c2ebd59b89a.zip
dpdk-a25904dbbbde02246addc0df71b35c2ebd59b89a.tar.gz
dpdk-a25904dbbbde02246addc0df71b35c2ebd59b89a.tar.xz
app: refactor dump_cfg
Signed-off-by: Intel
Diffstat (limited to 'app/dump_cfg')
-rw-r--r--app/dump_cfg/Makefile11
-rw-r--r--app/dump_cfg/dump_cfg_main.c228
-rw-r--r--app/dump_cfg/main.c95
-rw-r--r--app/dump_cfg/main.h46
4 files changed, 146 insertions, 234 deletions
diff --git a/app/dump_cfg/Makefile b/app/dump_cfg/Makefile
index 0bebd94..b6d741e 100644
--- a/app/dump_cfg/Makefile
+++ b/app/dump_cfg/Makefile
@@ -29,7 +29,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-#
include $(RTE_SDK)/mk/rte.vars.mk
@@ -37,12 +36,12 @@ APP = dump_cfg
CFLAGS += $(WERROR_FLAGS)
-#
# all source are stored in SRCS-y
-#
-SRCS-y := dump_cfg_main.c
+
+SRCS-y := main.c
# this application needs libraries first
-DEPDIRS-y += lib
+ DEPDIRS-y += lib
+
+ include $(RTE_SDK)/mk/rte.app.mk
-include $(RTE_SDK)/mk/rte.app.mk
diff --git a/app/dump_cfg/dump_cfg_main.c b/app/dump_cfg/dump_cfg_main.c
deleted file mode 100644
index e65267a..0000000
--- a/app/dump_cfg/dump_cfg_main.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*-
- * BSD LICENSE
- *
- * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 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
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <sys/queue.h>
-#include <limits.h>
-
-#include <rte_memory.h>
-#include <rte_memzone.h>
-#include <rte_tailq.h>
-#include <rte_eal.h>
-#include <rte_string_fns.h>
-
-
-/* some functions used for printing out the memory segments and memory zones information */
-
-#define PRINT_STR_FIELD(structname, field) do{ \
- count+= rte_snprintf(buf + count, len-count, " %s='%s',", \
- #field, (const char *)structname->field);\
-} while(0)
-
-#define PRINT_PTR_FIELD(structname, field) do{ \
- count+= rte_snprintf(buf + count, len-count, " %s=%p,", \
- #field, (void *)structname->field);\
-} while(0)
-
-#define PRINT_UINT_FIELD(structname, field) do{ \
- count+= rte_snprintf(buf + count, len-count, " %s=%llu,", \
- #field, (unsigned long long)structname->field);\
-} while(0)
-
-#define PRINT_INT_FIELD(structname, field) do{ \
- count+= rte_snprintf(buf + count, len-count, " %s=%lld,", \
- #field, (long long)structname->field);\
-} while(0)
-
-#define PRINT_CUSTOM_FIELD(structname, field, print_fn) do{ \
- char buf2[1024]; \
- count+= rte_snprintf(buf + count, len-count, " %s=%s,", \
- #field, print_fn(structname->field, buf2, sizeof(buf2)));\
-} while(0)
-
-static inline const char *
-memseg_to_str(const struct rte_memseg *seg, char *buf, size_t len)
-{
- int count = 0;
- count += rte_snprintf(buf + count, len - count, "{");
- PRINT_UINT_FIELD(seg, phys_addr);
- PRINT_PTR_FIELD(seg, addr);
- PRINT_UINT_FIELD(seg, len);
- PRINT_INT_FIELD(seg, socket_id);
- PRINT_UINT_FIELD(seg, hugepage_sz);
- PRINT_UINT_FIELD(seg, nchannel);
- PRINT_UINT_FIELD(seg, nrank);
- rte_snprintf(buf + count - 1, len - count + 1, " }");
- return buf;
-}
-
-static inline const char *
-memzone_to_str(const struct rte_memzone *zone, char *buf, size_t len)
-{
- int count = 0;
- count += rte_snprintf(buf + count, len - count, "{");
- PRINT_STR_FIELD(zone, name);
- PRINT_UINT_FIELD(zone, phys_addr);
- PRINT_PTR_FIELD(zone, addr);
- PRINT_UINT_FIELD(zone, len);
- PRINT_INT_FIELD(zone, socket_id);
- PRINT_UINT_FIELD(zone, flags);
- rte_snprintf(buf + count - 1, len - count + 1, " }");
- return buf;
-}
-
-static inline const char *
-tailq_to_str(const struct rte_tailq_head *tailq, char *buf, size_t len)
-{
- int count = 0;
- count += rte_snprintf(buf + count, len - count, "{");
- PRINT_STR_FIELD(tailq, qname);
- const struct rte_dummy_head *head = &tailq->tailq_head;
- PRINT_PTR_FIELD(head, tqh_first);
- PRINT_PTR_FIELD(head, tqh_last);
- rte_snprintf(buf + count - 1, len - count + 1, " }");
- return buf;
-}
-
-#define PREFIX "prefix"
-static const char *directory = "/var/run";
-static const char *pre = "rte";
-
-static void
-usage(const char *prgname)
-{
- printf("%s --prefix <prefix>\n\n"
- "dump_config option list:\n"
- "\t--"PREFIX": filename prefix\n",
- prgname);
-}
-
-static int
-dmp_cfg_parse_args(int argc, char **argv)
-{
- const char *prgname = argv[0];
- const char *home_dir = getenv("HOME");
- int opt;
- int option_index;
- static struct option lgopts[] = {
- {PREFIX, 1, 0, 0},
- {0, 0, 0, 0}
- };
-
- if (getuid() != 0 && home_dir != NULL)
- directory = home_dir;
-
- while ((opt = getopt_long(argc, argv, "",
- lgopts, &option_index)) != EOF) {
- switch (opt) {
- case 0:
- if (!strcmp(lgopts[option_index].name, PREFIX))
- pre = optarg;
- else{
- usage(prgname);
- return -1;
- }
- break;
-
- default:
- usage(prgname);
- return -1;
- }
- }
- return 0;
-}
-
-int
-main(int argc, char **argv)
-{
- char buffer[1024];
- char path[PATH_MAX];
- int i;
- int fd = 0;
-
- dmp_cfg_parse_args(argc, argv);
- rte_snprintf(path, sizeof(path), "%s/.%s_config", directory, pre);
- printf("Path to mem_config: %s\n\n", path);
-
- fd = open(path, O_RDWR);
- if (fd < 0){
- printf("Error with config open\n");
- return 1;
- }
- struct rte_mem_config *cfg = mmap(NULL, sizeof(*cfg), PROT_READ, \
- MAP_SHARED, fd, 0);
- if (cfg == NULL){
- printf("Error with config mmap\n");
- close(fd);
- return 1;
- }
- close(fd);
-
- printf("----------- MEMORY_SEGMENTS -------------\n");
- for (i = 0; i < RTE_MAX_MEMSEG; i++){
- if (cfg->memseg[i].addr == NULL) break;
- printf("Segment %d: ", i);
- printf("%s\n", memseg_to_str(&cfg->memseg[i], buffer, sizeof(buffer)));
- }
- printf("--------- END_MEMORY_SEGMENTS -----------\n");
-
- printf("------------ MEMORY_ZONES ---------------\n");
- for (i = 0; i < RTE_MAX_MEMZONE; i++){
- if (cfg->memzone[i].addr == NULL) break;
- printf("Zone %d: ", i);
- printf("%s\n", memzone_to_str(&cfg->memzone[i], buffer, sizeof(buffer)));
-
- }
- printf("---------- END_MEMORY_ZONES -------------\n");
-
- printf("------------- TAIL_QUEUES ---------------\n");
- for (i = 0; i < RTE_MAX_TAILQ; i++){
- if (cfg->tailq_head[i].qname[0] == '\0') break;
- printf("Tailq %d: ", i);
- printf("%s\n", tailq_to_str(&cfg->tailq_head[i], buffer, sizeof(buffer)));
-
- }
- printf("----------- END_TAIL_QUEUES -------------\n");
-
- return 0;
-}
-
diff --git a/app/dump_cfg/main.c b/app/dump_cfg/main.c
new file mode 100644
index 0000000..a66fbee
--- /dev/null
+++ b/app/dump_cfg/main.c
@@ -0,0 +1,95 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <inttypes.h>
+#include <sys/queue.h>
+#include <stdlib.h>
+
+#include <rte_memory.h>
+#include <rte_memzone.h>
+#include <rte_launch.h>
+#include <rte_tailq.h>
+#include <rte_eal.h>
+#include <rte_per_lcore.h>
+#include <rte_lcore.h>
+#include <rte_debug.h>
+#include <rte_log.h>
+#include <rte_atomic.h>
+#include <rte_branch_prediction.h>
+#include <rte_string_fns.h>
+
+#include "main.h"
+
+int
+MAIN(int argc, char **argv)
+{
+ int ret;
+ int i;
+ char c_flag[] = "-c1";
+ char n_flag[] = "-n4";
+ char mp_flag[] = "--proc-type=secondary";
+ char *argp[argc + 3];
+ argp[0] = argv[0];
+ argp[1] = c_flag;
+ argp[2] = n_flag;
+ argp[3] = mp_flag;
+
+ for(i = 1; i < argc; i++) {
+ argp[i + 3] = argv[i];
+ }
+ argc += 3;
+
+ ret = rte_eal_init(argc, argp);
+ if (ret < 0)
+ rte_panic("Cannot init EAL\n");
+
+ printf("----------- MEMORY_SEGMENTS -----------\n");
+ rte_dump_physmem_layout();
+ printf("--------- END_MEMORY_SEGMENTS ---------\n");
+
+ printf("------------ MEMORY_ZONES -------------\n");
+ rte_memzone_dump();
+ printf("---------- END_MEMORY_ZONES -----------\n");
+
+ printf("------------- TAIL_QUEUES -------------\n");
+ rte_dump_tailq();
+ printf("---------- END_TAIL_QUEUES ------------\n");
+
+ return 0;
+}
diff --git a/app/dump_cfg/main.h b/app/dump_cfg/main.h
new file mode 100644
index 0000000..77d6347
--- /dev/null
+++ b/app/dump_cfg/main.h
@@ -0,0 +1,46 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+#ifdef RTE_EXEC_ENV_BAREMETAL
+#define MAIN _main
+#else
+#define MAIN main
+#endif
+
+int MAIN(int argc, char **argv);
+
+#endif /* _MAIN_H_ */