From patchwork Tue May 10 15:08:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 67459 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2179944qge; Tue, 10 May 2016 08:09:01 -0700 (PDT) X-Received: by 10.36.104.4 with SMTP id v4mr1644634itb.12.1462892941424; Tue, 10 May 2016 08:09:01 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j80si3933500ioi.123.2016.05.10.08.09.01; Tue, 10 May 2016 08:09:01 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E6B2461649; Tue, 10 May 2016 15:09:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id D128961585; Tue, 10 May 2016 15:08:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 17ED5611FD; Tue, 10 May 2016 15:08:27 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id 239C2610DE for ; Tue, 10 May 2016 15:08:21 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id j8so18285565lfd.2 for ; Tue, 10 May 2016 08:08:21 -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:cc:subject:date:message-id:in-reply-to :references; bh=HWMuHD7EJR9Jpn/Faqqh5+ZmCI6UwekOBJwFtcIFYuk=; b=BCAgPdHO3dDGor6yi6EcNuCVkoC81HgHxouxmWbZ3EAuUVoaoSJAQh4xJerML1Zvk5 xyT5XzBg69U57Cxoal3aWYOYlN1TSZAjxX/C5t6Djx++7THAmVUFis5BguJzsZ85v/1W 6O91mVnJ5PmVSxsxar1RCpVqZC6Ev0v05xRaP979YM458RiZ03eQExebGQdoOAYATowy YvPXjp0TFy6/uPlsNCaBN2FLM4/ZeL9dRky3wx2uBwzcp/ugQ5RlewfOavgRIY8VLGZK fOE7fiFgHcgxO1V5B9C63IrioHxbHxdtc9q966iM9wga3Slt3BI7w+VRlUHBoneGpYGe 8iLw== X-Gm-Message-State: AOPr4FU4WLD+JtjQpzT2IbaZiTaELv8eh9RJzngoEqU/IZQ/XQRDZkGZyLEJQBdc8SB1Hs35r18= X-Received: by 10.112.198.72 with SMTP id ja8mr17088087lbc.112.1462892900055; Tue, 10 May 2016 08:08:20 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-173-31.pppoe.mtu-net.ru. [91.77.173.31]) by smtp.gmail.com with ESMTPSA id o10sm456150lbp.47.2016.05.10.08.08.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 May 2016 08:08:19 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 10 May 2016 18:08:03 +0300 Message-Id: <1462892884-9610-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1462892884-9610-1-git-send-email-maxim.uvarov@linaro.org> References: <1462892884-9610-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 1/2] linux-generic: use default huge page size X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" odp_shm_reserve() relays on huge page size to round up requested size. If 1 Gb pages present than parser takes it first as first alphabetical file name in sysfs. That lead to issue where all allocations wants 1 GB HP. This patch takes system default huge pages which are usually 2Mb, and has to be enough for existence odp example apps and validation tests. Reported-by: B.Nousilal Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_system_info.c | 46 +++++++++++++------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 0f1f3c7..14244c3 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -24,12 +24,9 @@ #include #include - #define CACHE_LNSZ_FILE \ "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size" -#define HUGE_PAGE_DIR "/sys/kernel/mm/hugepages" - /* * Report the number of logical CPUs detected at boot time */ @@ -77,37 +74,30 @@ static int systemcpu_cache_line_size(void) #endif -static int huge_page_size(void) +static int default_huge_page_size(void) { - DIR *dir; - struct dirent *dirent; - int size = 0; + char str[1024]; + char *pos; + uint64_t sz; + FILE *file; - dir = opendir(HUGE_PAGE_DIR); - if (dir == NULL) { - ODP_ERR("%s not found\n", HUGE_PAGE_DIR); - return 0; - } - - while ((dirent = readdir(dir)) != NULL) { - int temp = 0; - - if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1) - continue; - - if (temp > size) - size = temp; - } + file = fopen("/proc/meminfo", "rt"); - if (closedir(dir)) { - ODP_ERR("closedir failed\n"); - return 0; + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "Hugepagesize:"); + if (pos) { + *(pos - 1) = '\0'; + if (sscanf(pos, "@ %ld kB", &sz) == 1) { + fclose(file); + return sz * 1024; + } + } } - return size * 1024; + fclose(file); + return 0; } - /* * Analysis of /sys/devices/system/cpu/ files */ @@ -137,7 +127,7 @@ static int systemcpu(odp_system_info_t *sysinfo) return -1; } - sysinfo->huge_page_size = huge_page_size(); + sysinfo->huge_page_size = default_huge_page_size(); return 0; }