Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751998AbcDZOAP (ORCPT ); Tue, 26 Apr 2016 10:00:15 -0400 Received: from mail-db3on0069.outbound.protection.outlook.com ([157.55.234.69]:64224 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751221AbcDZOAM (ORCPT ); Tue, 26 Apr 2016 10:00:12 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=fail action=none header.from=mellanox.com; From: Chris Metcalf To: Peter Zijlstra , , , , , , , , CC: Chris Metcalf , Subject: [PATCH] tile: clarify barrier semantics of atomic_add_return Date: Tue, 26 Apr 2016 10:00:01 -0400 Message-ID: <1461679201-9202-1-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <571E87E2.3010306@mellanox.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:12.216.194.146;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(979002)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(50226001)(5001970100001)(960300001)(36756003)(104016004)(19580395003)(19580405001)(105596002)(105606002)(50986999)(47776003)(106466001)(15975445007)(229853001)(86362001)(85426001)(4326007)(33646002)(2950100001)(5008740100001)(2906002)(5001770100001)(50466002)(92566002)(2201001)(586003)(48376002)(189998001)(11100500001)(5003940100001)(6806005)(87936001)(1096002)(42186005)(1220700001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB1696;H:ld-1.internal.tilera.com;FPR:;SPF:SoftFail;MLV:ovrnspm;A:1;MX:1;PTR:wb-fw1.tilera.com;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD049;1:Jf3skaDrr5HcgAuwWbSZiHSK3mcOW3qXOFrfo22uA6Nh8e3v6B1f3/azcmMLYpDdO6y9jfuLylEwYN08KIbbfeVgR6BCTdRvDHyub6mWGtjw+RnDxbisXyZINP6sp5EuP3X9NbFJsRGAOifMJp7aBneCzV0mU34/EjLsEzWSWWsc4OPa5H0h4pI9Pbt/mcXjRhtTEwH9C+h1HbJPkPE1nmyszMkxJLuyvffnI2+Z+zNq/px2YRR/nWU0Y2rYvNs96qwlh7+1FzNs8OBLussSkWvpNyl63NIG9e+D4j6R49DlZ6Mo8WcvAntm3HjOuqr2YvV3kVs+0nF17M2uA+YWaRn2mStcnIMCywYpEYFN8lH8hMHyvDhK7Eefu2+ZqMcCrgrocmyW/bemzcihuze3tMPSlr5HereZ0I4T7sMRrekkDW65v83V1PhuWM2VXB13ISs7f9sld7fzNKjrdgUqwoXU2bu0i9MxFt7Ui+U3WgC6T3tQq+xcGeB6VVwSZsXJZcK9+pYejYjOs3nQPy48dEyIz8NahpOfP3aBG0PGE4mA9uprLphLxpnYdeuLIL6pZKwZYijpQxqvNlL9i7EFGA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ace3c347-147b-475e-9847-08d36ddb12c8 X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;2:ffUSCp73x7qZ3K3HSiFSBsNzjTdKPZjHRxGhy6BIZ/9kyLmUnzhMBF2wusPsGj5FOC+YS9bcwMkeeJIDSfR3JnNj3r9/irH4D7f4tWodvlHW0K8tRr5AwvNS3lBFGfqw1c/elOuxbrRvRkE2j6mY+T5Y5e5bhrzRbeiDnm+TIlBjuk8n+BgGj8Lepc/UYUBX;3:oRoVUuKe/hEzc+qjihD+Ov5HfXbprydHzTV6VBV5su3QMyfBGrdGkiL9quMprxCsBXEG5zC9QcpD6+9ex4quMeeer1n2xb9+UKlIXYjhTH9C2Fgp0/8UE5gunLtVeaX/oLinEijMokEDmOBKT72ZFWY3RWz4IkZNXVyPRXo+Fe/cDNZRdse6Hc25ZnMdu+ktcCjUhizamc6X52e+U1IM7QivAN/szU3alWHDJ8hZ05Y=;25:GDbWUu6zDcXpQpLB3Sm1TDXdEciUW7esoX55SYZor6EZ/kzylFcdV7L7RY8w5QekPpu6nxaAldS9gO/QgM8HQR3b+xIno5sq9cuwCm7YTYIpsnk1cXldIWC+bzWndWJ8qCe6ZF+5ciVqVCCxoszLJqHiCdlb4+gMTc5M31t0sadWrrvxDPn2FBnlqeyIhSiwxczIbHxU4z83WKBizwvOLCKy0+AYWMeskYlL8jAhiKfKH/9N1YQTsHrG/XZ3XrU2Pj7fngicJQi/Qb0+ag2FK5W0NnPkAt49yH/1j7PL196PB5NY/UnWybHX00dB28fA1V1+wC+xp7rYoQiwffB/MQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1696; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;20:O0xw3qNOHeiOLldbxvd8nsZW9bao3wpWKhUF1aVV1U1oMAlI+HKGCOIYXvcj5X7awY7O21cZoLn8VHAywsZRr6VAi5wqw4aTNECJkS6R5UBK7pgnaF6xkg4iKYmv1mwUbNRtOVNUskKdqFhlQBLUqPdq3U+gD/H1/r3gIbYfmnqETi+En6yw34m8ZCWDIiStLv5rWtNDcLxLkSq7Kv3p3ZP/w/B1RQWXarm7MOXQvNDzbmpNfTqxXDBAGC4jn6IOJQnrR2zUe+zz6TPBq+gsrA/K6bsVo6Gdd9FXOWkAhy7erjGdPTiJH5RXnteUR7UYnMPC2+hp/QZ0we5sA/iMRlfa6vHV/5+RBmqjyUoGqwTEPKCl/ufTcIqrAlLDDPFbwYTlHixs/lGJJiujfRDqfpB8Hd7bB4E6RjLOlpDavw3LqM2r3m8wZZiKKr0kU+J6Jp8LlPsuC4iL8vhhTv9+Q/sSI5H0AoX3C94Xsq9JtUIxemnC3puhdrwMdioZqZlx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521072)(601004)(2401047)(5005006)(13024025)(13017025)(8121501046)(13023025)(13015025)(13018025)(10201501046)(3002001)(6055026);SRVR:VI1PR05MB1696;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1696; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;4:wYlV73OwOLiqFcjF/tu7gwJZIByPw2eY88A9f4lRWo7fy7Ri4ugNf+CaxAYT7rCfuiJiFK1zjQtc3q/9U5ZUmjLZDTlg6/mhri1rGrZNEJPowfNYScYFk0niT0zCMgl+EgtaKyDIfvwBpilfO/MNCTxqudhATXLk7Z+jiYNGm3vQzmxKWQ5Xj1DHkp7m7ot7GQcCIWxwufTH/3NnNXSuHizidDqDyMBGEw+ljRPNEjY7euEv0CtnjZDkwE5B8tP1hhIJfV2jdUcFGM3m8qVlyfFkpi8EPg+eZtFzHAN/TozZeRiwYuxPvUf/zwrJBhcojRUWIHVB8zJyN47tD+KTkN334Prtam/7cg65RoQqppVkdfynnc7LtqE3VzeVVkM3L6FZ3X08KAaS7X7OeA3jU7O91t2hCVisgfcSDZxA/QVvSxgvlEvAecMdQIQ5Bj1O36prjmhsQl0UnUKmIy0/V4hlYRNZwq5k0/Jv1VeJYbYrhFHVYrqY4gvyxFypjPIO X-Forefront-PRVS: 0924C6A0D5 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR05MB1696;23:r/tx/aXN9wan8JO3hjTqcNU1b79brFaj7+a0ZFKh8?= =?us-ascii?Q?SZ6WsZuZJiv9uAYOrLySDDCOIgzhlJt+s2xeaakUDT4i3ylYBLiLKSbVevs6?= =?us-ascii?Q?3OD1KoeT2muA2j1/AkuCRb/2amU3Lo6pHlPXnKwLPsRx/9S+LpGKwen9owCp?= =?us-ascii?Q?jPG5KhLp+vGJs0jKomlhva7LVb3IvB2SQ3bzEYzXmKDSUoqbIuIHf1dwSwyQ?= =?us-ascii?Q?G8VDY5158bYmoEukfws0K7cDhKLyynrxXnrkdcinYzp5N4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0lC4YL6I0aFMXWTp/+a0vnlxEbtbVzwi3triHJCh+DvndIo?= =?us-ascii?Q?xaWydqIomdzNTOyqn+Oy5Xl/7Xh3Kd5z+lR?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;5:AQizd776MaJXWhdh0oKf3QdLhy2QYtgbv4K/hXYcGm4X4zyFcXWIpkS0KnvlV2RXqf0CXMd06sVg9ADV6yD+sC5WYmur2oo5k631L1ddQSnAX4pZ1PXMmzfdOta378mr02EANgTDq9QK5z6kUbTkXQ==;24:XEaAeVhqa389ZVHYiRX+5B/dKxUxvLN3f6UdVPR+n+vtRVySgrNj817sHCd6nbhxomh0mfl+TRwxLz6whpX7y2J4Q2cnUyENp/J/8tvnbDk=;7:emUCuWWX9D3X+Uj3bQmgCc7xFQxgY6TDYe/lY81T/CkepS7SILo6qYR7KhWVSG7NqzF9tf0x9zSbPCWrHQGyUnStJ3eKgDYOZQ4vWnAnP4+YKhIBNlNW3i1uJiQ2ekxL9/tJQSG78jKbfW/v2dHPd7E7a2lmM1+wFAr3c18ZwBg= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2016 14:00:06.5093 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1696 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1994 Lines: 52 A recent discussion on LKML made it clear that the one-line comment previously in atomic_add_return() was not clear enough: https://lkml.kernel.org/r/571E87E2.3010306@mellanox.com Signed-off-by: Chris Metcalf --- arch/tile/include/asm/atomic_64.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h index 51cabc26e387..b0531a623653 100644 --- a/arch/tile/include/asm/atomic_64.h +++ b/arch/tile/include/asm/atomic_64.h @@ -37,12 +37,25 @@ static inline void atomic_add(int i, atomic_t *v) __insn_fetchadd4((void *)&v->counter, i); } +/* + * Note a subtlety of the locking here. We are required to provide a + * full memory barrier before and after the operation. However, we + * only provide an explicit mb before the operation. After the + * operation, we use barrier() to get a full mb for free, because: + * + * (1) The barrier directive to the compiler prohibits any instructions + * being statically hoisted before the barrier; + * (2) the microarchitecture will not issue any further instructions + * until the fetchadd result is available for the "+ i" add instruction; + * (3) the smb_mb before the fetchadd ensures that no other memory + * operations are in flight at this point. + */ static inline int atomic_add_return(int i, atomic_t *v) { int val; smp_mb(); /* barrier for proper semantics */ val = __insn_fetchadd4((void *)&v->counter, i) + i; - barrier(); /* the "+ i" above will wait on memory */ + barrier(); /* equivalent to smp_mb(); see block comment above */ return val; } @@ -95,7 +108,7 @@ static inline long atomic64_add_return(long i, atomic64_t *v) int val; smp_mb(); /* barrier for proper semantics */ val = __insn_fetchadd((void *)&v->counter, i) + i; - barrier(); /* the "+ i" above will wait on memory */ + barrier(); /* equivalent to smp_mb; see atomic_add_return() */ return val; } -- 2.7.2