From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0973BC433FE for ; Wed, 20 Oct 2021 22:40:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E23DE6128E for ; Wed, 20 Oct 2021 22:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbhJTWmf (ORCPT ); Wed, 20 Oct 2021 18:42:35 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:46082 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbhJTWme (ORCPT ); Wed, 20 Oct 2021 18:42:34 -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=1634769620; x=1666305620; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y8ldQtnZtH2nNau0fDjjtgFR2uznY4wI2KcEdQP3NCw=; b=gnoMKgqsAB9NGlzlTCfBO2sW6W5zM1/L4v7jOQRJyuzD3TwiPkOgk9Lx wi2kuPN1PhWj/v7xrEbT3I+BE7ZtaCu7ru+MIqqfRd++yhdDDxPe0Ucfg tbQ/cRoHL20FE1cHECraTaFsGZRZO/fh7o9ZDOQMdqTSQXDVuv9zuOn9j 5ZqX7yGeHFm1ogNM9NpEJQZoHW5N1XNDV4Et8/AAFRqpTqt3IGyDdR04+ d/BO3fvDto6igeY3l2AnpyJcdM/CfIZf6pPu+oRoAVeZ7EVwQcTq4jH3w zvacXk3UR9hvOdOVlJGuA1kkaz3jirqSuMnklYi0AC04rTFOmYDlJfi7I g==; X-IronPort-AV: E=Sophos;i="5.87,168,1631548800"; d="scan'208";a="184393913" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 21 Oct 2021 06:40:19 +0800 IronPort-SDR: FU0XuVFGO48HR/ImpugtnFiOy/WVyBz5tPP3Dxz6DXXVjWRWuStSWKWxu6knPYO6vm10HWgciK ExxYc7OvwvampC0WUT8faBo+k6VsP9O/yQddlv/PzQ9ywcJMOA8H9sS2ODAYsh/xIKyg0eHFAb 334BMxGB9HmwkYsLwmbaWDqTUAHACtxm9Tp4hYjtv08gZ7LN1tcq73zwSQC/Nl+7xj3mv+iO4a LreqXpC4U56ZDCZdVHnHOFawHBHdnhBdMhQJG2/YbwJTi7HhruElSWXRGa+kJeHq56n6DOlAn5 HmGKwsk3EuhrQYNptyPtOZ3i Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2021 15:15:55 -0700 IronPort-SDR: el6PD1Ct6bZ4Qob1ObcVqdZQNbF4y3VQY1OTnil2rAF0QfGHggP6sLbxtO+U9plzvSsT8T1Id+ ItMivbfXiPuU7+SEj2XkEQTVQI6vXW3s93zi8Oz5wCkAOqVYMPYOcmWbyI4ELMr+GLOWy+ZJjJ 6NavZNKcp4wi78kD2TIULrZppPHU2ujEgOWCTFxLSxIG6hbIrJRLpQvfOFDm3DWZT9w9/m38ie v837QQvvrzHLDOG/Vh/Q6qz8NEEQ5P5+i9T4W02ZS//GZuZhC7uvuuwYXXSSVpHH6e/EROd/6k 5PQ= 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; 20 Oct 2021 15:40:19 -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 4HZQYG0kVTz1RvmL for ; Wed, 20 Oct 2021 15:40:18 -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=1634769616; x=1637361617; bh=Y8ldQtnZtH2nNau0fD jjtgFR2uznY4wI2KcEdQP3NCw=; b=WK0NYuGJdpZqBNJPokPtHztBAhbhlaT4MD e4vwlTrR1XjMEFYPuwJD7cp7Rd305TW9/D054K0mtEtQp040ZT4YM4F3TldzZii3 b88A0isBPV5Hul6AZP35l5x6IY6KnqY0OI9u46qHAC7gzFhbfAzuW7F1L4TsaonJ 9kCgVh419XVoXm6P14csyRgX5nU7oOeUWUfzKZ8WbkcAo9wC2gXqrT9NTPkvfjBW FD529WF0cxmg11JUCeD38fejiJmRcZkCwqxGZoD2vAUB8Q4aA18zoCd57/lBXlBV W2o4bU6vwZwoQv4IJv7mDkMngtTwcidqSJtuRvFnpu7bYVyG9lbw== 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 EKqRpjoR9o3q for ; Wed, 20 Oct 2021 15:40:16 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.39]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4HZQY10Kx0z1SGYQ; Wed, 20 Oct 2021 15:40:04 -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 v4 3/4] selftests: futex: Call the futex syscall from a function Date: Thu, 21 Oct 2021 08:39:19 +1000 Message-Id: <20211020223920.2810727-3-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211020223920.2810727-1-alistair.francis@opensource.wdc.com> References: <20211020223920.2810727-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 Call the futex syscall from a function In preparation for a more complex futex() function let's convert the current macro into two functions. We need two functions to avoid compiler failures as the macro is overloaded. This will allow us to include pre-processor conditionals in the futex syscall functions. Signed-off-by: Alistair Francis --- .../selftests/futex/include/futextest.h | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/te= sting/selftests/futex/include/futextest.h index ddbcfc9b7bac4..1b133f81e9b7b 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -48,7 +48,7 @@ typedef volatile u_int32_t futex_t; #endif =20 /** - * futex() - SYS_futex syscall wrapper + * futex_syscall() - SYS_futex syscall wrapper * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op @@ -58,17 +58,26 @@ typedef volatile u_int32_t futex_t; * @val3: varies by op * @opflags: flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLA= G * - * futex() is used by all the following futex op wrappers. It can also b= e + * futex_syscall() is used by all the following futex op wrappers. It ca= n also be * used for misuse and abuse testing. Generally, the specific op wrapper= s - * should be used instead. It is a macro instead of an static inline fun= ction as - * some of the types over overloaded (timeout is used for nr_requeue for - * example). + * should be used instead. * * 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) +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, ts32, uaddr2, val3)= ; +} + +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); +} =20 /** * futex_wait() - block on uaddr with optional timeout @@ -77,7 +86,7 @@ typedef volatile u_int32_t futex_t; static inline int futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int op= flags) { - return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags)= ; } =20 /** @@ -87,7 +96,7 @@ futex_wait(futex_t *uaddr, futex_t val, struct timespec= *timeout, int opflags) static inline int futex_wake(futex_t *uaddr, int nr_wake, int opflags) { - return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags= ); } =20 /** @@ -98,8 +107,8 @@ static inline int futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, u_int32_t bitset, int opflags) { - return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, - opflags); + return futex_syscall(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bits= et, + opflags); } =20 /** @@ -109,8 +118,8 @@ futex_wait_bitset(futex_t *uaddr, futex_t val, struct= timespec *timeout, static inline int futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opf= lags) { - return futex(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset, - opflags); + return futex_syscall(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bit= set, + opflags); } =20 /** @@ -121,7 +130,7 @@ static inline int futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect, int opflags) { - return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, op= flags); } =20 /** @@ -130,7 +139,7 @@ futex_lock_pi(futex_t *uaddr, struct timespec *timeou= t, int detect, static inline int futex_unlock_pi(futex_t *uaddr, int opflags) { - return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags)= ; } =20 /** @@ -140,8 +149,8 @@ static inline int futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2= , int wake_op, int opflags) { - return futex(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op, - opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2= , uaddr2, wake_op, + opflags); } =20 /** @@ -156,8 +165,8 @@ static inline int futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_reque= ue, int opflags) { - return futex(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0, - opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_REQUEUE, nr_wake, nr_reque= ue, uaddr2, 0, + opflags); } =20 /** @@ -169,8 +178,8 @@ static inline int futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_w= ake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_r= equeue, uaddr2, + val, opflags); } =20 /** @@ -185,8 +194,8 @@ static inline int futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, struct timespec *timeout, int opflags) { - return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0, - opflags); + return futex_syscall(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2= , 0, + opflags); } =20 /** @@ -200,8 +209,8 @@ static inline int futex_cmp_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, int n= r_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, n= r_requeue, uaddr2, + val, opflags); } =20 /** --=20 2.31.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F15FC433F5 for ; Wed, 20 Oct 2021 22:40:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1CF46121E for ; Wed, 20 Oct 2021 22:40:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C1CF46121E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=opensource.wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oKoffcmodLU83SCfXQ7z/O6nPf8aa6E20kaOa8qDJ20=; b=TRF6ZumYl608it cpFuL5u5vzQPtHMk/NnASfgK/U3F/5jqctgeoYZRGP912mia6k6QmY2j9qEYAyJvz711fWdWDXmCa 7kVypA4oazzZ2Rcoa6MXJBT2LiRhdqZCQ7StkLedFTUgLx78QgTC1/NXbonU0wrf5ZpFlutIGJF48 KOmoU2PoedHQewHQbmjmcqqerbcoL2gyXNEIuY4EL7Bd0U5TKdEEh6yp3Sx7kXJPFBRKRGLMjL94Y UsMFgn7EOPor1cCu7c8Kq/Wesu8x3bebfxchMIc2WwPaxcy09tef+1mouiqnw09k18EDLzJdop/wq sAhxJVxssAP8QNPHA/TQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdKFy-005vgK-IJ; Wed, 20 Oct 2021 22:40:22 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdKFv-005vej-W7 for linux-riscv@lists.infradead.org; Wed, 20 Oct 2021 22:40:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1634769619; x=1666305619; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y8ldQtnZtH2nNau0fDjjtgFR2uznY4wI2KcEdQP3NCw=; b=jB+BkNJK4+wDPrT4VCx6mJQIfdOhhO6ErquGKYNeKeHDyvTpNSc3OwUA nxF0WHG6Q1IwnPCL6bCmBVJtXzh5NulvV9NUlGykgM5z0RnYDzvY1bGRF C4fHZBimMSvliS7uChkQy87luwV7qNixbpx32/13s78ELm5OFHMItSLJu yeOjuikPWXXugjA3giigmSeVzA77rCiqjZ3E3O9w4fTiBbW6iu6FJKeiO WiTPrXN2hQ/pFR7eDH2n7rksawCQmeByyGDp0nd6SS4L17ga+5pZl9Pg3 NIz6tUm+m1NMKOyLgEslwftgbfgPXplRIxHAZIRi8zLuRa9CfXLJEboL7 w==; X-IronPort-AV: E=Sophos;i="5.87,168,1631548800"; d="scan'208";a="182470027" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 21 Oct 2021 06:40:18 +0800 IronPort-SDR: LLEjG7DiW3bJWbJCNTtubFYWFj5RnyLidAj8yd6vFk1vVRKtfbkYKD8KdccVLyM+J+FibqQ/Oe IDF3QNhZgbtnWZNJ80ICsH6zEwohJBJ51Qw9z/6XnREIx/XjcTu3xpFTX/aH3CgHUfcLJqfbW6 ad3dYIRlFVk0Ip1VblsJjrQYbCOfOhIOdbcSB0XRJM5CBQTd/ACml/EAeNYCI9jTVZAeBQphUB oBM/bdPHonvx5a6yoFRy4BolS1oUo2TyYyHoO0xHQzMucnx6g3mKxvX73JA1jCySAPxmr2PvKP eVhinc9KN3OFxA6OZZQRsLnU 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; 20 Oct 2021 15:14:22 -0700 IronPort-SDR: D0ONSfZngFH54qjnMqiSdYYqOtMN6OCLNEK/1BpSQwY4BE/ayYmIxDiiihsrVlNzeLqiWoQ38/ yZoXMTME194J6EiFTTpadTnqEDlOZZd6bmYM47hkYtHA7ZtyytdLt5FUWX7QAC41pEqZk6+XdW CHnxlVEKm1kc7EYcuuBmq3tz45dEP1ju9jcfmRhHH6CN5Jr7S93DIlbBHKqELPyg5H6iKRuyrb GLOSLk0yG5twikwXt75ppr7mJ7PLQhBArIAhqAHvRZTLgaiTTD3DwfAUEHpS1YX3C/nKDb2Uvh h2E= 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; 20 Oct 2021 15:40:19 -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 4HZQYG0mFxz1RwqK for ; Wed, 20 Oct 2021 15:40:18 -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=1634769616; x=1637361617; bh=Y8ldQtnZtH2nNau0fD jjtgFR2uznY4wI2KcEdQP3NCw=; b=WK0NYuGJdpZqBNJPokPtHztBAhbhlaT4MD e4vwlTrR1XjMEFYPuwJD7cp7Rd305TW9/D054K0mtEtQp040ZT4YM4F3TldzZii3 b88A0isBPV5Hul6AZP35l5x6IY6KnqY0OI9u46qHAC7gzFhbfAzuW7F1L4TsaonJ 9kCgVh419XVoXm6P14csyRgX5nU7oOeUWUfzKZ8WbkcAo9wC2gXqrT9NTPkvfjBW FD529WF0cxmg11JUCeD38fejiJmRcZkCwqxGZoD2vAUB8Q4aA18zoCd57/lBXlBV W2o4bU6vwZwoQv4IJv7mDkMngtTwcidqSJtuRvFnpu7bYVyG9lbw== 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 NhDo35G6Cg4d for ; Wed, 20 Oct 2021 15:40:16 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.39]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4HZQY10Kx0z1SGYQ; Wed, 20 Oct 2021 15:40:04 -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 v4 3/4] selftests: futex: Call the futex syscall from a function Date: Thu, 21 Oct 2021 08:39:19 +1000 Message-Id: <20211020223920.2810727-3-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211020223920.2810727-1-alistair.francis@opensource.wdc.com> References: <20211020223920.2810727-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211020_154020_110455_A7A08C2F X-CRM114-Status: GOOD ( 17.29 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Alistair Francis Call the futex syscall from a function In preparation for a more complex futex() function let's convert the current macro into two functions. We need two functions to avoid compiler failures as the macro is overloaded. This will allow us to include pre-processor conditionals in the futex syscall functions. Signed-off-by: Alistair Francis --- .../selftests/futex/include/futextest.h | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/testing/selftests/futex/include/futextest.h index ddbcfc9b7bac4..1b133f81e9b7b 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -48,7 +48,7 @@ typedef volatile u_int32_t futex_t; #endif /** - * futex() - SYS_futex syscall wrapper + * futex_syscall() - SYS_futex syscall wrapper * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op @@ -58,17 +58,26 @@ typedef volatile u_int32_t futex_t; * @val3: varies by op * @opflags: flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLAG * - * futex() is used by all the following futex op wrappers. It can also be + * futex_syscall() is used by all the following futex op wrappers. It can also be * used for misuse and abuse testing. Generally, the specific op wrappers - * should be used instead. It is a macro instead of an static inline function as - * some of the types over overloaded (timeout is used for nr_requeue for - * example). + * should be used instead. * * 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) +static inline int +futex_syscall(volatile u_int32_t *uaddr, int op, u_int32_t val, struct timespec *timeout, + volatile u_int32_t *uaddr2, int val3, int opflags) +{ + return syscall(SYS_futex, uaddr, op | opflags, val, ts32, uaddr2, val3); +} + +static inline int +futex_syscall_nr_requeue(volatile u_int32_t *uaddr, int op, u_int32_t val, int nr_requeue, + volatile u_int32_t *uaddr2, int val3, int opflags) +{ + return syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, val3); +} /** * futex_wait() - block on uaddr with optional timeout @@ -77,7 +86,7 @@ typedef volatile u_int32_t futex_t; static inline int futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags) { - return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); } /** @@ -87,7 +96,7 @@ futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags) static inline int futex_wake(futex_t *uaddr, int nr_wake, int opflags) { - return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags); } /** @@ -98,8 +107,8 @@ static inline int futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, u_int32_t bitset, int opflags) { - return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, - opflags); + return futex_syscall(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, + opflags); } /** @@ -109,8 +118,8 @@ futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, static inline int futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opflags) { - return futex(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset, - opflags); + return futex_syscall(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset, + opflags); } /** @@ -121,7 +130,7 @@ static inline int futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect, int opflags) { - return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags); } /** @@ -130,7 +139,7 @@ futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect, static inline int futex_unlock_pi(futex_t *uaddr, int opflags) { - return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags); } /** @@ -140,8 +149,8 @@ static inline int futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2, int wake_op, int opflags) { - return futex(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op, - opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op, + opflags); } /** @@ -156,8 +165,8 @@ static inline int futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0, - opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0, + opflags); } /** @@ -169,8 +178,8 @@ static inline int futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2, + val, opflags); } /** @@ -185,8 +194,8 @@ static inline int futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, struct timespec *timeout, int opflags) { - return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0, - opflags); + return futex_syscall(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0, + opflags); } /** @@ -200,8 +209,8 @@ static inline int futex_cmp_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2, + val, opflags); } /** -- 2.31.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv