Skip to content

Commit 2481163

Browse files
Peter Zijlstraingomolnar
authored andcommitted
locking/lock_events: Use raw_cpu_{add,inc}() for stats
Instead of playing silly games with CONFIG_DEBUG_PREEMPT toggling between this_cpu_*() and __this_cpu_*() use raw_cpu_*(), which is exactly what we want here. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will.deacon@arm.com> Cc: huang ying <huang.ying.caritas@gmail.com> Link: https://lkml.kernel.org/r/20190527082326.GP2623@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent d934985 commit 2481163

1 file changed

Lines changed: 4 additions & 41 deletions

File tree

‎kernel/locking/lock_events.h‎

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,58 +31,21 @@ enum lock_events {
3131
DECLARE_PER_CPU(unsigned long, lockevents[lockevent_num]);
3232

3333
/*
34-
* The purpose of the lock event counting subsystem is to provide a low
35-
* overhead way to record the number of specific locking events by using
36-
* percpu counters. It is the percpu sum that matters, not specifically
37-
* how many of them happens in each cpu.
38-
*
39-
* It is possible that the same percpu counter may be modified in both
40-
* the process and interrupt contexts. For architectures that perform
41-
* percpu operation with multiple instructions, it is possible to lose
42-
* count if a process context percpu update is interrupted in the middle
43-
* and the same counter is updated in the interrupt context. Therefore,
44-
* the generated percpu sum may not be precise. The error, if any, should
45-
* be small and insignificant.
46-
*
47-
* For those architectures that do multi-instruction percpu operation,
48-
* preemption in the middle and moving the task to another cpu may cause
49-
* a larger error in the count. Again, this will be few and far between.
50-
* Given the imprecise nature of the count and the possibility of resetting
51-
* the count and doing the measurement again, this is not really a big
52-
* problem.
53-
*
54-
* To get a better picture of what is happening under the hood, it is
55-
* suggested that a few measurements should be taken with the counts
56-
* reset in between to stamp out outliner because of these possible
57-
* error conditions.
58-
*
59-
* To minimize overhead, we use __this_cpu_*() in all cases except when
60-
* CONFIG_DEBUG_PREEMPT is defined. In this particular case, this_cpu_*()
61-
* will be used to avoid the appearance of unwanted BUG messages.
62-
*/
63-
#ifdef CONFIG_DEBUG_PREEMPT
64-
#define lockevent_percpu_inc(x) this_cpu_inc(x)
65-
#define lockevent_percpu_add(x, v) this_cpu_add(x, v)
66-
#else
67-
#define lockevent_percpu_inc(x) __this_cpu_inc(x)
68-
#define lockevent_percpu_add(x, v) __this_cpu_add(x, v)
69-
#endif
70-
71-
/*
72-
* Increment the PV qspinlock statistical counters
34+
* Increment the statistical counters. use raw_cpu_inc() because of lower
35+
* overhead and we don't care if we loose the occasional update.
7336
*/
7437
static inline void __lockevent_inc(enum lock_events event, bool cond)
7538
{
7639
if (cond)
77-
lockevent_percpu_inc(lockevents[event]);
40+
raw_cpu_inc(lockevents[event]);
7841
}
7942

8043
#define lockevent_inc(ev) __lockevent_inc(LOCKEVENT_ ##ev, true)
8144
#define lockevent_cond_inc(ev, c) __lockevent_inc(LOCKEVENT_ ##ev, c)
8245

8346
static inline void __lockevent_add(enum lock_events event, int inc)
8447
{
85-
lockevent_percpu_add(lockevents[event], inc);
48+
raw_cpu_add(lockevents[event], inc);
8649
}
8750

8851
#define lockevent_add(ev, c) __lockevent_add(LOCKEVENT_ ##ev, c)

0 commit comments

Comments
 (0)