[Pdbg] [PATCH] libpdbg: ensure thread state validity, only print requested targets
Nicholas Piggin
npiggin at gmail.com
Thu Aug 9 14:28:45 AEST 2018
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 <npiggin at gmail.com>
---
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 <errno.h>
#include <inttypes.h>
+#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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
--
2.17.0
More information about the Pdbg
mailing list