From patchwork Thu Aug 9 04:28:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 955336 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 41mFdB1xJkz9s4Z for ; Thu, 9 Aug 2018 14:29:02 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sicS0zWW"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41mFdB0J6jzDr5t for ; Thu, 9 Aug 2018 14:29:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sicS0zWW"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sicS0zWW"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41mFd509RKzDqCD for ; Thu, 9 Aug 2018 14:28:55 +1000 (AEST) Received: by mail-pf1-x42d.google.com with SMTP id x17-v6so2204731pfh.5 for ; Wed, 08 Aug 2018 21:28:55 -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; bh=MCIk+IzYMK39TDqtRvX7XtUOjj+6GF7tFCaGh8MJn+Q=; b=sicS0zWW0EBO4PFDzMFm/nvyLowI3eTzfhxteqZgUQV01DNcDqk9iM4CtB1KTq5sDK VT5D9dwBUn4HhVP9czCq1dNJkfddSH6OgsZK6fCUR9Iiqia3P7Y02cLiHoqdfCmmCzYL dK3aIVym7gJNsXju2CnlW8To4jtHu2YHQ4KZZjbzuKchw2K6OlkvunVrCh33DCIg5hpf +558dqSPdI6I4PL23HR47zcGLfz+xqwAjJXjRwUVUTZqSMY7SVucz+EjtfVZ5azxmeta FxRcuiz21vJXFVgVNKfuTACGQCzJ9UggmFoqoBWHXhEGqpI45s4ViqP0ZWkUADUcYSGP t89Q== 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; bh=MCIk+IzYMK39TDqtRvX7XtUOjj+6GF7tFCaGh8MJn+Q=; b=QUWQg7SmZR8jiB119+pGD/4DKw08lQPJiWJMXyR6Wnahzw9tePOQbBSOEnIgW8CWaH 5LkHmljvItzVWSp2yqjcAeci3lVw9IFtSaK5wXQiC0ZT19x7Msaun3+Ypl8mYEL8SM1s SBd3Ud74heVUxAR6J8mFurFr2UOjtyqKWtgQOU0QeURDidWhSVFQ9IDv3ahRec2dwwLB VptT4JhEqXtT8hXNt+/eAVcGU38/YNV/4RII2B8InHPrj0bj53V8w+oRj5ycfHxcJY8t LrmyGZT4pFcSgVE/tmBjWdmxt5G1iG+Cf4V4okRRTmMxIzn/c0SX4ENXhNnXvoqH3ugM SN+w== X-Gm-Message-State: AOUpUlFex3peI1vB/QOz2u4cb/ixqeODiL0m+lysbxpc5oTkUrVYMnwE IipN9nsXpucN3OISHZF+41PRJezQ X-Google-Smtp-Source: AA+uWPz4fUT/LHGncCnO95TsifUBZNVJpCPdDk928ZZBB61eSZMQ6TtaTNqzp+OmU6Atp1UbwTPHew== X-Received: by 2002:a63:1644:: with SMTP id 4-v6mr527165pgw.103.1533788933588; Wed, 08 Aug 2018 21:28:53 -0700 (PDT) Received: from roar.au.ibm.com (123-243-222-142.tpgi.com.au. [123.243.222.142]) by smtp.gmail.com with ESMTPSA id n9-v6sm9440455pfg.21.2018.08.08.21.28.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 21:28:53 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Thu, 9 Aug 2018 14:28:45 +1000 Message-Id: <20180809042845.16580-1-npiggin@gmail.com> X-Mailer: git-send-email 2.17.0 Subject: [Pdbg] [PATCH] libpdbg: ensure thread state validity, only print requested targets X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.27 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: Nicholas Piggin MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Thread state is not queried from the target each time, but cached. This patch adds a valid flag in the thread state cache to ensure this is being probed proprly before use. This also skips threads that were not targetted when printing thread status. Signed-off-by: Nicholas Piggin --- libpdbg/chip.c | 2 ++ libpdbg/libpdbg.h | 1 + libpdbg/p8chip.c | 3 +++ libpdbg/p9chip.c | 4 ++++ src/thread.c | 9 +++++++++ 5 files changed, 19 insertions(+) diff --git a/libpdbg/chip.c b/libpdbg/chip.c index 079592c..2103b2e 100644 --- a/libpdbg/chip.c +++ b/libpdbg/chip.c @@ -98,6 +98,8 @@ struct thread_state thread_status(struct pdbg_target *target) assert(!strcmp(target->class, "thread")); thread = target_to_thread(target); + assert(thread->status.valid); + return thread->status; } diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 1c345cb..39d12e8 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -156,6 +156,7 @@ enum pdbg_sleep_state {PDBG_THREAD_STATE_RUN, PDBG_THREAD_STATE_DOZE, enum pdbg_smt_state {PDBG_SMT_UNKNOWN, PDBG_SMT_1, PDBG_SMT_2, PDBG_SMT_4, PDBG_SMT_8}; struct thread_state { + bool valid; bool active; bool quiesced; enum pdbg_sleep_state sleep_state; diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c index 3e90c8d..453a6f4 100644 --- a/libpdbg/p8chip.c +++ b/libpdbg/p8chip.c @@ -125,6 +125,9 @@ static struct thread_state get_thread_status(struct thread *thread) uint64_t val, mode_reg; struct thread_state thread_status; + memset(&thread_status, 0, sizeof(thread_status)); + thread_status.valid = true; + /* Need to activete debug mode to get complete status */ pib_read(&thread->target, RAS_MODE_REG, &mode_reg); pib_write(&thread->target, RAS_MODE_REG, mode_reg | MR_THREAD_IN_DEBUG); diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 1433d19..f1e22cf 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -97,6 +97,9 @@ static struct thread_state p9_get_thread_status(struct thread *thread) uint64_t value; struct thread_state thread_state; + memset(&thread_state, 0, sizeof(thread_state)); + thread_state.valid = true; + thread_read(thread, P9_RAS_STATUS, &value); thread_state.quiesced = (GETFIELD(PPC_BITMASK(8*thread->id, 3 + 8*thread->id), value) == 0xf); @@ -121,6 +124,7 @@ static int p9_thread_probe(struct pdbg_target *target) thread->id = dt_prop_get_u32(target, "tid"); thread->status = p9_get_thread_status(thread); + assert(thread->status.valid); return 0; } diff --git a/src/thread.c b/src/thread.c index 4b95636..2625874 100644 --- a/src/thread.c +++ b/src/thread.c @@ -15,6 +15,7 @@ */ #include #include +#include #include #include @@ -28,6 +29,7 @@ static int print_thread_status(struct pdbg_target *target, uint32_t index, uint6 struct thread_state *status = (struct thread_state *) arg; status[index] = thread_status(target); + return 1; } @@ -36,12 +38,19 @@ static int print_core_thread_status(struct pdbg_target *core_target, uint32_t in struct thread_state status[8]; int i, rc; + memset(status, 0, sizeof(status)); + printf("c%02d: ", index); /* TODO: This cast is gross. Need to rewrite for_each_child_target as an iterator. */ rc = for_each_child_target("thread", core_target, print_thread_status, (uint64_t *) &status[0], NULL); for (i = 0; i <= *maxindex; i++) { + if (!status[i].valid) { + printf(" "); + continue; + } + if (status[i].active) printf("A"); else