Hi,
I am not sure if this is the right list for this mail or not, but another good one would be: linux-c-programming@vger.kernel.org
On 8 November 2012 07:09, 牟刚 mugang@actions-semi.com wrote:
I’m confused when I use memcpy() in pandaboard android. The test
code is very simple, as below:
#define PER_COPY_SIZE (1024*1024*4)
int main(int argc, char *argv[ ]){
char *src; char *dst; char *p; src=(char *)malloc(PER_COPY_SIZE); dst=(char*)malloc(PER_COPY_SIZE); p=src;
#if 1
for(int i=0; i<PER_COPY_SIZE; i++){ *p++=i%255; }
#endif
for(int j=0; j<1000; j++){ memcpy(dst, src, PER_COPY_SIZE); } free(src); free(dst); return 0;
}
It copies 4M byte data from source to dest repeatedly and takes 12
seconds. But when I get rid of the part of code in red color, it takes only 4 seconds. Why does the writing to source firstly has influence the memcpy( ) time so greatly?
I tested it on Vexpress TC2 with 2 A15's and 3 A7's.
Interesting. I added additional if, endif on the second loop to and checked their assembly in three conditions: - Both loops are enabled: full: Time: 3.7 sec - Only first loop is enabled: first: .189 sec - Only second loop is enabled: second: 1.6 sec
Find assembly of these attached.
I don't see any trick in assembly that can do it. That that is out of the way.
What is left is Cache. But yes, i must admit, i am still not able to solve this puzzle.
Lets see if Arnd can help here :)
-- viresh