From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sesbmg22.ericsson.net (sesbmg22.ericsson.net [193.180.251.48]) by dpdk.org (Postfix) with ESMTP id A5FDB4F90 for ; Tue, 18 Sep 2018 14:45:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1537274730; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=woE8RAdlTcuwj+1trtSicV02p6OTcLf5DP4WVMBYYlY=; b=P1bbJoQtBkOO/zaVpDg97bmCQQtfHo/BPADPA6BlkW/S20n0DeSnXYg+a6gVPMEQ jThGn+fbfbENbZAameg5fWRxL46mZtmfHn3v9W3tWgTnas4VUZW4tDtwpsIhmATt Ggm4ac9R8s7mWMHheVWD2TMNPV/zFwRWU0Ehm86kW2A=; X-AuditID: c1b4fb30-ff9ff700000055da-e1-5ba0f36abde6 Received: from ESESSMB501.ericsson.se (Unknown_Domain [153.88.183.119]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id 14.49.21978.A63F0AB5; Tue, 18 Sep 2018 14:45:30 +0200 (CEST) Received: from ESESBMB503.ericsson.se (153.88.183.170) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 18 Sep 2018 14:45:27 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.186) with Microsoft SMTP Server id 15.1.1466.3 via Frontend Transport; Tue, 18 Sep 2018 14:45:27 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id w8ICjQ1b011575; Tue, 18 Sep 2018 14:45:27 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: Jerin Jacob CC: Bruce Richardson , , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Date: Tue, 18 Sep 2018 14:45:12 +0200 Message-ID: <20180918124514.10615-9-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180918124514.10615-1-mattias.ronnblom@ericsson.com> References: <20180918124514.10615-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsUyM2J7uW7W5wXRBvMn8VvcWGVv8e7TdiaL iZNMHJg9NpzoZ/X4tWApq8fiPS+ZApijuGxSUnMyy1KL9O0SuDJOHvrHVjBDsWJu13qWBsYZ 0l2MnBwSAiYSjXuOMnYxcnEICRxllPjz/iGU841R4tP2bywQzkVGifd/dkBlLjNKfPw1mQ2k n03AU2Lyu24WEFtEwEBi0Zn7zCBFzAIdjBLNU/+AJYQFAiTezP8MZrMIqEocXHWUFcTmFXCS aN33ix3iEHmJ1RsOMIPYnALOEp+nrmPqYuQA2uYkcXGDMkS5oMTJmU/AxjALaEq0bv/NDmHL SzRvnQ3WKiSgJXF/yRfmCYxCs5C0zELSMgtJywJG5lWMosWpxUm56UZGeqlFmcnFxfl5enmp JZsYgcF9cMtvgx2ML587HmIU4GBU4uGNfrUgWog1say4MvcQowQHs5IIL2cOUIg3JbGyKrUo P76oNCe1+BCjNAeLkjivhd/mKCGB9MSS1OzU1ILUIpgsEwenVANjtFC3tW5um+Plsl8aRSsb RL2vbM9N9tpb8HWpWtCpytyJduGbPrrO+y4xvbosQX27RIpDfape04lvsl3X3r8461fxuvxu pOqZW6W7TvUeSMnbpB+Tqz8/oGjNrV/vdBZyMxZfM8v4lBh2553ys7Mtt+et3thb/XdaglDa /Wm/tydfSyzcfDpNiaU4I9FQi7moOBEAlCBckGoCAAA= Subject: [dpdk-dev] [PATCH v4 08/10] event/dsw: let DSW event device sort events on dequeue 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: , X-List-Received-Date: Tue, 18 Sep 2018 12:45:31 -0000 With this patch, the DSW event device will (optionally) sort the event burst before giving it to the application. The sorting will primarily be on queue id, and secondary on flow id. The sorting is an attempt to optimize data and instruction cache usage for the application, at the cost of additional event device overhead. Signed-off-by: Mattias Rönnblom --- drivers/event/dsw/dsw_evdev.h | 11 ++++++++ drivers/event/dsw/dsw_event.c | 23 +++++++++++++++++ drivers/event/dsw/dsw_sort.h | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 drivers/event/dsw/dsw_sort.h diff --git a/drivers/event/dsw/dsw_evdev.h b/drivers/event/dsw/dsw_evdev.h index 783c418bf..f6f8f0454 100644 --- a/drivers/event/dsw/dsw_evdev.h +++ b/drivers/event/dsw/dsw_evdev.h @@ -93,6 +93,17 @@ */ #define DSW_CTL_IN_RING_SIZE ((DSW_MAX_PORTS-1)*4) +/* With DSW_SORT_DEQUEUED enabled, the scheduler will, at the point of + * dequeue(), arrange events so that events with the same flow id on + * the same queue forms a back-to-back "burst", and also so that such + * bursts of different flow ids, but on the same queue, also come + * consecutively. All this in an attempt to improve data and + * instruction cache usage for the application, at the cost of a + * scheduler overhead increase. + */ + +/* #define DSW_SORT_DEQUEUED */ + struct dsw_queue_flow { uint8_t queue_id; uint16_t flow_hash; diff --git a/drivers/event/dsw/dsw_event.c b/drivers/event/dsw/dsw_event.c index f0347592d..a84b19c33 100644 --- a/drivers/event/dsw/dsw_event.c +++ b/drivers/event/dsw/dsw_event.c @@ -4,6 +4,10 @@ #include "dsw_evdev.h" +#ifdef DSW_SORT_DEQUEUED +#include "dsw_sort.h" +#endif + #include #include @@ -1121,6 +1125,21 @@ dsw_port_record_seen_events(struct dsw_port *port, struct rte_event *events, DSW_MAX_EVENTS_RECORDED); } +#ifdef DSW_SORT_DEQUEUED + +#define DSW_EVENT_TO_INT(_event) \ + ((int)((((_event)->queue_id)<<16)|((_event)->flow_id))) + +static inline int +dsw_cmp_event(const void *v_event_a, const void *v_event_b) +{ + const struct rte_event *event_a = v_event_a; + const struct rte_event *event_b = v_event_b; + + return DSW_EVENT_TO_INT(event_a) - DSW_EVENT_TO_INT(event_b); +} +#endif + static uint16_t dsw_port_dequeue_burst(struct dsw_port *port, struct rte_event *events, uint16_t num) @@ -1191,5 +1210,9 @@ dsw_event_dequeue_burst(void *port, struct rte_event *events, uint16_t num, * 0. */ +#ifdef DSW_SORT_DEQUEUED + dsw_stable_sort(events, dequeued, sizeof(events[0]), dsw_cmp_event); +#endif + return dequeued; } diff --git a/drivers/event/dsw/dsw_sort.h b/drivers/event/dsw/dsw_sort.h new file mode 100644 index 000000000..609767fdf --- /dev/null +++ b/drivers/event/dsw/dsw_sort.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Ericsson AB + */ + +#ifndef _DSW_SORT_ +#define _DSW_SORT_ + +#include + +#include + +#define DSW_ARY_ELEM_PTR(_ary, _idx, _elem_size) \ + RTE_PTR_ADD(_ary, (_idx) * (_elem_size)) + +#define DSW_ARY_ELEM_SWAP(_ary, _a_idx, _b_idx, _elem_size) \ + do { \ + char tmp[_elem_size]; \ + void *_a_ptr = DSW_ARY_ELEM_PTR(_ary, _a_idx, _elem_size); \ + void *_b_ptr = DSW_ARY_ELEM_PTR(_ary, _b_idx, _elem_size); \ + memcpy(tmp, _a_ptr, _elem_size); \ + memcpy(_a_ptr, _b_ptr, _elem_size); \ + memcpy(_b_ptr, tmp, _elem_size); \ + } while (0) + +static inline void +dsw_insertion_sort(void *ary, uint16_t len, uint16_t elem_size, + int (*cmp_fn)(const void *, const void *)) +{ + uint16_t i; + + for (i = 1; i < len; i++) { + uint16_t j; + for (j = i; j > 0 && + cmp_fn(DSW_ARY_ELEM_PTR(ary, j-1, elem_size), + DSW_ARY_ELEM_PTR(ary, j, elem_size)) > 0; + j--) + DSW_ARY_ELEM_SWAP(ary, j, j-1, elem_size); + } +} + +static inline void +dsw_stable_sort(void *ary, uint16_t len, uint16_t elem_size, + int (*cmp_fn)(const void *, const void *)) +{ + dsw_insertion_sort(ary, len, elem_size, cmp_fn); +} + +#endif -- 2.17.1