padata.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /**
  27. * struct padata_priv - Embedded to the users data structure.
  28. *
  29. * @list: List entry, to attach to the padata lists.
  30. * @pd: Pointer to the internal control structure.
  31. * @cb_cpu: Callback cpu for serializatioon.
  32. * @seq_nr: Sequence number of the parallelized data object.
  33. * @info: Used to pass information from the parallel to the serial function.
  34. * @parallel: Parallel execution function.
  35. * @serial: Serial complete function.
  36. */
  37. struct padata_priv {
  38. struct list_head list;
  39. struct parallel_data *pd;
  40. int cb_cpu;
  41. int seq_nr;
  42. int info;
  43. void (*parallel)(struct padata_priv *padata);
  44. void (*serial)(struct padata_priv *padata);
  45. };
  46. /**
  47. * struct padata_list
  48. *
  49. * @list: List head.
  50. * @lock: List lock.
  51. */
  52. struct padata_list {
  53. struct list_head list;
  54. spinlock_t lock;
  55. };
  56. /**
  57. * struct padata_queue - The percpu padata queues.
  58. *
  59. * @parallel: List to wait for parallelization.
  60. * @reorder: List to wait for reordering after parallel processing.
  61. * @serial: List to wait for serialization after reordering.
  62. * @pwork: work struct for parallelization.
  63. * @swork: work struct for serialization.
  64. * @pd: Backpointer to the internal control structure.
  65. * @num_obj: Number of objects that are processed by this cpu.
  66. * @cpu_index: Index of the cpu.
  67. */
  68. struct padata_queue {
  69. struct padata_list parallel;
  70. struct padata_list reorder;
  71. struct padata_list serial;
  72. struct work_struct pwork;
  73. struct work_struct swork;
  74. struct parallel_data *pd;
  75. atomic_t num_obj;
  76. int cpu_index;
  77. };
  78. /**
  79. * struct parallel_data - Internal control structure, covers everything
  80. * that depends on the cpumask in use.
  81. *
  82. * @pinst: padata instance.
  83. * @queue: percpu padata queues.
  84. * @seq_nr: The sequence number that will be attached to the next object.
  85. * @reorder_objects: Number of objects waiting in the reorder queues.
  86. * @refcnt: Number of objects holding a reference on this parallel_data.
  87. * @max_seq_nr: Maximal used sequence number.
  88. * @cpumask: cpumask in use.
  89. * @lock: Reorder lock.
  90. * @timer: Reorder timer.
  91. */
  92. struct parallel_data {
  93. struct padata_instance *pinst;
  94. struct padata_queue *queue;
  95. atomic_t seq_nr;
  96. atomic_t reorder_objects;
  97. atomic_t refcnt;
  98. unsigned int max_seq_nr;
  99. cpumask_var_t cpumask;
  100. spinlock_t lock;
  101. struct timer_list timer;
  102. };
  103. /**
  104. * struct padata_instance - The overall control structure.
  105. *
  106. * @cpu_notifier: cpu hotplug notifier.
  107. * @wq: The workqueue in use.
  108. * @pd: The internal control structure.
  109. * @cpumask: User supplied cpumask.
  110. * @lock: padata instance lock.
  111. * @flags: padata flags.
  112. */
  113. struct padata_instance {
  114. struct notifier_block cpu_notifier;
  115. struct workqueue_struct *wq;
  116. struct parallel_data *pd;
  117. cpumask_var_t cpumask;
  118. struct mutex lock;
  119. u8 flags;
  120. #define PADATA_INIT 1
  121. #define PADATA_RESET 2
  122. };
  123. extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
  124. struct workqueue_struct *wq);
  125. extern void padata_free(struct padata_instance *pinst);
  126. extern int padata_do_parallel(struct padata_instance *pinst,
  127. struct padata_priv *padata, int cb_cpu);
  128. extern void padata_do_serial(struct padata_priv *padata);
  129. extern int padata_set_cpumask(struct padata_instance *pinst,
  130. cpumask_var_t cpumask);
  131. extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
  132. extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
  133. extern void padata_start(struct padata_instance *pinst);
  134. extern void padata_stop(struct padata_instance *pinst);
  135. #endif