slow-work.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Worker thread pool for slow items, such as filesystem lookups or mkdirs
  2. *
  3. * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. *
  11. * See Documentation/slow-work.txt
  12. */
  13. #ifndef _LINUX_SLOW_WORK_H
  14. #define _LINUX_SLOW_WORK_H
  15. #ifdef CONFIG_SLOW_WORK
  16. #include <linux/sysctl.h>
  17. #include <linux/timer.h>
  18. struct slow_work;
  19. /*
  20. * The operations used to support slow work items
  21. */
  22. struct slow_work_ops {
  23. /* owner */
  24. struct module *owner;
  25. /* get a ref on a work item
  26. * - return 0 if successful, -ve if not
  27. */
  28. int (*get_ref)(struct slow_work *work);
  29. /* discard a ref to a work item */
  30. void (*put_ref)(struct slow_work *work);
  31. /* execute a work item */
  32. void (*execute)(struct slow_work *work);
  33. };
  34. /*
  35. * A slow work item
  36. * - A reference is held on the parent object by the thread pool when it is
  37. * queued
  38. */
  39. struct slow_work {
  40. struct module *owner; /* the owning module */
  41. unsigned long flags;
  42. #define SLOW_WORK_PENDING 0 /* item pending (further) execution */
  43. #define SLOW_WORK_EXECUTING 1 /* item currently executing */
  44. #define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */
  45. #define SLOW_WORK_VERY_SLOW 3 /* item is very slow */
  46. #define SLOW_WORK_CANCELLING 4 /* item is being cancelled, don't enqueue */
  47. #define SLOW_WORK_DELAYED 5 /* item is struct delayed_slow_work with active timer */
  48. const struct slow_work_ops *ops; /* operations table for this item */
  49. struct list_head link; /* link in queue */
  50. };
  51. struct delayed_slow_work {
  52. struct slow_work work;
  53. struct timer_list timer;
  54. };
  55. /**
  56. * slow_work_init - Initialise a slow work item
  57. * @work: The work item to initialise
  58. * @ops: The operations to use to handle the slow work item
  59. *
  60. * Initialise a slow work item.
  61. */
  62. static inline void slow_work_init(struct slow_work *work,
  63. const struct slow_work_ops *ops)
  64. {
  65. work->flags = 0;
  66. work->ops = ops;
  67. INIT_LIST_HEAD(&work->link);
  68. }
  69. /**
  70. * slow_work_init - Initialise a delayed slow work item
  71. * @work: The work item to initialise
  72. * @ops: The operations to use to handle the slow work item
  73. *
  74. * Initialise a delayed slow work item.
  75. */
  76. static inline void delayed_slow_work_init(struct delayed_slow_work *dwork,
  77. const struct slow_work_ops *ops)
  78. {
  79. init_timer(&dwork->timer);
  80. slow_work_init(&dwork->work, ops);
  81. }
  82. /**
  83. * vslow_work_init - Initialise a very slow work item
  84. * @work: The work item to initialise
  85. * @ops: The operations to use to handle the slow work item
  86. *
  87. * Initialise a very slow work item. This item will be restricted such that
  88. * only a certain number of the pool threads will be able to execute items of
  89. * this type.
  90. */
  91. static inline void vslow_work_init(struct slow_work *work,
  92. const struct slow_work_ops *ops)
  93. {
  94. work->flags = 1 << SLOW_WORK_VERY_SLOW;
  95. work->ops = ops;
  96. INIT_LIST_HEAD(&work->link);
  97. }
  98. extern int slow_work_enqueue(struct slow_work *work);
  99. extern void slow_work_cancel(struct slow_work *work);
  100. extern int slow_work_register_user(struct module *owner);
  101. extern void slow_work_unregister_user(struct module *owner);
  102. extern int delayed_slow_work_enqueue(struct delayed_slow_work *dwork,
  103. unsigned long delay);
  104. static inline void delayed_slow_work_cancel(struct delayed_slow_work *dwork)
  105. {
  106. slow_work_cancel(&dwork->work);
  107. }
  108. #ifdef CONFIG_SYSCTL
  109. extern ctl_table slow_work_sysctls[];
  110. #endif
  111. #endif /* CONFIG_SLOW_WORK */
  112. #endif /* _LINUX_SLOW_WORK_H */