From patchwork Sun Dec 10 08:37:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hanoch Haim (hhaim)" X-Patchwork-Id: 32058 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 51C1A2BAE; Sun, 10 Dec 2017 09:37:25 +0100 (CET) Received: from alln-iport-8.cisco.com (alln-iport-8.cisco.com [173.37.142.95]) by dpdk.org (Postfix) with ESMTP id 36EC4293B for ; Sun, 10 Dec 2017 09:37:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=2863; q=dns/txt; s=iport; t=1512895044; x=1514104644; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Q+0whP+ealAxX4HfH+PMun05iBrlvl7Cmm1bTM/KRlA=; b=iaFmqHzb8EKa8VF3UiObQV97E2VQePhHtAZ7bH7cSwv6VsU0a4Xfzjc5 xkmgDY+pWX7xeb/+Pgj4XNEUM8q6/+Ows0B66uMoyoYTs3TgNBUVnIie3 AFLc7CSzHjYC8m7NGiGtLA+en7JoaaMvBobxlN5W3LVsBI+p33KFqIpVo w=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D6AQDp8Sxa/4wNJK1cGQEBAQEBAQEBAQEBAQcBAQEBAYM+gVonB50ZgX2IdZAsCoU7AoRfQhUBAQEBAQEBAQFrKIUiAQEBAQMnEz8MBAIBCBEEAQEfCQchERQJCAIEAQ0FCIoIAxWofzqHMQ2DJgEBAQEBAQEBAQEBAQEBAQEBAQEBAR2DaIILgVaEXjaCaogtBaJUPQKQI4Rzk2yNR4hqAhEZAYE6ATUjgU9vFYJjhFV4iFsBgRQBAQE X-IronPort-AV: E=Sophos;i="5.45,387,1508803200"; d="scan'208";a="42128927" Received: from alln-core-7.cisco.com ([173.36.13.140]) by alln-iport-8.cisco.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Dec 2017 08:37:23 +0000 Received: from XCH-RTP-016.cisco.com (xch-rtp-016.cisco.com [64.101.220.156]) by alln-core-7.cisco.com (8.14.5/8.14.5) with ESMTP id vBA8bMw0005142 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 10 Dec 2017 08:37:23 GMT Received: from xch-rtp-017.cisco.com (64.101.220.157) by XCH-RTP-016.cisco.com (64.101.220.156) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Sun, 10 Dec 2017 03:37:22 -0500 Received: from xch-rtp-017.cisco.com ([64.101.220.157]) by XCH-RTP-017.cisco.com ([64.101.220.157]) with mapi id 15.00.1320.000; Sun, 10 Dec 2017 03:37:22 -0500 From: "Hanoch Haim (hhaim)" To: Olivier Matz , "dev@dpdk.org" CC: "matvejchikov@gmail.com" , "konstantin.ananyev@intel.com" Thread-Topic: [PATCH v4] mbuf: fix mbuf free performance with non atomic refcnt Thread-Index: AQHTcDvREOi1B3oEk0SsIe3FOK/BjaM8Q3Pw Date: Sun, 10 Dec 2017 08:37:22 +0000 Message-ID: <39032469f9204aa9b707d49670ceebba@XCH-RTP-017.cisco.com> References: <20171115091413.27119-1-hhaim@cisco.com> <20171208154651.16546-1-olivier.matz@6wind.com> In-Reply-To: <20171208154651.16546-1-olivier.matz@6wind.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [64.103.125.71] MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v4] mbuf: fix mbuf free performance with non atomic refcnt 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" Oliver, Looks great. Thanks, Hanoh -----Original Message----- From: Olivier Matz [mailto:olivier.matz@6wind.com] Sent: Friday, December 08, 2017 5:47 PM To: dev@dpdk.org; Hanoch Haim (hhaim) Cc: matvejchikov@gmail.com; konstantin.ananyev@intel.com Subject: [PATCH v4] mbuf: fix mbuf free performance with non atomic refcnt When RTE_MBUF_REFCNT_ATOMIC=n, the decrement of the mbuf reference counter uses an atomic operation. This is not necessary and impacts the performance (seen with TRex traffic generator). We cannot replace rte_atomic16_add_return() by rte_mbuf_refcnt_update() because it would add an additional check. Solves this by introducing __rte_mbuf_refcnt_update(), which updates the reference counter without doing anything else. Fixes: 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool") Suggested-by: Hanoch Haim Signed-off-by: Olivier Matz --- Hanoh, The following patch implements what was discussed in the thread. Are you ok with it? Thanks, Olivier lib/librte_mbuf/rte_mbuf.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) } - return (uint16_t)(rte_atomic16_add_return(&m->refcnt_atomic, value)); + return __rte_mbuf_refcnt_update(m, value); } #else /* ! RTE_MBUF_REFCNT_ATOMIC */ +/* internal */ +static inline uint16_t +__rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) { + m->refcnt = (uint16_t)(m->refcnt + value); + return m->refcnt; +} + /** * Adds given value to an mbuf's refcnt and returns its new value. */ static inline uint16_t rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) { - m->refcnt = (uint16_t)(m->refcnt + value); - return m->refcnt; + return __rte_mbuf_refcnt_update(m, value); } /** @@ -1364,8 +1378,7 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m) return m; - } else if (rte_atomic16_add_return(&m->refcnt_atomic, -1) == 0) { - + } else if (__rte_mbuf_refcnt_update(m, -1) == 0) { if (RTE_MBUF_INDIRECT(m)) rte_pktmbuf_detach(m); -- 2.11.0 diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index ce8a05ddf..dd08cb72b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -764,6 +764,13 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value) rte_atomic16_set(&m->refcnt_atomic, new_value); } +/* internal */ +static inline uint16_t +__rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) { + return (uint16_t)(rte_atomic16_add_return(&m->refcnt_atomic, value)); +} + /** * Adds given value to an mbuf's refcnt and returns its new value. * @param m @@ -788,19 +795,26 @@ rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) return 1 + value;