From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1C056A0501; Sat, 2 Apr 2022 20:16:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A6CE44067E; Sat, 2 Apr 2022 20:16:30 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2046.outbound.protection.outlook.com [40.107.22.46]) by mails.dpdk.org (Postfix) with ESMTP id BEA434003F for ; Sat, 2 Apr 2022 20:16:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qDUJhGYCVOkmVu3VbEWYGPa5lYt0aGIccYptN7CcqHE=; b=rXCUVqhsMjh3xDHzKjpB0Pxko91us3ylJehsIxqezDm6Y2P1vrgrDPbIOlvksRrYk6dwJ/Ei6OibcNM6/hno1+WmmLx42sDp9ci9dcmF2LfoIeIn9vmE2aT4++36B10Czk7bRwcj8j7Vz2uJHNqdYj+8FYZAIAjTIH/6ldg1M3k= Received: from DB6PR0201CA0031.eurprd02.prod.outlook.com (2603:10a6:4:3f::41) by AM0PR08MB4146.eurprd08.prod.outlook.com (2603:10a6:208:129::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.30; Sat, 2 Apr 2022 18:16:16 +0000 Received: from DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:3f:cafe::e3) by DB6PR0201CA0031.outlook.office365.com (2603:10a6:4:3f::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.30 via Frontend Transport; Sat, 2 Apr 2022 18:16:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT064.mail.protection.outlook.com (10.152.21.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.19 via Frontend Transport; Sat, 2 Apr 2022 18:16:16 +0000 Received: ("Tessian outbound ab7864ef57f2:v118"); Sat, 02 Apr 2022 18:16:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: dab37dc25d7f289e X-CR-MTA-TID: 64aa7808 Received: from a889d57d7faa.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 33ECD7DA-06E9-481F-99F9-909FDCAD582A.1; Sat, 02 Apr 2022 18:16:05 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a889d57d7faa.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Sat, 02 Apr 2022 18:16:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FxqTHriSuh0fkX2mMLiBpJSzkbnTXTg2lxWNIauUESlrWWuq83A9OTgA6EdcIgpCMNaEXh9Cz24eEaHU1Sc+irrM2XY5/FPsYB2zKeZeQ4mtaRlYMRqkBhhOEh90uYxhumDEGg0KKGx3awS/A7Eee3YPASAnHDXQQVT7oP0ppUWIgmLFUZ0ybej+hwNDE7vf45K1mrEOLEQCjQB6fMsIMCvy8+995b34ZWOk46Q23Es6bKaQn35s1ngLuyfczoNKtvL3aMe1HDf42GqwyegUQ5TjMKlokWKh8qeh4z7haos94Qy8JyM7obtok8fwld9gJfh3a6WDEBighNoJbrq30A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qDUJhGYCVOkmVu3VbEWYGPa5lYt0aGIccYptN7CcqHE=; b=lFnkIRgGCa1ytC6tgJn0sg0gi/F4+yPFxUR9NbvksW1aC/F3+rk0ohlW3LYXeC9Uz8eLP7z0txgOHLFfoAPtzpi+25QnhhwDY8zG63nwkb0K+MUiiXU+6j1YqHwVBd+jhJyi2OnIaHT7qlzwNxFnDJRXQ3iDlpDxFdQvuFfnSEovPWfWGFxykZNLFrpPx2azhcKupXszO5e3DC6Du41zpMbzv5X7mbHL2CrE1+5xviAj0zoUm03c4GPtQVuhP8dFuK4j10Bmmmg5udSbxl58rFwgXgqVlsn6YqcE7pi1spVzaRpkD39MRPjEWvW5KFI0QqVl0ql98OsoLcgwex+GMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qDUJhGYCVOkmVu3VbEWYGPa5lYt0aGIccYptN7CcqHE=; b=rXCUVqhsMjh3xDHzKjpB0Pxko91us3ylJehsIxqezDm6Y2P1vrgrDPbIOlvksRrYk6dwJ/Ei6OibcNM6/hno1+WmmLx42sDp9ci9dcmF2LfoIeIn9vmE2aT4++36B10Czk7bRwcj8j7Vz2uJHNqdYj+8FYZAIAjTIH/6ldg1M3k= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM8PR08MB6498.eurprd08.prod.outlook.com (2603:10a6:20b:364::11) by AM0PR08MB4418.eurprd08.prod.outlook.com (2603:10a6:208:146::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.30; Sat, 2 Apr 2022 18:16:02 +0000 Received: from AM8PR08MB6498.eurprd08.prod.outlook.com ([fe80::ec4f:1ad:e332:9f39]) by AM8PR08MB6498.eurprd08.prod.outlook.com ([fe80::ec4f:1ad:e332:9f39%5]) with mapi id 15.20.5123.030; Sat, 2 Apr 2022 18:16:02 +0000 Message-ID: <3efba44b-1a2e-831e-1e2c-782639d83c24@arm.com> Date: Sat, 2 Apr 2022 20:15:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v3] eal: add seqlock Content-Language: en-US To: =?UTF-8?Q?Mattias_R=c3=b6nnblom?= , dev@dpdk.org Cc: Thomas Monjalon , David Marchand , onar.olsen@ericsson.com, Honnappa.Nagarahalli@arm.com, nd@arm.com, konstantin.ananyev@intel.com, mb@smartsharesystems.com, stephen@networkplumber.org References: <20220401150749.136921-1-mattias.ronnblom@ericsson.com> From: Ola Liljedahl In-Reply-To: <20220401150749.136921-1-mattias.ronnblom@ericsson.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO2P265CA0025.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::13) To AM8PR08MB6498.eurprd08.prod.outlook.com (2603:10a6:20b:364::11) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: d38914b6-cdd0-4042-0dab-08da14d4e0a8 X-MS-TrafficTypeDiagnostic: AM0PR08MB4418:EE_|DB5EUR03FT064:EE_|AM0PR08MB4146:EE_ X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: urRupCEdwLNHvMENwNtbNZdEzOx1BpGRTFkD0bDMpL1tj8bJqhF5+do9hMfVRtYnaEifPE/E6mmUKUOjZSpFe2eS0/K0qXqmT1SQ5ggAdfjZmpVGJk7IO7hTZ2+NCvIxujV6wUujiYoPAYJ9jjbuT2Nj8My6uOWst0X2af3Gj+Epv4k88LZ2RRhrCoEGWJsMJ+2gNA5jNsa5a4qLdXYyBraB7ZH0Z4bAw+P0XDXWxlMRjghF6eicthfLMLPnr7Zn1vWD5Fa96ymjzOYC3ZkBmIz6WcTeNWYXxCMOfsK53HtMmgbP/2HYYLYhge6k1RMnHLvPKYTnHHkGE6C3vESbSkzDu3URcPoEtpJOcj80mH4/IdUew8yr8H2X3e56aCXjFCI2CjvXHo7CXPpk3kKoMThvxyo/wmPu/G5tgWfTymZKI6yBxuwD05+iKOQN3jKk2bFnNxGHA7s3kf9cWVzrwWy32TOLSHy+6F80QEwPLXsa56gpH2gpRh9Qr8gEhl3Zlq6fuIsWiB+S3mdXwPJHTjpHk9yD1xg6XspBGQhEEpC3aQW1y9HUGV0IsQ66d4qLKeoMr1yQwo/mOx0bB73w3H3WriaGbAJ/0G71s1EFVCXxOejykAvSQ21b/6WfSgcwG+6M3j2rzA7J1VYsSD/kuKax4JxmJmbyBSIzl2H6ufHraxxQj2y8iz4EHQXTJdgUncfFaKbXShXRwK8WhKGxNDk26CL7ttNvFkQl6yL+tjE= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM8PR08MB6498.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(8936002)(2616005)(186003)(38100700002)(26005)(6512007)(44832011)(53546011)(6666004)(6506007)(2906002)(5660300002)(83380400001)(66556008)(31696002)(8676002)(66574015)(86362001)(31686004)(6486002)(66946007)(66476007)(36756003)(316002)(54906003)(4326008)(508600001)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4418 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 30e5eebd-6170-448c-68ae-08da14d4d808 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /spZaIPdBxibEsLlW/2qQvC4L9RACG41A4TTAf4cRLPAGQwL3Jl3Dh5LqJvHscgr3VLYbB3LeOaxBvYTSYYJCfDmJeRQ1HqWSdlp5YbfG5PjC0lFbwIV6oW1gZ9OlUvwIQO8fnV+zDT54a4YO6gdNXpSOmrRDY2JUsu9H9PB8zSpFc/2NkGvgTg2HmAtKPHvVrFpBYZWmesDTTWb985e5zq6dX+gyoD7Om2XjwIY4EcBP/USxe7QGGxsp317WglIBnQH+y6/3N82RQwQDpJu3xWdIf/52INb+qmdL5g408qoXKsCy7SbuzMnNJmgLM1YjFVxCKSjaUgfD4l5gcEMvnf0S3270tTnPkS/rEaz22DRfmY2xPBvKCxO7mgbHhV06qZV4josQi9P2YvYbIipD7z1vZAI2j5sHKH6fd8Iul+M8upMtgKcmm5TkUT8SXJUuZu9oJZS9PmrNe7PXPq/z93MImOKKvI8r22N7lfsPFFkfCUYHbUlHPmUrZaGEtQeGqZIGMUwXpBmm3Sm0pnzuoatiB5XgU3V9ka17kGAlDJbMsQujtRjClHIVvhVhpVHMAuppov8B7zlR1o+ozmBsatMlzmosOWqNqqTM5+o9YnNdVkJLvnPlsABS5aD9/PwRAHl+M7LBTnAuZaMrh8d+/l/oLnmSReuODkZfRf54caqQuATTecrNDarOV1ukk9XuZ+y8t/R2R0iaI3tZawFiQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(26005)(2616005)(336012)(66574015)(356005)(186003)(81166007)(316002)(107886003)(54906003)(70586007)(86362001)(6512007)(70206006)(4326008)(8676002)(31696002)(36860700001)(82310400004)(6506007)(5660300002)(40460700003)(83380400001)(6666004)(53546011)(31686004)(36756003)(47076005)(8936002)(508600001)(2906002)(6486002)(44832011)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2022 18:16:16.0998 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d38914b6-cdd0-4042-0dab-08da14d4e0a8 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4146 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 4/1/22 17:07, Mattias Rönnblom wrote: > + > +/** > + * End a read-side critical section. > + * > + * A call to this function marks the end of a read-side critical > + * section, for @p seqlock. The application must supply the sequence > + * number produced by the corresponding rte_seqlock_read_lock() (or, > + * in case of a retry, the rte_seqlock_tryunlock()) call. > + * > + * After this function has been called, the caller should not access > + * the protected data. > + * > + * In case this function returns true, the just-read data was > + * consistent and the set of atomic and non-atomic load operations > + * performed between rte_seqlock_read_lock() and > + * rte_seqlock_read_tryunlock() were atomic, as a whole. > + * > + * In case rte_seqlock_read_tryunlock() returns false, the data was > + * modified as it was being read and may be inconsistent, and thus > + * should be discarded. The @p begin_sn is updated with the > + * now-current sequence number. > + * > + * @param seqlock > + * A pointer to the seqlock. > + * @param begin_sn > + * The seqlock sequence number returned by > + * rte_seqlock_read_lock() (potentially updated in subsequent > + * rte_seqlock_read_tryunlock() calls) for this critical section. > + * @return > + * true or false, if the just-read seqlock-protected data was consistent > + * or inconsistent, respectively, at the time it was read. > + * > + * @see rte_seqlock_read_lock() > + */ > +__rte_experimental > +static inline bool > +rte_seqlock_read_tryunlock(const rte_seqlock_t *seqlock, uint32_t *begin_sn) > +{ > + uint32_t end_sn; > + > + /* make sure the data loads happens before the sn load */ > + rte_atomic_thread_fence(__ATOMIC_ACQUIRE); > + > + end_sn = __atomic_load_n(&seqlock->sn, __ATOMIC_RELAXED); Since we are reading and potentially returning the sequence number here (repeating the read of the protected data), we need to use load-acquire. I assume it is not expected that the user will call rte_seqlock_read_lock() again. Seeing this implementation, I might actually prefer the original implementation, I think it is cleaner. But I would like for the begin function also to wait for an even sequence number, the end function would only have to check for same sequence number, this might improve performance a little bit as readers won't perform one or several broken reads while a write is in progress. The function names are a different thing though. The writer side behaves much more like a lock with mutual exclusion so write_lock/write_unlock makes sense. > + > + if (unlikely(end_sn & 1 || *begin_sn != end_sn)) { > + *begin_sn = end_sn; > + return false; > + } > + > + return true; > +} > +