summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlistair Popple <alistair@popple.id.au>2018-05-24 13:42:49 +1000
committerAlistair Popple <alistair@popple.id.au>2018-05-24 13:42:49 +1000
commit070d7cd51ed14b5c9997524305004de0fbabb7da (patch)
tree6025dad79e0918c25aba6456ef30c3d7917d98c7 /src
parent9d8dfd7ea4a133c1c14198ba4a00df043ca1911b (diff)
downloadpdbg-070d7cd51ed14b5c9997524305004de0fbabb7da.tar.gz
pdbg-070d7cd51ed14b5c9997524305004de0fbabb7da.zip
libpdbg: Abstract thread status
There is currently no abstraction of thread status between library and application. It just passes the hardware specific values down. There is also no interface exported in the library headers to read status. This makes it difficult to implement more advanced functionality in the application as there is no way hardware agnostic way to determine if a thread is in powersave mode or not for example. Instead introduce a hardware agnostic thread state so that we can implement more advanced functionality such as automatically stopping threads if required. Signed-off-by: Alistair Popple <alistair@popple.id.au>
Diffstat (limited to 'src')
-rw-r--r--src/htm.c7
-rw-r--r--src/thread.c54
2 files changed, 31 insertions, 30 deletions
diff --git a/src/htm.c b/src/htm.c
index 1e65a04..945d8d6 100644
--- a/src/htm.c
+++ b/src/htm.c
@@ -338,9 +338,10 @@ int run_htm(int optind, int argc, char *argv[])
if (pdbg_target_status(target) == PDBG_TARGET_NONEXISTENT)
continue;
- if ((!(thread_status(target) & THREAD_STATUS_ACTIVE)) ||
- (thread_status(target) & THREAD_STATUS_STOP)) {
- fprintf(stderr, "It appears powersave is on 0x%" PRIx64 "%p\n", thread_status(target), target);
+ if ((!(thread_status(target).active)) ||
+ (thread_status(target).sleep_state != PDBG_THREAD_STATE_RUN)) {
+ fprintf(stderr, "It appears powersave is on on %s@%d\n",
+ pdbg_target_name(target), pdbg_target_index(target));
fprintf(stderr, "core HTM needs to run with powersave off\n");
fprintf(stderr, "Hint: put powersave=off on the kernel commandline\n");
return 0;
diff --git a/src/thread.c b/src/thread.c
index 0e4627f..e8b54cb 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -18,58 +18,58 @@
#include <stdio.h>
#include <stdlib.h>
-#include <bitutils.h>
-
-#include <target.h>
-#include <operations.h>
+#include <libpdbg.h>
#include "main.h"
#include "mem.h"
-static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *status, uint64_t *unused1)
+static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *arg, uint64_t *unused1)
{
+ struct thread_state *status = (struct thread_state *) arg;
+
status[index] = thread_status(target);
return 1;
}
static int print_core_thread_status(struct pdbg_target *core_target, uint32_t index, uint64_t *maxindex, uint64_t *unused1)
{
- uint64_t status[8];
+ struct thread_state status[8];
int i, rc;
- memset(status, 0xff, sizeof(status));
+ printf("c%02d: ", index);
- printf("c%02d: ", index);
- rc = for_each_child_target("thread", core_target, print_thread_status, &status[0], NULL);
+ /* 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] == -1ULL) {
- printf(" ");
- continue;
- }
- if (status[i] & ~(THREAD_STATUS_ACTIVE|THREAD_STATUS_DOZE|
- THREAD_STATUS_NAP|THREAD_STATUS_SLEEP|
- THREAD_STATUS_STOP|THREAD_STATUS_QUIESCE)) {
- printf("%" PRIx64 " ", status[i]);
- continue;
- }
- if (status[i] & THREAD_STATUS_ACTIVE)
+ if (status[i].active)
printf("A");
else
printf(".");
- if (status[i] & THREAD_STATUS_DOZE)
+ switch (status[i].sleep_state) {
+ case PDBG_THREAD_STATE_DOZE:
printf("D");
- else if (status[i] & THREAD_STATUS_NAP)
+ break;
+
+ case PDBG_THREAD_STATE_NAP:
printf("N");
- else if (status[i] & THREAD_STATUS_SLEEP)
- printf("S");
- else if (status[i] & THREAD_STATUS_STOP)
+ break;
+
+ case PDBG_THREAD_STATE_SLEEP:
+ printf("Z");
+ break;
+
+ case PDBG_THREAD_STATE_STOP:
printf("S");
- else
+ break;
+
+ default:
printf(".");
+ break;
+ }
- if (status[i] & THREAD_STATUS_QUIESCE)
+ if (status[i].quiesced)
printf("Q");
else
printf(".");
OpenPOWER on IntegriCloud