From patchwork Tue Aug 29 16:19:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 28066 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 89BD458EC; Tue, 29 Aug 2017 18:20:06 +0200 (CEST) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by dpdk.org (Postfix) with ESMTP id F21E758CE for ; Tue, 29 Aug 2017 18:20:04 +0200 (CEST) Received: by mail-wm0-f50.google.com with SMTP id b14so21207655wme.0 for ; Tue, 29 Aug 2017 09:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=v2BLfeiYSLFOOS582KZagV6hwDRUsWBhZ4KcU/xJDVg=; b=cXbgKgNJdCOk/chPnY/gDF/cmRa1jjI56tDCwHlahg3MwzgW6CLt0pHzWevdl4FZ53 isQziHuxtB2KKlP31A4hT9cYSiqsirM44NiCW9p6lGXoxhm2RgBvmpsiXV5qxTVlWM8j adPLjfCwDtKkMujOpWTf2TM8SnCHMcMz4LhT6fsGsBc/xPGlf5ekUeMlELWthaGEBUyg 8DbbIwCm9e40gw940afY3LvU32H2Gktk/k0guygXeQ0NjwYY2XXCo7J9F9neZEk7Z0D+ +MOHC8P0lrlSJt7Yye5jmtdMDdxFwhysoyRn9DoERl3EcVIq2FDM6hGAcWkFGo84cweu q29A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=v2BLfeiYSLFOOS582KZagV6hwDRUsWBhZ4KcU/xJDVg=; b=sLbDirP71NIUpvPtFfxGu1iTYKx7tpq/diI044LREvcKHv5E3Qrx1Cw6UlW1JHl15B 4u328EjkjheBcrsTCgT5IhNxAafkQ5xnVIxUEiO452bNurn+NzQRBztL1Qb4tgrGR1lK SGw8xTczYsXmigW/Bv+51FJp5b/fYVvbzcJShYJqgr2pDi9FqFyQ/rSVmc6utgIOSeAO F2Xx89NG7rSwP0zXs5wBypA6bP1iw96Ny/yxW03UygBytAa3fjqUowcVDbSSstpukhKK n06j1VdGHQ9gyQxBWgomQUbHMa/GLOVmAsoWLgj0iSt7xkZLbJLNg5gv1M3VqR0A/9pX 7RZA== X-Gm-Message-State: AHYfb5gQ1dJVYsEDbexCK++3VufGl40BHoCuW+zFA3CwG/AkzBJjPkxZ EdoJF6TCLJMDm5LzTo4= X-Received: by 10.28.101.86 with SMTP id z83mr25418wmb.141.1504023604167; Tue, 29 Aug 2017 09:20:04 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id u1sm2886431wrd.77.2017.08.29.09.20.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Aug 2017 09:20:03 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 29 Aug 2017 18:19:48 +0200 Message-Id: <1504023588-13085-1-git-send-email-gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] bus: skip useless iterations in rte_bus_find 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" The starting point is known. The iterator can be directly set to it. The function rte_bus_find can easily be used with a comparison function always returning True. This would make it a regular bus iterator. Users doing so would however accomplish such iteration in O(N * N/2) = O(N^2) Which can be avoided. Signed-off-by: Gaetan Rivet Reviewed-by: Ferruh Yigit --- In practice, such cost is entirely negligible of course. It is cleaner and more correct though. lib/librte_eal/common/eal_common_bus.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 9d1be8a..53bb004 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -153,15 +153,16 @@ struct rte_bus * rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, const void *data) { - struct rte_bus *bus = NULL; + struct rte_bus *bus; - TAILQ_FOREACH(bus, &rte_bus_list, next) { - if (start && bus == start) { - start = NULL; /* starting point found */ - continue; - } + if (start != NULL) + bus = TAILQ_NEXT(start, next); + else + bus = TAILQ_FIRST(&rte_bus_list); + while (bus != NULL) { if (cmp(bus, data) == 0) break; + bus = TAILQ_NEXT(bus, next); } return bus; }