]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame_incremental - include/linux/padata.h
UBUNTU: Ubuntu-5.3.0-29.31
[mirror_ubuntu-eoan-kernel.git] / include / linux / padata.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: GPL-2.0-only */
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>
7 */
8
9#ifndef PADATA_H
10#define PADATA_H
11
12#include <linux/workqueue.h>
13#include <linux/spinlock.h>
14#include <linux/list.h>
15#include <linux/timer.h>
16#include <linux/notifier.h>
17#include <linux/kobject.h>
18
19#define PADATA_CPU_SERIAL 0x01
20#define PADATA_CPU_PARALLEL 0x02
21
22/**
23 * struct padata_priv - Embedded to the users data structure.
24 *
25 * @list: List entry, to attach to the padata lists.
26 * @pd: Pointer to the internal control structure.
27 * @cb_cpu: Callback cpu for serializatioon.
28 * @cpu: Cpu for parallelization.
29 * @seq_nr: Sequence number of the parallelized data object.
30 * @info: Used to pass information from the parallel to the serial function.
31 * @parallel: Parallel execution function.
32 * @serial: Serial complete function.
33 */
34struct padata_priv {
35 struct list_head list;
36 struct parallel_data *pd;
37 int cb_cpu;
38 int cpu;
39 int info;
40 void (*parallel)(struct padata_priv *padata);
41 void (*serial)(struct padata_priv *padata);
42};
43
44/**
45 * struct padata_list
46 *
47 * @list: List head.
48 * @lock: List lock.
49 */
50struct padata_list {
51 struct list_head list;
52 spinlock_t lock;
53};
54
55/**
56* struct padata_serial_queue - The percpu padata serial queue
57*
58* @serial: List to wait for serialization after reordering.
59* @work: work struct for serialization.
60* @pd: Backpointer to the internal control structure.
61*/
62struct padata_serial_queue {
63 struct padata_list serial;
64 struct work_struct work;
65 struct parallel_data *pd;
66};
67
68/**
69 * struct padata_parallel_queue - The percpu padata parallel queue
70 *
71 * @parallel: List to wait for parallelization.
72 * @reorder: List to wait for reordering after parallel processing.
73 * @serial: List to wait for serialization after reordering.
74 * @pwork: work struct for parallelization.
75 * @swork: work struct for serialization.
76 * @pd: Backpointer to the internal control structure.
77 * @work: work struct for parallelization.
78 * @reorder_work: work struct for reordering.
79 * @num_obj: Number of objects that are processed by this cpu.
80 * @cpu_index: Index of the cpu.
81 */
82struct padata_parallel_queue {
83 struct padata_list parallel;
84 struct padata_list reorder;
85 struct parallel_data *pd;
86 struct work_struct work;
87 struct work_struct reorder_work;
88 atomic_t num_obj;
89 int cpu_index;
90};
91
92/**
93 * struct padata_cpumask - The cpumasks for the parallel/serial workers
94 *
95 * @pcpu: cpumask for the parallel workers.
96 * @cbcpu: cpumask for the serial (callback) workers.
97 */
98struct padata_cpumask {
99 cpumask_var_t pcpu;
100 cpumask_var_t cbcpu;
101};
102
103/**
104 * struct parallel_data - Internal control structure, covers everything
105 * that depends on the cpumask in use.
106 *
107 * @pinst: padata instance.
108 * @pqueue: percpu padata queues used for parallelization.
109 * @squeue: percpu padata queues used for serialuzation.
110 * @reorder_objects: Number of objects waiting in the reorder queues.
111 * @refcnt: Number of objects holding a reference on this parallel_data.
112 * @max_seq_nr: Maximal used sequence number.
113 * @cpumask: The cpumasks in use for parallel and serial workers.
114 * @lock: Reorder lock.
115 * @processed: Number of already processed objects.
116 * @timer: Reorder timer.
117 */
118struct parallel_data {
119 struct padata_instance *pinst;
120 struct padata_parallel_queue __percpu *pqueue;
121 struct padata_serial_queue __percpu *squeue;
122 atomic_t reorder_objects;
123 atomic_t refcnt;
124 atomic_t seq_nr;
125 struct padata_cpumask cpumask;
126 spinlock_t lock ____cacheline_aligned;
127 unsigned int processed;
128 struct timer_list timer;
129};
130
131/**
132 * struct padata_instance - The overall control structure.
133 *
134 * @cpu_notifier: cpu hotplug notifier.
135 * @wq: The workqueue in use.
136 * @pd: The internal control structure.
137 * @cpumask: User supplied cpumasks for parallel and serial works.
138 * @cpumask_change_notifier: Notifiers chain for user-defined notify
139 * callbacks that will be called when either @pcpu or @cbcpu
140 * or both cpumasks change.
141 * @kobj: padata instance kernel object.
142 * @lock: padata instance lock.
143 * @flags: padata flags.
144 */
145struct padata_instance {
146 struct hlist_node node;
147 struct workqueue_struct *wq;
148 struct parallel_data *pd;
149 struct padata_cpumask cpumask;
150 struct blocking_notifier_head cpumask_change_notifier;
151 struct kobject kobj;
152 struct mutex lock;
153 u8 flags;
154#define PADATA_INIT 1
155#define PADATA_RESET 2
156#define PADATA_INVALID 4
157};
158
159extern struct padata_instance *padata_alloc_possible(
160 struct workqueue_struct *wq);
161extern void padata_free(struct padata_instance *pinst);
162extern int padata_do_parallel(struct padata_instance *pinst,
163 struct padata_priv *padata, int cb_cpu);
164extern void padata_do_serial(struct padata_priv *padata);
165extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
166 cpumask_var_t cpumask);
167extern int padata_start(struct padata_instance *pinst);
168extern void padata_stop(struct padata_instance *pinst);
169extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
170 struct notifier_block *nblock);
171extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
172 struct notifier_block *nblock);
173#endif