get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 109034,
    "url": "https://patches.dpdk.org/api/patches/109034/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20220330142602.108061-1-mattias.ronnblom@ericsson.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<20220330142602.108061-1-mattias.ronnblom@ericsson.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220330142602.108061-1-mattias.ronnblom@ericsson.com",
    "date": "2022-03-30T14:26:02",
    "name": "[v2] eal: add seqlock",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "19caa9cef857f6cdcc2e3c7364917592d8bcd38b",
    "submitter": {
        "id": 1077,
        "url": "https://patches.dpdk.org/api/people/1077/?format=api",
        "name": "Mattias Rönnblom",
        "email": "mattias.ronnblom@ericsson.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20220330142602.108061-1-mattias.ronnblom@ericsson.com/mbox/",
    "series": [
        {
            "id": 22294,
            "url": "https://patches.dpdk.org/api/series/22294/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=22294",
            "date": "2022-03-30T14:26:02",
            "name": "[v2] eal: add seqlock",
            "version": 2,
            "mbox": "https://patches.dpdk.org/series/22294/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/109034/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/109034/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 8A5FCA050D;\n\tWed, 30 Mar 2022 16:27:10 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 3516142854;\n\tWed, 30 Mar 2022 16:27:10 +0200 (CEST)",
            "from EUR01-VE1-obe.outbound.protection.outlook.com\n (mail-eopbgr140053.outbound.protection.outlook.com [40.107.14.53])\n by mails.dpdk.org (Postfix) with ESMTP id 590294013F\n for <dev@dpdk.org>; Wed, 30 Mar 2022 16:27:08 +0200 (CEST)",
            "from AM6PR10CA0105.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::46)\n by DB6PR07MB4181.eurprd07.prod.outlook.com (2603:10a6:6:50::26) with\n Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.15; Wed, 30 Mar\n 2022 14:27:04 +0000",
            "from VE1EUR02FT066.eop-EUR02.prod.protection.outlook.com\n (2603:10a6:209:8c:cafe::43) by AM6PR10CA0105.outlook.office365.com\n (2603:10a6:209:8c::46) 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; Wed, 30 Mar 2022 14:27:03 +0000",
            "from oa.msg.ericsson.com (192.176.1.74) by\n VE1EUR02FT066.mail.protection.outlook.com (10.152.13.141) with Microsoft SMTP\n Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id\n 15.20.5123.19 via Frontend Transport; Wed, 30 Mar 2022 14:27:03 +0000",
            "from ESESSMB501.ericsson.se (153.88.183.162) by\n ESESSMR503.ericsson.se (153.88.183.112) with Microsoft SMTP Server\n (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id\n 15.1.2308.27; Wed, 30 Mar 2022 16:27:01 +0200",
            "from seliiuapp00218.seli.gic.ericsson.se (153.88.183.153) by\n smtp.internal.ericsson.com (153.88.183.189) with Microsoft SMTP Server id\n 15.1.2308.27 via Frontend Transport; Wed, 30 Mar 2022 16:27:01 +0200",
            "from localhost.localdomain (seliicwb00002.seli.gic.ericsson.se\n [10.156.25.100])\n by seliiuapp00218.seli.gic.ericsson.se (Postfix) with ESMTP id 8CCF5602E9;\n Wed, 30 Mar 2022 16:27:01 +0200 (CEST)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;\n b=RMInhJ7UKDj+buBxMaz77rJ1Dt3z/mXdPCMzy1O1uSOtT4ADAWiBSF8tMI+UYWPmmY2WsC85u05q1+MVUVmshQt54oMCl8m1pnbY5E5+0EUKg7uRhmq0uHNk0Mza3yTEyYKOSIlWAaovIlptXIRiJRuaNiwRFLDhN0rcSowYGDq5BTRMxH7CjGxAQkaiNQn/8sPTl/2WZXiG0tQ0sL+FZ/Z8pDfrsTSWLuYHcLtvhoMJF/PzRZVpT9yhWvngRDbwiwp42zk1I07ENlQSNVgmyRmjRAIiL4dPMAczEqfiiF6mudqwgZSkm6uFpCoHowgncIBmGOkSeeHeVL9lDzGl8Q==",
        "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=tUHBmmnb1pDzl+8Oyl5uFL4PCtHfZsv6yiyloS2MMwQ=;\n b=kjJPkISPiZZ/8mR2V4LwsSLQKRn5YyDckO+YIJ5ZVtSccz+i1lA6DwNPFbuKQdHTFGEb42FojAgPdqf/Dpw5jeThIDZf5J9McAvyuZqL3ueEEK6XYnfagKvtyz8UyWfj3wPYZ2iUc8Wk/DtANXxYLVLqopLlUsu1g6rMbi4zEhFqK0EBy406266BoxgY1FZpXnmTSNVdK28tmGcP2QfWy02OzHEdjCSsoMwf7dUMlFsb18uIovCz0hhlaaUJXuYqT+JwQaefrnyXS97C6nZKnTnj388dkQ8dlViPefv+u6b9Q3kWTbQGsp2qmzSvsdvb2VTSg/sE9CASqfuj/dFWJg==",
        "ARC-Authentication-Results": "i=1; mx.microsoft.com 1; spf=pass (sender ip is\n 192.176.1.74) smtp.rcpttodomain=arm.com smtp.mailfrom=ericsson.com;\n dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com;\n dkim=none (message not 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=tUHBmmnb1pDzl+8Oyl5uFL4PCtHfZsv6yiyloS2MMwQ=;\n b=oih2+6Tr6iGZQagvQD4KgCO5b02H/j6rnHfMDDlfN0SUeYEOoIenn3JEjUSvg1z5uSRcauLfIUNoMxzYqerTp2zWspbwAN7ghCjxt4OkF3v7WAnp7Dvu7O2FBwZJqGSbeK+lSOnDMziRT3JroBCZz3c5MyoZVA9q6QmfSHhD55M=",
        "X-MS-Exchange-Authentication-Results": "spf=pass (sender IP is 192.176.1.74)\n smtp.mailfrom=ericsson.com; dkim=none (message not signed)\n header.d=none;dmarc=pass action=none header.from=ericsson.com;",
        "Received-SPF": "Pass (protection.outlook.com: domain of ericsson.com designates\n 192.176.1.74 as permitted sender)\n receiver=protection.outlook.com;\n client-ip=192.176.1.74; helo=oa.msg.ericsson.com;",
        "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": "[PATCH v2] eal: add seqlock",
        "Date": "Wed, 30 Mar 2022 16:26:02 +0200",
        "Message-ID": "<20220330142602.108061-1-mattias.ronnblom@ericsson.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "\n <98CBD80474FA8B44BF855DF32C47DC35D86F84@smartserver.smartshare.dk>",
        "References": "<98CBD80474FA8B44BF855DF32C47DC35D86F84@smartserver.smartshare.dk>",
        "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": "2a5d637e-4410-4b64-062f-08da12595c64",
        "X-MS-TrafficTypeDiagnostic": "DB6PR07MB4181:EE_",
        "X-Microsoft-Antispam-PRVS": "\n <DB6PR07MB4181BB90568E97848E47912FE11F9@DB6PR07MB4181.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 xb1n5RSyURJoaIWSGkckgNaXOR3OZbccQlglvyxDloM4zO4lUv4LG5CTTgz5b3KLsrFfrJoy395yDP6Wm6GDmMZEkD5H7RoD0mGMlqK5qHj+/aWmwNhOxXfo/e4tWsN+A3uht9qz47N9GUJnZkJWSyXEo1Ibqk5KziOHyAFKDrjO+6WN6Q3DeHMja7jwkExAx8Yo5GpInKpbenja6Gn4ge3x2vW/oMd1AsDGqafT8cav0LosT80e+Ty4NMFew0lNn/0uVlMbPTP8Dpd2OaTp+xfyC5jn9MdQ84uqrIqzp+dzbSLYR+D3S0lMTK6xxMR3J7XfRqQ/1N4eEp9jwxq+AyVM7wNB7NPK4NDQtvdL4CBX5/x4yoH0k76XCoOsfql+hduJ2dJgSK+9LwPF+XL7xAudyFsUDQhKnMbaqL1HI9GWl8Y37c9pku4ulWuPSTnjKTl0E76biYKgd0tDeOuiZcF+cI3wQpDaj62xQOg+YF3jMege+Ze3bHz4y+9u+hX/iNSey3IpBcUdRcZpP7fKzxQKx3eFV2yXr7s/vVfbimaon+FYYdBoPVyXZr3o0qhIqf4ESFrjQRi9LY4U8d1dGYorCoRRAf6zhL5CgSrSA63lpNnDo1AKqaPuqtwVCs2xo1DHlVlqEpWpYqtKDiBuMTm++vdDkZhdXdTwSIXdElNIqehwLp4gI9ZQr/nwozaJ1sWRq9O48oYY+yb7PM+wB011qrMkgn7Tk3wMRRi3/1Zfns868IoZkbs4Ws45cBop",
        "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)(40470700004)(46966006)(36840700001)(7636003)(82310400004)(356005)(6266002)(2616005)(186003)(26005)(966005)(1076003)(66574015)(83380400001)(508600001)(40460700003)(47076005)(36860700001)(36756003)(336012)(8936002)(70206006)(70586007)(54906003)(316002)(5660300002)(30864003)(2906002)(8676002)(4326008)(6916009)(86362001)(82960400001);\n DIR:OUT; SFP:1101;",
        "X-OriginatorOrg": "ericsson.com",
        "X-MS-Exchange-CrossTenant-OriginalArrivalTime": "30 Mar 2022 14:27:03.7169 (UTC)",
        "X-MS-Exchange-CrossTenant-Network-Message-Id": "\n 2a5d637e-4410-4b64-062f-08da12595c64",
        "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 VE1EUR02FT066.eop-EUR02.prod.protection.outlook.com",
        "X-MS-Exchange-CrossTenant-AuthAs": "Anonymous",
        "X-MS-Exchange-CrossTenant-FromEntityHeader": "HybridOnPrem",
        "X-MS-Exchange-Transport-CrossTenantHeadersStamped": "DB6PR07MB4181",
        "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 infrequently.\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\nFor more information on seqlocks, see\nhttps://en.wikipedia.org/wiki/Seqlock\n\nPATCH v2:\n  * Skip instead of fail unit test in case too few lcores are available.\n  * Use main lcore for testing, reducing the minimum number of lcores\n    required to run the unit tests to four.\n  * Consistently refer to sn field as the \"sequence number\" in the\n    documentation.\n  * Fixed spelling mistakes in documentation.\n\nUpdates since RFC:\n  * Added API documentation.\n  * Added link to Wikipedia article in the commit message.\n  * Changed seqlock sequence number field from uint64_t (which was\n    overkill) to uint32_t. The sn type needs to be sufficiently large\n    to assure no reader will read a sn, access the data, and then read\n    the same sn, but the sn has been updated to many times during the\n    read, so it has wrapped.\n  * Added RTE_SEQLOCK_INITIALIZER macro for static initialization.\n  * Removed the rte_seqlock struct + separate rte_seqlock_t typedef\n    with an anonymous struct typedef:ed to rte_seqlock_t.\n\nAcked-by: Morten Brørup <mb@smartsharesystems.com>\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       | 202 ++++++++++++++++++++++++\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 | 282 ++++++++++++++++++++++++++++++++++\n lib/eal/version.map           |   3 +\n 7 files changed, 503 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..ba1755d9ad\n--- /dev/null\n+++ b/app/test/test_seqlock.c\n@@ -0,0 +1,202 @@\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_run(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_run(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\tuint32_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_run() for an explanation 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) /* master lcore + one worker */\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)\n+\n+/* Only a compile-time test */\n+static rte_seqlock_t __rte_unused static_init_lock = RTE_SEQLOCK_INITIALIZER;\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 reader_lcore_ids[MAX_READERS];\n+\tunsigned int worker_writer_lcore_id = 0;\n+\tint rc = 0;\n+\n+\tnum_lcores = rte_lcore_count();\n+\n+\tif (num_lcores < MIN_LCORE_COUNT) {\n+\t\tprintf(\"Too few cores to run test. Skipping.\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tnum_readers = num_lcores - NUM_WRITERS;\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 == 0) {\n+\t\t\trte_eal_remote_launch(writer_run, data, lcore_id);\n+\t\t\tworker_writer_lcore_id = lcore_id;\n+\t\t} else {\n+\t\t\tunsigned int reader_idx = i - 1;\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_run, reader, lcore_id);\n+\t\t\treader_lcore_ids[reader_idx] = lcore_id;\n+\t\t}\n+\t\ti++;\n+\t}\n+\n+\tif (writer_run(data) != 0 ||\n+\t    rte_eal_wait_lcore(worker_writer_lcore_id) != 0)\n+\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..12cc3cdcb2\n--- /dev/null\n+++ b/lib/eal/include/rte_seqlock.h\n@@ -0,0 +1,282 @@\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+/**\n+ * @file\n+ * RTE Seqlock\n+ *\n+ * A sequence lock (seqlock) is a synchronization primitive allowing\n+ * multiple, parallel, readers to efficiently and safely (i.e., in a\n+ * data-race free manner) access the lock-protected data. The RTE\n+ * seqlock permits multiple writers as well. A spinlock is used for\n+ * writer-writer synchronization.\n+ *\n+ * A reader never blocks a writer. Very high frequency writes may\n+ * prevent readers from making progress.\n+ *\n+ * A seqlock is not preemption-safe on the writer side. If a writer is\n+ * preempted, it may block readers until the writer thread is again\n+ * allowed to execute. Heavy computations should be kept out of the\n+ * writer-side critical section, to avoid delaying readers.\n+ *\n+ * Seqlocks are useful for data which are read by many cores, at a\n+ * high frequency, and relatively infrequently written to.\n+ *\n+ * One way to think about seqlocks is that they provide means to\n+ * perform atomic operations on objects larger than what the native\n+ * machine instructions allow for.\n+ *\n+ * To avoid resource reclamation issues, the data protected by a\n+ * seqlock should typically be kept self-contained (e.g., no pointers\n+ * to mutable, dynamically allocated data).\n+ *\n+ * Example usage:\n+ * @code{.c}\n+ * #define MAX_Y_LEN (16)\n+ * // Application-defined example data structure, protected by a seqlock.\n+ * struct config {\n+ *         rte_seqlock_t lock;\n+ *         int param_x;\n+ *         char param_y[MAX_Y_LEN];\n+ * };\n+ *\n+ * // Accessor function for reading config fields.\n+ * void\n+ * config_read(const struct config *config, int *param_x, char *param_y)\n+ * {\n+ *         // Temporary variables, just to improve readability.\n+ *         int tentative_x;\n+ *         char tentative_y[MAX_Y_LEN];\n+ *\n+ *         do {\n+ *                 rte_seqlock_read(&config->lock);\n+ *                 // Loads may be atomic or non-atomic, as in this example.\n+ *                 tentative_x = config->param_x;\n+ *                 strcpy(tentative_y, config->param_y);\n+ *         } while (rte_seqlock_read_retry(&config->lock));\n+ *         // An application could skip retrying, and try again later, if\n+ *         // it can make progress without the data.\n+ *\n+ *         *param_x = tentative_x;\n+ *         strcpy(param_y, tentative_y);\n+ * }\n+ *\n+ * // Accessor function for writing config fields.\n+ * void\n+ * config_update(struct config *config, int param_x, const char *param_y)\n+ * {\n+ *         rte_seqlock_write_begin(&config->lock);\n+ *         // Stores may be atomic or non-atomic, as in this example.\n+ *         config->param_x = param_x;\n+ *         strcpy(config->param_y, param_y);\n+ *         rte_seqlock_write_end(&config->lock);\n+ * }\n+ * @endcode\n+ *\n+ * @see\n+ * https://en.wikipedia.org/wiki/Seqlock.\n+ */\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+/**\n+ * The RTE seqlock type.\n+ */\n+typedef struct {\n+\tuint32_t sn; /**< A sequence number for the protected data. */\n+\trte_spinlock_t lock; /**< Spinlock used to serialize writers.  */\n+} rte_seqlock_t;\n+\n+/**\n+ * A static seqlock initializer.\n+ */\n+#define RTE_SEQLOCK_INITIALIZER { 0, RTE_SPINLOCK_INITIALIZER }\n+\n+/**\n+ * Initialize the seqlock.\n+ *\n+ * This function initializes the seqlock, and leaves the writer-side\n+ * spinlock unlocked.\n+ *\n+ * @param seqlock\n+ *   A pointer to the seqlock.\n+ */\n+__rte_experimental\n+void\n+rte_seqlock_init(rte_seqlock_t *seqlock);\n+\n+/**\n+ * Begin a read-side critical section.\n+ *\n+ * A call to this function marks the beginning of a read-side critical\n+ * section, for @p seqlock.\n+ *\n+ * rte_seqlock_read_begin() returns a sequence number, which is later\n+ * used in rte_seqlock_read_retry() to check if the protected data\n+ * underwent any modifications during the read transaction.\n+ *\n+ * After (in program order) rte_seqlock_read_begin() has been called,\n+ * the calling thread may read and copy the protected data. The\n+ * protected data read *must* be copied (either in pristine form, or\n+ * in the form of some derivative). A copy is required since the\n+ * application only may read the data in the read-side critical\n+ * section (i.e., after rte_seqlock_read_begin() and before\n+ * rte_seqlock_read_retry()), but must not act upon the retrieved data\n+ * while in the critical section, since it does not yet know if it is\n+ * consistent.\n+ *\n+ * The data may be accessed with both atomic and/or non-atomic loads.\n+ *\n+ * After (in program order) all required data loads have been\n+ * performed, rte_seqlock_read_retry() must be called, marking the end\n+ * of the read-side critical section.\n+ *\n+ * If rte_seqlock_read_retry() returns true, the just-read data is\n+ * inconsistent and should be discarded. If rte_seqlock_read_retry()\n+ * returns false, the data was read atomically and the copied data is\n+ * consistent.\n+ *\n+ * If rte_seqlock_read_retry() returns false, the application has the\n+ * option to immediately restart the whole procedure (e.g., calling\n+ * rte_seqlock_read_being() again), or do the same at some later time.\n+ *\n+ * @param seqlock\n+ *   A pointer to the seqlock.\n+ * @return\n+ *   The seqlock sequence number for this critical section, to\n+ *   later be passed to rte_seqlock_read_retry().\n+ *\n+ * @see rte_seqlock_read_retry()\n+ */\n+__rte_experimental\n+static inline uint32_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. Synchronizes-with the\n+\t * store release in rte_seqlock_end().\n+\t */\n+\treturn __atomic_load_n(&seqlock->sn, __ATOMIC_ACQUIRE);\n+}\n+\n+/**\n+ * End a read-side critical section.\n+ *\n+ * A call to this function marks the end of a read-side critical\n+ * section, for @p seqlock. The application must supply the sequence\n+ * number returned from the corresponding rte_seqlock_read_begin()\n+ * call.\n+ *\n+ * After this function has been called, the caller should not access\n+ * the protected data.\n+ *\n+ * In case this function returns false, the just-read data was\n+ * consistent and the set of atomic and non-atomic load operations\n+ * performed between rte_seqlock_read_begin() and\n+ * rte_seqlock_read_retry() were atomic, as a whole.\n+ *\n+ * In case rte_seqlock_read_retry() returns true, the data was\n+ * modified as it was being read and may be inconsistent, and thus\n+ * should be discarded.\n+ *\n+ * @param seqlock\n+ *   A pointer to the seqlock.\n+ * @param begin_sn\n+ *   The seqlock sequence number that was returned by\n+ *   rte_seqlock_read_begin() for this critical section.\n+ * @return\n+ *   true or false, if the just-read seqlock-protected data is inconsistent\n+ *   or consistent, respectively.\n+ *\n+ * @see rte_seqlock_read_begin()\n+ */\n+__rte_experimental\n+static inline bool\n+rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)\n+{\n+\tuint32_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+/**\n+ * Begin write-side critical section.\n+ *\n+ * A call to this function acquires the write lock associated @p\n+ * seqlock, and marks the beginning of a write-side critical section.\n+ *\n+ * After having called this function, the caller may go on to modify\n+ * the protected data, in an atomic or non-atomic manner.\n+ *\n+ * After the necessary updates have been performed, the application\n+ * calls rte_seqlock_write_end().\n+ *\n+ * This function is not preemption-safe in the sense that preemption\n+ * of the calling thread may block reader progress until the writer\n+ * thread is rescheduled.\n+ *\n+ * @param seqlock\n+ *   A pointer to the seqlock.\n+ *\n+ * @see rte_seqlock_write_end()\n+ */\n+__rte_experimental\n+static inline void\n+rte_seqlock_write_begin(rte_seqlock_t *seqlock)\n+{\n+\tuint32_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+/**\n+ * End write-side critical section.\n+ *\n+ * A call to this function marks the end of the write-side critical\n+ * section, for @p seqlock. After this call has been made, the protected\n+ * data may no longer be modified.\n+ *\n+ * @param seqlock\n+ *   A pointer to the seqlock.\n+ *\n+ * @see rte_seqlock_write_begin()\n+ */\n+__rte_experimental\n+static inline void\n+rte_seqlock_write_end(rte_seqlock_t *seqlock)\n+{\n+\tuint32_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": [
        "v2"
    ]
}