padata.h 6.0 KB

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