From patchwork Sun Apr 25 13:02:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 92131 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9CC06A0548; Sun, 25 Apr 2021 15:02:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1C98D41139; Sun, 25 Apr 2021 15:02:20 +0200 (CEST) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id 4EA2B4110A for ; Sun, 25 Apr 2021 15:02:19 +0200 (CEST) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FSp4v1VxZzpbgS for ; Sun, 25 Apr 2021 20:59:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Sun, 25 Apr 2021 21:02:10 +0800 From: "Min Hu (Connor)" To: CC: , Date: Sun, 25 Apr 2021 21:02:22 +0800 Message-ID: <1619355742-15429-1-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] app/procinfo: add device registers dump X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Chengchang Tang This patch add support for dump the device registers from a running application. It can help developers locate the problem. Signed-off-by: Chengchang Tang Signed-off-by: Min Hu (Connor) --- app/proc-info/main.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/app/proc-info/main.c b/app/proc-info/main.c index b9587f7..c555be5 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -94,6 +94,9 @@ static char *mempool_name; /**< Enable iter mempool. */ static uint32_t enable_iter_mempool; static char *mempool_iter_name; +/**< Enable dump regs. */ +static uint32_t enable_dump_regs; +static char *dump_regs_file_prefix; /**< display usage */ static void @@ -119,7 +122,8 @@ proc_info_usage(const char *prgname) " --show-crypto: to display crypto information\n" " --show-ring[=name]: to display ring information\n" " --show-mempool[=name]: to display mempool information\n" - " --iter-mempool=name: iterate mempool elements to display content\n", + " --iter-mempool=name: iterate mempool elements to display content\n" + " --dump-regs=file-prefix: dump reg to file with the file-prefix\n", prgname); } @@ -226,6 +230,7 @@ proc_info_parse_args(int argc, char **argv) {"show-ring", optional_argument, NULL, 0}, {"show-mempool", optional_argument, NULL, 0}, {"iter-mempool", required_argument, NULL, 0}, + {"dump-regs", required_argument, NULL, 0}, {NULL, 0, 0, 0} }; @@ -288,6 +293,10 @@ proc_info_parse_args(int argc, char **argv) "iter-mempool", MAX_LONG_OPT_SZ)) { enable_iter_mempool = 1; mempool_iter_name = optarg; + } else if (!strncmp(long_option[option_index].name, + "dump-regs", MAX_LONG_OPT_SZ)) { + enable_dump_regs = 1; + dump_regs_file_prefix = optarg; } break; case 1: @@ -1349,6 +1358,85 @@ iter_mempool(char *name) } } +static void +dump_regs(char *file_prefix) +{ +#define MAX_FILE_NAME_SZ (MAX_LONG_OPT_SZ + 10) + char file_name[MAX_FILE_NAME_SZ]; + struct rte_dev_reg_info reg_info; + struct rte_eth_dev_info dev_info; + unsigned char *buf_data; + FILE *fp_regs; + int buf_size; + uint16_t i; + int ret; + + snprintf(bdr_str, MAX_STRING_LEN, " dump - Port REG"); + STATS_BDR_STR(10, bdr_str); + + RTE_ETH_FOREACH_DEV(i) { + /* Skip if port is not in mask */ + if ((enabled_port_mask & (1ul << i)) == 0) + continue; + + snprintf(bdr_str, MAX_STRING_LEN, " Port (%u)", i); + STATS_BDR_STR(5, bdr_str); + + memset(®_info, 0, sizeof(reg_info)); + memset(&dev_info, 0, sizeof(dev_info)); + + ret = rte_eth_dev_info_get(i, &dev_info); + if (ret) { + printf("Error getting device info: %d\n", ret); + continue; + } + + ret = rte_eth_dev_get_reg_info(i, ®_info); + if (ret) { + printf("Error getting device reg info: %d\n", ret); + continue; + } + + buf_size = reg_info.length * reg_info.width; + buf_data = malloc(buf_size); + if (buf_data == NULL) { + printf("Error allocating %d bytes buffer\n", buf_size); + continue; + } + + reg_info.data = buf_data; + reg_info.length = 0; + ret = rte_eth_dev_get_reg_info(i, ®_info); + if (ret) { + printf("Error getting regs from device: %d\n", ret); + free(buf_data); + continue; + } + + snprintf(file_name, MAX_FILE_NAME_SZ, "%s-port%u", + file_prefix, i); + fp_regs = fopen(file_name, "wb"); + if (fp_regs == NULL) { + printf("Error during opening '%s' for writing\n", + file_name); + } else { + if ((int)fwrite(buf_data, 1, buf_size, fp_regs) != + buf_size) + printf("Error during writing %s\n", + file_prefix); + else + printf("dump device (%s) regs successfully, " + "driver:%s version:0X%08X\n", + dev_info.device->name, + dev_info.driver_name, reg_info.version); + + fclose(fp_regs); + } + + free(buf_data); + } +} + int main(int argc, char **argv) { @@ -1454,6 +1542,8 @@ main(int argc, char **argv) show_mempool(mempool_name); if (enable_iter_mempool) iter_mempool(mempool_iter_name); + if (enable_dump_regs) + dump_regs(dump_regs_file_prefix); RTE_ETH_FOREACH_DEV(i) rte_eth_dev_close(i);