Skip to content

Commit 0b6b098

Browse files
Mathias Krauseherbertx
authored andcommitted
padata: make the sequence counter an atomic_t
Using a spinlock to atomically increase a counter sounds wrong -- we've atomic_t for this! Also move 'seq_nr' to a different cache line than 'lock' to reduce cache line trashing. This has the nice side effect of decreasing the size of struct parallel_data from 192 to 128 bytes for a x86-64 build, e.g. occupying only two instead of three cache lines. Those changes results in a 5% performance increase on an IPsec test run using pcrypt. Btw. the seq_lock spinlock was never explicitly initialized -- one more reason to get rid of it. Signed-off-by: Mathias Krause <mathias.krause@secunet.com> Acked-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent cfc6f11 commit 0b6b098

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎include/linux/padata.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ struct parallel_data {
129129
struct padata_serial_queue __percpu *squeue;
130130
atomic_t reorder_objects;
131131
atomic_t refcnt;
132+
atomic_t seq_nr;
132133
struct padata_cpumask cpumask;
133134
spinlock_t lock ____cacheline_aligned;
134-
spinlock_t seq_lock;
135-
unsigned int seq_nr;
136135
unsigned int processed;
137136
struct timer_list timer;
138137
};

‎kernel/padata.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,16 @@ static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index)
4646

4747
static int padata_cpu_hash(struct parallel_data *pd)
4848
{
49+
unsigned int seq_nr;
4950
int cpu_index;
5051

5152
/*
5253
* Hash the sequence numbers to the cpus by taking
5354
* seq_nr mod. number of cpus in use.
5455
*/
5556

56-
spin_lock(&pd->seq_lock);
57-
cpu_index = pd->seq_nr % cpumask_weight(pd->cpumask.pcpu);
58-
pd->seq_nr++;
59-
spin_unlock(&pd->seq_lock);
57+
seq_nr = atomic_inc_return(&pd->seq_nr);
58+
cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
6059

6160
return padata_index_to_cpu(pd, cpu_index);
6261
}
@@ -429,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
429428
padata_init_pqueues(pd);
430429
padata_init_squeues(pd);
431430
setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
432-
pd->seq_nr = 0;
431+
atomic_set(&pd->seq_nr, -1);
433432
atomic_set(&pd->reorder_objects, 0);
434433
atomic_set(&pd->refcnt, 0);
435434
pd->pinst = pinst;

0 commit comments

Comments
 (0)