From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F27DBA0524; Tue, 1 Jun 2021 05:18:01 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E02F640E64; Tue, 1 Jun 2021 05:18:01 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id B7F6040041 for ; Tue, 1 Jun 2021 05:18:00 +0200 (CEST) IronPort-SDR: FWJdBM8wRcovLnTcMC7atDNZk+3TXagjFzUX1ZNfO5wLbFlCcljwaXUfk1pC9G6gqH8QJlvbVN nqadjeur+NUA== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="289079337" X-IronPort-AV: E=Sophos;i="5.83,239,1616482800"; d="scan'208";a="289079337" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 20:17:59 -0700 IronPort-SDR: +MJuUDgC2I4+WO0/p93GNXzhreq3LyP0hRGRJ9KI9UMA/kdFTlcb6oNHBKZ6Z896cOITJDZAcP Lb2VsDl0viOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,239,1616482800"; d="scan'208";a="482315466" Received: from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.118.250]) by fmsmga002.fm.intel.com with ESMTP; 31 May 2021 20:17:53 -0700 From: Chenbo Xia To: dev@dpdk.org, thomas@monjalon.net, cunming.liang@intel.com, jingjing.wu@intel.com Cc: anatoly.burakov@intel.com, ferruh.yigit@intel.com, mdr@ashroe.eu, nhorman@tuxdriver.com, bruce.richardson@intel.com, david.marchand@redhat.com, stephen@networkplumber.org, konstantin.ananyev@intel.com, Tiwei Bie Date: Tue, 1 Jun 2021 11:06:42 +0800 Message-Id: <20210601030644.3318-5-chenbo.xia@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210601030644.3318-1-chenbo.xia@intel.com> References: <20190715075214.16616-6-tiwei.bie@intel.com> <20210601030644.3318-1-chenbo.xia@intel.com> Subject: [dpdk-dev] [RFC v3 4/6] eal: add a helper for reading string from sysfs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Tiwei Bie This patch adds a helper for reading string from sysfs. Signed-off-by: Cunming Liang Signed-off-by: Tiwei Bie --- lib/eal/common/eal_filesystem.h | 10 ++++++++++ lib/eal/freebsd/eal.c | 22 ++++++++++++++++++++++ lib/eal/linux/eal.c | 22 ++++++++++++++++++++++ lib/eal/version.map | 3 +++ 4 files changed, 57 insertions(+) diff --git a/lib/eal/common/eal_filesystem.h b/lib/eal/common/eal_filesystem.h index 5d21f07c20..be4c51ebb2 100644 --- a/lib/eal/common/eal_filesystem.h +++ b/lib/eal/common/eal_filesystem.h @@ -104,4 +104,14 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id * Used to read information from files on /sys */ int eal_parse_sysfs_value(const char *filename, unsigned long *val); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Function to read a line from a file on the filesystem. + * Used to read information from files on /sys + */ +__rte_experimental +int rte_eal_parse_sysfs_str(const char *filename, char *buf, unsigned long sz); + #endif /* EAL_FILESYSTEM_H */ diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index f4d1676754..002f07f4da 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -169,6 +169,28 @@ eal_parse_sysfs_value(const char *filename, unsigned long *val) return 0; } +int +rte_eal_parse_sysfs_str(const char *filename, char *buf, unsigned long sz) +{ + FILE *f; + + f = fopen(filename, "r"); + if (f == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot open sysfs file %s\n", + __func__, filename); + return -1; + } + + if (fgets(buf, sz, f) == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot read sysfs file %s\n", + __func__, filename); + fclose(f); + return -1; + } + + fclose(f); + return 0; +} /* create memory configuration in shared/mmap memory. Take out * a write lock on the memsegs, so we can auto-detect primary/secondary. diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index ba19fc6347..d5917a48ca 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -260,6 +260,28 @@ eal_parse_sysfs_value(const char *filename, unsigned long *val) return 0; } +int +rte_eal_parse_sysfs_str(const char *filename, char *buf, unsigned long sz) +{ + FILE *f; + + f = fopen(filename, "r"); + if (f == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot open sysfs file %s\n", + __func__, filename); + return -1; + } + + if (fgets(buf, sz, f) == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot read sysfs file %s\n", + __func__, filename); + fclose(f); + return -1; + } + + fclose(f); + return 0; +} /* create memory configuration in shared/mmap memory. Take out * a write lock on the memsegs, so we can auto-detect primary/secondary. diff --git a/lib/eal/version.map b/lib/eal/version.map index fe5c3dac98..3d7fce26a4 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -423,6 +423,9 @@ EXPERIMENTAL { rte_version_release; # WINDOWS_NO_EXPORT rte_version_suffix; # WINDOWS_NO_EXPORT rte_version_year; # WINDOWS_NO_EXPORT + + # added in 21.08 + rte_eal_parse_sysfs_str; # WINDOWS_NO_EXPORT }; INTERNAL { -- 2.17.1