From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f171.google.com (mail-yk0-f171.google.com [209.85.160.171]) by dpdk.org (Postfix) with ESMTP id A48128041 for ; Wed, 17 Dec 2014 14:31:32 +0100 (CET) Received: by mail-yk0-f171.google.com with SMTP id 142so6835434ykq.16 for ; Wed, 17 Dec 2014 05:31:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aE64zOiIhV3xgkR2W53r1AQx0ADfQsTtRJBehBPq9CQ=; b=PQ3cZR/eKVoZxFZOMuviPbiSoSLN8rYnHJ3Y9S2+ejKyPvv15oh1LArcsgFtB5y5B7 I9H0TZPiVHOq+/Olhk9zLbmEog4X+Iol5dOxWYaNmZOulLM7g6eyJG0QSz/rQFocDdkj aFIpRIMHVEwP0nOwfi8N6+VOLBBeFNyyCdHRu5TbAOojiTwEXK745W7w/T4UR5MOx/Ib nIE0CzScjdu+Y5uhXVv3h1JqqoT1KWHb7jIFZBMwjID12hdqmB7XWKDIPzBy1sCBTJ1V JcVxipVtrtM4IPQ71PXBkwm/El6fQWMrALJL+SE3YUcDfM90CRT6RowTq04Oy+2N8LuH hPrg== X-Gm-Message-State: ALoCoQmhFcY+pdhlusyShjskg0aUg9ePg+7MCtQkT8vkSS3TmfkQNq0UGVExYH6eNGbbn+Embnms X-Received: by 10.170.225.135 with SMTP id r129mr34676898ykf.9.1418823092052; Wed, 17 Dec 2014 05:31:32 -0800 (PST) Received: from localhost.localdomain (104-57-181-38.lightspeed.austtx.sbcglobal.net. [104.57.181.38]) by mx.google.com with ESMTPSA id v69sm2190002yhc.34.2014.12.17.05.31.31 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 17 Dec 2014 05:31:31 -0800 (PST) From: Jay Rolette To: dev@dpdk.org Date: Wed, 17 Dec 2014 07:31:17 -0600 Message-Id: <1418823077-9129-1-git-send-email-rolette@infiniteio.com> X-Mailer: git-send-email 1.9.3 (Apple Git-50) Subject: [dpdk-dev] [PATCH] replaced O(n^2) sort in sort_by_physaddr() with qsort() from standard library X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Dec 2014 13:31:33 -0000 Signed-off-by: Jay Rolette --- lib/librte_eal/linuxapp/eal/eal_memory.c | 59 +++++++++++--------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index bae2507..3656515 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -670,6 +670,25 @@ error: return -1; } +static int +cmp_physaddr(const void *a, const void *b) +{ +#ifndef RTE_ARCH_PPC_64 + const struct hugepage_file *p1 = (const struct hugepage_file *)a; + const struct hugepage_file *p2 = (const struct hugepage_file *)b; +#else + // PowerPC needs memory sorted in reverse order from x86 + const struct hugepage_file *p1 = (const struct hugepage_file *)b; + const struct hugepage_file *p2 = (const struct hugepage_file *)a; +#endif + if (p1->physaddr < p2->physaddr) + return -1; + else if (p1->physaddr > p2->physaddr) + return 1; + else + return 0; +} + /* * Sort the hugepg_tbl by physical address (lower addresses first on x86, * higher address first on powerpc). We use a slow algorithm, but we won't @@ -678,45 +697,7 @@ error: static int sort_by_physaddr(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi) { - unsigned i, j; - int compare_idx; - uint64_t compare_addr; - struct hugepage_file tmp; - - for (i = 0; i < hpi->num_pages[0]; i++) { - compare_addr = 0; - compare_idx = -1; - - /* - * browse all entries starting at 'i', and find the - * entry with the smallest addr - */ - for (j=i; j< hpi->num_pages[0]; j++) { - - if (compare_addr == 0 || -#ifdef RTE_ARCH_PPC_64 - hugepg_tbl[j].physaddr > compare_addr) { -#else - hugepg_tbl[j].physaddr < compare_addr) { -#endif - compare_addr = hugepg_tbl[j].physaddr; - compare_idx = j; - } - } - - /* should not happen */ - if (compare_idx == -1) { - RTE_LOG(ERR, EAL, "%s(): error in physaddr sorting\n", __func__); - return -1; - } - - /* swap the 2 entries in the table */ - memcpy(&tmp, &hugepg_tbl[compare_idx], - sizeof(struct hugepage_file)); - memcpy(&hugepg_tbl[compare_idx], &hugepg_tbl[i], - sizeof(struct hugepage_file)); - memcpy(&hugepg_tbl[i], &tmp, sizeof(struct hugepage_file)); - } + qsort(hugepg_tbl, hpi->num_pages[0], sizeof(struct hugepage_file), cmp_physaddr); return 0; } -- 1.9.3 (Apple Git-50)