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 3B6B7A0544; Tue, 7 Jun 2022 11:25:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2691F4021D; Tue, 7 Jun 2022 11:25:38 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 7FAF240156 for ; Tue, 7 Jun 2022 11:25:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654593936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q5giKH17MKk5m6i9EmCaVnn55M5xS9baolKD7o6fQKA=; b=SlE6Uehvi9ZOjwoUPkQkk3EvKVh4Gip0mRyEK1Uo4bengVi0wWGCRZhEB9dqn0YwTJeVY0 CAHerGaV2Cy9zRQ75Y5CKYlFI0P5kLPF05DSdq3DncbzcgJImqXZBRfCPOIBzhbZdvHr62 j3Z5Vja/vb14Xvmrg3J5BrWhnmdnygI= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-KvVrLJKmPSS8M6eqvB8SNQ-1; Tue, 07 Jun 2022 05:25:35 -0400 X-MC-Unique: KvVrLJKmPSS8M6eqvB8SNQ-1 Received: by mail-lj1-f198.google.com with SMTP id f10-20020a2e9e8a000000b00250925fec6aso2837218ljk.20 for ; Tue, 07 Jun 2022 02:25:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=q5giKH17MKk5m6i9EmCaVnn55M5xS9baolKD7o6fQKA=; b=iDY1THa6qUvp+CG2Ht/UfZbwTHJXGfzdDbchRe7ChbaOj42tuJeVMcQwduUM2ZyOJp 9w0RK6uOhs81OktNmU5xnBfDJMHRtBiaan5nGDEAaZrR7JICrzRQ/2VFewfOvuX7W7ps tEOd3WsqRbVuoU57Ho3JrdT2LR5C66QTR/TRvzSXvuWD6WofAzfLHNuvJsbpS0HcQz0e Y0BnD4r4s/irHUOLYeD0sPislQeRJ6WHsu1Bo9p8fenCR0xzoPreeIAXXGaJVHKUqgbK 64bqa454A2+iov4RvAy2eh+LAU25uUcIa6CXFD1IWigaypeFlKFId2kjQBd/+bnzMwF7 vdJQ== X-Gm-Message-State: AOAM5305dW+/dTwbTOcrtStPJEXIlmFBDPR7mpBWhdoGXCmUMFb46LUU ranpD+Yr+ydrHMQfcoxZ7lCHpJ6NfXwSO9Fr2YK6PEqpPXsAvH05O1iN5zYUxX7BPVlIVRanbjv T2y6ePh1hW7BgUVq7CEE= X-Received: by 2002:a05:6512:b8b:b0:479:3e3b:9699 with SMTP id b11-20020a0565120b8b00b004793e3b9699mr7400869lfv.217.1654593933553; Tue, 07 Jun 2022 02:25:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCFxj8r8oOFpJUdEWhF7IDTDtiTtpmb9x2hfeMSC3+13zFA7Nk5cdr/LC1dt2OQn26vLZod20h1P3ln128EZ0= X-Received: by 2002:a05:6512:b8b:b0:479:3e3b:9699 with SMTP id b11-20020a0565120b8b00b004793e3b9699mr7400855lfv.217.1654593933243; Tue, 07 Jun 2022 02:25:33 -0700 (PDT) MIME-Version: 1.0 References: <20220523113111.366599-1-mattias.ronnblom@ericsson.com> <20220523142346.366902-1-mattias.ronnblom@ericsson.com> In-Reply-To: <20220523142346.366902-1-mattias.ronnblom@ericsson.com> From: David Marchand Date: Tue, 7 Jun 2022 11:25:20 +0200 Message-ID: Subject: Re: [PATCH v9] eal: add seqlock To: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= Cc: Thomas Monjalon , dev , onar.olsen@ericsson.com, Honnappa Nagarahalli , nd , "Ananyev, Konstantin" , =?UTF-8?Q?Morten_Br=C3=B8rup?= , Stephen Hemminger , =?UTF-8?Q?Mattias_R=C3=B6nnblom?= , Chengwen Feng , Ola Liljedahl Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Mon, May 23, 2022 at 4:24 PM Mattias R=C3=B6nnblom wrote: > > A sequence lock (seqlock) is a synchronization primitive which allows > for data-race free, low-overhead, high-frequency reads, suitable for > data structures shared across many cores and which are updated > relatively infrequently. > > A seqlock permits multiple parallel readers. A spinlock is used to > serialize writers. In cases where there is only a single writer, or > writer-writer synchronization is done by some external means, the > "raw" sequence counter type (and accompanying rte_seqcount_*() > functions) may be used instead. > > To avoid resource reclamation and other issues, the data protected by > a seqlock is best off being self-contained (i.e., no pointers [except > to constant data]). > > One way to think about seqlocks is that they provide means to perform > atomic operations on data objects larger than what the native atomic > machine instructions allow for. > > DPDK seqlocks (and the underlying sequence counters) are not > preemption safe on the writer side. A thread preemption affects > performance, not correctness. > > A seqlock contains a sequence number, which can be thought of as the > generation of the data it protects. > > A reader will > 1. Load the sequence number (sn). > 2. Load, in arbitrary order, the seqlock-protected data. > 3. Load the sn again. > 4. Check if the first and second sn are equal, and even numbered. > If they are not, discard the loaded data, and restart from 1. > > The first three steps need to be ordered using suitable memory fences. > > A writer will > 1. Take the spinlock, to serialize writer access. > 2. Load the sn. > 3. Store the original sn + 1 as the new sn. > 4. Perform load and stores to the seqlock-protected data. > 5. Store the original sn + 2 as the new sn. > 6. Release the spinlock. > > Proper memory fencing is required to make sure the first sn store, the > data stores, and the second sn store appear to the reader in the > mentioned order. > > The sn loads and stores must be atomic, but the data loads and stores > need not be. > > The original seqlock design and implementation was done by Stephen > Hemminger. This is an independent implementation, using C11 atomics. > > For more information on seqlocks, see > https://en.wikipedia.org/wiki/Seqlock > > Acked-by: Morten Br=C3=B8rup > Acked-by: Konstantin Ananyev > Reviewed-by: Ola Liljedahl > Reviewed-by: Chengwen Feng > Signed-off-by: Mattias R=C3=B6nnblom As mentionned before, I did some little style fixes, and one last minute update following discussion between Stephen and Mattias. This patch passes my checks and the CI was okay. Thanks Mattias, and reviewers. Applied for -rc1. --=20 David Marchand