From: Intel Date: Wed, 19 Dec 2012 23:00:00 +0000 (+0100) Subject: app: refactor dump_cfg X-Git-Tag: spdx-start~11334 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=a25904dbbbde02246addc0df71b35c2ebd59b89a;p=dpdk.git app: refactor dump_cfg Signed-off-by: Intel --- diff --git a/app/dump_cfg/Makefile b/app/dump_cfg/Makefile index 0bebd9456c..b6d741e83e 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 e65267abe9..0000000000 --- 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -/* 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 \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 0000000000..a66fbee4b0 --- /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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 0000000000..77d6347927 --- /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_ */