HACK/WIP: locking/atomic: allow statistics to be collected for atomics

When analysing some workloads it can be helpful to gather statistics for
the various atomic/atomic64/atomic_long operations, such as the number
of times an atomic is used, or the number of retries required by cmpxchg
loops.

This patch adds some basic statistics for atomic operations, which are
exposed in aggregate under debugfs.

To minimize cross-cpu contention on shared counters, per-cpu buckets are
used. CPUs are allowed to write to other CPUs' buckets (and e.g. may do
so if preempted), but in the common case this should minimize
contention.

This is *VERY* incomplete, and is not intended for use in any production
environment. Enabling these statistics *WILL* pertub workloads.

For example, shortly after booting a VM, the top 10 atomics can be found
with:

| # mount -t debugfs none /sys/kernel/debug/
| #  cat /sys/kernel/debug/atomic_stats | (head -n 1; sort -k 2 -rn) | head -n 11
|                        operation                 used                 fail                 loop
|                  atomic_long_set               250053                    0                    0
|       atomic_try_cmpxchg_acquire               231703                  161                    0
|  atomic_long_try_cmpxchg_acquire               124637                    8                    0
|              atomic_dec_and_test               117357               105789                    0
|    atomic_long_fetch_add_release               104879                    0                    0
|                 atomic_long_read                74008                    0                    0
|                atomic_add_unless                46777                  155                    0
|              atomic_add_negative                41078                35447                    0
|              atomic_inc_and_test                40172                36428                    0
|                  atomic_long_add                15050                    0                    0

TODO: implement loop counting.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
10 files changed