From patchwork Thu Jul 30 18:09:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 247286 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2656626ilg; Thu, 30 Jul 2020 11:37:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBmc1B4LlA3mfNlCRRZy/dVam3rgxYa8ay1J7xXt4r/bJysMuGAoYSK2+huGIzq7FRBSNB X-Received: by 2002:a17:906:e251:: with SMTP id gq17mr387249ejb.445.1596134243664; Thu, 30 Jul 2020 11:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596134243; cv=none; d=google.com; s=arc-20160816; b=FTe81ckp2TyoXvM/0amy4mdONCSDQefRmiqkE4e0PBNCBOajmIvmLBLZSGYwUwh4sN rCQMKWc/W4IlcpLDqe8jM7oAgInP7/E9Ekvq2xWQJtEhUzrPKoDSHmzuoI4WsZyuNMHL 3/FOam4o7pBErFrA85y7lxCF75ICFuWP8Bv3nXwefLIEmes9gdg3SSYGOMOuxx2daGfU 4qqpo2jTVo2fFH9GlH+dABW/uTrSm5Mvu5F6XzUVRhQHMVJ5x0XAKktTqUs1FrqkIZaZ sjxIGgnUBp3AvGwzF5JntctLPYszbc4eVlOGsbtj2TpKv9/0zCTQPoNkT+J5iAF9eIIH 1JLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z9dmyv/DsFgv+ocZzlK/UmZjtNZj4Q1kSOcomY2rLbs=; b=FYjJ7mRPOykIxWcXHa6sklp7ORUUqUVaHswgmZTP6RFCLPRE175hpwKf3rUv7VpsNA z8BPJwz84HQQVPmSxdq7w+Or+XzJIJO5IJzqxGz13JODbekzsjvVJ+7BJRVzfOeFgM7+ +GfMWuXfjXoKwEhqNl+golr8JICKgZ4TcCNBut5GXXjvHYEENcVCWQEWlORsnxmb0I0W UjT1yYmN/SzWDFcHVfqUwly7Ombu0QS98Eg8bjaqzlCWXerLAAS9GPzq+VN0CEMUiFNt r3IqRh+kD/dj3OqC6d1lyGtZ60iMXkBvdSOPBXnU0BPEOCBelO1Bo2spEdccpPJkdzXx +dVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rCdp+A9T; spf=pass (google.com: domain of linux-kselftest-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kselftest-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rn4si4022473ejb.29.2020.07.30.11.37.23; Thu, 30 Jul 2020 11:37:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kselftest-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rCdp+A9T; spf=pass (google.com: domain of linux-kselftest-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kselftest-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730357AbgG3ShT (ORCPT + 6 others); Thu, 30 Jul 2020 14:37:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:57336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730244AbgG3ShT (ORCPT ); Thu, 30 Jul 2020 14:37:19 -0400 Received: from localhost (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A11A2072A; Thu, 30 Jul 2020 18:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596134238; bh=0KUG667BqBQH7R9oDKcdtnatIv4iRLCgQg18W5V0byE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rCdp+A9ToDiysepw7RYIe8NE9bGECqyDN0X3FxbWZxNfiqO53aMiwDacFVaxM2RR4 snhVlyYobin6wynwriaabMiE+hgZoyslaC58y3e2e2OgM9SKYDqjBabSeUJ+XGnCNS Usw2rlLeOa/TXRgJ/lA1frJV6Di0+hZTZiJ784Y8= From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Dave Martin Cc: linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH 4/6] selftests: arm64: Add utility to set SVE vector lengths Date: Thu, 30 Jul 2020 19:09:18 +0100 Message-Id: <20200730180920.23527-5-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200730180920.23527-1-broonie@kernel.org> References: <20200730180920.23527-1-broonie@kernel.org> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org vlset is a small utility for use in conjunction with tests like the sve-test stress test which allows another executable to be invoked with a configured SVE vector length. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/fp/vlset.c | 155 +++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tools/testing/selftests/arm64/fp/vlset.c -- 2.20.1 diff --git a/tools/testing/selftests/arm64/fp/vlset.c b/tools/testing/selftests/arm64/fp/vlset.c new file mode 100644 index 000000000000..308d27a68226 --- /dev/null +++ b/tools/testing/selftests/arm64/fp/vlset.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2015-2019 ARM Limited. + * Original author: Dave Martin + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int inherit = 0; +static int no_inherit = 0; +static int force = 0; +static unsigned long vl; + +static const struct option options[] = { + { "force", no_argument, NULL, 'f' }, + { "inherit", no_argument, NULL, 'i' }, + { "max", no_argument, NULL, 'M' }, + { "no-inherit", no_argument, &no_inherit, 1 }, + { "help", no_argument, NULL, '?' }, + {} +}; + +static char const *program_name; + +static int parse_options(int argc, char **argv) +{ + int c; + char *rest; + + program_name = strrchr(argv[0], '/'); + if (program_name) + ++program_name; + else + program_name = argv[0]; + + while ((c = getopt_long(argc, argv, "Mfhi", options, NULL)) != -1) + switch (c) { + case 'M': vl = SVE_VL_MAX; break; + case 'f': force = 1; break; + case 'i': inherit = 1; break; + case 0: break; + default: goto error; + } + + if (inherit && no_inherit) + goto error; + + if (!vl) { + /* vector length */ + if (optind >= argc) + goto error; + + errno = 0; + vl = strtoul(argv[optind], &rest, 0); + if (*rest) { + vl = ULONG_MAX; + errno = EINVAL; + } + if (vl == ULONG_MAX && errno) { + fprintf(stderr, "%s: %s: %s\n", + program_name, argv[optind], strerror(errno)); + goto error; + } + + ++optind; + } + + /* command */ + if (optind >= argc) + goto error; + + return 0; + +error: + fprintf(stderr, + "Usage: %s [-f | --force] " + "[-i | --inherit | --no-inherit] " + "{-M | --max | } " + " [ ...]\n", + program_name); + return -1; +} + +int main(int argc, char **argv) +{ + int ret = 126; /* same as sh(1) command-not-executable error */ + long flags; + char *path; + int t, e; + + if (parse_options(argc, argv)) + return 2; /* same as sh(1) builtin incorrect-usage */ + + if (vl & ~(vl & PR_SVE_VL_LEN_MASK)) { + fprintf(stderr, "%s: Invalid vector length %lu\n", + program_name, vl); + return 2; /* same as sh(1) builtin incorrect-usage */ + } + + if (!(getauxval(AT_HWCAP) & HWCAP_SVE)) { + fprintf(stderr, "%s: Scalable Vector Extension not present\n", + program_name); + + if (!force) + goto error; + + fputs("Going ahead anyway (--force): " + "This is a debug option. Don't rely on it.\n", + stderr); + } + + flags = PR_SVE_SET_VL_ONEXEC; + if (inherit) + flags |= PR_SVE_VL_INHERIT; + + t = prctl(PR_SVE_SET_VL, vl | flags); + if (t < 0) { + fprintf(stderr, "%s: PR_SVE_SET_VL: %s\n", + program_name, strerror(errno)); + goto error; + } + + t = prctl(PR_SVE_GET_VL); + if (t == -1) { + fprintf(stderr, "%s: PR_SVE_GET_VL: %s\n", + program_name, strerror(errno)); + goto error; + } + flags = PR_SVE_VL_LEN_MASK; + flags = t & ~flags; + + assert(optind < argc); + path = argv[optind]; + + execvp(path, &argv[optind]); + e = errno; + if (errno == ENOENT) + ret = 127; /* same as sh(1) not-found error */ + fprintf(stderr, "%s: %s: %s\n", program_name, path, strerror(e)); + +error: + return ret; /* same as sh(1) not-executable error */ +}