slow-work.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef _LINUX_SLOW_WORK_H
  12. #define _LINUX_SLOW_WORK_H
  13. #ifdef CONFIG_SLOW_WORK
  14. #include <linux/sysctl.h>
  15. struct slow_work;
  16. /*
  17. * The operations used to support slow work items
  18. */
  19. struct slow_work_ops {
  20. /* get a ref on a work item
  21. * - return 0 if successful, -ve if not
  22. */
  23. int (*get_ref)(struct slow_work *work);
  24. /* discard a ref to a work item */
  25. void (*put_ref)(struct slow_work *work);
  26. /* execute a work item */
  27. void (*execute)(struct slow_work *work);
  28. };
  29. /*
  30. * A slow work item
  31. * - A reference is held on the parent object by the thread pool when it is
  32. * queued
  33. */
  34. struct slow_work {
  35. unsigned long flags;
  36. #define SLOW_WORK_PENDING 0 /* item pending (further) execution */
  37. #define SLOW_WORK_EXECUTING 1 /* item currently executing */
  38. #define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */
  39. #define SLOW_WORK_VERY_SLOW 3 /* item is very slow */
  40. const struct slow_work_ops *ops; /* operations table for this item */
  41. struct list_head link; /* link in queue */
  42. };
  43. /**
  44. * slow_work_init - Initialise a slow work item
  45. * @work: The work item to initialise
  46. * @ops: The operations to use to handle the slow work item
  47. *
  48. * Initialise a slow work item.
  49. */
  50. static inline void slow_work_init(struct slow_work *work,
  51. const struct slow_work_ops *ops)
  52. {
  53. work->flags = 0;
  54. work->ops = ops;
  55. INIT_LIST_HEAD(&work->link);
  56. }
  57. /**
  58. * slow_work_init - Initialise a very slow work item
  59. * @work: The work item to initialise
  60. * @ops: The operations to use to handle the slow work item
  61. *
  62. * Initialise a very slow work item. This item will be restricted such that
  63. * only a certain number of the pool threads will be able to execute items of
  64. * this type.
  65. */
  66. static inline void vslow_work_init(struct slow_work *work,
  67. const struct slow_work_ops *ops)
  68. {
  69. work->flags = 1 << SLOW_WORK_VERY_SLOW;
  70. work->ops = ops;
  71. INIT_LIST_HEAD(&work->link);
  72. }
  73. extern int slow_work_enqueue(struct slow_work *work);
  74. extern int slow_work_register_user(void);
  75. extern void slow_work_unregister_user(void);
  76. #ifdef CONFIG_SYSCTL
  77. extern ctl_table slow_work_sysctls[];
  78. #endif
  79. #endif /* CONFIG_SLOW_WORK */
  80. #endif /* _LINUX_SLOW_WORK_H */