From mboxrd@z Thu Jan 1 00:00:00 1970 From: greg@kroah.com (Greg KH) Date: Tue, 10 Jul 2018 16:57:48 +0200 Subject: Question about memcpy In-Reply-To: References: <229150.1530989084@turing-police.cc.vt.edu> <20180709140443.GA12104@himanshu-Vostro-3559> <20180710062259.GA341@kroah.com> Message-ID: <20180710145748.GA16629@kroah.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Tue, Jul 10, 2018 at 10:51:34PM +0800, bing zhu wrote: > Thank you ,I use this func for both kernel and user ,result are same. > void *memcpy(void *dest, const void *src, size_t n) > { > long d0, d1, d2; > asm volatile( > "rep ; movsq\n\t" > "movq %4,%%rcx\n\t" > "rep ; movsb\n\t" > : "=&c" (d0), "=&D" (d1), "=&S" (d2) > : "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src) > : "memory"); > > return dest; > } > kernel is indeed faster than user. Ok, and that is due to the fact that the kernel thread does not get scheduled, unlike your userspace program. So this means the kernel is working as designed :) greg k-h