Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4165427pxb; Wed, 13 Oct 2021 23:00:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwosaI+trhhDTfodiW1hGwpqGYoK0AMShPK1DPZnUsRVx8FudRjH3vr56KpSwHMuNyxxnWc X-Received: by 2002:a50:da0a:: with SMTP id z10mr5800926edj.95.1634191219207; Wed, 13 Oct 2021 23:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634191219; cv=none; d=google.com; s=arc-20160816; b=pwtMrN90C5xLIhp6LObAR7JIsMgGx+kWllxa107YFIrK6qUkrZCAxl7JnUDIT4D1Ud m/DsKjbVTFh92OOhRSF+N0Xmjwq4vi47gKLyPUKUryYxuk2QTGv+E3qGpoRKPxf/uo5h bAXXW0BhT99a3hPGDhC+GBoR3rBwH7VpZTBf/1yPRmK3UWdkhkkVWZIOXxtJ+ZK0eoAE R0/iveo3SxoHh5KWCqh5kDox0YystIBWADEub41WyrXBXvRGg2WZXVf5blb6NwdBoySq htMSglp/jDzkdpsnY7kxNo8UzBjzdiJcUQh2GAwU72doxfwLgqL1Kpo1R0dUcPftLyXq r0rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=kgCQQxPtfXY7SW650nKzruP0aRpicXnXT6LDmSPLsUk=; b=gOW8kcd0KZkftT1wDtAS8k8bWLoOvEL9w5FweJeojG4T9WTED132AtYa+vYJI07icJ OozTB1rScbOAitpf3KcXrP430WBWBjp57ILWzDAGik60qFIPlyuxkmACWf6f9bXt8ISO tHiXU0qCAzjUXK4HrsKvuRVTQqkNs40NYD3pFw0/ONiodOhPgdGq8dFy8JuwTxIcckTY XfiAZp5RRK20xmK57Ifrwcwydj9OkfqHAgfZEszsoyJRKprTRQIY1Fh7Nrght5vQ0Prr Li7cyttX0Lx8hTFlGpA28ML63gqfaEfWVE/LgiEePn8ON+V2vlTg2jjiF6vTuOYpN+3y 9G0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=LwrDm4sj; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=hC46IN7c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m6si2607191edb.172.2021.10.13.22.59.55; Wed, 13 Oct 2021 23:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=LwrDm4sj; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=hC46IN7c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbhJNF6N (ORCPT + 99 others); Thu, 14 Oct 2021 01:58:13 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43063 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbhJNF6M (ORCPT ); Thu, 14 Oct 2021 01:58:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1634190968; x=1665726968; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sf+179vW/iQYlKmtz8f0y7xIP3dUveU16tfuDHqj1X0=; b=LwrDm4sjMnvQsbwMumj/a8HsIyZPRJm9FqyNbkXPgf9NbANTWpAlowzf hvnoOrvksqbDMbyzxvkJ7sO3TfQ+V0nNUgkAmJR8JD+cFbUqnLMCZj4Xp xZvGBDi4zoLt8bLCEzP1qRQ96+W5T3syX50nW3mdz/b6xvJiQEVtU6OgJ PM8N0Vbj/6EVEm/Aa0SHGv3trQ0R5B9xDOVpxaLUDp8tNnkhsE7Bo+fi0 31k3xijnL8+FlQrMBPBQowDsL2pO+x8gBMVxmozi6JlzreasqjBv0wUc0 Vl0IW3zVz0/FY3NI1IsLeJNXfxB1Z3bBt2vqjVfqKVwhb44rX1MLX6S1g A==; X-IronPort-AV: E=Sophos;i="5.85,371,1624291200"; d="scan'208";a="294531048" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Oct 2021 13:56:07 +0800 IronPort-SDR: EjVfLNhNaaKCBNKcz3dFcCwdmEXR/dkVX/OexLDUfhqAkydsq679UHKQmBArsPCg/G7lIhx0XH /Vh0f2ZgpL9TaBt0zT4M/eckPnyt+cr56e/SQAf2f17FW5QKBsvijtl8fmrgBVC+bkwAYMqyVg hj07DgtEbi6HLB8vaJH2of2NGJH/6CjmhB2FNaHrAzLa3FgRXJk0puwunK9g7dzKSMTDHSxGhY Hrh9yjlnuZgxpowkhTXxQvZIOGx+4tgr6LsKy4sGiQwx9urbGmmb2+26igaxar6Fgi+tQ/YXwr kq6uBLEgl91SaInEyNWcBVcg Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 22:30:20 -0700 IronPort-SDR: I7ubRgn34tJqhhNmaeB9Ce2g7ZCU9QSEEAUD6dtXFg/2Gas4XyrbGqeJ3hZc4d8P8pOpUFIXr8 div2Bqjj/aX1dPXsbZtLeeE3UQgpYGXMvdFLFaa4CGeuYBC29zrFGTp0SckpRkbY6CLTXMAhwI 8z48VReDDhghVAeL+O5m4TaOxm1DGE+yV8/quthK1LUy9JCGtXzhP86YPnXx+61BHaaOBkJ+3D Ok0JBaZSMRmAlv42660sz7AH8M8gEE4SCBOnSQvtYg+ELiZdm559jhkjA9W/bvjZc//zNsb279 xYo= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 22:56:08 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4HVJYM1ZHdz1RvmH for ; Wed, 13 Oct 2021 22:56:07 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1634190965; x=1636782966; bh=Sf+179vW/iQYlKmtz8 f0y7xIP3dUveU16tfuDHqj1X0=; b=hC46IN7cy5gRrX4LT14zPDnZWoNyg48Yal 2OfYpq+jCdC0M1FUwYdvCamDDUARVTRbvzae9xDK0xF1mp7LR3eBeGdbhK7m7L7P EQ7vprUmO0CUhi5sOAR8k2bEfMCoWbOxg0vJqYkkWWPInFPrt4cjfZe/NK6k3H6H sEqOdz8yLwvULfkxGhGdIEoa0cLgEBV4KMav/t4gjdFZZBhy2NzrqdcsYOAip/Gy JNmavE6kkozByqzIoVNJU0M4XAlYq2dmTyht0FoPtH3D0xMoHZACwmOnQxQsnWdT 8Ywzr39lIz/qG/H6uCEygHC7ez+mnvUCafFqhMOiKTh+6E7i/fTg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qv-EKH-tOnj6 for ; Wed, 13 Oct 2021 22:56:05 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.36]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4HVJY54SCtz1Rvlw; Wed, 13 Oct 2021 22:55:52 -0700 (PDT) From: Alistair Francis To: linux-riscv@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, alistair23@gmail.com, namhyung@kernel.org, jolsa@redhat.com, alexander.shishkin@linux.intel.com, mark.rutland@arm.com, acme@kernel.org, dave@stgolabs.net, dvhart@infradead.org, peterz@infradead.org, mingo@redhat.com, tglx@linutronix.de, atish.patra@wdc.com, arnd@arndb.de, Alistair Francis Subject: [PATCH 2/2] selftests: futex: Use a 64-bit time_t Date: Thu, 14 Oct 2021 15:55:27 +1000 Message-Id: <20211014055527.1238645-2-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211014055527.1238645-1-alistair.francis@opensource.wdc.com> References: <20211014055527.1238645-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alistair Francis Convert the futex selftests to only use a 64-bit time_t. On 64-bit architectures this isn't a functional change. On 32-bit architectures we now only perform 64-bit time_t syscalls (__NR_futex_time64) and use a struct timespec64. This won't work on kernels before 5.1, but as perf is tied to the kernel that's ok. This allows the tests to run and pass on RISC-V 32-bit. Signed-off-by: Alistair Francis --- .../futex/functional/futex_requeue.c | 2 +- .../futex/functional/futex_requeue_pi.c | 6 +-- .../selftests/futex/functional/futex_wait.c | 2 +- .../futex_wait_private_mapped_file.c | 2 +- .../futex/functional/futex_wait_timeout.c | 8 ++-- .../futex/functional/futex_wait_wouldblock.c | 2 +- .../selftests/futex/include/futextest.h | 39 +++++++++++++++---- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue.c b/t= ools/testing/selftests/futex/functional/futex_requeue.c index 51485be6eb2f1..f51aedffcd161 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue.c +++ b/tools/testing/selftests/futex/functional/futex_requeue.c @@ -27,7 +27,7 @@ void usage(char *prog) =20 void *waiterfn(void *arg) { - struct timespec to; + struct timespec64 to; =20 to.tv_sec =3D 0; to.tv_nsec =3D timeout_ns; diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c = b/tools/testing/selftests/futex/functional/futex_requeue_pi.c index 1ee5518ee6b7f..497c0dc80916f 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c @@ -48,7 +48,7 @@ static int locked; =20 struct thread_arg { long id; - struct timespec *timeout; + struct timespec64 *timeout; int lock; int ret; }; @@ -281,7 +281,7 @@ int unit_test(int broadcast, long lock, int third_par= ty_owner, long timeout_ns) struct thread_arg blocker_arg =3D THREAD_ARG_INITIALIZER; struct thread_arg waker_arg =3D THREAD_ARG_INITIALIZER; pthread_t waiter[THREAD_MAX], waker, blocker; - struct timespec ts, *tsp =3D NULL; + struct timespec64 ts, *tsp =3D NULL; struct thread_arg args[THREAD_MAX]; int *waiter_ret; int i, ret =3D RET_PASS; @@ -290,7 +290,7 @@ int unit_test(int broadcast, long lock, int third_par= ty_owner, long timeout_ns) time_t secs; =20 info("timeout_ns =3D %ld\n", timeout_ns); - ret =3D clock_gettime(CLOCK_MONOTONIC, &ts); + ret =3D gettime64(CLOCK_MONOTONIC, &ts); secs =3D (ts.tv_nsec + timeout_ns) / 1000000000; ts.tv_nsec =3D ((int64_t)ts.tv_nsec + timeout_ns) % 1000000000; ts.tv_sec +=3D secs; diff --git a/tools/testing/selftests/futex/functional/futex_wait.c b/tool= s/testing/selftests/futex/functional/futex_wait.c index 685140d9b93d2..d1c8a4212c74c 100644 --- a/tools/testing/selftests/futex/functional/futex_wait.c +++ b/tools/testing/selftests/futex/functional/futex_wait.c @@ -30,7 +30,7 @@ void usage(char *prog) =20 static void *waiterfn(void *arg) { - struct timespec to; + struct timespec64 to; unsigned int flags =3D 0; =20 if (arg) diff --git a/tools/testing/selftests/futex/functional/futex_wait_private_= mapped_file.c b/tools/testing/selftests/futex/functional/futex_wait_priva= te_mapped_file.c index fb4148f23fa37..5e84e136ad99e 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_= file.c +++ b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_= file.c @@ -38,7 +38,7 @@ futex_t val =3D 1; char pad2[PAGE_SZ] =3D {1}; =20 #define WAKE_WAIT_US 3000000 -struct timespec wait_timeout =3D { .tv_sec =3D 5, .tv_nsec =3D 0}; +struct timespec64 wait_timeout =3D { .tv_sec =3D 5, .tv_nsec =3D 0}; =20 void usage(char *prog) { diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.= c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index 1f8f6daaf1e70..86b1e847a0246 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -71,11 +71,11 @@ static void test_timeout(int res, int *ret, char *tes= t_name, int err) /* * Calculate absolute timeout and correct overflow */ -static int futex_get_abs_timeout(clockid_t clockid, struct timespec *to, +static int futex_get_abs_timeout(clockid_t clockid, struct timespec64 *t= o, long timeout_ns) { - if (clock_gettime(clockid, to)) { - error("clock_gettime failed\n", errno); + if (gettime64(clockid, to)) { + error("gettime64 failed\n", errno); return errno; } =20 @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) { futex_t f1 =3D FUTEX_INITIALIZER; int res, ret =3D RET_PASS; - struct timespec to; + struct timespec64 to; pthread_t thread; int c; =20 diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblo= ck.c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c index 0ae390ff81644..76faa664544d6 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -38,7 +38,7 @@ void usage(char *prog) =20 int main(int argc, char *argv[]) { - struct timespec to =3D {.tv_sec =3D 0, .tv_nsec =3D timeout_ns}; + struct timespec64 to =3D {.tv_sec =3D 0, .tv_nsec =3D timeout_ns}; futex_t f1 =3D FUTEX_INITIALIZER; int res, ret =3D RET_PASS; int c; diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/te= sting/selftests/futex/include/futextest.h index ddbcfc9b7bac4..72361b41cdbae 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -47,12 +47,17 @@ typedef volatile u_int32_t futex_t; FUTEX_PRIVATE_FLAG) #endif =20 +struct timespec64 { + long long tv_sec; /* seconds */ + long long tv_nsec; /* nanoseconds */ +}; + /** * futex() - SYS_futex syscall wrapper * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op - * @timeout: typically an absolute struct timespec (except where noted + * @timeout: typically an absolute struct timespec64 (except where noted * otherwise). Overloaded by some ops * @uaddr2: address of second futex for some ops\ * @val3: varies by op @@ -67,15 +72,35 @@ typedef volatile u_int32_t futex_t; * These argument descriptions are the defaults for all * like-named arguments in the following wrappers except where noted bel= ow. */ -#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \ - syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3) +/** + * We only support 64-bit time_t for the timeout. + * On 64-bit architectures we can use __NR_futex + * On 32-bit architectures we use __NR_futex_time64. This only works on = kernel + * versions 5.1+. + */ +#if __BITS_PER_LONG =3D=3D 64 || (defined(__x86_64__) && defined(__ILP32= __)) +# define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \ + syscall(__NR_futex, uaddr, op | opflags, val, timeout, uaddr2, val3) +#else +# define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \ + syscall(__NR_futex_time64, uaddr, op | opflags, val, timeout, uaddr2, v= al3) +#endif + +static inline int gettime64(clock_t clockid, struct timespec64 *tv) +{ +#if __BITS_PER_LONG =3D=3D 64 || (defined(__x86_64__) && defined(__ILP32= __)) + return syscall(__NR_clock_gettime, clockid, tv); +#else + return syscall(__NR_clock_gettime64, clockid, tv); +#endif +} =20 /** * futex_wait() - block on uaddr with optional timeout * @timeout: relative timeout */ static inline int -futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int op= flags) +futex_wait(futex_t *uaddr, futex_t val, struct timespec64 *timeout, int = opflags) { return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); } @@ -95,7 +120,7 @@ futex_wake(futex_t *uaddr, int nr_wake, int opflags) * @bitset: bitset to be used with futex_wake_bitset */ static inline int -futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, +futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec64 *timeou= t, u_int32_t bitset, int opflags) { return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, @@ -118,7 +143,7 @@ futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int3= 2_t bitset, int opflags) * @detect: whether (1) or not (0) to perform deadlock detection */ static inline int -futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect, +futex_lock_pi(futex_t *uaddr, struct timespec64 *timeout, int detect, int opflags) { return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags); @@ -183,7 +208,7 @@ futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_= t *uaddr2, int nr_wake, */ static inline int futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, - struct timespec *timeout, int opflags) + struct timespec64 *timeout, int opflags) { return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0, opflags); --=20 2.31.1