Do not copy elf section to same adress
PATCH 1/1 Do not copy elf section to same adress
When an elf section is already at the right position (e.g. after image decompression by bootm) there is no need to copy it.
--- common/cmd_elf.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
common/cmd_elf.c +4 -3
@@ -342,9 +342,10 @@ static unsigned long load_elf_image_shdr(unsigned long addr)memset ((void *)shdr->sh_addr,0 , shdr->sh_size); }else { image = (unsigned char *) addr + shdr->sh_offset; -memcpy ((void *) shdr->sh_addr, - (const void *) image, - shdr->sh_size); +if ((void *) shdr->sh_addr != (void *) image) +memcpy ((void *) shdr->sh_addr, + (const void *) image, + shdr->sh_size); }flush_cache (shdr->sh_addr, shdr->sh_size); }
Signature · 1 line
1.7.0.4
PATCH 1/1 Do not copy elf section to same adress
Dear Matthias Weisser,
Quoted 13 lines · In message <[email protected]> you wrote:
When an elf section is already at the right position (e.g. after image decompression by bootm) there is no need to copy it.
Signed-off-by Matthias Weisser <[email protected]>--- common/cmd_elf.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)common/cmd_elf.c +0
-0
common/cmd_elf.c static unsigned long load_elf_image_shdr(unsigned long addr) · line 348
Quoted 10 lines
common/cmd_elf.c +4
-3@@ -342,9 +342,10 @@ static unsigned long load_elf_image_shdr(unsigned long addr)memset ((void *)shdr->sh_addr,0 , shdr->sh_size); }else { image = (unsigned char *) addr + shdr->sh_offset; -memcpy ((void *) shdr->sh_addr, - (const void *) image, - shdr->sh_size); +if ((void *) shdr->sh_addr != (void *) image) +memcpy ((void *) shdr->sh_addr, + (const void *) image, + shdr->sh_size);
Braces required for multi-line statement.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Egotist: A person of low taste, more interested in himself than in me. - Ambrose Bierce
PATCH v2 1/1 Do not copy elf section to same adress
In reply to Matthias WeisserWhen an elf section is already at the right position (e.g. after image decompression by bootm) there is no need to copy it. This saves some ms when bootig an elf image.
Changes since V1
- Fixed style issues
--- common/cmd_elf.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
common/cmd_elf.c +5 -3
@@ -342,9 +342,11 @@ static unsigned long load_elf_image_shdr(unsigned long addr)memset ((void *)shdr->sh_addr,0 , shdr->sh_size); }else { image = (unsigned char *) addr + shdr->sh_offset; -memcpy ((void *) shdr->sh_addr, - (const void *) image, - shdr->sh_size); +if ((void *) shdr->sh_addr != (void *) image) { +memcpy ((void *) shdr->sh_addr, + (const void *) image, + shdr->sh_size); + } }flush_cache (shdr->sh_addr, shdr->sh_size); }
Signature · 1 line
1.7.0.4
PATCH v2 1/1 Do not copy elf section to same adress
Hi
Am 19.01.2011 12:03, schrieb Matthias Weisser:
Quoted 21 lines
When an elf section is already at the right position (e.g. after image decompression by bootm) there is no need to copy it. This saves some ms when bootig an elf image.
Changes since V1
- Fixed style issuesSigned-off-by Matthias Weisser <[email protected]>--- common/cmd_elf.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)common/cmd_elf.c +0
-1@@ -342,9 +342,11 @@ static unsigned long load_elf_image_shdr(unsigned long addr)memset ((void *)shdr->sh_addr,0 , shdr->sh_size); }else { image = (unsigned char *) addr + shdr->sh_offset; - memcpy ((void *) shdr->sh_addr,
common/cmd_elf.c static unsigned long load_elf_image_shdr(unsigned long addr) · line 352
Quoted 10 lines
common/cmd_elf.c +5
-2- (const void *) image, - shdr->sh_size); +if ((void *) shdr->sh_addr != (void *) image) { +memcpy ((void *) shdr->sh_addr, + (const void *) image, + shdr->sh_size); + } }flush_cache (shdr->sh_addr, shdr->sh_size); }
Any comments on this patch? Any problems with it? I would like to see it in mainline and I am open for any comments.
Regards,
Matthias Wei?er
PATCH v2 1/1 Do not copy elf section to same adress
In reply to Matthias WeisserDear Matthias Weisser,
Quoted 18 lines · In message <[email protected]> you wrote:
When an elf section is already at the right position (e.g. after image decompression by bootm) there is no need to copy it. This saves some ms when bootig an elf image.
Changes since V1
- Fixed style issuesSigned-off-by Matthias Weisser <[email protected]>--- common/cmd_elf.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)common/cmd_elf.c +0
-0@@ -342,9 +342,11 @@ static unsigned long load_elf_image_shdr(unsigned long addr)memset ((void *)shdr->sh_addr,0 , shdr->sh_size);
common/cmd_elf.c static unsigned long load_elf_image_shdr(unsigned long addr) · line 349
Quoted 10 lines
common/cmd_elf.c +5
-3}else { image = (unsigned char *) addr + shdr->sh_offset; -memcpy ((void *) shdr->sh_addr, - (const void *) image, - shdr->sh_size); +if ((void *) shdr->sh_addr != (void *) image) { +memcpy ((void *) shdr->sh_addr, + (const void *) image, + shdr->sh_size); + }
The idea is correct, but I think the implementation is suboptimal. Instead of fixing this use case only, the test should be moved into the implementation of memcpy() itself so any other callers with such a situation benefit from it, too.
While we are at it, we should do the same with bcopy() and memmove(), too.
Thanks.
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Marriage is the triumph of imagination over intelligence. Second marriage is the triumph of hope over experience.
PATCH v2 1/1 Do not copy elf section to same adress
Am 11.04.2011 21:59, schrieb Wolfgang Denk:
Quoted 27 lines
Dear Matthias Weisser,
Quoted 24 lines · In message <[email protected]> you wrote:
Quoted 24 lines
When an elf section is already at the right position (e.g. after image decompression by bootm) there is no need to copy it. This saves some ms when bootig an elf image.
Changes since V1
- Fixed style issuesSigned-off-by Matthias Weisser <[email protected]>--- common/cmd_elf.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)common/cmd_elf.c +1
-3@@ -342,9 +342,11 @@ static unsigned long load_elf_image_shdr(unsigned long addr)memset ((void *)shdr->sh_addr,0 , shdr->sh_size); }else { image = (unsigned char *) addr + shdr->sh_offset; -memcpy ((void *) shdr->sh_addr, - (const void *) image, - shdr->sh_size); +if ((void *) shdr->sh_addr != (void *) image) {
Quoted 8 lines
Quoted 4 lines
common/cmd_elf.c static unsigned long load_elf_image_shdr(unsigned long addr) · line 349
Quoted 4 lines
common/cmd_elf.c +4
-0+memcpy ((void *) shdr->sh_addr, + (const void *) image, + shdr->sh_size); + }The idea is correct, but I think the implementation is suboptimal. Instead of fixing this use case only, the test should be moved into the implementation of
memcpy()itself so any other callers with such a situation benefit from it, too.
Well, I thought about that too. But decided against it as I thought it will be a bit too intervening for a patch from me as this will hit all boards.
I can't come up with an example where this may produce a problem but who knows which exotic hardware is out there which expects that a memcpy with identical src and dst addresses is executed exactly in that way. But maybe we can ignore this and let these exotic boards come up with a solution handling that special situation.
Quoted 2 lines
While we are at it, we should do the same with
bcopy()andmemmove(), too.
Maybe I can post a patch tomorrow. The only thing which I can't handle are architecture specific memcpy/memmove/... functions besides ARM.
Regards,
Matthias Wei?er
PATCH v2 1/1 Do not copy elf section to same adress
Dear Matthias Weisser,
Quoted 6 lines · In message <[email protected]> you wrote:
I can't come up with an example where this may produce a problem but who knows which exotic hardware is out there which expects that a memcpy with identical src and dst addresses is executed exactly in that way. But maybe we can ignore this and let these exotic boards come up with a solution handling that special situation.
Right.
Quoted 5 lines
Quoted 2 lines
While we are at it, we should do the same with
bcopy()andmemmove(), too.Maybe I can post a patch tomorrow. The only thing which I can't handle are architecture specific memcpy/memmove/... functions besides ARM.
That's fine. Optimized arch specific code probably already implements such a shortcut anyway.
Best regards,
Wolfgang Denk
Signature · 7 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Winners never talk about glorious victories. That's because they're
the ones who see what the battlefield looks like afterwards. It's
only the losers who have glorious victories.
- Terry Pratchett, _Small Gods_