lock_events.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * Authors: Waiman Long <longman@redhat.com>
  14. */
  15. #ifndef __LOCKING_LOCK_EVENTS_H
  16. #define __LOCKING_LOCK_EVENTS_H
  17. enum lock_events {
  18. #include "lock_events_list.h"
  19. lockevent_num, /* Total number of lock event counts */
  20. LOCKEVENT_reset_cnts = lockevent_num,
  21. };
  22. #ifdef CONFIG_LOCK_EVENT_COUNTS
  23. /*
  24. * Per-cpu counters
  25. */
  26. DECLARE_PER_CPU(unsigned long, lockevents[lockevent_num]);
  27. /*
  28. * Increment the statistical counters. use raw_cpu_inc() because of lower
  29. * overhead and we don't care if we loose the occasional update.
  30. */
  31. static inline void __lockevent_inc(enum lock_events event, bool cond)
  32. {
  33. if (cond)
  34. raw_cpu_inc(lockevents[event]);
  35. }
  36. #define lockevent_inc(ev) __lockevent_inc(LOCKEVENT_ ##ev, true)
  37. #define lockevent_cond_inc(ev, c) __lockevent_inc(LOCKEVENT_ ##ev, c)
  38. static inline void __lockevent_add(enum lock_events event, int inc)
  39. {
  40. raw_cpu_add(lockevents[event], inc);
  41. }
  42. #define lockevent_add(ev, c) __lockevent_add(LOCKEVENT_ ##ev, c)
  43. #else /* CONFIG_LOCK_EVENT_COUNTS */
  44. #define lockevent_inc(ev)
  45. #define lockevent_add(ev, c)
  46. #define lockevent_cond_inc(ev, c)
  47. #endif /* CONFIG_LOCK_EVENT_COUNTS */
  48. #endif /* __LOCKING_LOCK_EVENTS_H */