From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Bruce Richardson <bruce.richardson@intel.com>,
Kevin Laatz <kevin.laatz@intel.com>
Subject: [PATCH 2/9] dma/idxd: use common sysfs routines
Date: Fri, 11 Sep 2026 23:30:21 -0700 [thread overview]
Message-ID: <20260912063319.4117869-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20260912063319.4117869-1-stephen@networkplumber.org>
The three local helpers each rebuilt a path and read a value; they
now wrap the EAL routines instead. Note that "numa_node" is -1 when
the device is not tied to a node, so the integer reads use the
signed routine.
The wq "size" and "max_batch_size" attributes were read with
fscanf("%u") and are now converted with base 0, so a value with a
leading zero would parse as octal. The kernel does not print either
with leading zeros.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/dma/idxd/idxd_bus.c | 80 ++++++-------------------------------
1 file changed, 12 insertions(+), 68 deletions(-)
diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index 2ec526ec09..684dee3d6d 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -16,6 +16,7 @@
#include <rte_log.h>
#include <rte_dmadev_pmd.h>
#include <rte_string_fns.h>
+#include <rte_sysfs.h>
#include "idxd_internal.h"
@@ -121,82 +122,24 @@ static int
read_wq_string(const struct rte_dsa_device *dev, const char *filename,
char *value, size_t valuelen)
{
- char sysfs_node[PATH_MAX];
- int len;
- int fd;
-
- snprintf(sysfs_node, sizeof(sysfs_node), "%s/%s/%s",
+ return rte_sysfs_parse_string(value, valuelen, "%s/%s/%s",
dsa_get_sysfs_path(), dev->wq_name, filename);
- fd = open(sysfs_node, O_RDONLY);
- if (fd < 0) {
- IDXD_PMD_ERR("%s(): opening file '%s' failed: %s",
- __func__, sysfs_node, strerror(errno));
- return -1;
- }
-
- len = read(fd, value, valuelen - 1);
- close(fd);
- if (len < 0) {
- IDXD_PMD_ERR("%s(): error reading file '%s': %s",
- __func__, sysfs_node, strerror(errno));
- return -1;
- }
- value[len] = '\0';
- return 0;
}
static int
read_wq_int(struct rte_dsa_device *dev, const char *filename,
- int *value)
+ long *value)
{
- char sysfs_node[PATH_MAX];
- FILE *f;
- int ret = 0;
-
- snprintf(sysfs_node, sizeof(sysfs_node), "%s/%s/%s",
+ return rte_sysfs_parse_int(value, "%s/%s/%s",
dsa_get_sysfs_path(), dev->wq_name, filename);
- f = fopen(sysfs_node, "r");
- if (f == NULL) {
- IDXD_PMD_ERR("%s(): opening file '%s' failed: %s",
- __func__, sysfs_node, strerror(errno));
- return -1;
- }
-
- if (fscanf(f, "%d", value) != 1) {
- IDXD_PMD_ERR("%s(): error reading file '%s': %s",
- __func__, sysfs_node, strerror(errno));
- ret = -1;
- }
-
- fclose(f);
- return ret;
}
static int
read_device_int(struct rte_dsa_device *dev, const char *filename,
- int *value)
+ long *value)
{
- char sysfs_node[PATH_MAX];
- FILE *f;
- int ret = 0;
-
- snprintf(sysfs_node, sizeof(sysfs_node), "%s/dsa%d/%s",
+ return rte_sysfs_parse_int(value, "%s/dsa%d/%s",
dsa_get_sysfs_path(), dev->addr.device_id, filename);
- f = fopen(sysfs_node, "r");
- if (f == NULL) {
- IDXD_PMD_ERR("%s(): opening file '%s' failed: %s",
- __func__, sysfs_node, strerror(errno));
- return -1;
- }
-
- if (fscanf(f, "%d", value) != 1) {
- IDXD_PMD_ERR("%s(): error reading file '%s': %s",
- __func__, sysfs_node, strerror(errno));
- ret = -1;
- }
-
- fclose(f);
- return ret;
}
static int
@@ -205,15 +148,16 @@ dsa_probe_device(__rte_unused struct rte_driver *drv, struct rte_device *dev)
struct rte_dsa_device *dsa_dev = RTE_BUS_DEVICE(dev, *dsa_dev);
struct idxd_dmadev idxd = {0};
int ret = 0;
+ long val;
IDXD_PMD_INFO("Probing device %s on numa node %d",
dsa_dev->wq_name, dsa_dev->device.numa_node);
- if (read_wq_int(dsa_dev, "size", &ret) < 0)
+ if (read_wq_int(dsa_dev, "size", &val) < 0)
return -1;
- idxd.max_batches = ret;
- if (read_wq_int(dsa_dev, "max_batch_size", &ret) < 0)
+ idxd.max_batches = val;
+ if (read_wq_int(dsa_dev, "max_batch_size", &val) < 0)
return -1;
- idxd.max_batch_size = ret;
+ idxd.max_batch_size = val;
idxd.qid = dsa_dev->addr.wq_id;
idxd.u.bus.dsa_id = dsa_dev->addr.device_id;
idxd.sva_support = 1;
@@ -286,7 +230,7 @@ dsa_scan(void)
while ((wq = readdir(dev_dir)) != NULL) {
struct rte_dsa_device *dev;
- int numa_node = SOCKET_ID_ANY;
+ long numa_node = SOCKET_ID_ANY;
if (strncmp(wq->d_name, "wq", 2) != 0)
continue;
--
2.53.0
next prev parent reply other threads:[~2026-09-12 6:33 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 6:30 [PATCH 0/9] consolidate sysfs access Stephen Hemminger
2026-09-12 6:30 ` [PATCH 1/9] eal: add common sysfs value routines Stephen Hemminger
2026-09-12 6:30 ` Stephen Hemminger [this message]
2026-09-12 6:30 ` [PATCH 3/9] common/ionic: use common sysfs routines Stephen Hemminger
2026-09-12 6:30 ` [PATCH 4/9] bus/vmbus: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 5/9] power: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 6/9] drivers/bus: remove duplicate sysfs string helpers Stephen Hemminger
2026-09-12 6:30 ` [PATCH 7/9] common/mlx5: use common sysfs routines Stephen Hemminger
2026-09-12 6:30 ` [PATCH 8/9] net/mlx5: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 9/9] net/mana: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 0/9] consolidate sysfs access Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 1/9] eal: add common sysfs value routines Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 2/9] dma/idxd: use common sysfs routines Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 3/9] common/ionic: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 4/9] bus/vmbus: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 5/9] power: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 6/9] drivers/bus: remove duplicate sysfs string helpers Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 7/9] common/mlx5: use common sysfs routines Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 8/9] net/mlx5: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 9/9] net/mana: " Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260912063319.4117869-3-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=kevin.laatz@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.