From patchwork Tue Nov 20 04:19:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1000263 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42zXYg0bdFz9s8r for ; Tue, 20 Nov 2018 15:20:23 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="gHd4Xagg"; 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 42zXYf5Z1XzF3Rv for ; Tue, 20 Nov 2018 15:20:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="gHd4Xagg"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42zXYH0SFCzF3QJ for ; Tue, 20 Nov 2018 15:20:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="gHd4Xagg"; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42zXYG4tftz9s3q; Tue, 20 Nov 2018 15:20:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542687602; bh=2awv0Xn7DU2H3ciluB88SNap1ftuXT3PdmCH5ZnkuDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gHd4XaggzPfGxbyd8NR2QgXFbDg5QWEUF39XiA+04QEFJx3t23qxTnzFZghh85JxD M9pfh9x1ZZSoDzEL5rJlv/fQWNWjVQKCrmK1k7O25Iagf3lyTWSNNS5RKcIwYg2HI/ xE+hd+66rIn3ssf36ooBMCl/xhBhmp/TTgME6529M58fWup95RhvfAbn7xg26IbEW/ fGwVsK/KgJh25Kl8ECE8MSfPp7ZaWGals4eJr2wufoD2dvM2klxev29fbxQXWQuvgR sYh/eVjUPuJzBPg8pLiyEARfmzvaXYhNI8d7+5+s+2+dP/4SZPdW5P2lrOkDLbKq3I fzeP9NqqYYYyw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Tue, 20 Nov 2018 15:19:48 +1100 Message-Id: <20181120041953.402413-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181120041953.402413-1-amitay@ozlabs.org> References: <20181120041953.402413-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 4/9] main: Convert threadstatus command to path based targeting 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: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- src/thread.c | 183 +++++++++++++++++++++++++-------------------------- 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/src/thread.c b/src/thread.c index 97becc4..3af37be 100644 --- a/src/thread.c +++ b/src/thread.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -24,70 +25,6 @@ #include "optcmd.h" #include "path.h" -static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *arg, uint64_t *valid) -{ - struct thread_state *status = (struct thread_state *) arg; - - status[index] = thread_status(target); - valid[index] = true; - return 1; -} - -static int print_core_thread_status(struct pdbg_target *core_target, uint32_t index, uint64_t *maxindex, uint64_t *unused1) -{ - struct thread_state status[8]; - uint64_t valid[8] = {0}; - int i, rc; - - 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], &valid[0]); - for (i = 0; i <= *maxindex; i++) { - if (!valid[i]) { - printf(" "); - continue; - } - - if (status[i].active) - printf("A"); - else - printf("."); - - switch (status[i].sleep_state) { - case PDBG_THREAD_STATE_DOZE: - printf("D"); - break; - - case PDBG_THREAD_STATE_NAP: - printf("N"); - break; - - case PDBG_THREAD_STATE_SLEEP: - printf("Z"); - break; - - case PDBG_THREAD_STATE_STOP: - printf("S"); - break; - - default: - printf("."); - break; - } - - if (status[i].quiesced) - printf("Q"); - else - printf("."); - printf(" "); - - } - printf("\n"); - - return rc; -} - static bool is_real_address(struct thread_regs *regs, uint64_t addr) { return true; @@ -214,33 +151,6 @@ no_flip: return 0; } -static int get_thread_max_index(struct pdbg_target *target, uint32_t index, uint64_t *maxindex, uint64_t *unused) -{ - if (index > *maxindex) - *maxindex = index; - return 1; -} - -static int get_core_max_threads(struct pdbg_target *core_target, uint32_t index, uint64_t *maxindex, uint64_t *unused1) -{ - return for_each_child_target("thread", core_target, get_thread_max_index, maxindex, NULL); -} - -static int print_proc_thread_status(struct pdbg_target *pib_target, uint32_t index, uint64_t *unused, uint64_t *unused1) -{ - int i; - uint64_t maxindex = 0; - - for_each_child_target("core", pib_target, get_core_max_threads, &maxindex, NULL); - - printf("\np%01dt:", index); - for (i = 0; i <= maxindex; i++) - printf(" %d", i); - printf("\n"); - - return for_each_child_target("core", pib_target, print_core_thread_status, &maxindex, NULL); -}; - static int state_thread(struct pdbg_target *thread_target, uint32_t index, uint64_t *i_doBacktrace, uint64_t *unused) { struct thread_regs regs; @@ -306,9 +216,98 @@ static int thread_stop(void) } OPTCMD_DEFINE_CMD(stop, thread_stop); + +static int print_one_thread(struct pdbg_target *thread) +{ + struct thread_state tstate; + char c; + + if (!path_target_selected(thread)) { + printf("... "); + return 0; + } + + tstate = thread_status(thread); + + + switch (tstate.sleep_state) { + case PDBG_THREAD_STATE_DOZE: + c = 'D'; + break; + + case PDBG_THREAD_STATE_NAP: + c = 'N'; + break; + + case PDBG_THREAD_STATE_SLEEP: + c = 'Z'; + break; + + case PDBG_THREAD_STATE_STOP: + c = 'S'; + break; + + default: + c = '.'; + break; + } + + printf("%c%c%c ", + (tstate.active ? 'A' : '.'), + c, + (tstate.quiesced ? 'Q': '.')); + return 1; +} + static int thread_status_print(void) { - return for_each_target("pib", print_proc_thread_status, NULL, NULL); + struct pdbg_target *thread, *core, *pib; + int threads_per_core = 0; + int count = 0; + + for_each_path_target_class("thread", thread) { + core = pdbg_target_parent("core", thread); + assert(path_target_add(core)); + + pib = pdbg_target_parent("pib", core); + assert(path_target_add(pib)); + } + + pib = __pdbg_next_target("pib", pdbg_target_root(), NULL); + assert(pib); + + core = __pdbg_next_target("core", pib, NULL); + assert(core); + + pdbg_for_each_target("thread", core, thread) + threads_per_core++; + + for_each_path_target_class("pib", pib) { + int i; + + if (pdbg_target_status(pib) != PDBG_TARGET_ENABLED) + continue; + + printf("\np%01dt:", pdbg_target_index(pib)); + for (i = 0; i < threads_per_core; i++) + printf(" %d", i); + printf("\n"); + + pdbg_for_each_target("core", pib, core) { + if (!path_target_selected(core)) + continue; + if (pdbg_target_status(core) != PDBG_TARGET_ENABLED) + continue; + + printf("c%02d: ", pdbg_target_index(core)); + + pdbg_for_each_target("thread", core, thread) + count += print_one_thread(thread); + printf("\n"); + } + } + + return count; } OPTCMD_DEFINE_CMD(threadstatus, thread_status_print);