blob: 5d13d25da2c86b0f996979afbf5bf225c8ee5002 [file] [log] [blame]
Steffen Klassert16295be2010-01-06 19:47:10 +11001/*
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 <steffen.klassert@secunet.com>
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>
Steffen Klassertd46a5ac2010-05-19 13:43:14 +100027#include <linux/timer.h>
Dan Kruchinine15bacb2010-07-14 14:31:57 +040028#include <linux/notifier.h>
Dan Kruchinin5e017dc2010-07-14 14:33:08 +040029#include <linux/kobject.h>
Dan Kruchinine15bacb2010-07-14 14:31:57 +040030
31#define PADATA_CPU_SERIAL 0x01
32#define PADATA_CPU_PARALLEL 0x02
Steffen Klassert16295be2010-01-06 19:47:10 +110033
Steffen Klassert0198ffd2010-05-19 13:44:27 +100034/**
35 * struct padata_priv - Embedded to the users data structure.
36 *
37 * @list: List entry, to attach to the padata lists.
38 * @pd: Pointer to the internal control structure.
39 * @cb_cpu: Callback cpu for serializatioon.
Mathias Krause350ef882017-09-08 20:57:11 +020040 * @cpu: Cpu for parallelization.
Steffen Klassert0198ffd2010-05-19 13:44:27 +100041 * @seq_nr: Sequence number of the parallelized data object.
42 * @info: Used to pass information from the parallel to the serial function.
43 * @parallel: Parallel execution function.
44 * @serial: Serial complete function.
45 */
Steffen Klassert16295be2010-01-06 19:47:10 +110046struct padata_priv {
47 struct list_head list;
48 struct parallel_data *pd;
49 int cb_cpu;
Mathias Krause350ef882017-09-08 20:57:11 +020050 int cpu;
Steffen Klassert16295be2010-01-06 19:47:10 +110051 int info;
52 void (*parallel)(struct padata_priv *padata);
53 void (*serial)(struct padata_priv *padata);
54};
55
Steffen Klassert0198ffd2010-05-19 13:44:27 +100056/**
57 * struct padata_list
58 *
59 * @list: List head.
60 * @lock: List lock.
61 */
Steffen Klassert16295be2010-01-06 19:47:10 +110062struct padata_list {
63 struct list_head list;
64 spinlock_t lock;
65};
66
Steffen Klassert0198ffd2010-05-19 13:44:27 +100067/**
Dan Kruchinine15bacb2010-07-14 14:31:57 +040068* struct padata_serial_queue - The percpu padata serial queue
69*
70* @serial: List to wait for serialization after reordering.
71* @work: work struct for serialization.
72* @pd: Backpointer to the internal control structure.
73*/
74struct padata_serial_queue {
75 struct padata_list serial;
76 struct work_struct work;
77 struct parallel_data *pd;
78};
79
80/**
81 * struct padata_parallel_queue - The percpu padata parallel queue
Steffen Klassert0198ffd2010-05-19 13:44:27 +100082 *
83 * @parallel: List to wait for parallelization.
84 * @reorder: List to wait for reordering after parallel processing.
85 * @serial: List to wait for serialization after reordering.
86 * @pwork: work struct for parallelization.
87 * @swork: work struct for serialization.
88 * @pd: Backpointer to the internal control structure.
Dan Kruchinine15bacb2010-07-14 14:31:57 +040089 * @work: work struct for parallelization.
Mathias Krausecf5868c2017-09-08 20:57:10 +020090 * @reorder_work: work struct for reordering.
Dan Kruchinine15bacb2010-07-14 14:31:57 +040091 * @num_obj: Number of objects that are processed by this cpu.
Steffen Klassert0198ffd2010-05-19 13:44:27 +100092 * @cpu_index: Index of the cpu.
93 */
Dan Kruchinine15bacb2010-07-14 14:31:57 +040094struct padata_parallel_queue {
95 struct padata_list parallel;
96 struct padata_list reorder;
97 struct parallel_data *pd;
98 struct work_struct work;
Mathias Krausecf5868c2017-09-08 20:57:10 +020099 struct work_struct reorder_work;
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400100 atomic_t num_obj;
101 int cpu_index;
Steffen Klassert16295be2010-01-06 19:47:10 +1100102};
103
Steffen Klassertc6356962010-07-27 07:15:50 +0200104/**
105 * struct padata_cpumask - The cpumasks for the parallel/serial workers
106 *
107 * @pcpu: cpumask for the parallel workers.
108 * @cbcpu: cpumask for the serial (callback) workers.
109 */
110struct padata_cpumask {
111 cpumask_var_t pcpu;
112 cpumask_var_t cbcpu;
113};
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400114
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000115/**
116 * struct parallel_data - Internal control structure, covers everything
117 * that depends on the cpumask in use.
118 *
119 * @pinst: padata instance.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400120 * @pqueue: percpu padata queues used for parallelization.
121 * @squeue: percpu padata queues used for serialuzation.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000122 * @reorder_objects: Number of objects waiting in the reorder queues.
123 * @refcnt: Number of objects holding a reference on this parallel_data.
124 * @max_seq_nr: Maximal used sequence number.
Steffen Klassertc6356962010-07-27 07:15:50 +0200125 * @cpumask: The cpumasks in use for parallel and serial workers.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000126 * @lock: Reorder lock.
Steffen Klassert5f1a8c12010-07-07 15:32:39 +0200127 * @processed: Number of already processed objects.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000128 * @timer: Reorder timer.
129 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100130struct parallel_data {
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400131 struct padata_instance *pinst;
Namhyung Kim57a2ce52010-09-03 19:09:46 +0800132 struct padata_parallel_queue __percpu *pqueue;
133 struct padata_serial_queue __percpu *squeue;
Steffen Klassertc6356962010-07-27 07:15:50 +0200134 atomic_t reorder_objects;
135 atomic_t refcnt;
Mathias Krause0b6b0982013-10-25 12:14:15 +0200136 atomic_t seq_nr;
Steffen Klassertc6356962010-07-27 07:15:50 +0200137 struct padata_cpumask cpumask;
138 spinlock_t lock ____cacheline_aligned;
139 unsigned int processed;
140 struct timer_list timer;
Steffen Klassert16295be2010-01-06 19:47:10 +1100141};
142
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000143/**
144 * struct padata_instance - The overall control structure.
145 *
146 * @cpu_notifier: cpu hotplug notifier.
147 * @wq: The workqueue in use.
148 * @pd: The internal control structure.
Steffen Klassertc6356962010-07-27 07:15:50 +0200149 * @cpumask: User supplied cpumasks for parallel and serial works.
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400150 * @cpumask_change_notifier: Notifiers chain for user-defined notify
151 * callbacks that will be called when either @pcpu or @cbcpu
Dan Kruchinin5e017dc2010-07-14 14:33:08 +0400152 * or both cpumasks change.
153 * @kobj: padata instance kernel object.
Steffen Klassert0198ffd2010-05-19 13:44:27 +1000154 * @lock: padata instance lock.
155 * @flags: padata flags.
156 */
Steffen Klassert16295be2010-01-06 19:47:10 +1100157struct padata_instance {
Sebastian Andrzej Siewior30e92152016-09-06 19:04:49 +0200158 struct hlist_node node;
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400159 struct workqueue_struct *wq;
160 struct parallel_data *pd;
Steffen Klassertc6356962010-07-27 07:15:50 +0200161 struct padata_cpumask cpumask;
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400162 struct blocking_notifier_head cpumask_change_notifier;
Dan Kruchinin5e017dc2010-07-14 14:33:08 +0400163 struct kobject kobj;
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400164 struct mutex lock;
165 u8 flags;
166#define PADATA_INIT 1
167#define PADATA_RESET 2
168#define PADATA_INVALID 4
Steffen Klassert16295be2010-01-06 19:47:10 +1100169};
170
Steffen Klasserte6cc1172010-07-27 07:14:28 +0200171extern struct padata_instance *padata_alloc_possible(
172 struct workqueue_struct *wq);
Steffen Klassert16295be2010-01-06 19:47:10 +1100173extern void padata_free(struct padata_instance *pinst);
174extern int padata_do_parallel(struct padata_instance *pinst,
175 struct padata_priv *padata, int cb_cpu);
176extern void padata_do_serial(struct padata_priv *padata);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400177extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
Steffen Klassert16295be2010-01-06 19:47:10 +1100178 cpumask_var_t cpumask);
Steffen Klassert4c879172010-07-07 15:30:10 +0200179extern int padata_start(struct padata_instance *pinst);
Steffen Klassert16295be2010-01-06 19:47:10 +1100180extern void padata_stop(struct padata_instance *pinst);
Dan Kruchinine15bacb2010-07-14 14:31:57 +0400181extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
182 struct notifier_block *nblock);
183extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
184 struct notifier_block *nblock);
Steffen Klassert16295be2010-01-06 19:47:10 +1100185#endif