slow-work.h 2.6 KB

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