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