From patchwork Wed Jun 13 12:56:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 138474 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp719814lji; Wed, 13 Jun 2018 06:23:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLz7YurPjLgZqUc8yw0fCz61MU40eVtg0pg/JI3FCCiR80EAEFGIK2xE1+xFJvt7XOyECiM X-Received: by 2002:a37:678b:: with SMTP id b133-v6mr4349213qkc.54.1528896222250; Wed, 13 Jun 2018 06:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528896222; cv=none; d=google.com; s=arc-20160816; b=hysuC0I7gN0RZv5AOchmvbfKsjhF883otYFTC7yOl/SxVxF9wKQFvIk06kwUN7T2HF 3pTS0/N35torWG1ZF52irci6Z1wrcF0eTVsbDSrYSYIYYLxO/wy9zTxk05gZaTry4xni ai6gjgF0TrdkgZo3RRtfBR5faJK7ep7eCgUxXYSp5cNRHQ6wLUJUbAJIQIco2BUMRFxE zCY7drNe3Yl4Dug/Kr9rHMgWDGVbZmzWh3c1Tt0eYQqqwLlxH9RFLILMvDqAGcMUB7+N egoPoswHht7TdckabbuH73IpxUmj9lYbWxZwbpFeEXrYYQUAEDSlW34sfJ2YrqqPePf0 6w2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=LgQ7v8FSvW3rYAYloOho4U2Wg8+IrRIeB0BXVRYCzj0=; b=eKf7NbtJVuilKKxVszbhtRgDG84cSKGlGpE9wI+/1i+STEDTrF73WCduXKer6Ww7xO MDuPxd5IkRkW6q7aJSadL6pLxbj7SN3Dj+iiwLanhwT+zW68igAid6REWFC4WSz3GqSp vwXRQD5c8Z3ZaLrVxcdjp1ZdiVjwvICbmCsKMa//yujJtQjInajTy42ersXOlhgPduMO joGQMfzhsv02SH/VszhkFOwgD+wzzFC4yiHcFggPN9ZBYzvOup99UlBaH9YNnOPV2cUq 3iPF9A9ToxbYOWyEuzhptnKu4UJ/f7hVi7tozVTv6Ra3mS5LH4cSTFh1+0CQTGS0Z3pC 6kqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cL6XUzg4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 19-v6si2040926qvh.164.2018.06.13.06.23.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Jun 2018 06:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cL6XUzg4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT5kT-0008WT-Nm for patch@linaro.org; Wed, 13 Jun 2018 09:23:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT5SJ-0001ZD-31 for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fT5SG-0005X0-P4 for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:55 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:41612) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fT5SG-0005Um-F7 for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:52 -0400 Received: by mail-wr0-x22d.google.com with SMTP id h10-v6so2662866wrq.8 for ; Wed, 13 Jun 2018 06:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LgQ7v8FSvW3rYAYloOho4U2Wg8+IrRIeB0BXVRYCzj0=; b=cL6XUzg4vQ47BteW2zBLywsm3NKH92XdKgGba8BnwE4f+3lnQ+p1IrccYSwL1wuaJ3 D15gjgz98BkkHsUYm0yXUebyRMG1fjhVzgLvgN/bucnvUA6spoDbHfpQhrpq1CQ9QV0K ki6fDuzjvVrTp1vRXZqBbuN845ExlUny3vRng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LgQ7v8FSvW3rYAYloOho4U2Wg8+IrRIeB0BXVRYCzj0=; b=OYHlOQcaQZzxEuHcaR11evr6rC5/YkPFsQJr680g0ZeJwRczGqhaSrP0osd8me5pds G7cQVtMfhigcEhVQuB6m9kz+Rns6OiQYLzPwcZc5HUMP+H4QXYrDff15t0DQGIUDEE4I NcDrRqBA39i3v3p/EHVKWoTAw4kmgwRnKFSz5MP4akHeBVprboXR7xqoRdZ4cWwl4DEw fWYxE24E4S7AUnCpBxwCUTJ0wmpwnNhU4JIQclZKJGPgxiqOvqsMkOUHTE0lgcN3M8vv igizfkGIXICRAKZz3/iTPCZAtmzzBoeplHSgSucYDVX/q/FbXgVnnvBisjaqzdqfCXFq EmgQ== X-Gm-Message-State: APt69E0OfBb4EIN0qXQBFpyNm5aD+9/gcVM+mmUVCuYiFYUSgJpL7Whz YC3uoQs1J/DPzpidnTfCGPsoug== X-Received: by 2002:adf:dc52:: with SMTP id m18-v6mr4379645wrj.84.1528895091357; Wed, 13 Jun 2018 06:04:51 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a1-v6sm2742974wrq.54.2018.06.13.06.04.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 06:04:49 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 49EB33E1357; Wed, 13 Jun 2018 13:56:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 13 Jun 2018 13:56:01 +0100 Message-Id: <20180613125601.14371-23-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180613125601.14371-1-alex.bennee@linaro.org> References: <20180613125601.14371-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [RISU PATCH v3 22/22] risu_reginfo_aarch64: handle variable VQ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This involves parsing the command line parameter and calling the kernel to set the VQ limit. We also add dumping of the register state in the main register dump. Signed-off-by: Alex Bennée --- risu_reginfo_aarch64.c | 164 +++++++++++++++++++++++++++++------------ 1 file changed, 115 insertions(+), 49 deletions(-) -- 2.17.1 diff --git a/risu_reginfo_aarch64.c b/risu_reginfo_aarch64.c index a352b4c..71c57b9 100644 --- a/risu_reginfo_aarch64.c +++ b/risu_reginfo_aarch64.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "risu.h" #include "risu_reginfo_aarch64.h" @@ -30,17 +32,41 @@ const char * const arch_extra_help; /* Should we test SVE register state */ static int test_sve; static const struct option extra_opts[] = { - {"test-sve", no_argument, &test_sve, 1}, + {"test-sve", required_argument, NULL, FIRST_ARCH_OPT }, {0, 0, 0, 0} }; const struct option * const arch_long_opts = &extra_opts[0]; -const char * const arch_extra_help = " --test-sve Compare SVE registers\n"; +const char * const arch_extra_help + = " --test-sve= Compare SVE registers with VQ\n"; #endif void process_arch_opt(int opt, const char *arg) { +#ifdef SVE_MAGIC + long want, got; + + assert(opt == FIRST_ARCH_OPT); + test_sve = strtol(arg, 0, 10); + + if (test_sve <= 0 || test_sve > SVE_VQ_MAX) { + fprintf(stderr, "Invalid value for VQ (1-%d)\n", SVE_VQ_MAX); + exit(1); + } + want = sve_vl_from_vq(test_sve); + got = prctl(PR_SVE_SET_VL, want); + if (want != got) { + if (got < 0) { + perror("prctl PR_SVE_SET_VL"); + } else { + fprintf(stderr, "Unsupported value for VQ (%d != %d)\n", + test_sve, (int)sve_vq_from_vl(got)); + } + exit(1); + } +#else abort(); +#endif } const int reginfo_size(void) @@ -113,12 +139,18 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) #ifdef SVE_MAGIC if (test_sve) { - int vq = sve_vq_from_vl(sve->vl); /* number of quads for whole vl */ + int vq = test_sve; if (sve == NULL) { fprintf(stderr, "risu_reginfo_aarch64: failed to get SVE state\n"); return; } + if (sve->vl != sve_vl_from_vq(vq)) { + fprintf(stderr, "risu_reginfo_aarch64: " + "unexpected SVE state: %d != %d\n", + sve->vl, sve_vl_from_vq(vq)); + return; + } ri->sve.vl = sve->vl; @@ -147,12 +179,12 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) } /* Finally the FFR */ - memcpy(&ri->sve.ffr,(void *)sve + SVE_SIG_FFR_OFFSET(vq), + memcpy(&ri->sve.ffr, (void *)sve + SVE_SIG_FFR_OFFSET(vq), SVE_SIG_FFR_SIZE(vq)); return; } -#endif +#endif /* SVE_MAGIC */ for (i = 0; i < 32; i++) { ri->simd.vregs[i] = fp->vregs[i]; @@ -166,32 +198,49 @@ int reginfo_is_eq(struct reginfo *r1, struct reginfo *r2) } #ifdef SVE_MAGIC -static int sve_zreg_is_eq(struct reginfo *r1, struct reginfo *r2, int z) +static int sve_zreg_is_eq(int vq, const void *z1, const void *z2) { - return memcmp(r1->sve.zregs[z], r2->sve.zregs[z], sizeof(*r1->sve.zregs[z])) == 0; + return memcmp(z1, z2, vq * 16) == 0; } -static int sve_preg_is_eq(uint16_t const (*p1)[SVE_VQ_MAX], - uint16_t const (*p2)[SVE_VQ_MAX]) +static int sve_preg_is_eq(int vq, const void *p1, const void *p2) { - return memcmp(p1, p2, sizeof *p1) == 0; + return memcmp(p1, p2, vq * 2) == 0; } -static void sve_dump_preg_diff(FILE *f, int vq, - uint16_t const (*p1)[SVE_VQ_MAX], - uint16_t const (*p2)[SVE_VQ_MAX]) +static void sve_dump_preg(FILE *f, int vq, const uint16_t *p) { int q; - - for (q = 0; q < vq; q++) { - fprintf(f, "%#04x", *p1[q]); + for (q = vq - 1; q >= 0; q--) { + fprintf(f, "%04x", p[q]); } +} + +static void sve_dump_preg_diff(FILE *f, int vq, const uint16_t *p1, + const uint16_t *p2) +{ + sve_dump_preg(f, vq, p1); fprintf(f, " vs "); - for (q = 0; q < vq; q++) { - fprintf(f, "%#04x", *p2[q]); - } + sve_dump_preg(f, vq, p2); fprintf(f, "\n"); } + +static void sve_dump_zreg_diff(FILE *f, int vq, const __uint128_t *z1, + const __uint128_t *z2) +{ + const char *pad = ""; + int q; + + for (q = 0; q < vq; ++q) { + if (z1[q] != z2[q]) { + fprintf(f, "%sq%02d: %016" PRIx64 "%016" PRIx64 + " vs %016" PRIx64 "%016" PRIx64"\n", pad, q, + (uint64_t)(z1[q] >> 64), (uint64_t)z1[q], + (uint64_t)(z2[q] >> 64), (uint64_t)z2[q]); + pad = " "; + } + } +} #endif /* reginfo_dump: print state to a stream, returns nonzero on success */ @@ -210,6 +259,36 @@ int reginfo_dump(struct reginfo *ri, FILE * f) fprintf(f, " fpsr : %08x\n", ri->fpsr); fprintf(f, " fpcr : %08x\n", ri->fpcr); +#ifdef SVE_MAGIC + if (test_sve) { + int q, vq = test_sve; + + fprintf(f, " vl : %d\n", ri->sve.vl); + + for (i = 0; i < 32; i++) { + fprintf(f, " Z%-2d q%-2d: %016" PRIx64 "%016" PRIx64 "\n", i, 0, + (uint64_t)(ri->sve.zregs[i][0] >> 64), + (uint64_t)ri->sve.zregs[i][0]); + for (q = 1; q < vq; ++q) { + fprintf(f, " q%-2d: %016" PRIx64 "%016" PRIx64 "\n", q, + (uint64_t)(ri->sve.zregs[i][q] >> 64), + (uint64_t)ri->sve.zregs[i][q]); + } + } + + for (i = 0; i < 16; i++) { + fprintf(f, " P%-2d : ", i); + sve_dump_preg(f, vq, &ri->sve.pregs[i][0]); + fprintf(f, "\n"); + } + fprintf(f, " FFR : "); + sve_dump_preg(f, vq, &ri->sve.ffr[0]); + fprintf(f, "\n"); + + return !ferror(f); + } +#endif + for (i = 0; i < 32; i++) { fprintf(f, " V%-2d : %016" PRIx64 "%016" PRIx64 "\n", i, (uint64_t) (ri->simd.vregs[i] >> 64), @@ -259,42 +338,29 @@ int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE * f) #ifdef SVE_MAGIC if (test_sve) { - struct sve_reginfo *ms = &m->sve; - struct sve_reginfo *as = &a->sve; + int vq = sve_vq_from_vl(m->sve.vl); - if (ms->vl != as->vl) { - fprintf(f, " SVE VL : %d vs %d\n", ms->vl, as->vl); + if (m->sve.vl != a->sve.vl) { + fprintf(f, " vl : %d vs %d\n", m->sve.vl, a->sve.vl); } - if (!sve_preg_is_eq(&ms->ffr, &as->ffr)) { - fprintf(f, " FFR : "); - sve_dump_preg_diff(f, sve_vq_from_vl(ms->vl), - &ms->pregs[i], &as->pregs[i]); + for (i = 0; i < SVE_NUM_ZREGS; i++) { + if (!sve_zreg_is_eq(vq, &m->sve.zregs[i], &a->sve.zregs[i])) { + fprintf(f, " Z%-2d : ", i); + sve_dump_zreg_diff(f, vq, &m->sve.zregs[i][0], + &a->sve.zregs[i][0]); + } } for (i = 0; i < SVE_NUM_PREGS; i++) { - if (!sve_preg_is_eq(&ms->pregs[i], &as->pregs[i])) { - fprintf(f, " P%2d : ", i); - sve_dump_preg_diff(f, sve_vq_from_vl(ms->vl), - &ms->pregs[i], &as->pregs[i]); - } + if (!sve_preg_is_eq(vq, &m->sve.pregs[i], &a->sve.pregs[i])) { + fprintf(f, " P%-2d : ", i); + sve_dump_preg_diff(f, vq, &m->sve.pregs[i][0], + &a->sve.pregs[i][0]); + } } - for (i = 0; i < SVE_NUM_ZREGS; i++) { - if (!sve_zreg_is_eq(m, a, i)) { - int q; - char *pad=""; - fprintf(f, " Z%2d : ", i); - for (q = 0; q < sve_vq_from_vl(ms->vl); q++) { - if (ms->zregs[i][q] != as->zregs[i][q]) { - fprintf(f, "%sq%02d: %016" PRIx64 "%016" PRIx64 - " vs %016" PRIx64 "%016" PRIx64"\n", pad, q, - (uint64_t) (ms->zregs[i][q] >> 64), - (uint64_t) ms->zregs[i][q], - (uint64_t) (as->zregs[i][q] >> 64), - (uint64_t) as->zregs[i][q]); - pad = " "; - } - } - } + if (!sve_preg_is_eq(vq, &m->sve.ffr, &a->sve.ffr)) { + fprintf(f, " FFR : "); + sve_dump_preg_diff(f, vq, &m->sve.pregs[i][0], &a->sve.pregs[i][0]); } return !ferror(f);