padata.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * @reorder_work: work struct for reordering.
  82. * @num_obj: Number of objects that are processed by this cpu.
  83. * @cpu_index: Index of the cpu.
  84. */
  85. struct padata_parallel_queue {
  86. struct padata_list parallel;
  87. struct padata_list reorder;
  88. struct parallel_data *pd;
  89. struct work_struct work;
  90. struct work_struct reorder_work;
  91. atomic_t num_obj;
  92. int cpu_index;
  93. };
  94. /**
  95. * struct padata_cpumask - The cpumasks for the parallel/serial workers
  96. *
  97. * @pcpu: cpumask for the parallel workers.
  98. * @cbcpu: cpumask for the serial (callback) workers.
  99. */
  100. struct padata_cpumask {
  101. cpumask_var_t pcpu;
  102. cpumask_var_t cbcpu;
  103. };
  104. /**
  105. * struct parallel_data - Internal control structure, covers everything
  106. * that depends on the cpumask in use.
  107. *
  108. * @pinst: padata instance.
  109. * @pqueue: percpu padata queues used for parallelization.
  110. * @squeue: percpu padata queues used for serialuzation.
  111. * @reorder_objects: Number of objects waiting in the reorder queues.
  112. * @refcnt: Number of objects holding a reference on this parallel_data.
  113. * @max_seq_nr: Maximal used sequence number.
  114. * @cpumask: The cpumasks in use for parallel and serial workers.
  115. * @lock: Reorder lock.
  116. * @processed: Number of already processed objects.
  117. * @timer: Reorder timer.
  118. */
  119. struct parallel_data {
  120. struct padata_instance *pinst;
  121. struct padata_parallel_queue __percpu *pqueue;
  122. struct padata_serial_queue __percpu *squeue;
  123. atomic_t reorder_objects;
  124. atomic_t refcnt;
  125. atomic_t seq_nr;
  126. struct padata_cpumask cpumask;
  127. spinlock_t lock ____cacheline_aligned;
  128. unsigned int processed;
  129. struct timer_list timer;
  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. */
  145. struct 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. extern struct padata_instance *padata_alloc_possible(
  159. struct workqueue_struct *wq);
  160. extern void padata_free(struct padata_instance *pinst);
  161. extern int padata_do_parallel(struct padata_instance *pinst,
  162. struct padata_priv *padata, int cb_cpu);
  163. extern void padata_do_serial(struct padata_priv *padata);
  164. extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
  165. cpumask_var_t cpumask);
  166. extern int padata_start(struct padata_instance *pinst);
  167. extern void padata_stop(struct padata_instance *pinst);
  168. extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
  169. struct notifier_block *nblock);
  170. extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
  171. struct notifier_block *nblock);
  172. #endif