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 2D58BA0032; Wed, 20 Jul 2022 00:33:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BE2F140A7A; Wed, 20 Jul 2022 00:33:44 +0200 (CEST) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by mails.dpdk.org (Postfix) with ESMTP id 2DA2940697 for ; Wed, 20 Jul 2022 00:33:44 +0200 (CEST) Received: by mail-pj1-f44.google.com with SMTP id q41-20020a17090a1b2c00b001f2043c727aso372330pjq.1 for ; Tue, 19 Jul 2022 15:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I6O04R33NCfYTCnVBXZnmQYn0yyT8hV2CWLHY81g9CQ=; b=dzZy/0+SnY/hhOqv19uzQmsSYQv5EYi72K4oBfYYoEryb7KcUZhwEXZM3IFv0ksU/L VWyZKUiwGHCFTi6ZblNoFBqCSAmiZs9k04GlyETDq/SpZt/WK7FpjjWSl7LMLr8bkime QF7BPTpQOGNs0EDQwTUhFmy4J1164c1rbHr8MGcTLC4uUE7X4AISerw81QzQG9f/mVa/ 3Mtsl6eDPgQJL6vbcKyLKpbSXXgGCrbXVzhsyVA8hDsgWoZfQlJTtkZiM1UFOPs2UqZO I7QSRacxNoBI4Xup7QLi6fnEO3ZzLgIi7BytY/kbPIfDH0MYi0r48ZwSEVFUBelT/Mh8 N2iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I6O04R33NCfYTCnVBXZnmQYn0yyT8hV2CWLHY81g9CQ=; b=nN5OoPNwpWcentXTD4tsUfBG8w5c+dDZVz9eWLSL76aF2ed4Q4ycaRJQRZTxTyQX1v ut5QhBnuWzRy3dXXsuI7wil4duWG3kAbWDdiEiTrvU8GQzHGR5DPq5/nvrDoINxih46N VebQF7TLIYqQnXUFnITiWBAfJIEmolVO85FWsXzesUvS0p6FPwF48Ax952hDl69Q5E/u TX60vGcKhjA/NFRMYIau3Qe4erAdPDOupSEIZ8Dj2nUNjvm4EmU0OamM5cA8rQ9tVtKf Jg5q4aZlO4ytCVrySrVjYaro8aATUbylklUmvtgRTZ4wbNjbzuYXk3/cZd4z/SObwRHh Omuw== X-Gm-Message-State: AJIora/+fI+omASFZN2Ml/sAHEvpB3J+2cIRzFXgTes208GtMvU2wjzR 8rsSzizNRJUfGOXy5XZT5FfY3GfUoPC7EA== X-Google-Smtp-Source: AGRyM1vshQLHX3Kz53AyKqrmV+ikAxez0fkU+x+lxRL8GrroOWCs1JXyioXBHo588juKFLZf7v41ug== X-Received: by 2002:a17:90a:a404:b0:1ee:e545:288b with SMTP id y4-20020a17090aa40400b001eee545288bmr1751378pjp.142.1658270023235; Tue, 19 Jul 2022 15:33:43 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id n8-20020a056a00212800b0052877d6f66bsm12048350pfj.50.2022.07.19.15.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 15:33:42 -0700 (PDT) Date: Tue, 19 Jul 2022 15:33:41 -0700 From: Stephen Hemminger To: Morten =?UTF-8?B?QnLDuHJ1cA==?= Cc: Subject: Re: [PATCH v2] rwlock: prevent readers from starving writers Message-ID: <20220719153341.57bf8ecb@hermes.local> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D871D6@smartserver.smartshare.dk> References: <20220707201226.618611-1-stephen@networkplumber.org> <20220719202750.563166-1-stephen@networkplumber.org> <98CBD80474FA8B44BF855DF32C47DC35D871D6@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 > > /** > > @@ -179,7 +226,7 @@ rte_rwlock_write_lock(rte_rwlock_t *rwl) > > static inline void > > rte_rwlock_write_unlock(rte_rwlock_t *rwl) > > { > > - __atomic_store_n(&rwl->cnt, 0, __ATOMIC_RELEASE); > > + __atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_WRITE, > > __ATOMIC_RELEASE); > > Yes. This is correct, regardless if another writer thread is waiting or not. (Reviewed for one writer thread using rte_rwlock_write_lock() and another using rte_rwlock_write_trylock().) > Was trying to stick to original logic. After writer releases want both writer and reader to be able to get in equally. This provide a measure of fairness (no preference) so writers can't starve readers either.