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 5E60CA0C45; Mon, 5 Jul 2021 18:20:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D495A4068C; Mon, 5 Jul 2021 18:20:25 +0200 (CEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id 9DFB140141 for ; Mon, 5 Jul 2021 18:20:24 +0200 (CEST) Received: by mail-pf1-f176.google.com with SMTP id b12so15944878pfv.6 for ; Mon, 05 Jul 2021 09:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Nv28RJ5Hc0XxoUuM3sAxsgbX2zFxSjZ6DdtBCshPfw=; b=vbZSTnYvm2G0Qy07qGyy2F+1kI5k8ZOTfBBGSEDl7jkonkSeQzlGjjf/TG3OxW4mha 49d9yi9M6lOicoFmoDxPuz2Wdz3dl2ZFIoipGUNZblPfZhFB6uNR51V/+9h3RJAlDTbR YcXu9+GP2IIYZ5PHdyZ8/zvCD0QOQZW5tKzCFX/Fnf6y+bx3DtvsuvM+2FSzXZtOa/i7 D+zIv+A2u0T/f5lsduRHsa3nRMXqOR8gtdEXM8zncVDMhRJOoSzJZBBxBW3gzMeNoZtf rDatp9pRLnpAQe4bs7DBkUMfeOP2DE+PrF27fltd7HeG+RCjX6in2r0DNrtxV5GS+XRm lNVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Nv28RJ5Hc0XxoUuM3sAxsgbX2zFxSjZ6DdtBCshPfw=; b=seOa3jXRgn8RYzYOeufscNsggNyU2RRKP201WApEqkkBHTKyMgAkeBoLl7PzqgvdcR SIwJj1C0MhNm6e7tV3ksXJHzrikX4kaosHW+P17WH1/dX6Rc1pPFz3EycHRVb8j/zCdK R3g8qL9hvsvk04KGmYnlZhi1NLZFFcFrsGZOwddpCYHQKMMb3wu6XVw7JC7hxq9B3rGn Pc22dXi3SmR+GAVh+fTVSkwp2KBc342cDm8Uh1+Arvad+FfsRthvGxpgPRcw5n+Tu64q qRBr+UdQAn94wQE8hemNmpFL9uENInD77U2s8c2PvNGLmw7D3ZVOwLKwk4esojxnlvBr v9aQ== X-Gm-Message-State: AOAM532wFxdkCmEj5glnKYMsPy9ZZH8MPQ9Sp0Bwtor3ezNN1OL2jP1J z+TlXsTokZGPu+rD4xm15gGvHw== X-Google-Smtp-Source: ABdhPJxh3nFIyETOxYerv3RcXZfxUDuw7gBLTYiARE/g18//eQfo1bnByz4Nx2DColaYA8+7kKkxTA== X-Received: by 2002:aa7:8489:0:b029:2fb:4ce0:339c with SMTP id u9-20020aa784890000b02902fb4ce0339cmr15903838pfn.16.1625502023707; Mon, 05 Jul 2021 09:20:23 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id p17sm22017659pjg.54.2021.07.05.09.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 09:20:23 -0700 (PDT) Date: Mon, 5 Jul 2021 09:20:20 -0700 From: Stephen Hemminger To: Ruifeng Wang Cc: "thomas@monjalon.net" , Honnappa Nagarahalli , "dev@dpdk.org" , "bruce.richardson@intel.com" , "konstantin.ananyev@intel.com" , "david.marchand@redhat.com" , David Christensen , nd Message-ID: <20210705092020.77b291b4@hermes.local> In-Reply-To: References: <1879045.6WiRxTbeAL@thomas> <1806192.QIeOlYoxj9@thomas> <2658239.2zj59f8sm8@thomas> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] atomic operations 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 Sender: "dev" On Mon, 5 Jul 2021 08:33:21 +0000 Ruifeng Wang wrote: > > > > > > One simple example: increment a counter atomically. > > > > __atomic_fetch_add(&counter, 1, __ATOMIC_RELAXED); or > > > > __atomic_add_fetch(&counter, 1, __ATOMIC_RELAXED); > > > > I really hate how atomics are "documented" in GCC doc. > > For instance, it doesn't say what is returned (old or new value) in above > > functions. > > > Returns are described as "the result of the operation" and "the value that had previously been in *ptr". > It can be more concise. Since English language parses left to right, the function name seem really obvious to me. __atomic_fetch_add returns the result before the add, and __atomic_add_fetch returns the result after the add. The one non-obvious question is which way is faster if the result is not being used?