2019-05-30 07:57:49 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2010-01-06 16:47:10 +08:00
|
|
|
/*
|
|
|
|
* padata.h - header for the padata parallelization interface
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008, 2009 secunet Security Networks AG
|
|
|
|
* Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PADATA_H
|
|
|
|
#define PADATA_H
|
|
|
|
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/list.h>
|
2010-07-14 18:31:57 +08:00
|
|
|
#include <linux/notifier.h>
|
2010-07-14 18:33:08 +08:00
|
|
|
#include <linux/kobject.h>
|
2010-07-14 18:31:57 +08:00
|
|
|
|
|
|
|
#define PADATA_CPU_SERIAL 0x01
|
|
|
|
#define PADATA_CPU_PARALLEL 0x02
|
2010-01-06 16:47:10 +08:00
|
|
|
|
2010-05-19 11:44:27 +08:00
|
|
|
/**
|
|
|
|
* struct padata_priv - Embedded to the users data structure.
|
|
|
|
*
|
|
|
|
* @list: List entry, to attach to the padata lists.
|
|
|
|
* @pd: Pointer to the internal control structure.
|
|
|
|
* @cb_cpu: Callback cpu for serializatioon.
|
2017-09-09 02:57:11 +08:00
|
|
|
* @cpu: Cpu for parallelization.
|
2010-05-19 11:44:27 +08:00
|
|
|
* @seq_nr: Sequence number of the parallelized data object.
|
|
|
|
* @info: Used to pass information from the parallel to the serial function.
|
|
|
|
* @parallel: Parallel execution function.
|
|
|
|
* @serial: Serial complete function.
|
|
|
|
*/
|
2010-01-06 16:47:10 +08:00
|
|
|
struct padata_priv {
|
|
|
|
struct list_head list;
|
|
|
|
struct parallel_data *pd;
|
|
|
|
int cb_cpu;
|
2017-09-09 02:57:11 +08:00
|
|
|
int cpu;
|
2010-01-06 16:47:10 +08:00
|
|
|
int info;
|
|
|
|
void (*parallel)(struct padata_priv *padata);
|
|
|
|
void (*serial)(struct padata_priv *padata);
|
|
|
|
};
|
|
|
|
|
2010-05-19 11:44:27 +08:00
|
|
|
/**
|
|
|
|
* struct padata_list
|
|
|
|
*
|
|
|
|
* @list: List head.
|
|
|
|
* @lock: List lock.
|
|
|
|
*/
|
2010-01-06 16:47:10 +08:00
|
|
|
struct padata_list {
|
|
|
|
struct list_head list;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
2010-05-19 11:44:27 +08:00
|
|
|
/**
|
2010-07-14 18:31:57 +08:00
|
|
|
* struct padata_serial_queue - The percpu padata serial queue
|
|
|
|
*
|
|
|
|
* @serial: List to wait for serialization after reordering.
|
|
|
|
* @work: work struct for serialization.
|
|
|
|
* @pd: Backpointer to the internal control structure.
|
|
|
|
*/
|
|
|
|
struct padata_serial_queue {
|
|
|
|
struct padata_list serial;
|
|
|
|
struct work_struct work;
|
|
|
|
struct parallel_data *pd;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct padata_parallel_queue - The percpu padata parallel queue
|
2010-05-19 11:44:27 +08:00
|
|
|
*
|
|
|
|
* @parallel: List to wait for parallelization.
|
|
|
|
* @reorder: List to wait for reordering after parallel processing.
|
|
|
|
* @serial: List to wait for serialization after reordering.
|
|
|
|
* @pwork: work struct for parallelization.
|
|
|
|
* @swork: work struct for serialization.
|
2010-07-14 18:31:57 +08:00
|
|
|
* @work: work struct for parallelization.
|
|
|
|
* @num_obj: Number of objects that are processed by this cpu.
|
2010-05-19 11:44:27 +08:00
|
|
|
* @cpu_index: Index of the cpu.
|
|
|
|
*/
|
2010-07-14 18:31:57 +08:00
|
|
|
struct padata_parallel_queue {
|
|
|
|
struct padata_list parallel;
|
|
|
|
struct padata_list reorder;
|
|
|
|
struct work_struct work;
|
|
|
|
atomic_t num_obj;
|
|
|
|
int cpu_index;
|
2010-01-06 16:47:10 +08:00
|
|
|
};
|
|
|
|
|
2010-07-27 13:15:50 +08:00
|
|
|
/**
|
|
|
|
* struct padata_cpumask - The cpumasks for the parallel/serial workers
|
|
|
|
*
|
|
|
|
* @pcpu: cpumask for the parallel workers.
|
|
|
|
* @cbcpu: cpumask for the serial (callback) workers.
|
|
|
|
*/
|
|
|
|
struct padata_cpumask {
|
|
|
|
cpumask_var_t pcpu;
|
|
|
|
cpumask_var_t cbcpu;
|
|
|
|
};
|
2010-07-14 18:31:57 +08:00
|
|
|
|
2010-05-19 11:44:27 +08:00
|
|
|
/**
|
|
|
|
* struct parallel_data - Internal control structure, covers everything
|
|
|
|
* that depends on the cpumask in use.
|
|
|
|
*
|
|
|
|
* @pinst: padata instance.
|
2010-07-14 18:31:57 +08:00
|
|
|
* @pqueue: percpu padata queues used for parallelization.
|
|
|
|
* @squeue: percpu padata queues used for serialuzation.
|
2010-05-19 11:44:27 +08:00
|
|
|
* @reorder_objects: Number of objects waiting in the reorder queues.
|
|
|
|
* @refcnt: Number of objects holding a reference on this parallel_data.
|
|
|
|
* @max_seq_nr: Maximal used sequence number.
|
2019-07-18 23:01:46 +08:00
|
|
|
* @cpu: Next CPU to be processed.
|
2010-07-27 13:15:50 +08:00
|
|
|
* @cpumask: The cpumasks in use for parallel and serial workers.
|
2019-07-18 23:01:46 +08:00
|
|
|
* @reorder_work: work struct for reordering.
|
2010-05-19 11:44:27 +08:00
|
|
|
* @lock: Reorder lock.
|
|
|
|
*/
|
2010-01-06 16:47:10 +08:00
|
|
|
struct parallel_data {
|
2010-07-14 18:31:57 +08:00
|
|
|
struct padata_instance *pinst;
|
2010-09-03 19:09:46 +08:00
|
|
|
struct padata_parallel_queue __percpu *pqueue;
|
|
|
|
struct padata_serial_queue __percpu *squeue;
|
2010-07-27 13:15:50 +08:00
|
|
|
atomic_t reorder_objects;
|
|
|
|
atomic_t refcnt;
|
2013-10-25 18:14:15 +08:00
|
|
|
atomic_t seq_nr;
|
2019-07-18 23:01:46 +08:00
|
|
|
int cpu;
|
2010-07-27 13:15:50 +08:00
|
|
|
struct padata_cpumask cpumask;
|
2019-07-18 23:01:46 +08:00
|
|
|
struct work_struct reorder_work;
|
2010-07-27 13:15:50 +08:00
|
|
|
spinlock_t lock ____cacheline_aligned;
|
2010-01-06 16:47:10 +08:00
|
|
|
};
|
|
|
|
|
2010-05-19 11:44:27 +08:00
|
|
|
/**
|
|
|
|
* struct padata_instance - The overall control structure.
|
|
|
|
*
|
|
|
|
* @cpu_notifier: cpu hotplug notifier.
|
|
|
|
* @wq: The workqueue in use.
|
|
|
|
* @pd: The internal control structure.
|
2010-07-27 13:15:50 +08:00
|
|
|
* @cpumask: User supplied cpumasks for parallel and serial works.
|
2010-07-14 18:31:57 +08:00
|
|
|
* @cpumask_change_notifier: Notifiers chain for user-defined notify
|
|
|
|
* callbacks that will be called when either @pcpu or @cbcpu
|
2010-07-14 18:33:08 +08:00
|
|
|
* or both cpumasks change.
|
|
|
|
* @kobj: padata instance kernel object.
|
2010-05-19 11:44:27 +08:00
|
|
|
* @lock: padata instance lock.
|
|
|
|
* @flags: padata flags.
|
|
|
|
*/
|
2010-01-06 16:47:10 +08:00
|
|
|
struct padata_instance {
|
2016-09-07 01:04:49 +08:00
|
|
|
struct hlist_node node;
|
2010-07-14 18:31:57 +08:00
|
|
|
struct workqueue_struct *wq;
|
|
|
|
struct parallel_data *pd;
|
2010-07-27 13:15:50 +08:00
|
|
|
struct padata_cpumask cpumask;
|
2010-07-14 18:31:57 +08:00
|
|
|
struct blocking_notifier_head cpumask_change_notifier;
|
2010-07-14 18:33:08 +08:00
|
|
|
struct kobject kobj;
|
2010-07-14 18:31:57 +08:00
|
|
|
struct mutex lock;
|
|
|
|
u8 flags;
|
|
|
|
#define PADATA_INIT 1
|
|
|
|
#define PADATA_RESET 2
|
|
|
|
#define PADATA_INVALID 4
|
2010-01-06 16:47:10 +08:00
|
|
|
};
|
|
|
|
|
2019-09-06 09:40:21 +08:00
|
|
|
extern struct padata_instance *padata_alloc_possible(const char *name);
|
2010-01-06 16:47:10 +08:00
|
|
|
extern void padata_free(struct padata_instance *pinst);
|
|
|
|
extern int padata_do_parallel(struct padata_instance *pinst,
|
2019-09-06 09:40:24 +08:00
|
|
|
struct padata_priv *padata, int *cb_cpu);
|
2010-01-06 16:47:10 +08:00
|
|
|
extern void padata_do_serial(struct padata_priv *padata);
|
2010-07-14 18:31:57 +08:00
|
|
|
extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
|
2010-01-06 16:47:10 +08:00
|
|
|
cpumask_var_t cpumask);
|
2010-07-07 21:30:10 +08:00
|
|
|
extern int padata_start(struct padata_instance *pinst);
|
2010-01-06 16:47:10 +08:00
|
|
|
extern void padata_stop(struct padata_instance *pinst);
|
2010-07-14 18:31:57 +08:00
|
|
|
extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
|
|
|
|
struct notifier_block *nblock);
|
|
|
|
extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
|
|
|
|
struct notifier_block *nblock);
|
2010-01-06 16:47:10 +08:00
|
|
|
#endif
|