162306a36Sopenharmony_ci====================
262306a36Sopenharmony_ciPercpu rw semaphores
362306a36Sopenharmony_ci====================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciPercpu rw semaphores is a new read-write semaphore design that is
662306a36Sopenharmony_cioptimized for locking for reading.
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThe problem with traditional read-write semaphores is that when multiple
962306a36Sopenharmony_cicores take the lock for reading, the cache line containing the semaphore
1062306a36Sopenharmony_ciis bouncing between L1 caches of the cores, causing performance
1162306a36Sopenharmony_cidegradation.
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciLocking for reading is very fast, it uses RCU and it avoids any atomic
1462306a36Sopenharmony_ciinstruction in the lock and unlock path. On the other hand, locking for
1562306a36Sopenharmony_ciwriting is very expensive, it calls synchronize_rcu() that can take
1662306a36Sopenharmony_cihundreds of milliseconds.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciThe lock is declared with "struct percpu_rw_semaphore" type.
1962306a36Sopenharmony_ciThe lock is initialized percpu_init_rwsem, it returns 0 on success and
2062306a36Sopenharmony_ci-ENOMEM on allocation failure.
2162306a36Sopenharmony_ciThe lock must be freed with percpu_free_rwsem to avoid memory leak.
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciThe lock is locked for read with percpu_down_read, percpu_up_read and
2462306a36Sopenharmony_cifor write with percpu_down_write, percpu_up_write.
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciThe idea of using RCU for optimized rw-lock was introduced by
2762306a36Sopenharmony_ciEric Dumazet <eric.dumazet@gmail.com>.
2862306a36Sopenharmony_ciThe code was written by Mikulas Patocka <mpatocka@redhat.com>
29