Skip to content

Commit bdba833

Browse files
paulmckrcuFrederic Weisbecker
authored andcommitted
refscale: Add this_cpu_inc() readers
This commit adds refscale readers based on this_cpu_inc() and this_cpu_inc() ("refscale.scale_type=percpuinc"). On my x86 laptop, these are about 4.5ns per pair. Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
1 parent 057df3e commit bdba833

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

kernel/rcu/refscale.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ static const struct ref_scale_ops rcu_trace_ops = {
323323
// Definitions for reference count
324324
static atomic_t refcnt;
325325

326+
// Definitions acquire-release.
327+
static DEFINE_PER_CPU(unsigned long, test_acqrel);
328+
326329
static void ref_refcnt_section(const int nloops)
327330
{
328331
int i;
@@ -351,6 +354,34 @@ static const struct ref_scale_ops refcnt_ops = {
351354
.name = "refcnt"
352355
};
353356

357+
static void ref_percpuinc_section(const int nloops)
358+
{
359+
int i;
360+
361+
for (i = nloops; i >= 0; i--) {
362+
this_cpu_inc(test_acqrel);
363+
this_cpu_dec(test_acqrel);
364+
}
365+
}
366+
367+
static void ref_percpuinc_delay_section(const int nloops, const int udl, const int ndl)
368+
{
369+
int i;
370+
371+
for (i = nloops; i >= 0; i--) {
372+
this_cpu_inc(test_acqrel);
373+
un_delay(udl, ndl);
374+
this_cpu_dec(test_acqrel);
375+
}
376+
}
377+
378+
static const struct ref_scale_ops percpuinc_ops = {
379+
.init = rcu_sync_scale_init,
380+
.readsection = ref_percpuinc_section,
381+
.delaysection = ref_percpuinc_delay_section,
382+
.name = "percpuinc"
383+
};
384+
354385
// Definitions for rwlock
355386
static rwlock_t test_rwlock;
356387

@@ -494,9 +525,6 @@ static const struct ref_scale_ops lock_irq_ops = {
494525
.name = "lock-irq"
495526
};
496527

497-
// Definitions acquire-release.
498-
static DEFINE_PER_CPU(unsigned long, test_acqrel);
499-
500528
static void ref_acqrel_section(const int nloops)
501529
{
502530
unsigned long x;
@@ -1291,7 +1319,7 @@ ref_scale_init(void)
12911319
static const struct ref_scale_ops *scale_ops[] = {
12921320
&rcu_ops, &srcu_ops, &srcu_fast_ops, RCU_TRACE_OPS RCU_TASKS_OPS
12931321
&refcnt_ops, &rwlock_ops, &rwsem_ops, &lock_ops, &lock_irq_ops,
1294-
&acqrel_ops, &sched_clock_ops, &clock_ops, &jiffies_ops,
1322+
&percpuinc_ops, &acqrel_ops, &sched_clock_ops, &clock_ops, &jiffies_ops,
12951323
&preempt_ops, &bh_ops, &irq_ops, &irqsave_ops,
12961324
&typesafe_ref_ops, &typesafe_lock_ops, &typesafe_seqlock_ops,
12971325
};

0 commit comments

Comments
 (0)