From patchwork Thu Jun 7 06:54:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Neuling X-Patchwork-Id: 926173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 411brg0gmWz9s1b for ; Thu, 7 Jun 2018 16:54:59 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 411brf6ZFGzF32k for ; Thu, 7 Jun 2018 16:54:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 411brL4M7wzF32p for ; Thu, 7 Jun 2018 16:54:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org Received: from localhost.localdomain (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 411brK6rjYz9s7L; Thu, 7 Jun 2018 16:54:41 +1000 (AEST) Received: by localhost.localdomain (Postfix, from userid 1000) id A6856EE7925; Thu, 7 Jun 2018 16:54:41 +1000 (AEST) From: Michael Neuling To: alistair@popple.id.au Date: Thu, 7 Jun 2018 16:54:38 +1000 Message-Id: <20180607065438.18257-11-mikey@neuling.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180607065438.18257-1-mikey@neuling.org> References: <20180607065438.18257-1-mikey@neuling.org> Subject: [Pdbg] [PATCH 11/11] htm: Fix dump filename X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pdbg@lists.ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Currently we always generate 0.0-htm.dump irrespective of the chip, core and thread it's generated from. This changes it to htm-p??-c??-t??.dump using the correct CPU being run on. Signed-off-by: Michael Neuling --- libpdbg/htm.c | 23 +++++++++-------------- libpdbg/libpdbg.h | 2 +- libpdbg/target.h | 2 +- src/htm.c | 35 ++++++++++++++--------------------- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/libpdbg/htm.c b/libpdbg/htm.c index da381f5811..a1975448c2 100644 --- a/libpdbg/htm.c +++ b/libpdbg/htm.c @@ -221,7 +221,7 @@ int htm_status(struct pdbg_target *target) return htm ? htm->status(htm) : -1; } -int htm_dump(struct pdbg_target *target, uint64_t size, const char *filename) +int htm_dump(struct pdbg_target *target, uint64_t size, char *filename) { struct htm *htm = check_and_convert(target); @@ -834,16 +834,16 @@ static int do_htm_status(struct htm *htm) return 1; } -static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename) +static int do_htm_dump(struct htm *htm, uint64_t size, char *filename) { - char *trace_file, *dump_file; + char *trace_file; struct htm_status status; uint64_t trace[0x1000]; int trace_fd, dump_fd; uint32_t chip_id; size_t r; - if (!basename) + if (!filename) return -1; if (HTM_ERR(get_status(htm, &status))) @@ -880,15 +880,10 @@ static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename) return -1; } - if (asprintf(&dump_file, "%d.%d-%s", chip_id, htm->target.index, basename) == -1) { - free(trace_file); - close(trace_fd); - return -1; - } - dump_fd = open(dump_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + dump_fd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (dump_fd == -1) { - PR_ERROR("Failed to open %s: %m\n", dump_file); - free(dump_file); + PR_ERROR("Failed to open %s: %m\n", filename); + free(filename); free(trace_file); close(trace_fd); return -1; @@ -899,7 +894,7 @@ static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename) if (r == -1) { PR_ERROR("Failed to read from %s: %m\n", trace_file); free(trace_file); - free(dump_file); + free(filename); close(trace_fd); close(dump_fd); return -1; @@ -912,7 +907,7 @@ static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename) } free(trace_file); - free(dump_file); + free(filename); close(trace_fd); close(dump_fd); return 1; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index c73cf21fed..c0990d928c 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -166,7 +166,7 @@ int htm_start(struct pdbg_target *target); int htm_stop(struct pdbg_target *target); int htm_status(struct pdbg_target *target); int htm_reset(struct pdbg_target *target, uint64_t *base, uint64_t *size); -int htm_dump(struct pdbg_target *target, uint64_t size, const char *filename); +int htm_dump(struct pdbg_target *target, uint64_t size, char *filename); int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size); int adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size); diff --git a/libpdbg/target.h b/libpdbg/target.h index 716ba42bef..e4a3ed41f0 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -95,7 +95,7 @@ struct htm { int (*stop)(struct htm *); int (*reset)(struct htm *, uint64_t *, uint64_t *); int (*status)(struct htm *); - int (*dump)(struct htm *, uint64_t, const char *); + int (*dump)(struct htm *, uint64_t, char *); }; #define target_to_htm(x) container_of(x, struct htm, target) diff --git a/src/htm.c b/src/htm.c index f2fc8cfb52..e28c75ece3 100644 --- a/src/htm.c +++ b/src/htm.c @@ -39,8 +39,6 @@ #include "main.h" -#define HTM_DUMP_BASENAME "htm.dump" - #define HTM_ENUM_TO_STRING(e) ((e == HTM_NEST) ? "nhtm" : "chtm") #define PR_ERROR(x, args...) \ @@ -61,23 +59,18 @@ static inline void print_htm_address(enum htm_type type, printf("t%d\n", pdbg_target_index(target)); } -static char *get_htm_dump_filename(void) +static char *get_htm_dump_filename(struct pdbg_target *target) { char *filename; - int i; + int rc; - filename = strdup(HTM_DUMP_BASENAME); - if (!filename) + rc = asprintf(&filename, "htm-p%d-c%d-t%d.dump", + pdbg_parent_index(target, "pib"), + pdbg_parent_index(target, "core"), + pdbg_target_index(target)); + if (rc == -1) return NULL; - i = 0; - while (access(filename, F_OK) == 0) { - free(filename); - if (asprintf(&filename, "%s.%d", HTM_DUMP_BASENAME, i) == -1) - return NULL; - i++; - } - return filename; } @@ -192,12 +185,6 @@ static int run_dump(enum htm_type type) char *filename; int rc = 0; - filename = get_htm_dump_filename(); - if (!filename) - return 0; - - /* size = 0 will dump everything */ - printf("Dumping HTM trace to file [chip].[#]%s\n", filename); pdbg_for_each_class_target(HTM_ENUM_TO_STRING(type), target) { if (!target_selected(target)) continue; @@ -205,15 +192,21 @@ static int run_dump(enum htm_type type) if (target_is_disabled(target)) continue; + filename = get_htm_dump_filename(target); + if (!filename) + return 0; + + /* size = 0 will dump everything */ printf("Dumping HTM@"); print_htm_address(type, target); + printf("File: %s\n", filename); if (htm_dump(target, 0, filename) != 1) { printf("Couldn't dump HTM@"); print_htm_address(type, target); } rc++; + free(filename); } - free(filename); return rc; }