From patchwork Mon Aug 2 05:41:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Niethe X-Patchwork-Id: 1512293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Xagd0ljz; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GdTLp5sZ5z9sfG for ; Mon, 2 Aug 2021 16:56:34 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GdTLp57dCz30C6 for ; Mon, 2 Aug 2021 16:56:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Xagd0ljz; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=jniethe5@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Xagd0ljz; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GdRhR1Cbnz306F for ; Mon, 2 Aug 2021 15:41:43 +1000 (AEST) Received: by mail-pl1-x633.google.com with SMTP id k2so888359plk.13 for ; Sun, 01 Aug 2021 22:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E7j3jZ1QnYWpfM6HCZIMTgkMgGDd7dZEacDO5q/g2fU=; b=Xagd0ljz71+z8MG8SYti01XxtHuZOAxw9saFDHOd6mwt0dvH2wUYUWN8Zm2xKfcBdD xHn6J19qzn+t2ML2blpDEMgcMNeCm0Gd/XGx5iZG0S3eytXdWFxYCMYWv1z3uLuN4Pqy yymFGm8XxwqfHgVBzn3NWByclEuNnqUmZ9S+sE/DTu6G1hVXQzmezcJcjEHTirl4wRTL oeHjgYin8+Ps15xPPF27rLxLyN7uo07WOXXtVV8LDr+pUPSGxecH8tTDHnjuV8O75tYn aJZS0KKGYr6XBlGCWbRqvmp9a68VxwjS5oKShOFzzbQewwAEnIkA/+NNpWGhdE2aGs7E t3Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E7j3jZ1QnYWpfM6HCZIMTgkMgGDd7dZEacDO5q/g2fU=; b=GNiOuzmKVDIRV9wyzYgxXCzb7NINjK80t+1pIIIoQjP5oAZ7j1i2gB+AVjklvSe4mz 6oPi6bZbNXtVSXl+aoPR0E59nKrEuEzxINA6MCTF410ZHyFUR/wBUU+Zioukv+sjqdZP /DefbGlyLfn3y18EoBJVHwBUws7lIcVbn8BFzhVZEkWpdJzKaPTxK1+9DYSNf86ii9sL WhSYcpkd3m3ORu9T0EVpGn6XgB/5EuZPTMVFyvQtun5nVStHMIujuuT+ZEeiQpn9beP6 xTJNCYHI9jez3xl2ESskrhglTAU+uSxQ6f0dGSVVQrstHmGaAd3WhetD2dDiTAIdOLNS y6oA== X-Gm-Message-State: AOAM531TfiooE2oDwWVdXtcVAAXtgJ/aNQLso3RM6VJs2j7h+2QP6RVZ GbDmuEw09Hzw+RIjzSAsUIPI5UjaaMQ= X-Google-Smtp-Source: ABdhPJyeuTJIr17CHY6x3+duv0obEy8Ugf1zEaP8XE0fXDrTgTvq05BKjf0oMnnO+RO0FJWTK8ykXQ== X-Received: by 2002:a62:ed06:0:b029:32c:a800:ba47 with SMTP id u6-20020a62ed060000b029032ca800ba47mr14536432pfh.56.1627882900521; Sun, 01 Aug 2021 22:41:40 -0700 (PDT) Received: from tee480.ozlabs.ibm.com (159-196-117-139.9fc475.syd.nbn.aussiebb.net. [159.196.117.139]) by smtp.gmail.com with ESMTPSA id 189sm1741852pfx.135.2021.08.01.22.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 22:41:40 -0700 (PDT) From: Jordan Niethe To: pdbg@lists.ozlabs.org Date: Mon, 2 Aug 2021 15:41:07 +1000 Message-Id: <20210802054112.461728-8-jniethe5@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210802054112.461728-1-jniethe5@gmail.com> References: <20210802054112.461728-1-jniethe5@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 02 Aug 2021 16:56:28 +1000 Subject: [Pdbg] [PATCH 07/12] main: Use pdbg_get_proc() for mapping to linux CPUs X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 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: Jordan Niethe Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Use pdbg_get_proc() instead of device_node for mapping to linux CPUs. Now it is not required to use device (-d) when using the -l option. Signed-off-by: Jordan Niethe --- src/main.c | 67 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/main.c b/src/main.c index b2474d87135a..4c117f68bab5 100644 --- a/src/main.c +++ b/src/main.c @@ -59,6 +59,8 @@ static int i2c_addr = 0x50; static const char *pathsel[MAX_PATH_ARGS]; static int pathsel_count; +static int l_list[MAX_LINUX_CPUS]; +static int l_count; static int probe(void); @@ -131,7 +133,6 @@ static void print_usage(void) printf("\t-t, --thread=<0-%d>||\n", MAX_THREADS-1); #ifdef TARGET_PPC printf("\t-l, --cpu=<0-%d>||\n", MAX_PROCESSORS-1); - printf("\t\tRequires device (-d) to be set to p8|p9\n"); #endif printf("\t-P, --path=\n"); printf("\t-a, --all\n"); @@ -205,25 +206,32 @@ out2: #define P8_PIR2COREID(pir) (((pir) >> 3) & 0xf) #define P8_PIR2THREADID(pir) ((pir) & 0x7) -void pir_map(int pir, int *chip, int *core, int *thread) +bool pir_map(int pir, int *chip, int *core, int *thread) { assert(chip && core && thread); - if (!strncmp(device_node, "p9", 2)) { + switch (pdbg_get_proc()) { + case PDBG_PROC_P9: *chip = P9_PIR2GCID(pir); *core = P9_PIR2COREID(pir); *thread = P9_PIR2THREADID(pir); - } else if (!strncmp(device_node, "p8", 2)) { + break; + case PDBG_PROC_P8: *chip = P8_PIR2GCID(pir); *core = P8_PIR2COREID(pir); *thread = P8_PIR2THREADID(pir); - } else if (!strncmp(device_node, "p10", 2)) { + break; + case PDBG_PROC_P10: *chip = P10_PIR2GCID(pir); *core = P10_PIR2COREID(pir); *thread = P10_PIR2THREADID(pir); - } else - assert(0); + break; + default: + PR_ERROR("Unable to determine processor type for mapping to Linux CPU number\n"); + return false; + } + return true; } #define PPC_OPTS "l:" @@ -290,8 +298,7 @@ static bool parse_options(int argc, char *argv[]) int p_list[MAX_PROCESSORS]; int c_list[MAX_CHIPS]; int t_list[MAX_THREADS]; - int l_list[MAX_LINUX_CPUS]; - int p_count = 0, c_count = 0, t_count = 0, l_count = 0; + int p_count = 0, c_count = 0, t_count = 0; int i; struct option long_opts[] = { {"all", no_argument, NULL, 'a'}, @@ -489,33 +496,34 @@ static bool parse_options(int argc, char *argv[]) return false; } - if (l_count) { - int pir = -1, i, chip, core, thread; + return true; +} - if (!device_node) - return false; +bool cpus_parse(int args[], int arg_count) +{ + int pir = -1, i, chip, core, thread; - for (i = 0; i < MAX_LINUX_CPUS; i++) { - if (l_list[i] == 1) { - pir = get_pir(i); - if (pir < 0) - return false; + for (i = 0; i < MAX_LINUX_CPUS; i++) { + if (args[i] == 1) { + pir = get_pir(i); + if (pir < 0) + return false; - pir_map(pir, &chip, &core, &thread); + if (!pir_map(pir, &chip, &core, &thread)) + return false; - if (!pathsel_add("pib%d", chip)) - return false; - if (!pathsel_add("pib%d/core%d", chip, core)) - return false; - if (!pathsel_add("pib%d/core%d/thread%d", chip, core, thread)) - return false; - } + if (!pathsel_add("pib%d", chip)) + return false; + if (!pathsel_add("pib%d/core%d", chip, core)) + return false; + if (!pathsel_add("pib%d/core%d/thread%d", chip, core, thread)) + return false; } } - return true; } + static void print_target(struct pdbg_target *target, int level) { int i; @@ -587,6 +595,11 @@ int main(int argc, char *argv[]) if (!pdbg_targets_init(NULL)) return 1; + if (l_count) { + if (!cpus_parse(l_list, l_count)) + return 1; + } + if (pathsel_count) { if (!path_target_parse(pathsel, pathsel_count)) return 1;