Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B14FC433EF for ; Thu, 9 Dec 2021 23:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234715AbhLJAC4 (ORCPT ); Thu, 9 Dec 2021 19:02:56 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:20816 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbhLJACz (ORCPT ); Thu, 9 Dec 2021 19:02:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639094361; x=1670630361; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=cnkxM+v3e7Rw5Wac6Yp3jXRam56qrhimBukSct1R/EI=; b=PQcofmeAVXwpVMJipAQFEfHRzXVRIg0dXTz+Uok5pNx1KUkKl06BNtoi F273Hnj6FDuGf7hkoh1gypPICEErCeSbbEoMGJ18bbOHX0pZ+7WTjHGTT /ia05XbdODK/3GAmrUCvhiexMitSpKtv0oqCVGWTDFtgjaqvz6ydMvH9b MSrWwgc31rEx9n8Or2xKXywLtnJcblpsEJ+jIGbh8Y4nALGGKkzf2RxHx 1XUkX7rKM/jM0eEQMZCo39IlXAFJGBHtBJlWRqcvZHTc1EE5en2wxGD8M mJpZnZ+6ik5ApZpL/dt/++SfOCHiHX9KZqvyvidklFKvt5mPYpGChL7cU A==; X-IronPort-AV: E=Sophos;i="5.88,194,1635177600"; d="scan'208";a="299733816" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Dec 2021 07:59:21 +0800 IronPort-SDR: VpaQEO8iOZRWh64tA5dpqU6fzgBUcH4GWTQSOF1+ZI9+uN8zqs6Bh9Uoo5JyL6FOUlEXAmnoYT CaQragXYXUEjdmoY3l4pNh72xwuZ6MOXCMjqJRLMDmArNib4O2QdmNItIz8S7uAHVhgt6plmEC dVIX/YEwVWC6VoPP+3zUEG5XCw6YVzjF7DY4wAmXG2E98HJQJWrDznn7VyQyv01DjaXBRRhLoD 6V51XN0xuwIuUMDfPmYT4k3s8oFimQ6g6YGOv6WArJ0Iba/OWIk+g6jZi63WEtTNTtdlB0tkEe jkoKuNZ9YwV+gM0WffgoA4HU Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2021 15:32:22 -0800 IronPort-SDR: qlICnACCR3RQnT3j1BJWoxOdwmJN45bR6fk3I8BuYv71aWcD4oN/TK55BpatB6YutkfQNLI+fg XwzY1RllIN9GqxYrG3tEEpusqzdnpVkGhI5IZt58weZkCtCDrAu3WT7tfHfJnPwzqjKHKQnx9+ YruNW3MdxpgcCoNv4h9x+XWkE8W8Fjb+mtIoyA0diVZo6Gujlsqe20CXVW107B0MiCVQKc8+AJ uzqs7XX6pl/EiLzsENWA/LczJ2qbriwRkZaqkVZQTPcfle/96XpzxDbymioXkUyMBBF6+o4/xp fK8= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2021 15:59:22 -0800 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 4J99xN4b3Fz1Rwvk for ; Thu, 9 Dec 2021 15:59:20 -0800 (PST) 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 :x-mailer:message-id:date:subject:to:from; s=dkim; t=1639094359; x=1641686360; bh=cnkxM+v3e7Rw5Wac6Yp3jXRam56qrhimBukSct1R/EI=; b= QQ2lIM0w8R5/FXjkEH0OugTtSDERPVkfLnsvK1UEfiTOtWgcTpfIjHLxj2tWf84/ NwirDS1cU3ZjutIIkIafGap0mT4LMuZ9EBEaWidR5Nhww14V+8gSsnJjm7hcZ5tB CfJQGyo+NlKCCgM9unnCFZB2XByLQG+XuqM6vnx7oQ6xsgl0B0msEawD/TDjdSY/ VBJ7zsXib3uiLqBuCqf9ODs4iSkKMFXfvPzbF0LrUPpqnk2FrbsNQoZV7u/S52xB 6xKAGhJsGSjoC7MBKfULXVGUWoigq/qzga02Q8ReibV7N3TDRWLc8iw0gA2/NCUi fMsPG8TGV0RMASQDC59NxQ== 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 l1Kjq4rT-1mn for ; Thu, 9 Dec 2021 15:59:19 -0800 (PST) Received: from localhost.localdomain (unknown [10.225.165.65]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4J99x959wWz1RtVG; Thu, 9 Dec 2021 15:59:09 -0800 (PST) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: dave@stgolabs.net, dvhart@infradead.org, arnd@arndb.de, alistair23@gmail.com, namhyung@kernel.org, acme@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, alexander.shishkin@linux.intel.com, mark.rutland@arm.com, mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de, Alistair Francis , Atish Patra , linux-riscv@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH v5 1/6] perf bench futex: Add support for 32-bit systems with 64-bit time_t Date: Fri, 10 Dec 2021 09:58:52 +1000 Message-Id: <20211209235857.423773-1-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alistair Francis Some 32-bit architectures (such are 32-bit RISC-V) only have a 64-bit time_t and as such don't have the SYS_futex syscall. This patch will allow us to use the SYS_futex_time64 syscall on those platforms. This also converts the futex calls to be y2038 safe (when built for a 5.1+ kernel). This is a revert of commit ba4026b09d83acf56c040b6933eac7916c27e728 "Revert "perf bench futex: Add support for 32-bit systems with 64-bit tim= e_t"". The original commit was reverted as including linux/time_types.h would fail to compile on older kernels. This commit doesn't include linux/time_types.h to avoid this issue. Signed-off-by: Alistair Francis Cc: Alexander Shishkin Cc: Alistair Francis Cc: Atish Patra Cc: Darren Hart Cc: Davidlohr Bueso Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-riscv@lists.infradead.org Cc: Arnaldo Carvalho de Melo Reviewed-by: Arnd Bergmann --- tools/perf/bench/futex.h | 52 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h index ebdc2b032afc..385d2bdfaa9f 100644 --- a/tools/perf/bench/futex.h +++ b/tools/perf/bench/futex.h @@ -8,6 +8,7 @@ #ifndef _FUTEX_H #define _FUTEX_H =20 +#include #include #include #include @@ -28,7 +29,17 @@ struct bench_futex_parameters { }; =20 /** - * futex_syscall() - SYS_futex syscall wrapper + * This is copied from linux/time_types.h. + * We copy this here to avoid compilation failures when running + * on systems that don't ship with linux/time_types.h. + */ +struct __kernel_old_timespec { + __kernel_old_time_t tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ +}; + +/** + * futex_syscall() - __NR_futex syscall wrapper * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op @@ -49,14 +60,49 @@ static inline int futex_syscall(volatile u_int32_t *uaddr, int op, u_int32_t val, struct t= imespec *timeout, volatile u_int32_t *uaddr2, int val3, int opflags) { - return syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, va= l3); +#if defined(__NR_futex_time64) + if (sizeof(*timeout) !=3D sizeof(struct __kernel_old_timespec)) { + int ret =3D syscall(__NR_futex_time64, uaddr, op | opflags, val, timeo= ut, + uaddr2, val3); + if (ret =3D=3D 0 || errno !=3D ENOSYS) + return ret; + } +#endif + +#if defined(__NR_futex) + if (sizeof(*timeout) =3D=3D sizeof(struct __kernel_old_timespec)) + return syscall(__NR_futex, uaddr, op | opflags, val, timeout, uaddr2, = val3); + + if (timeout && timeout->tv_sec =3D=3D (long)timeout->tv_sec) { + struct __kernel_old_timespec ts32; + + ts32.tv_sec =3D (__kernel_long_t) timeout->tv_sec; + ts32.tv_nsec =3D (__kernel_long_t) timeout->tv_nsec; + + return syscall(__NR_futex, uaddr, op | opflags, val, ts32, uaddr2, val= 3); + } else if (!timeout) { + return syscall(__NR_futex, uaddr, op | opflags, val, NULL, uaddr2, val= 3); + } +#endif + + errno =3D ENOSYS; + return -1; } =20 static inline int futex_syscall_nr_requeue(volatile u_int32_t *uaddr, int op, u_int32_t va= l, int nr_requeue, volatile u_int32_t *uaddr2, int val3, int opflags) { - return syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2,= val3); +#if defined(__NR_futex_time64) + int ret =3D syscall(__NR_futex_time64, uaddr, op | opflags, val, nr_re= queue, + uaddr2, val3); + if (ret =3D=3D 0 || errno !=3D ENOSYS) + return ret; +#endif + +#if defined(__NR_futex) + return syscall(__NR_futex, uaddr, op | opflags, val, nr_requeue, uaddr2= , val3); +#endif } =20 /** --=20 2.31.1