From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0E965A0563; Wed, 15 Apr 2020 22:28:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 92A5B1DA1B; Wed, 15 Apr 2020 22:28:11 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id A40BF1DA12 for ; Wed, 15 Apr 2020 22:28:09 +0200 (CEST) IronPort-SDR: drJMYaubGy8qBdEaRpPXq8UyuY0zcQaYUrP822EWw06I31ijokuPoeNGaTUYCrbQRQRz5y5KWr ElIIUGYQn/vw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2020 13:28:08 -0700 IronPort-SDR: U9V+HhBV++Iws1HQHhxb6kG12GbPeYGekixNMIwlONzpIoK3COKNPiwfSIZo0jJ4tyE5o1K61u PqnORbbrnh8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,388,1580803200"; d="scan'208";a="245780973" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga008.fm.intel.com with ESMTP; 15 Apr 2020 13:28:08 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 Apr 2020 13:28:08 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 Apr 2020 13:28:08 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.109) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 Apr 2020 13:28:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NiGT+gsPGw1E3qpqhd0UHwJ6TZXe6BCJ0afmAGg8Qmw2NKzQtvxhP0cyZAsq6Z9/GX4LwXMdzFleUH0tPby+QN87p76+ndPBN84KB2kD9qdmsUzGWwCiU6tm0FpNVAqYdqDNulIqMCwcWliOP0vUsAUTYFQOHGZKB80Vb86UrzReeXiFeRn+gm7hFVEVvB6wcE/bPjFQjcpvu6qOt5uCUTZFBjgUfqnlvYkSTTjMjCzWwUe7VbMrEVt1MnmkwsPKYQnUU5WtKPXy06HbkLULF+YtmA9Zi2PWS3MrO8kDhOla3Kc+/1SNPf5vkZ3J4zTLiUa6bEw1CXFz2BxqWc/RJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k6TEM7LpZpuOttWwVjDO+keR4auuhssHKL2YRT05PNw=; b=WsTtWFEcwF40N7p15ppfY3PipuxkB/snNjVzbnSThIcg9ymZD8uZMNP2JMpnwSw6CDPqJ1RxPxmGog6mrw6khLo6IyZuJFfNnfglWUfUhxBcVswMtv50KYgARxmbxS9ou2XwJQdbD+DqIewPUHwMs2n+tYm+fi90SXtJTFVtz5Ng/zQEuWvsBzTNAdDGxGfrK3d1cY2uqKJ6Lx3gZ2cSi25b/T4DY30hnpjEGZRM2LqwvDt68qIYc2ix/QpkmG88aG6xTFlftUcESfAEMWYMkJWKh6jcHPu326qqOVPn/jlYn8U7H43ShLnroaWew1K+KyZV+0JOq/5SARQCJuLZpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k6TEM7LpZpuOttWwVjDO+keR4auuhssHKL2YRT05PNw=; b=duh7GiNCwVzc8K/SKUteNDbQAE/uk4KINstj8E0kAAjXLJ99F0mZERaVRt6n7yCPMLJY/pd6wO4YG3Qp32d1fne0iqwSdsQeGJI95PTRFHo5PcOWZbdlGAw2YBbXV4aKCjJL8BqCQ75r2uhkZIC+e9rcOvUpLzMfgwLT17qHpMo= Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26) by BYAPR11MB3094.namprd11.prod.outlook.com (2603:10b6:a03:87::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.28; Wed, 15 Apr 2020 20:28:07 +0000 Received: from BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f8cb:58cd:e958:fff4]) by BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f8cb:58cd:e958:fff4%6]) with mapi id 15.20.2900.028; Wed, 15 Apr 2020 20:28:06 +0000 From: "Ananyev, Konstantin" To: Honnappa Nagarahalli , "dev@dpdk.org" CC: "david.marchand@redhat.com" , "jielong.zjl@antfin.com" , nd , nd Thread-Topic: [PATCH v3 9/9] ring: add C11 memory model for new sync modes Thread-Index: AQHWCd93VYpM5k5NKEiYni6AJ1o026h4FqUAgAKYR+A= Date: Wed, 15 Apr 2020 20:28:06 +0000 Message-ID: References: <20200402220959.29885-1-konstantin.ananyev@intel.com> <20200403174235.23308-1-konstantin.ananyev@intel.com> <20200403174235.23308-10-konstantin.ananyev@intel.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: spf=none (sender IP is ) smtp.mailfrom=konstantin.ananyev@intel.com; x-originating-ip: [192.198.151.178] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c67c43ea-ac6f-40b6-789d-08d7e17b81b4 x-ms-traffictypediagnostic: BYAPR11MB3094: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0374433C81 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3301.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10019020)(366004)(346002)(396003)(39860400002)(136003)(376002)(66556008)(2906002)(66946007)(8676002)(52536014)(64756008)(316002)(76116006)(81156014)(66446008)(33656002)(66476007)(8936002)(110136005)(54906003)(9686003)(186003)(7696005)(5660300002)(6506007)(478600001)(26005)(55016002)(71200400001)(4326008)(86362001); DIR:OUT; SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HVw1+1ieBI5CMiJVYZBiAA0HbRNLuWk2DSo+Dn4NNu8yoHloHh8UrZyWsxmKmndMUgn24/Q3tcpjOxv/aVW96kSlKVlJWFwqiltEppHQ4TFpXWiBj9KG1OrJSO4aft1LSaFkl8sBtczhFr7hr3wtsle+5qdXvJ344lpN8cHAjw+uA4E+jzuD8M7k2bHO+Y8GeRdxaKksNGi1bGHuffOjpEiCzMMND/uFfOTi76/SWdIWCi3HSzIyGPc2iKONorpvJwfGvMQg9OJyQ3hXBrHcsin1BCpCVj/+hz89aWUCCQRf+FN+KrET8G2NENmB7y6WldD6C4JiGILOYRD6bAS4HDJrbjAfTgVebwDg9bclqr2e7JiZV736R9fPH3T0ukDhHoQgYABuWwKsnVXB31YwcSSfanod8+08UrKkLZerP3SjSV6cONoCp3bOMeBBlFLf x-ms-exchange-antispam-messagedata: mb7Wc2hoeF5OiVk/zc3AMfBqYwLKX+NJGedM50TQNArbRGwDwLKPwQRlf1oruC7ztxk1cr6IGrhOkGsBpnQ6Gi+BAJcmt+Ndic1vlu1XGVnMDzAGzCtCUZGJwadBfcg53B28Y6wKTdI+rTNk7hc17A== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c67c43ea-ac6f-40b6-789d-08d7e17b81b4 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2020 20:28:06.8480 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PKUpZ43fhUgbNJ01QDw6n0nJyLw6ODyanc8130lZUll9hIBsh2KI4xZ5aToo8LDEeiAN6DEaG+mgryTCE2014PBnh/J9wwiieUt+UmlP9xk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3094 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v3 9/9] ring: add C11 memory model for new sync modes X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Hi Honnappa, > > + > > +/** > > + * @internal This function updates the producer head for enqueue > > + * > > + * @param r > > + * A pointer to the ring structure > > + * @param is_sp > > + * Indicates whether multi-producer path is needed or not > > + * @param n > > + * The number of elements we will want to enqueue, i.e. how far shou= ld the > > + * head be moved > > + * @param behavior > > + * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a r= ing > > + * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from > > ring > > + * @param old_head > > + * Returns head value as it was before the move, i.e. where enqueue = starts > > + * @param new_head > > + * Returns the current/new head value i.e. where enqueue finishes > > + * @param free_entries > > + * Returns the amount of free space in the ring BEFORE head was move= d > > + * @return > > + * Actual number of objects enqueued. > > + * If behavior =3D=3D RTE_RING_QUEUE_FIXED, this will be 0 or n only= . > > + */ > > +static __rte_always_inline unsigned int > > +__rte_ring_hts_move_prod_head(struct rte_ring *r, unsigned int num, > > + enum rte_ring_queue_behavior behavior, uint32_t *old_head, > > + uint32_t *free_entries) > > +{ > > + uint32_t n; > > + union rte_ring_ht_pos np, op; > > + > > + const uint32_t capacity =3D r->capacity; > > + > > + do { > > + /* Reset n to the initial burst count */ > > + n =3D num; > > + > > + /* wait for tail to be equal to head, , acquire point */ > > + __rte_ring_hts_head_wait(&r->hts_prod, &op); > > + > > + /* > > + * The subtraction is done between two unsigned 32bits value > > + * (the result is always modulo 32 bits even if we have > > + * *old_head > cons_tail). So 'free_entries' is always between > > 0 > > + * and capacity (which is < size). > > + */ > > + *free_entries =3D capacity + r->cons.tail - op.pos.head; > > + > > + /* check that we have enough room in ring */ > > + if (unlikely(n > *free_entries)) > > + n =3D (behavior =3D=3D RTE_RING_QUEUE_FIXED) ? > > + 0 : *free_entries; > > + > > + if (n =3D=3D 0) > > + break; > > + > > + np.pos.tail =3D op.pos.tail; > > + np.pos.head =3D op.pos.head + n; > > + > > + } while (__atomic_compare_exchange_n(&r->hts_prod.ht.raw, > > + &op.raw, np.raw, > > + 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED) =3D=3D 0); > __ATOMIC_RELEASE can be __ATOMIC_RELAXED. The RELEASE while updating afte= r the elements are written is enough. I looked at it once again and I think RELAXED probably not enough here (same as RELEASE). Seems we have to use ACQUIRE here (and in other similar places) to forbid CPU speculatively do actual objects copy before CAS. Another alternative would probably use : cons_tail =3D __atomic_load_n(&r->cons.tail, __ATOMIC_ACQUIRE); *free_entries =3D capacity + cons_tail - op.pos.head; instead of just *free_entries =3D capacity + r->cons.tail - op.pos.head; above. But that would mean two acquire points inside the loop: load(prod, ACQUIRE); load(cons.tail, ACQUIRE); Plus for me CAS(..., ACQUIRE, ACQUIRE) seems more logical here, so leaning that way. =20 >=20 > > + > > + *old_head =3D op.pos.head; > > + return n; > > +}