DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Srikanth Yalavarthi <syalavarthi@marvell.com>
Cc: Anup Prabhu <aprabhu@marvell.com>, <dev@dpdk.org>,
	<sshankarnara@marvell.com>, <ptakkar@marvell.com>
Subject: Re: [PATCH 1/1] app/mldev: add internal function for file read
Date: Tue, 28 Mar 2023 08:52:29 -0700	[thread overview]
Message-ID: <20230328085229.51e5dc06@hermes.local> (raw)
In-Reply-To: <20230323152801.27666-1-syalavarthi@marvell.com>

On Thu, 23 Mar 2023 08:28:01 -0700
Srikanth Yalavarthi <syalavarthi@marvell.com> wrote:

> +	if (fseek(fp, 0, SEEK_END) == 0) {
> +		file_size = ftell(fp);
> +		if (file_size == -1) {
> +			ret = -EIO;
> +			goto error;
> +		}
> +
> +		file_buffer = rte_malloc(NULL, file_size, RTE_CACHE_LINE_SIZE);
> +		if (file_buffer == NULL) {
> +			ml_err("Failed to allocate memory: %s\n", file);
> +			ret = -ENOMEM;
> +			goto error;
> +		}
> +
> +		if (fseek(fp, 0, SEEK_SET) != 0) {
> +			ret = -EIO;
> +			goto error;
> +		}
> +
> +		if (fread(file_buffer, sizeof(char), file_size, fp) != (unsigned long)file_size) {
> +			ml_err("Failed to read file : %s\n", file);
> +			ret = -EIO;
> +			goto error;
> +		}
> +		fclose(fp);
> +	} else {
> +		ret = -EIO;
> +		goto error;
> +	}
> +
> +	*buffer = file_buffer;
> +	*size = file_size;
> +
> +	return 0;

Granted this only test code, but is the slowest way to do this.
Stdio is buffered (in 4K chunks). And using rte_malloc comes from hugepages.

Three levels of improvement are possible:
  1. don't use rte_malloc() use malloc() instead.
  2. use direct system call for I/O
  3. use mmap() to directly map in the file instead read


  reply	other threads:[~2023-03-28 15:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 15:28 Srikanth Yalavarthi
2023-03-28 15:52 ` Stephen Hemminger [this message]
2023-04-12  8:48   ` [EXT] " Srikanth Yalavarthi
2023-04-23  4:55 ` [PATCH v2] " Srikanth Yalavarthi
2023-05-03  8:56 ` [PATCH v3] " Srikanth Yalavarthi
2023-05-03 14:54   ` Stephen Hemminger
2023-05-03 14:59     ` [EXT] " Srikanth Yalavarthi
2023-05-03 18:28       ` Stephen Hemminger
2023-05-03 23:04         ` Tyler Retzlaff
2023-06-07 11:35 ` [PATCH v4] " Srikanth Yalavarthi
2023-06-07 15:02   ` Stephen Hemminger
2023-06-07 16:21     ` [EXT] " Srikanth Yalavarthi
2023-06-07 16:20 ` [PATCH v5] " Srikanth Yalavarthi
2023-06-07 16:49   ` Stephen Hemminger
2023-06-07 17:24     ` [EXT] " Srikanth Yalavarthi
2023-06-07 17:24 ` [PATCH v6] " Srikanth Yalavarthi
2023-07-07  8:06   ` Thomas Monjalon

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=20230328085229.51e5dc06@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=aprabhu@marvell.com \
    --cc=dev@dpdk.org \
    --cc=ptakkar@marvell.com \
    --cc=sshankarnara@marvell.com \
    --cc=syalavarthi@marvell.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).