From patchwork Tue Jul 7 09:00:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 6147 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 DAFAC5A53; Tue, 7 Jul 2015 11:00:52 +0200 (CEST) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by dpdk.org (Postfix) with ESMTP id 6C97F595E for ; Tue, 7 Jul 2015 11:00:49 +0200 (CEST) Received: by wiga1 with SMTP id a1so250304269wig.0 for ; Tue, 07 Jul 2015 02:00:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=FyCehKxVaVAOnM1CLBguWxZ7RNpQx37K2LGk88H2x28=; b=R4VVd7eQdGL9iCbKrjPxaGiOj1tnem5n3zoR0xc2uuaBI0p5xv7F5V9Izn1/Ee+pVi xNUgkU8LD+ivtFW/23lxIvaAV1HXXdu/KPyohhssWFl2/s8l3YfG1pfbqCyL73l5Rmoj zHCcNHZNFbgEqIPUyQYN5bCgNhxM+7c0SO2mRgmwu0/oxtmMkMIeJv0CKbeqUbZo+DeC koDI5ZnDk7c3ng9x6dynaKaVZNGuo7KRgx//4l2gRy3vw2gx+3tgGUR6eO76vXV0doOb 0YiRDciQ/y4cNBgbnr4iGtH/yhVuJ5ZOYbSE5rVrWiT8SWc1QsmFP6DeJshC0OQvzDqZ Reiw== X-Gm-Message-State: ALoCoQlI76Iys0gK1NHcuSp1e1PyT1uwYNMdd3wxciNNgszqLj1sGwkrXaeJ8mqEDdTz2JYUmOkP X-Received: by 10.194.176.201 with SMTP id ck9mr6322712wjc.108.1436259649283; Tue, 07 Jul 2015 02:00:49 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.151.210]) by mx.google.com with ESMTPSA id y19sm32737674wia.15.2015.07.07.02.00.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2015 02:00:48 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Tue, 7 Jul 2015 11:00:30 +0200 Message-Id: <1436259634-7077-3-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> References: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH 2/6] eal/linux: remove useless casts 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Rather than cast the huge pages number returned by get_num_hugepages, rework this function so that it returns 0 when something goes wrong. And no need for casts in log. Signed-off-by: David Marchand --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index 6dd8a0b..0b6ece7 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -63,7 +63,7 @@ static const char sys_dir_path[] = "/sys/kernel/mm/hugepages"; /* this function is only called from eal_hugepage_info_init which itself * is only called from a primary process */ -static int32_t +static unsigned long get_num_hugepages(const char *subdir) { char path[PATH_MAX]; @@ -87,10 +87,12 @@ get_num_hugepages(const char *subdir) subdir); /* adjust num_pages */ - if (num_pages > 0) + if (num_pages >= resv_pages) num_pages -= resv_pages; + else if (resv_pages) + num_pages = 0; - return (int32_t)num_pages; + return num_pages; } static uint64_t @@ -288,12 +290,13 @@ eal_hugepage_info_init(void) /* first, check if we have a mountpoint */ if (hpi->hugedir == NULL){ - int32_t num_pages; - if ((num_pages = get_num_hugepages(dirent->d_name)) > 0) - RTE_LOG(INFO, EAL, "%u hugepages of size %llu reserved, "\ - "but no mounted hugetlbfs found for that size\n", - (unsigned)num_pages, - (unsigned long long)hpi->hugepage_sz); + unsigned long num_pages; + + num_pages = get_num_hugepages(dirent->d_name); + if (num_pages > 0) + RTE_LOG(INFO, EAL, "%lu hugepages of size %lu reserved, " + "but no mounted hugetlbfs found for that size\n", + num_pages, hpi->hugepage_sz); } else { /* try to obtain a writelock */ hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY);