All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabio Estevam <fabio.estevam@nxp.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 4/4] cmd: mem: Use memcpy for 'cp' command
Date: Thu, 15 Dec 2016 16:00:13 -0200	[thread overview]
Message-ID: <1481824813-14432-4-git-send-email-fabio.estevam@nxp.com> (raw)
In-Reply-To: <1481824813-14432-1-git-send-email-fabio.estevam@nxp.com>

Simplify the 'cp' command implementation by using the memcpy() function,
which brings the additional benefit of performance gain for those who have
CONFIG_USE_ARCH_MEMCPY selected.

Tested on a mx6qsabreauto board where a 5x gain in performance is seen
when reading 10MB from the parallel NOR memory.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
Changes since v1:
- Always use memcpy()

 cmd/mem.c | 28 ++--------------------------
 1 file changed, 2 insertions(+), 26 deletions(-)

diff --git a/cmd/mem.c b/cmd/mem.c
index a690957..ff6a770 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -372,10 +372,8 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	ulong	addr, dest, count, bytes;
+	ulong	addr, dest, count;
 	int	size;
-	const void *src;
-	void *buf;
 
 	if (argc != 4)
 		return CMD_RET_USAGE;
@@ -465,29 +463,7 @@ static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 #endif
 
-	bytes = size * count;
-	buf = map_sysmem(dest, bytes);
-	src = map_sysmem(addr, bytes);
-	while (count-- > 0) {
-		if (size == 4)
-			*((u32 *)buf) = *((u32  *)src);
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-		else if (size == 8)
-			*((u64 *)buf) = *((u64 *)src);
-#endif
-		else if (size == 2)
-			*((u16 *)buf) = *((u16 *)src);
-		else
-			*((u8 *)buf) = *((u8 *)src);
-		src += size;
-		buf += size;
-
-		/* reset watchdog from time to time */
-		if ((count % (64 << 10)) == 0)
-			WATCHDOG_RESET();
-	}
-	unmap_sysmem(buf);
-	unmap_sysmem(src);
+	memcpy((void *)dest, (void *)addr, count * size);
 
 	return 0;
 }
-- 
2.7.4

  parent reply	other threads:[~2016-12-15 18:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-15 18:00 [U-Boot] [PATCH v2 1/4] mx6qsabreauto: Configure the WEIM controller like the kernel Fabio Estevam
2016-12-15 18:00 ` [U-Boot] [PATCH v2 2/4] mx6qsabreauto: Pass the correct parallel NOR width Fabio Estevam
2017-01-27  9:33   ` Stefano Babic
2017-02-03 13:10     ` Fabio Estevam
2017-02-03 14:31       ` Stefano Babic
2016-12-15 18:00 ` [U-Boot] [PATCH v2 3/4] Kconfig: Move USE_ARCH_MEMCPY/MEMSET to Kconfig Fabio Estevam
2016-12-15 18:06   ` Tom Rini
2016-12-15 18:00 ` Fabio Estevam [this message]
2016-12-17 15:11   ` [U-Boot] [PATCH v2 4/4] cmd: mem: Use memcpy for 'cp' command Tom Rini
2016-12-19 22:09   ` Tom Rini
2016-12-19 22:11     ` Fabio Estevam
2017-01-11 15:49     ` Fabio Estevam
2017-01-11 16:21       ` Tom Rini
2017-01-13  0:51   ` [U-Boot] [U-Boot,v2,4/4] " Tom Rini

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=1481824813-14432-4-git-send-email-fabio.estevam@nxp.com \
    --to=fabio.estevam@nxp.com \
    --cc=u-boot@lists.denx.de \
    /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.