18c2ecf20Sopenharmony_ci==================== 28c2ecf20Sopenharmony_ciPercpu rw semaphores 38c2ecf20Sopenharmony_ci==================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciPercpu rw semaphores is a new read-write semaphore design that is 68c2ecf20Sopenharmony_cioptimized for locking for reading. 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciThe problem with traditional read-write semaphores is that when multiple 98c2ecf20Sopenharmony_cicores take the lock for reading, the cache line containing the semaphore 108c2ecf20Sopenharmony_ciis bouncing between L1 caches of the cores, causing performance 118c2ecf20Sopenharmony_cidegradation. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciLocking for reading is very fast, it uses RCU and it avoids any atomic 148c2ecf20Sopenharmony_ciinstruction in the lock and unlock path. On the other hand, locking for 158c2ecf20Sopenharmony_ciwriting is very expensive, it calls synchronize_rcu() that can take 168c2ecf20Sopenharmony_cihundreds of milliseconds. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciThe lock is declared with "struct percpu_rw_semaphore" type. 198c2ecf20Sopenharmony_ciThe lock is initialized percpu_init_rwsem, it returns 0 on success and 208c2ecf20Sopenharmony_ci-ENOMEM on allocation failure. 218c2ecf20Sopenharmony_ciThe lock must be freed with percpu_free_rwsem to avoid memory leak. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciThe lock is locked for read with percpu_down_read, percpu_up_read and 248c2ecf20Sopenharmony_cifor write with percpu_down_write, percpu_up_write. 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciThe idea of using RCU for optimized rw-lock was introduced by 278c2ecf20Sopenharmony_ciEric Dumazet <eric.dumazet@gmail.com>. 288c2ecf20Sopenharmony_ciThe code was written by Mikulas Patocka <mpatocka@redhat.com> 29