in kernel you should use this func: static unsigned long usec(void) { struct timeval tv; do_gettimeofday(&tv); return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec; } 2018-07-09 15:54 GMT+08:00 袁建鹏 <yuanjp@hust.edu.cn>:
can you show all code kernel and userspace ?
Kernel compile options are optimized, very different from userspace.
you can use the same object (memcpy.o) to link userspace program and kernel module.
-----原始邮件----- *发件人:*"bing zhu" <zhubohong12@gmail.com> *发送时间:*2018-07-08 22:03:48 (星期日) *收件人:* "Valdis Kletnieks" <valdis.kletnieks@vt.edu> *抄送:* kernelnewbies@kernelnewbies.org *主题:* Re: Question about memcpy
void *p = malloc(4096 * max); start = usec(); for (i = 0; i < max; i++) { memcpy(p + i * 4096, page, 4096); } end = usec(); printf("%s : %d time use %lu us \n", __func__, max,end - start);
static unsigned long usec(void) { struct timeval tv; gettimeofday(&tv, 0); return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec; }
I'm don't think it's really precise but i did notice a difference ,
2018-07-08 2:44 GMT+08:00 <valdis.kletnieks@vt.edu>:
On Sat, 07 Jul 2018 19:36:47 +0800, bing zhu said:
and in user space i do the same thing,I noticed that kernel is faster than user ,
How did you measure the times? Doing this right is actually harder than it looks...