From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id DCE3C298F for ; Wed, 26 Apr 2017 06:00:52 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id l9so16241902wre.1 for ; Tue, 25 Apr 2017 21:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=weka.io; s=google; h=from:to:subject:date:message-id:organization:mime-version :content-transfer-encoding; bh=3eeJuczR0gB9acp2gf4LR2XN2ibbuQgVSI9k/n1/6d0=; b=Z0vFZs22qg+m4PiyMyNYLFtBigg1uZ5ew73ckYJQH7v748OYdHvHCWpHlzSadDj5Po iZ3JQhj0XIu2Xa9BAkTAbDXlAGNudCN7yaKCcxw8MNNuj0vrynyMU6qg+BUV7RzTfWdp bsiLo22aiSZqYQ5VIR3zv9KEIAqFtXINdxEOw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:organization :mime-version:content-transfer-encoding; bh=3eeJuczR0gB9acp2gf4LR2XN2ibbuQgVSI9k/n1/6d0=; b=NhdrE+8B7liNJoNsI+TaFBuxO3ns1b2F5Oo2DKLkSC6SMh7SNRTJYGkdwlEZlZaaEa 0cdjX+rPTn+aAMazNR9Rg1kI+tImjCSOL1rYT86bhjY8tADCN5ipOZ2hUgzJ3iIo9bAt 5ST7eSGCMsomQq7VQy4rtVLRvylDKOhCxsviBdN1+3vQxjSjBEJFQIzwcaI4sRhQDGnW n3SPcrDeeOhcFkd+Xufn0LoF5ytsExQguHzyb6/2ucmtoJrvHOVGIK4XKM4fnyXvEvQg feN39Z635akaBxXHlOlR6i30TakUmqE60pvinAHqxFmA8V/YAOWklm46UsijNo9bCbyj Yvqw== X-Gm-Message-State: AN3rC/5hP3Z+jQDHO8BsxMjg+N+k/ifHzH6Cbwyxx7OTpipkE+Adfwd3 gD1m55FJeFKcbDn1CrI= X-Received: by 10.223.150.167 with SMTP id u36mr12222400wrb.184.1493179252152; Tue, 25 Apr 2017 21:00:52 -0700 (PDT) Received: from polaris.localnet (bzq-82-81-85-138.red.bezeqint.net. [82.81.85.138]) by smtp.gmail.com with ESMTPSA id 8sm388810wrb.55.2017.04.25.21.00.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 21:00:51 -0700 (PDT) From: Gregory Etelson To: dev@dpdk.org Date: Wed, 26 Apr 2017 07:00:49 +0300 Message-ID: <4486793.msUSBAJSWm@polaris> Organization: Weka.IO MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] custom align for mempool elements 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: Wed, 26 Apr 2017 04:00:53 -0000 Signed-off-by: Gregory Etelson --- lib/librte_mempool/rte_mempool.c | 27 ++++++++++++++++++++------- lib/librte_mempool/rte_mempool.h | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index f65310f..c780df3 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -382,7 +382,7 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, if (mp->flags & MEMPOOL_F_NO_CACHE_ALIGN) off = RTE_PTR_ALIGN_CEIL(vaddr, 8) - vaddr; else - off = RTE_PTR_ALIGN_CEIL(vaddr, RTE_CACHE_LINE_SIZE) - vaddr; + off = RTE_PTR_ALIGN_CEIL(vaddr, mp->elt_align) - vaddr; while (off + total_elt_sz <= len && mp->populated_size < mp->size) { off += mp->header_size; @@ -392,6 +392,7 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, else mempool_add_elem(mp, (char *)vaddr + off, paddr + off); off += mp->elt_size + mp->trailer_size; + off = RTE_ALIGN_CEIL(off, mp->elt_align); i++; } @@ -508,6 +509,20 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, return ret; } +static uint32_t +mempool_default_elt_aligment(void) +{ + uint32_t align; + if (rte_xen_dom0_supported()) { + align = RTE_PGSIZE_2M;; + } else if (rte_eal_has_hugepages()) { + align = RTE_CACHE_LINE_SIZE; + } else { + align = getpagesize(); + } + return align; +} + /* Default function to populate the mempool: allocate memory in memzones, * and populate them. Return the number of objects added, or a negative * value on error. @@ -518,7 +533,7 @@ rte_mempool_populate_default(struct rte_mempool *mp) int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY; char mz_name[RTE_MEMZONE_NAMESIZE]; const struct rte_memzone *mz; - size_t size, total_elt_sz, align, pg_sz, pg_shift; + size_t size, total_elt_sz, pg_sz, pg_shift; phys_addr_t paddr; unsigned mz_id, n; int ret; @@ -530,15 +545,12 @@ rte_mempool_populate_default(struct rte_mempool *mp) if (rte_xen_dom0_supported()) { pg_sz = RTE_PGSIZE_2M; pg_shift = rte_bsf32(pg_sz); - align = pg_sz; } else if (rte_eal_has_hugepages()) { pg_shift = 0; /* not needed, zone is physically contiguous */ pg_sz = 0; - align = RTE_CACHE_LINE_SIZE; } else { pg_sz = getpagesize(); pg_shift = rte_bsf32(pg_sz); - align = pg_sz; } total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size; @@ -553,11 +565,11 @@ rte_mempool_populate_default(struct rte_mempool *mp) } mz = rte_memzone_reserve_aligned(mz_name, size, - mp->socket_id, mz_flags, align); + mp->socket_id, mz_flags, mp->elt_align); /* not enough memory, retry with the biggest zone we have */ if (mz == NULL) mz = rte_memzone_reserve_aligned(mz_name, 0, - mp->socket_id, mz_flags, align); + mp->socket_id, mz_flags, mp->elt_align); if (mz == NULL) { ret = -rte_errno; goto fail; @@ -827,6 +839,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, /* Size of default caches, zero means disabled. */ mp->cache_size = cache_size; mp->private_data_size = private_data_size; + mp->elt_align = mempool_default_elt_aligment(); STAILQ_INIT(&mp->elt_list); STAILQ_INIT(&mp->mem_list); diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 48bc8ea..6631973 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -245,6 +245,7 @@ struct rte_mempool { * this mempool. */ int32_t ops_index; + uint32_t elt_align; struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */ -- 2.9.3