Hi, On 2018/10/30 14:04, Gao Xiang wrote: > It is better to use wrapped smp_cond_load_relaxed > instead of open-coded busy waiting for bit_spinlock. > > Signed-off-by: Gao Xiang <gaoxian...@huawei.com> > --- > > change log v2: > - fix the incorrect expression !(VAL >> (bitnum & (BITS_PER_LONG-1))) > - the test result is described in the following reply. > > Thanks, > Gao Xiang
Simple test script: #include <linux/kthread.h> #include <linux/bit_spinlock.h> #include <linux/module.h> unsigned long global_lock; int test_thread(void *data) { unsigned long thread_id = (unsigned long)data; int i; u64 start = ktime_get_ns(); for (i = 0; i < 500000; ++i) { bit_spin_lock(0, &global_lock); __asm__("yield"); bit_spin_unlock(0, &global_lock); } pr_err("Thread id: %lu time: %llu\n", thread_id, ktime_get_ns() - start); do_exit(0); } static int __init bitspinlock_test_module_init(void) { int i; for (i = 0; i < 8; ++i) { if (IS_ERR(kthread_run(test_thread, (void *)(unsigned long)i, "thread-%d", i))) pr_err("fail to create thread %d\n", i); } return 0; } static void __exit bitspinlock_test_module_exit(void) { } module_init(bitspinlock_test_module_init); module_exit(bitspinlock_test_module_exit); MODULE_LICENSE("GPL"); ...and tested in the following ARM server environment: Processor: HI1616 (https://en.wikichip.org/wiki/hisilicon/hi16xx/hi1616) Board: HiSilicon D05 Development Board (http://open-estuary.org/d05/) Memory: 512GB Host OS: Ubuntu 18.04.1 LTS (Ubuntu 4.15.0-29.31-generic 4.15.18) QEMU KVM OS: Linux 4.19 + buildroot QEMU KVM cmdline: qemu-system-aarch64 -enable-kvm -cpu host -smp 4 -m 256M -kernel Image -M virt,kernel_irqchip=on -nographic -hda rootfs.ext2 -append 'root=/dev/vda console=ttyAMA0 earlycon=pl011,0x9000000' -serial mon:stdio -net none Without this patch: Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 6 Thread 7 1 1283709480 1271869280 454742480 1173673820 1145643640 1118846920 774616920 1144146140 2 643580180 625143860 576841700 322982340 649987880 585749000 529178880 373374780 3 672307220 847315000 880801860 1039502040 667086380 1033939940 1035381120 1046898300 4 568635580 440547020 737000380 910040880 804543740 712314280 868896880 867049000 5 749107320 726397720 776134480 611970100 756721040 753449440 711691300 609343300 With this patch: Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 6 Thread 7 1 170327620 196322160 169434180 74723860 178145600 178873460 143843260 70998780 2 166415220 129649200 166161240 175241520 155474460 112811860 157003140 150087420 3 511420780 117655640 598641860 596213720 462888760 430838600 554346300 428035120 4 174520240 156311800 120274280 87465380 172781400 136118620 163728340 63026360 5 153677940 202786860 183626500 140721300 150311360 161266840 168154340 107247460 Thanks, Gao Xiang