Hi,
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?
Thanks & Best Regards! 牟刚 Actions Semiconductor Co.,Ltd Tel: +86-756-3392353 ext.3103 Fax: +86-756-3392251 Email: mugang@actions-semi.com HTTP://www.actions-semi.com
________________________________
发件人: 牟刚 发送时间: 2012年10月30日 16:04 收件人: 'linaro-android@lists.linaro.org' 主题: pandaboard GPU driver
Hi,
I want compile pandaboard GPU driver myself and get the library, such as “libEGL_POWERVR_SGX540_120.so”, “libIMGegl.so” and so on. How can I get the GPU driver source code and compile environment?
Thanks & Best Regards! 牟刚 Actions Semiconductor Co.,Ltd Tel: +86-756-3392353 ext.3103 Fax: +86-756-3392251 Email: mugang@actions-semi.com HTTP://www.actions-semi.com
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
On Thursday 08 November 2012, Viresh Kumar wrote:
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 :)
When you allocate memory in user space but never write to it, the backing pages are in the "empty zero page" in the kernel and don't consume any physical memory beyond that. Moreover, after reading the page the first time, all data will be in clean cache lines and readily available for the CPU to read from.
If you initialize the data first, all 4 MB end up in actual memory. Since this is larger than your available cache memory, copying out of that area generates lots of cache misses.
Arnd
linaro-android@lists.linaro.org