Skip to content

Commit 16295be

Browse files
klassertherbertx
authored andcommitted
padata: Generic parallelization/serialization interface
This patch introduces an interface to process data objects in parallel. The parallelized objects return after serialization in the same order as they were before the parallelization. Signed-off-by: Steffen Klassert <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 863b557 commit 16295be

File tree

4 files changed

+783
-0
lines changed

4 files changed

+783
-0
lines changed

include/linux/padata.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* padata.h - header for the padata parallelization interface
3+
*
4+
* Copyright (C) 2008, 2009 secunet Security Networks AG
5+
* Copyright (C) 2008, 2009 Steffen Klassert <[email protected]>
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms and conditions of the GNU General Public License,
9+
* version 2, as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19+
*/
20+
21+
#ifndef PADATA_H
22+
#define PADATA_H
23+
24+
#include <linux/workqueue.h>
25+
#include <linux/spinlock.h>
26+
#include <linux/list.h>
27+
28+
struct padata_priv {
29+
struct list_head list;
30+
struct parallel_data *pd;
31+
int cb_cpu;
32+
int seq_nr;
33+
int info;
34+
void (*parallel)(struct padata_priv *padata);
35+
void (*serial)(struct padata_priv *padata);
36+
};
37+
38+
struct padata_list {
39+
struct list_head list;
40+
spinlock_t lock;
41+
};
42+
43+
struct padata_queue {
44+
struct padata_list parallel;
45+
struct padata_list reorder;
46+
struct padata_list serial;
47+
struct work_struct pwork;
48+
struct work_struct swork;
49+
struct parallel_data *pd;
50+
atomic_t num_obj;
51+
int cpu_index;
52+
};
53+
54+
struct parallel_data {
55+
struct padata_instance *pinst;
56+
struct padata_queue *queue;
57+
atomic_t seq_nr;
58+
atomic_t reorder_objects;
59+
atomic_t refcnt;
60+
unsigned int max_seq_nr;
61+
cpumask_var_t cpumask;
62+
spinlock_t lock;
63+
};
64+
65+
struct padata_instance {
66+
struct notifier_block cpu_notifier;
67+
struct workqueue_struct *wq;
68+
struct parallel_data *pd;
69+
cpumask_var_t cpumask;
70+
struct mutex lock;
71+
u8 flags;
72+
#define PADATA_INIT 1
73+
#define PADATA_RESET 2
74+
};
75+
76+
extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
77+
struct workqueue_struct *wq);
78+
extern void padata_free(struct padata_instance *pinst);
79+
extern int padata_do_parallel(struct padata_instance *pinst,
80+
struct padata_priv *padata, int cb_cpu);
81+
extern void padata_do_serial(struct padata_priv *padata);
82+
extern int padata_set_cpumask(struct padata_instance *pinst,
83+
cpumask_var_t cpumask);
84+
extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
85+
extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
86+
extern void padata_start(struct padata_instance *pinst);
87+
extern void padata_stop(struct padata_instance *pinst);
88+
#endif

init/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,4 +1252,8 @@ source "block/Kconfig"
12521252
config PREEMPT_NOTIFIERS
12531253
bool
12541254

1255+
config PADATA
1256+
depends on SMP
1257+
bool
1258+
12551259
source "kernel/Kconfig.locks"

kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ obj-$(CONFIG_SLOW_WORK_DEBUG) += slow-work-debugfs.o
100100
obj-$(CONFIG_PERF_EVENTS) += perf_event.o
101101
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
102102
obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
103+
obj-$(CONFIG_PADATA) += padata.o
103104

104105
ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
105106
# According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is

0 commit comments

Comments
 (0)