f9micro / f9-kernel

An efficient and secure microkernel built for ARM Cortex-M cores, inspired by L4
Other
682 stars 145 forks source link

Implement Thumb-2 optimized memcpy/memset #67

Open jserv opened 10 years ago

jserv commented 10 years ago

Directory kernel/lib contains the implementation of memcpy and memset, but it is too generic. We can utilize several ARM Cortex-M3/M4 specific features to optimize:

jserv commented 10 years ago

Reference:

jserv commented 10 years ago

lk implements arm-m optimized memcpy and memset routines in git commit https://github.com/travisg/lk/commit/33b94d9b97ef835d68aca2e5edb54f7267c70625

gapry commented 10 years ago

@jserv The profile result:

  1. unalignment unalignment
  2. alignment alignment
jserv commented 10 years ago

It looks so weird. Can you explain?

gapry commented 10 years ago

@jserv The implementation is the branch. https://github.com/gapry/f9-kernel/blob/benchmark_memcpy/benchmark/benchmark.c

My approach is that measure the case, alignment and unalignment, five times and take the avg time. Assume my approach is correct, the data imply the conclusion is the unalignment case is better than alignment after the optimized on the stm32F407.

jserv commented 10 years ago

@gapry In order to clarify the performance gain, please compare the optimized memcpy routines with plain byte-oriented C version.

gapry commented 10 years ago

@jserv What does plain byte-oriented mean ?

jserv commented 10 years ago

The simplest and inefficient implementation of memcpy:

void memcpy(void* src, void* dst, size_t len)
{
    char* p = (char*)src;
    char* q = (char*)dst;
    while(len--) *p++ = *q++;
}
gapry commented 10 years ago

@jserv For now, I use DWT to measure the elapsed clock cycles. You can check the commit: https://github.com/gapry/f9-kernel/commit/33e58dfcb1105140365132269c596763531e9ede

and the completed Implementation: https://github.com/gapry/f9-kernel/blob/benchmark_memcpy/benchmark/benchmark.c

The profile result: unalignment: dwt_unalign

alignment: dwt_align

jserv commented 10 years ago

@gapry I don't think your benchmarking is valid since it doesn't represent the variance. There must be something wrong.