[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211015005634.2658470-1-alistair.francis@opensource.wdc.com>
Date: Fri, 15 Oct 2021 10:56:33 +1000
From: Alistair Francis <alistair.francis@...nsource.wdc.com>
To: linux-riscv@...ts.infradead.org, linux-perf-users@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, alistair23@...il.com,
namhyung@...nel.org, jolsa@...hat.com,
alexander.shishkin@...ux.intel.com, mark.rutland@....com,
acme@...nel.org, dave@...olabs.net, dvhart@...radead.org,
peterz@...radead.org, mingo@...hat.com, tglx@...utronix.de,
atish.patra@....com, arnd@...db.de,
Alistair Francis <alistair.francis@....com>
Subject: [PATCH v2 1/2] perf bench futex: Use a 64-bit time_t
From: Alistair Francis <alistair.francis@....com>
Convert tools/perf 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 us to build perf for 32-bit architectures with 64-bit time_t
like RISC-V 32-bit.
Signed-off-by: Alistair Francis <alistair.francis@....com>
---
tools/perf/bench/futex.h | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index b3853aac3021c..b9665d43d2988 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -12,6 +12,7 @@
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/futex.h>
+#include <linux/time_types.h>
struct bench_futex_parameters {
bool silent;
@@ -27,12 +28,14 @@ struct bench_futex_parameters {
unsigned int nrequeue;
};
+#define timespec64 __kernel_timespec
+
/**
* 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
@@ -47,15 +50,26 @@ struct bench_futex_parameters {
* These argument descriptions are the defaults for all
* like-named arguments in the following wrappers except where noted below.
*/
-#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 == 64
+# 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, val3)
+#endif
/**
* futex_wait() - block on uaddr with optional timeout
* @timeout: relative timeout
*/
static inline int
-futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
+futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec64 *timeout, int opflags)
{
return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
}
@@ -74,7 +88,7 @@ futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
* futex_lock_pi() - block on uaddr as a PI mutex
*/
static inline int
-futex_lock_pi(u_int32_t *uaddr, struct timespec *timeout, int opflags)
+futex_lock_pi(u_int32_t *uaddr, struct timespec64 *timeout, int opflags)
{
return futex(uaddr, FUTEX_LOCK_PI, 0, timeout, NULL, 0, opflags);
}
@@ -111,7 +125,7 @@ futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wak
*/
static inline int
futex_wait_requeue_pi(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2,
- struct timespec *timeout, int opflags)
+ struct timespec64 *timeout, int opflags)
{
return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0,
opflags);
--
2.31.1
Powered by blists - more mailing lists