get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/108877/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 108877,
    "url": "http://patches.dpdk.org/api/patches/108877/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20220325202428.94628-1-mattias.ronnblom@ericsson.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20220325202428.94628-1-mattias.ronnblom@ericsson.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220325202428.94628-1-mattias.ronnblom@ericsson.com",
    "date": "2022-03-25T20:24:28",
    "name": "[RFC] eal: add seqlock",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "eb7b5f36bffcd285a94e884dac2a6bbbc137c1b1",
    "submitter": {
        "id": 1077,
        "url": "http://patches.dpdk.org/api/people/1077/?format=api",
        "name": "Mattias Rönnblom",
        "email": "mattias.ronnblom@ericsson.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20220325202428.94628-1-mattias.ronnblom@ericsson.com/mbox/",
    "series": [
        {
            "id": 22252,
            "url": "http://patches.dpdk.org/api/series/22252/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=22252",
            "date": "2022-03-25T20:24:28",
            "name": "[RFC] eal: add seqlock",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/22252/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/108877/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/108877/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 26185A04FD;\n\tFri, 25 Mar 2022 21:25:40 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id CEE5740687;\n\tFri, 25 Mar 2022 21:25:39 +0100 (CET)",
            "from EUR05-AM6-obe.outbound.protection.outlook.com\n (mail-am6eur05on2042.outbound.protection.outlook.com [40.107.22.42])\n by mails.dpdk.org (Postfix) with ESMTP id D235340140\n for <dev@dpdk.org>; Fri, 25 Mar 2022 21:25:38 +0100 (CET)",
            "from AM6PR0202CA0037.eurprd02.prod.outlook.com\n (2603:10a6:20b:3a::14) by AS8PR07MB7574.eurprd07.prod.outlook.com\n (2603:10a6:20b:2a7::9) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.15; Fri, 25 Mar\n 2022 20:25:37 +0000",
            "from AM5EUR02FT042.eop-EUR02.prod.protection.outlook.com\n (2603:10a6:20b:3a:cafe::dc) by AM6PR0202CA0037.outlook.office365.com\n (2603:10a6:20b:3a::14) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17 via Frontend\n Transport; Fri, 25 Mar 2022 20:25:37 +0000",
            "from oa.msg.ericsson.com (192.176.1.74) by\n AM5EUR02FT042.mail.protection.outlook.com (10.152.9.106) with Microsoft SMTP\n Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id\n 15.20.5102.18 via Frontend Transport; Fri, 25 Mar 2022 20:25:36 +0000",
            "from ESESSMB503.ericsson.se (153.88.183.164) by\n ESESBMR502.ericsson.se (153.88.183.134) with Microsoft SMTP Server\n (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id\n 15.1.2308.27; Fri, 25 Mar 2022 21:25:35 +0100",
            "from seliiuapp00218.seli.gic.ericsson.se (153.88.183.153) by\n smtp.internal.ericsson.com (153.88.183.191) with Microsoft SMTP Server id\n 15.1.2308.27 via Frontend Transport; Fri, 25 Mar 2022 21:25:35 +0100",
            "from localhost.localdomain (seliicwb00002.seli.gic.ericsson.se\n [10.156.25.100])\n by seliiuapp00218.seli.gic.ericsson.se (Postfix) with ESMTP id 6F26D6028A;\n Fri, 25 Mar 2022 21:25:35 +0100 (CET)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;\n b=CeqisxAWLqz1LN9AJu39Ob46y3zWeNJ4oYI9/6E88XNNnwnr2ZjW+nWKz5t2GdvU7CHiShdyK6kxUZ1Ab8xNndp2/5FLXvJVfqwedKms3cy7yYmw2ys5P1EON3xsbV5rNVBVukGE5B9pZuN0C3ExszucLqDMTxltwpwP8yGqDwzKEjd023s3JFsqbPECwStuH0g+3QiSUAoTFXtg7MDjoArSAMynbVwaFMGpg/6mml0fxHQlwMswx/PD8UWMuYdxGvllnl1KsTtIJxGo4AoCTIJzVXaMKhV3dgSPQtcgKI2+NYz6LYf0ORovpAzAAVN6/xhx+7HDZPZE2hxLIYDlig==",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector9901;\n 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;\n bh=tzInlpEx9fmyK8cE/aovxy1PLDtkE0luGXD2CObrwTM=;\n b=O9Wrbno0O+JqJ/MlVcSAx6iSY3IKEZiStUwTuzD575XXnidlFPlC6HKVpqLzlH0WB7ewC4lu6Pnj2wel8Lfuy1GEb/uBLdHfI51ueIXqQY9QiZ4UmJDwzsefNu1YrOi/CI1k0jkfDnFYNl3MsJvI5S7pgQSZv774xZ7KWthJehY/gemKU2jhtMp92M/z2LNriZ3wZ+ZpqEL9bTckKE1JAAGTIvma2HRwXDo+cLY2rnihfutchCmJpcJQ8pbRU0Hkbx+q7l8pGNezMADn2WqhmRBA7OWKGAo6+QGKKUlyReuuaVjjcHkDt9eKRvtQhq1f3w48SL0d+y7K0bWvQInOWw==",
        "ARC-Authentication-Results": "i=1; mx.microsoft.com 1; spf=temperror (sender ip\n is 192.176.1.74) smtp.rcpttodomain=arm.com\n smtp.mailfrom=ericsson.com;\n dmarc=temperror action=none header.from=ericsson.com; dkim=none (message not\n signed); arc=none",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com;\n s=selector1;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=tzInlpEx9fmyK8cE/aovxy1PLDtkE0luGXD2CObrwTM=;\n b=QLjA5qwZSxC7uOz7DgDKPNjzK4uvaE9Egoi/NcYzlmCn3oLQXgWz5Sd9H5Yt6plUxQ+PllLtNGGEFr/MBj6MfZv66KHQRXVcae5/SkfrLUMSIqAKmRvnkxcu8jqTRziuq8p30Aj3u8ghGK2XvnP0FQgGCgCmY1sAzuc75dXbX6o=",
        "X-MS-Exchange-Authentication-Results": "spf=temperror (sender IP is\n 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed)\n header.d=none;dmarc=temperror action=none header.from=ericsson.com;",
        "Received-SPF": "TempError (protection.outlook.com: error in processing during\n lookup of ericsson.com: DNS Timeout)",
        "From": "=?utf-8?q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>",
        "To": "<dev@dpdk.org>",
        "CC": "Thomas Monjalon <thomas@monjalon.net>,\n David Marchand <david.marchand@redhat.com>, <onar.olsen@ericsson.com>,\n <Honnappa.Nagarahalli@arm.com>, <nd@arm.com>, <konstantin.ananyev@intel.com>,\n  <mb@smartsharesystems.com>, <stephen@networkplumber.org>, =?utf-8?q?Mattia?=\n\t=?utf-8?q?s_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>,\n \"Ola Liljedahl\" <ola.liljedahl@arm.com>",
        "Subject": "[RFC] eal: add seqlock",
        "Date": "Fri, 25 Mar 2022 21:24:28 +0100",
        "Message-ID": "<20220325202428.94628-1-mattias.ronnblom@ericsson.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<ef0fe83b-0af0-3210-4c40-e26c5b7d416b@ericsson.com>",
        "References": "<ef0fe83b-0af0-3210-4c40-e26c5b7d416b@ericsson.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"UTF-8\"",
        "Content-Transfer-Encoding": "8bit",
        "X-EOPAttributedMessage": "0",
        "X-MS-PublicTrafficType": "Email",
        "X-MS-Office365-Filtering-Correlation-Id": "c3baef2f-6f1d-4965-feb2-08da0e9d9eaf",
        "X-MS-TrafficTypeDiagnostic": "AS8PR07MB7574:EE_",
        "X-Microsoft-Antispam-PRVS": "\n <AS8PR07MB7574BC12FA50865C7E01A093E11A9@AS8PR07MB7574.eurprd07.prod.outlook.com>",
        "X-MS-Exchange-SenderADCheck": "1",
        "X-MS-Exchange-AntiSpam-Relay": "0",
        "X-Microsoft-Antispam": "BCL:0;",
        "X-Microsoft-Antispam-Message-Info": "\n +FNmNPlGHl7Nb3b/Ow5k9jB0m7QzZpcxM3MSQ1/1wIXYszWJzFyW7ZHdzxYPM1pAOJN5FyNUIe6dKkii8fyRubjoEy6Njyf41hO4g4+roM6EWhybntJucZn9cBMvKRIc+F66A84FHzI4ggWeAaV/1+JrkpT7qEju7GBuivTJqtIKCs/+Bko8DOiQtdv+OpdpCR9fIGycuvdimdiEzKTZVIEvm4a3CDhER21SZCMdnu8S33YF3I0P8TV6uvW75W35nFyNDjtoGyjemuUrjqVUzDsEBPmbmArmCaG4OcdIACo2JI7mIs1WqacVTRWKNM+L7G32XKNMulJs22rZNpgR05aLusSSaFZVRzNEOsldsHbVskg/Brc0V0wO6MasUf+DuS1l/+OFUBW52g9WmLCoXIma+y5BdgwiYTu4+S/bLWrTw9UA3h44HYzYbeNIo7jnRtCfx7ZetSDzEq+ftjFWojraz2/arvih880wZ0QdNyPRZyuVk7na9zcwyu/lLB201w79mb4en38o4Ent0cJBH5RofnGQ7PgU6+WWVOtt+6CD4fOm+n9haTrCbxKjSbe04QKx5S/HQBC5h/708c70snsaJsdbZrJPMJYkX7O0Ek37WD7mqXxGt31irHpzYfKIbf4cRWMgemSJVl2WAFwETJeSk7os1tvQpTtDC+IRQCQYRRa3scsz6kUWR+R1omoL/j9Swr+Po3IOfsr7SY9l86JMHD/zALbn0Zd839LzeoI=",
        "X-Forefront-Antispam-Report": "CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:;\n IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net;\n CAT:NONE;\n SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(4326008)(30864003)(5660300002)(2906002)(54906003)(316002)(8936002)(6916009)(66574015)(1076003)(336012)(6266002)(36756003)(186003)(26005)(508600001)(63350400001)(63370400001)(83380400001)(2616005)(36860700001)(356005)(86362001)(82310400004)(6666004)(70586007)(70206006)(8676002)(7636003)(82960400001)(47076005)(40460700003);\n DIR:OUT; SFP:1101;",
        "X-OriginatorOrg": "ericsson.com",
        "X-MS-Exchange-CrossTenant-OriginalArrivalTime": "25 Mar 2022 20:25:36.0710 (UTC)",
        "X-MS-Exchange-CrossTenant-Network-Message-Id": "\n c3baef2f-6f1d-4965-feb2-08da0e9d9eaf",
        "X-MS-Exchange-CrossTenant-Id": "92e84ceb-fbfd-47ab-be52-080c6b87953f",
        "X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp": "\n TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74];\n Helo=[oa.msg.ericsson.com]",
        "X-MS-Exchange-CrossTenant-AuthSource": "\n AM5EUR02FT042.eop-EUR02.prod.protection.outlook.com",
        "X-MS-Exchange-CrossTenant-AuthAs": "Anonymous",
        "X-MS-Exchange-CrossTenant-FromEntityHeader": "HybridOnPrem",
        "X-MS-Exchange-Transport-CrossTenantHeadersStamped": "AS8PR07MB7574",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "A sequence lock (seqlock) is synchronization primitive which allows\nfor data-race free, low-overhead, high-frequency reads, especially for\ndata structures shared across many cores and which are updated with\nrelatively low frequency.\n\nA seqlock permits multiple parallel readers. The variant of seqlock\nimplemented in this patch supports multiple writers as well. A\nspinlock is used for writer-writer serialization.\n\nTo avoid resource reclamation and other issues, the data protected by\na seqlock is best off being self-contained (i.e., no pointers [except\nto constant data]).\n\nOne way to think about seqlocks is that they provide means to perform\natomic operations on data objects larger what the native atomic\nmachine instructions allow for.\n\nDPDK seqlocks are not preemption safe on the writer side. A thread\npreemption affects performance, not correctness.\n\nA seqlock contains a sequence number, which can be thought of as the\ngeneration of the data it protects.\n\nA reader will\n  1. Load the sequence number (sn).\n  2. Load, in arbitrary order, the seqlock-protected data.\n  3. Load the sn again.\n  4. Check if the first and second sn are equal, and even numbered.\n     If they are not, discard the loaded data, and restart from 1.\n\nThe first three steps need to be ordered using suitable memory fences.\n\nA writer will\n  1. Take the spinlock, to serialize writer access.\n  2. Load the sn.\n  3. Store the original sn + 1 as the new sn.\n  4. Perform load and stores to the seqlock-protected data.\n  5. Store the original sn + 2 as the new sn.\n  6. Release the spinlock.\n\nProper memory fencing is required to make sure the first sn store, the\ndata stores, and the second sn store appear to the reader in the\nmentioned order.\n\nThe sn loads and stores must be atomic, but the data loads and stores\nneed not be.\n\nThe original seqlock design and implementation was done by Stephen\nHemminger. This is an independent implementation, using C11 atomics.\n\nThis RFC version lacks API documentation.\n\nReviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>\nSigned-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>\n---\n app/test/meson.build          |   2 +\n app/test/test_seqlock.c       | 197 ++++++++++++++++++++++++++++++++++\n lib/eal/common/meson.build    |   1 +\n lib/eal/common/rte_seqlock.c  |  12 +++\n lib/eal/include/meson.build   |   1 +\n lib/eal/include/rte_seqlock.h |  84 +++++++++++++++\n lib/eal/version.map           |   3 +\n 7 files changed, 300 insertions(+)\n create mode 100644 app/test/test_seqlock.c\n create mode 100644 lib/eal/common/rte_seqlock.c\n create mode 100644 lib/eal/include/rte_seqlock.h",
    "diff": "diff --git a/app/test/meson.build b/app/test/meson.build\nindex 5fc1dd1b7b..5e418e8766 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -125,6 +125,7 @@ test_sources = files(\n         'test_rwlock.c',\n         'test_sched.c',\n         'test_security.c',\n+        'test_seqlock.c',\n         'test_service_cores.c',\n         'test_spinlock.c',\n         'test_stack.c',\n@@ -214,6 +215,7 @@ fast_tests = [\n         ['rwlock_rde_wro_autotest', true],\n         ['sched_autotest', true],\n         ['security_autotest', false],\n+        ['seqlock_autotest', true],\n         ['spinlock_autotest', true],\n         ['stack_autotest', false],\n         ['stack_lf_autotest', false],\ndiff --git a/app/test/test_seqlock.c b/app/test/test_seqlock.c\nnew file mode 100644\nindex 0000000000..a727e16caf\n--- /dev/null\n+++ b/app/test/test_seqlock.c\n@@ -0,0 +1,197 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2022 Ericsson AB\n+ */\n+\n+#include <rte_seqlock.h>\n+\n+#include <rte_cycles.h>\n+#include <rte_malloc.h>\n+#include <rte_random.h>\n+\n+#include <inttypes.h>\n+\n+#include \"test.h\"\n+\n+struct data {\n+\trte_seqlock_t lock;\n+\n+\tuint64_t a;\n+\tuint64_t b __rte_cache_aligned;\n+\tuint64_t c __rte_cache_aligned;\n+} __rte_cache_aligned;\n+\n+struct reader {\n+\tstruct data *data;\n+\tuint8_t stop;\n+};\n+\n+#define WRITER_RUNTIME (2.0) /* s */\n+\n+#define WRITER_MAX_DELAY (100) /* us */\n+\n+#define INTERRUPTED_WRITER_FREQUENCY (1000)\n+#define WRITER_INTERRUPT_TIME (1) /* us */\n+\n+static int\n+writer_start(void *arg)\n+{\n+\tstruct data *data = arg;\n+\tuint64_t deadline;\n+\n+\tdeadline = rte_get_timer_cycles() +\n+\t\tWRITER_RUNTIME * rte_get_timer_hz();\n+\n+\twhile (rte_get_timer_cycles() < deadline) {\n+\t\tbool interrupted;\n+\t\tuint64_t new_value;\n+\t\tunsigned int delay;\n+\n+\t\tnew_value = rte_rand();\n+\n+\t\tinterrupted = rte_rand_max(INTERRUPTED_WRITER_FREQUENCY) == 0;\n+\n+\t\trte_seqlock_write_begin(&data->lock);\n+\n+\t\tdata->c = new_value;\n+\n+\t\t/* These compiler barriers (both on the test reader\n+\t\t * and the test writer side) are here to ensure that\n+\t\t * loads/stores *usually* happen in test program order\n+\t\t * (always on a TSO machine). They are arrange in such\n+\t\t * a way that the writer stores in a different order\n+\t\t * than the reader loads, to emulate an arbitrary\n+\t\t * order. A real application using a seqlock does not\n+\t\t * require any compiler barriers.\n+\t\t */\n+\t\trte_compiler_barrier();\n+\t\tdata->b = new_value;\n+\n+\t\tif (interrupted)\n+\t\t\trte_delay_us_block(WRITER_INTERRUPT_TIME);\n+\n+\t\trte_compiler_barrier();\n+\t\tdata->a = new_value;\n+\n+\t\trte_seqlock_write_end(&data->lock);\n+\n+\t\tdelay = rte_rand_max(WRITER_MAX_DELAY);\n+\n+\t\trte_delay_us_block(delay);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+#define INTERRUPTED_READER_FREQUENCY (1000)\n+#define READER_INTERRUPT_TIME (1000) /* us */\n+\n+static int\n+reader_start(void *arg)\n+{\n+\tstruct reader *r = arg;\n+\tint rc = 0;\n+\n+\twhile (__atomic_load_n(&r->stop, __ATOMIC_RELAXED) == 0 && rc == 0) {\n+\t\tstruct data *data = r->data;\n+\t\tbool interrupted;\n+\t\tuint64_t a;\n+\t\tuint64_t b;\n+\t\tuint64_t c;\n+\t\tuint64_t sn;\n+\n+\t\tinterrupted = rte_rand_max(INTERRUPTED_READER_FREQUENCY) == 0;\n+\n+\t\tdo {\n+\t\t\tsn = rte_seqlock_read_begin(&data->lock);\n+\n+\t\t\ta = data->a;\n+\t\t\t/* See writer_start() for an explaination why\n+\t\t\t * these barriers are here.\n+\t\t\t */\n+\t\t\trte_compiler_barrier();\n+\n+\t\t\tif (interrupted)\n+\t\t\t\trte_delay_us_block(READER_INTERRUPT_TIME);\n+\n+\t\t\tc = data->c;\n+\n+\t\t\trte_compiler_barrier();\n+\t\t\tb = data->b;\n+\n+\t\t} while (rte_seqlock_read_retry(&data->lock, sn));\n+\n+\t\tif (a != b || b != c) {\n+\t\t\tprintf(\"Reader observed inconsistent data values \"\n+\t\t\t       \"%\" PRIu64 \" %\" PRIu64 \" %\" PRIu64 \"\\n\",\n+\t\t\t       a, b, c);\n+\t\t\trc = -1;\n+\t\t}\n+\t}\n+\n+\treturn rc;\n+}\n+\n+static void\n+reader_stop(struct reader *reader)\n+{\n+\t__atomic_store_n(&reader->stop, 1, __ATOMIC_RELAXED);\n+}\n+\n+#define NUM_WRITERS (2)\n+#define MIN_NUM_READERS (2)\n+#define MAX_READERS (RTE_MAX_LCORE - NUM_WRITERS - 1)\n+#define MIN_LCORE_COUNT (NUM_WRITERS + MIN_NUM_READERS + 1)\n+\n+static int\n+test_seqlock(void)\n+{\n+\tstruct reader readers[MAX_READERS];\n+\tunsigned int num_readers;\n+\tunsigned int num_lcores;\n+\tunsigned int i;\n+\tunsigned int lcore_id;\n+\tunsigned int writer_lcore_ids[NUM_WRITERS] = { 0 };\n+\tunsigned int reader_lcore_ids[MAX_READERS];\n+\tint rc = 0;\n+\n+\tnum_lcores = rte_lcore_count();\n+\n+\tif (num_lcores < MIN_LCORE_COUNT)\n+\t\treturn -1;\n+\n+\tnum_readers = num_lcores - NUM_WRITERS - 1;\n+\n+\tstruct data *data = rte_zmalloc(NULL, sizeof(struct data), 0);\n+\n+\ti = 0;\n+\tRTE_LCORE_FOREACH_WORKER(lcore_id) {\n+\t\tif (i < NUM_WRITERS) {\n+\t\t\trte_eal_remote_launch(writer_start, data, lcore_id);\n+\t\t\twriter_lcore_ids[i] = lcore_id;\n+\t\t} else {\n+\t\t\tunsigned int reader_idx = i - NUM_WRITERS;\n+\t\t\tstruct reader *reader = &readers[reader_idx];\n+\n+\t\t\treader->data = data;\n+\t\t\treader->stop = 0;\n+\n+\t\t\trte_eal_remote_launch(reader_start, reader, lcore_id);\n+\t\t\treader_lcore_ids[reader_idx] = lcore_id;\n+\t\t}\n+\t\ti++;\n+\t}\n+\n+\tfor (i = 0; i < NUM_WRITERS; i++)\n+\t\tif (rte_eal_wait_lcore(writer_lcore_ids[i]) != 0)\n+\t\t\trc = -1;\n+\n+\tfor (i = 0; i < num_readers; i++) {\n+\t\treader_stop(&readers[i]);\n+\t\tif (rte_eal_wait_lcore(reader_lcore_ids[i]) != 0)\n+\t\t\trc = -1;\n+\t}\n+\n+\treturn rc;\n+}\n+\n+REGISTER_TEST_COMMAND(seqlock_autotest, test_seqlock);\ndiff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build\nindex 917758cc65..a41343bfed 100644\n--- a/lib/eal/common/meson.build\n+++ b/lib/eal/common/meson.build\n@@ -35,6 +35,7 @@ sources += files(\n         'rte_malloc.c',\n         'rte_random.c',\n         'rte_reciprocal.c',\n+\t'rte_seqlock.c',\n         'rte_service.c',\n         'rte_version.c',\n )\ndiff --git a/lib/eal/common/rte_seqlock.c b/lib/eal/common/rte_seqlock.c\nnew file mode 100644\nindex 0000000000..d4fe648799\n--- /dev/null\n+++ b/lib/eal/common/rte_seqlock.c\n@@ -0,0 +1,12 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2022 Ericsson AB\n+ */\n+\n+#include <rte_seqlock.h>\n+\n+void\n+rte_seqlock_init(rte_seqlock_t *seqlock)\n+{\n+\tseqlock->sn = 0;\n+\trte_spinlock_init(&seqlock->lock);\n+}\ndiff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build\nindex 9700494816..48df5f1a21 100644\n--- a/lib/eal/include/meson.build\n+++ b/lib/eal/include/meson.build\n@@ -36,6 +36,7 @@ headers += files(\n         'rte_per_lcore.h',\n         'rte_random.h',\n         'rte_reciprocal.h',\n+        'rte_seqlock.h',\n         'rte_service.h',\n         'rte_service_component.h',\n         'rte_string_fns.h',\ndiff --git a/lib/eal/include/rte_seqlock.h b/lib/eal/include/rte_seqlock.h\nnew file mode 100644\nindex 0000000000..b975ca848a\n--- /dev/null\n+++ b/lib/eal/include/rte_seqlock.h\n@@ -0,0 +1,84 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2022 Ericsson AB\n+ */\n+\n+#ifndef _RTE_SEQLOCK_H_\n+#define _RTE_SEQLOCK_H_\n+\n+#include <stdbool.h>\n+#include <stdint.h>\n+\n+#include <rte_atomic.h>\n+#include <rte_branch_prediction.h>\n+#include <rte_spinlock.h>\n+\n+struct rte_seqlock {\n+\tuint64_t sn;\n+\trte_spinlock_t lock;\n+};\n+\n+typedef struct rte_seqlock rte_seqlock_t;\n+\n+__rte_experimental\n+void\n+rte_seqlock_init(rte_seqlock_t *seqlock);\n+\n+__rte_experimental\n+static inline uint64_t\n+rte_seqlock_read_begin(const rte_seqlock_t *seqlock)\n+{\n+\t/* __ATOMIC_ACQUIRE to prevent loads after (in program order)\n+\t * from happening before the sn load. Syncronizes-with the\n+\t * store release in rte_seqlock_end().\n+\t */\n+\treturn __atomic_load_n(&seqlock->sn, __ATOMIC_ACQUIRE);\n+}\n+\n+__rte_experimental\n+static inline bool\n+rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint64_t begin_sn)\n+{\n+\tuint64_t end_sn;\n+\n+\t/* make sure the data loads happens before the sn load */\n+\trte_atomic_thread_fence(__ATOMIC_ACQUIRE);\n+\n+\tend_sn = __atomic_load_n(&seqlock->sn, __ATOMIC_RELAXED);\n+\n+\treturn unlikely(begin_sn & 1 || begin_sn != end_sn);\n+}\n+\n+__rte_experimental\n+static inline void\n+rte_seqlock_write_begin(rte_seqlock_t *seqlock)\n+{\n+\tuint64_t sn;\n+\n+\t/* to synchronize with other writers */\n+\trte_spinlock_lock(&seqlock->lock);\n+\n+\tsn = seqlock->sn + 1;\n+\n+\t__atomic_store_n(&seqlock->sn, sn, __ATOMIC_RELAXED);\n+\n+\t/* __ATOMIC_RELEASE to prevent stores after (in program order)\n+\t * from happening before the sn store.\n+\t */\n+\trte_atomic_thread_fence(__ATOMIC_RELEASE);\n+}\n+\n+__rte_experimental\n+static inline void\n+rte_seqlock_write_end(rte_seqlock_t *seqlock)\n+{\n+\tuint64_t sn;\n+\n+\tsn = seqlock->sn + 1;\n+\n+\t/* synchronizes-with the load acquire in rte_seqlock_begin() */\n+\t__atomic_store_n(&seqlock->sn, sn, __ATOMIC_RELEASE);\n+\n+\trte_spinlock_unlock(&seqlock->lock);\n+}\n+\n+#endif  /* _RTE_SEQLOCK_H_ */\ndiff --git a/lib/eal/version.map b/lib/eal/version.map\nindex b53eeb30d7..4a9d0ed899 100644\n--- a/lib/eal/version.map\n+++ b/lib/eal/version.map\n@@ -420,6 +420,9 @@ EXPERIMENTAL {\n \trte_intr_instance_free;\n \trte_intr_type_get;\n \trte_intr_type_set;\n+\n+\t# added in 22.07\n+\trte_seqlock_init;\n };\n \n INTERNAL {\n",
    "prefixes": [
        "RFC"
    ]
}