Merge branch 'topic/tasklet-convert' into for-linus
[linux-block.git] / include / linux / padata.h
CommitLineData
a61127c2 1/* SPDX-License-Identifier: GPL-2.0-only */
16295bec
SK
2/*
3 * padata.h - header for the padata parallelization interface
4 *
5 * Copyright (C) 2008, 2009 secunet Security Networks AG
6 * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com>
004ed426
DJ
7 *
8 * Copyright (c) 2020 Oracle and/or its affiliates.
9 * Author: Daniel Jordan <daniel.m.jordan@oracle.com>
16295bec
SK
10 */
11
12#ifndef PADATA_H
13#define PADATA_H
14
bbefa1dd 15#include <linux/compiler_types.h>
16295bec
SK
16#include <linux/workqueue.h>
17#include <linux/spinlock.h>
18#include <linux/list.h>
5e017dc3 19#include <linux/kobject.h>
e15bacbe
DK
20
21#define PADATA_CPU_SERIAL 0x01
22#define PADATA_CPU_PARALLEL 0x02
16295bec 23
0198ffd1 24/**
bfcdcef8 25 * struct padata_priv - Represents one job
0198ffd1
SK
26 *
27 * @list: List entry, to attach to the padata lists.
28 * @pd: Pointer to the internal control structure.
29 * @cb_cpu: Callback cpu for serializatioon.
30 * @seq_nr: Sequence number of the parallelized data object.
31 * @info: Used to pass information from the parallel to the serial function.
32 * @parallel: Parallel execution function.
33 * @serial: Serial complete function.
34 */
16295bec
SK
35struct padata_priv {
36 struct list_head list;
37 struct parallel_data *pd;
38 int cb_cpu;
bfde23ce 39 unsigned int seq_nr;
16295bec
SK
40 int info;
41 void (*parallel)(struct padata_priv *padata);
42 void (*serial)(struct padata_priv *padata);
43};
44
0198ffd1 45/**
bfcdcef8 46 * struct padata_list - one per work type per CPU
0198ffd1
SK
47 *
48 * @list: List head.
49 * @lock: List lock.
50 */
16295bec
SK
51struct padata_list {
52 struct list_head list;
53 spinlock_t lock;
54};
55
0198ffd1 56/**
e15bacbe
DK
57* struct padata_serial_queue - The percpu padata serial queue
58*
59* @serial: List to wait for serialization after reordering.
60* @work: work struct for serialization.
61* @pd: Backpointer to the internal control structure.
62*/
63struct padata_serial_queue {
64 struct padata_list serial;
65 struct work_struct work;
66 struct parallel_data *pd;
67};
68
c635696c
SK
69/**
70 * struct padata_cpumask - The cpumasks for the parallel/serial workers
71 *
72 * @pcpu: cpumask for the parallel workers.
73 * @cbcpu: cpumask for the serial (callback) workers.
74 */
75struct padata_cpumask {
76 cpumask_var_t pcpu;
77 cpumask_var_t cbcpu;
78};
e15bacbe 79
0198ffd1
SK
80/**
81 * struct parallel_data - Internal control structure, covers everything
82 * that depends on the cpumask in use.
83 *
bfcdcef8 84 * @ps: padata_shell object.
f601c725 85 * @reorder_list: percpu reorder lists
e15bacbe 86 * @squeue: percpu padata queues used for serialuzation.
0198ffd1 87 * @refcnt: Number of objects holding a reference on this parallel_data.
bfcdcef8 88 * @seq_nr: Sequence number of the parallelized data object.
bfde23ce 89 * @processed: Number of already processed objects.
6fc4dbcf 90 * @cpu: Next CPU to be processed.
c635696c 91 * @cpumask: The cpumasks in use for parallel and serial workers.
6fc4dbcf 92 * @reorder_work: work struct for reordering.
0198ffd1 93 * @lock: Reorder lock.
0198ffd1 94 */
16295bec 95struct parallel_data {
bbefa1dd 96 struct padata_shell *ps;
f601c725 97 struct padata_list __percpu *reorder_list;
57a2ce5f 98 struct padata_serial_queue __percpu *squeue;
c635696c 99 atomic_t refcnt;
4611ce22 100 unsigned int seq_nr;
bfde23ce 101 unsigned int processed;
6fc4dbcf 102 int cpu;
c635696c 103 struct padata_cpumask cpumask;
6fc4dbcf 104 struct work_struct reorder_work;
bfcdcef8 105 spinlock_t ____cacheline_aligned lock;
16295bec
SK
106};
107
bbefa1dd
HX
108/**
109 * struct padata_shell - Wrapper around struct parallel_data, its
110 * purpose is to allow the underlying control structure to be replaced
111 * on the fly using RCU.
112 *
113 * @pinst: padat instance.
114 * @pd: Actual parallel_data structure which may be substituted on the fly.
115 * @opd: Pointer to old pd to be freed by padata_replace.
116 * @list: List entry in padata_instance list.
117 */
118struct padata_shell {
119 struct padata_instance *pinst;
120 struct parallel_data __rcu *pd;
121 struct parallel_data *opd;
122 struct list_head list;
123};
124
004ed426
DJ
125/**
126 * struct padata_mt_job - represents one multithreaded job
127 *
128 * @thread_fn: Called for each chunk of work that a padata thread does.
129 * @fn_arg: The thread function argument.
130 * @start: The start of the job (units are job-specific).
131 * @size: size of this node's work (units are job-specific).
132 * @align: Ranges passed to the thread function fall on this boundary, with the
133 * possible exceptions of the beginning and end of the job.
134 * @min_chunk: The minimum chunk size in job-specific units. This allows
135 * the client to communicate the minimum amount of work that's
136 * appropriate for one worker thread to do at once.
137 * @max_threads: Max threads to use for the job, actual number may be less
138 * depending on task size and minimum chunk size.
139 */
140struct padata_mt_job {
141 void (*thread_fn)(unsigned long start, unsigned long end, void *arg);
142 void *fn_arg;
143 unsigned long start;
144 unsigned long size;
145 unsigned long align;
146 unsigned long min_chunk;
147 int max_threads;
148};
149
0198ffd1
SK
150/**
151 * struct padata_instance - The overall control structure.
152 *
3c2214b6
DJ
153 * @cpu_online_node: Linkage for CPU online callback.
154 * @cpu_dead_node: Linkage for CPU offline callback.
45d153c0
DJ
155 * @parallel_wq: The workqueue used for parallel work.
156 * @serial_wq: The workqueue used for serial work.
bbefa1dd 157 * @pslist: List of padata_shell objects attached to this instance.
c635696c 158 * @cpumask: User supplied cpumasks for parallel and serial works.
5e017dc3 159 * @kobj: padata instance kernel object.
0198ffd1
SK
160 * @lock: padata instance lock.
161 * @flags: padata flags.
162 */
16295bec 163struct padata_instance {
3c2214b6
DJ
164 struct hlist_node cpu_online_node;
165 struct hlist_node cpu_dead_node;
45d153c0
DJ
166 struct workqueue_struct *parallel_wq;
167 struct workqueue_struct *serial_wq;
bbefa1dd 168 struct list_head pslist;
c635696c 169 struct padata_cpumask cpumask;
5e017dc3 170 struct kobject kobj;
e15bacbe
DK
171 struct mutex lock;
172 u8 flags;
173#define PADATA_INIT 1
174#define PADATA_RESET 2
175#define PADATA_INVALID 4
16295bec
SK
176};
177
f1b192b1
DJ
178#ifdef CONFIG_PADATA
179extern void __init padata_init(void);
180#else
181static inline void __init padata_init(void) {}
182#endif
183
3f257191 184extern struct padata_instance *padata_alloc(const char *name);
16295bec 185extern void padata_free(struct padata_instance *pinst);
bbefa1dd
HX
186extern struct padata_shell *padata_alloc_shell(struct padata_instance *pinst);
187extern void padata_free_shell(struct padata_shell *ps);
188extern int padata_do_parallel(struct padata_shell *ps,
e6ce0e08 189 struct padata_priv *padata, int *cb_cpu);
16295bec 190extern void padata_do_serial(struct padata_priv *padata);
004ed426 191extern void __init padata_do_multithreaded(struct padata_mt_job *job);
e15bacbe 192extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
16295bec 193 cpumask_var_t cpumask);
16295bec 194#endif