From patchwork Mon May 16 18:51:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 67912 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1685410qge; Mon, 16 May 2016 11:52:39 -0700 (PDT) X-Received: by 10.55.15.150 with SMTP id 22mr32823845qkp.53.1463424759630; Mon, 16 May 2016 11:52:39 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j128si24182419qkd.264.2016.05.16.11.52.39; Mon, 16 May 2016 11:52:39 -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 4A6B06174F; Mon, 16 May 2016 18:52:39 +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 9105C61738; Mon, 16 May 2016 18:52:15 +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 6D0126174F; Mon, 16 May 2016 18:52:11 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 362CD61738 for ; Mon, 16 May 2016 18:52:10 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id m64so120378317lfd.1 for ; Mon, 16 May 2016 11:52:10 -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=9yCUofBnV0jTR/6o3QcWHx9X/e5x4JyycTDalxcFQUo=; b=h/UsCy6TpyciR8hU/tyyknmEBJXID9DhDbygpRtQBYtHPs1MwCETrLrhpFtVTGWqaY WZfRaJJSOylv83QzkxtpElqeVDSGVkf6xd+aO00TY5ZzZYCRDV36NA2Rz3e8opLyxfRf oqLJd+QcZ4k+gPCbjL461UDpLm2lAdWJClMC8MjqaP9jyjAovIuxYoHwG1HI6BNme6o7 Fo2AjdhyVDNfCctL38yQee3CWpL7ccJg4DTigMnmCSzQ1JJAplvyPcGnEdibAGUHJ5J2 B9DgC+OM5cGQZuHn3QX8UpaRaw2DVk6dI70ktjxQfYxRQS+oZSqR2zgPNW6d9iU/6DzR OYSg== X-Gm-Message-State: AOPr4FU6BFisGTSG2RSYQLc6PV0/z91AVoXmlQ+lznRUMPRD7hut+EwGB4Y1L3HgrVaypjahjf8= X-Received: by 10.25.196.9 with SMTP id u9mr12268756lff.129.1463424729119; Mon, 16 May 2016 11:52:09 -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 oq7sm4587325lbb.47.2016.05.16.11.52.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 May 2016 11:52:08 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 16 May 2016 21:51:59 +0300 Message-Id: <1463424720-32215-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1463424720-32215-1-git-send-email-maxim.uvarov@linaro.org> References: <1463424720-32215-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 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 Reviewed-by: Bill Fischofer #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,27 @@ static int systemcpu_cache_line_size(void) #endif -static int huge_page_size(void) +static uint64_t default_huge_page_size(void) { - DIR *dir; - struct dirent *dirent; - int size = 0; + char str[1024]; + unsigned long 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) { + if (sscanf(str, "Hugepagesize: %8lu kB", &sz) == 1) { + ODP_DBG("defaut hp size is %" PRIu64 " kB\n", sz); + fclose(file); + return (uint64_t)sz * 1024; + } } - return size * 1024; + ODP_ERR("unable to get default hp size\n"); + fclose(file); + return 0; } - /* * Analysis of /sys/devices/system/cpu/ files */ @@ -137,7 +124,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; }