[Pdbg] [PATCH v2 10/11] pdbg/htm: Enforce powersave=off

Amitay Isaacs amitay at ozlabs.org
Thu Apr 12 16:01:59 AEST 2018


From: Cyril Bur <cyrilbur at gmail.com>

Core HTM has a nasty habit of not working if the stars haven't aligned
with the exact polar axis of Mars. To complicate matters if Zeus got up
on the incorrect side of the bed Core HTM will likely reflect his mood.

Core HTM requires that no threads be in powersave. It isn't clear if
this restriction only applies to threads on the core being traced on or
if this is a global thing. In order to be as safe as possible, pdbg
will enforce that powersave be disabled globally.

Signed-off-by: Cyril Bur <cyrilbur at gmail.com>
---
 src/htm.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/htm.c b/src/htm.c
index 80501c5..5d9c51a 100644
--- a/src/htm.c
+++ b/src/htm.c
@@ -264,6 +264,7 @@ static void print_usage(enum htm_type type)
 
 int run_htm(int optind, int argc, char *argv[])
 {
+	struct pdbg_target *target;
 	enum htm_type type;
 	int i, rc = 0;
 
@@ -283,9 +284,45 @@ int run_htm(int optind, int argc, char *argv[])
 		return 0;
 	}
 
-	if (type == HTM_CORE)
+	if (type == HTM_CORE) {
 		fprintf(stderr, "Warning: Core HTM is currently experimental\n");
 
+		/*
+		 * Check that powersave is off.
+		 *
+		 * This is as easy as checking that every single
+		 * thread is "ACTIVE" and hasn't gone into any sleep
+		 * state.
+		 */
+		pdbg_for_each_class_target("thread", target) {
+			pdbg_target_probe(target);
+
+			if (pdbg_target_status(target) == PDBG_TARGET_NONEXISTENT)
+				continue;
+
+			if ((thread_status(target) & THREAD_STATUS_ACTIVE) != THREAD_STATUS_ACTIVE) {
+				fprintf(stderr, "It appears powersave is on 0x%"  PRIx64 "%p\n", thread_status(target), 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;
+			}
+		}
+
+		i = 0;
+		pdbg_for_each_class_target("core", target)
+			if (!target_is_disabled(target))
+				i++;
+		if (i == 0)
+			fprintf(stderr, "You haven't selected any HTM Cores\n");
+		if (i > 1) {
+			fprintf(stderr, "It doesn't make sense to core trace on"
+				" multiple cores at once. %d\n", i);
+			fprintf(stderr, "What you probably want is -p 0 -c x\n");
+		}
+		if (i != 1)
+			return 0;
+	}
+
 	optind++;
 	for (i = 0; i < ARRAY_SIZE(actions); i++) {
 		if (strcmp(argv[optind], actions[i].name) == 0) {
-- 
2.14.3



More information about the Pdbg mailing list