public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
	kvm-ppc@vger.kernel.org, "Laurent Vivier" <lvivier@redhat.com>,
	"Drew Jones" <drjones@redhat.com>,
	"Suraj Jitindar Singh" <sjitindarsingh@gmail.com>
Subject: [kvm-unit-tests PATCH v2] powerpc: Check whether TM is available before running other tests
Date: Fri, 30 Sep 2016 11:54:53 +0200	[thread overview]
Message-ID: <1475229293-11605-1-git-send-email-thuth@redhat.com> (raw)

Transactional memory is currently only supported on KVM-HV, and
not yet on KVM-PR. So it's better to check the device tree first
and fail gracefully if it is not available.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 v2:
 - Reworked the check for the "ibm,pa-features" and added a comment
 - Use a dedicated variable "has_tm" instead of "i" in main()

 Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for
 that!) from v1 here since I changed the code a little bit. So it
 would be great if you could have another quick look at this v2.

 powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/powerpc/tm.c b/powerpc/tm.c
index 6ce750a..8344318 100644
--- a/powerpc/tm.c
+++ b/powerpc/tm.c
@@ -10,6 +10,41 @@
 #include <asm/processor.h>
 #include <asm/handlers.h>
 #include <asm/smp.h>
+#include <asm/setup.h>
+#include <devicetree.h>
+
+/* Check "ibm,pa-features" property of a CPU node for the TM flag */
+static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr)
+{
+	const struct fdt_property *prop;
+	int plen;
+
+	prop = fdt_get_property(dt_fdt(), fdtnode, "ibm,pa-features", &plen);
+	if (!prop)	/* No features means TM is also not available */
+		return;
+	/* Sanity check for the property layout (first two bytes are header) */
+	assert(plen >= 8 && prop->data[1] == 0 && prop->data[0] <= plen - 2);
+
+	/*
+	 * The "Transactional Memory Category Support" flags are at byte
+	 * offset 22 and 23 of the attribute type 0, so when adding the
+	 * two bytes for the header, we've got to look at offset 24 for
+	 * the TM support bit.
+	 */
+	if (plen >= 26 && prop->data[0] >= 24 && (prop->data[24] & 0x80) != 0)
+		*(int *)ptr += 1;
+}
+
+/* Check whether all CPU nodes have the TM flag */
+static bool all_cpus_have_tm(void)
+{
+	int ret;
+	int available = 0;
+
+	ret = dt_for_each_cpu_node(cpu_has_tm, &available);
+
+	return ret == 0 && available == nr_cpus;
+}
 
 static int h_cede(void)
 {
@@ -101,11 +136,17 @@ struct {
 
 int main(int argc, char **argv)
 {
-	bool all;
+	bool all, has_tm;
 	int i;
 
 	report_prefix_push("tm");
 
+	has_tm = all_cpus_have_tm();
+	report_xfail("TM available in 'ibm,pa-features' property",
+		     !has_tm, has_tm);
+	if (!has_tm)
+		return report_summary();
+
 	all = argc == 1 || !strcmp(argv[1], "all");
 
 	for (i = 0; hctests[i].name != NULL; i++) {
-- 
1.8.3.1


             reply	other threads:[~2016-09-30  9:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30  9:54 Thomas Huth [this message]
2016-09-30 10:01 ` [kvm-unit-tests PATCH v2] powerpc: Check whether TM is available before running other tests Laurent Vivier
2016-09-30 11:32 ` Andrew Jones
2016-10-04  0:48 ` Suraj Jitindar Singh
2016-10-04  8:23   ` Thomas Huth
2016-10-05  7:22     ` Suraj Jitindar Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475229293-11605-1-git-send-email-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=sjitindarsingh@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox