async.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * async.h: Asynchronous function calls for boot performance
  4. *
  5. * (C) Copyright 2009 Intel Corporation
  6. * Author: Arjan van de Ven <arjan@linux.intel.com>
  7. */
  8. #ifndef __ASYNC_H__
  9. #define __ASYNC_H__
  10. #include <linux/types.h>
  11. #include <linux/list.h>
  12. #include <linux/numa.h>
  13. #include <linux/device.h>
  14. typedef u64 async_cookie_t;
  15. typedef void (*async_func_t) (void *data, async_cookie_t cookie);
  16. struct async_domain {
  17. struct list_head pending;
  18. unsigned registered:1;
  19. };
  20. /*
  21. * domain participates in global async_synchronize_full
  22. */
  23. #define ASYNC_DOMAIN(_name) \
  24. struct async_domain _name = { .pending = LIST_HEAD_INIT(_name.pending), \
  25. .registered = 1 }
  26. /*
  27. * domain is free to go out of scope as soon as all pending work is
  28. * complete, this domain does not participate in async_synchronize_full
  29. */
  30. #define ASYNC_DOMAIN_EXCLUSIVE(_name) \
  31. struct async_domain _name = { .pending = LIST_HEAD_INIT(_name.pending), \
  32. .registered = 0 }
  33. async_cookie_t async_schedule_node(async_func_t func, void *data,
  34. int node);
  35. async_cookie_t async_schedule_node_domain(async_func_t func, void *data,
  36. int node,
  37. struct async_domain *domain);
  38. /**
  39. * async_schedule - schedule a function for asynchronous execution
  40. * @func: function to execute asynchronously
  41. * @data: data pointer to pass to the function
  42. *
  43. * Returns an async_cookie_t that may be used for checkpointing later.
  44. * Note: This function may be called from atomic or non-atomic contexts.
  45. */
  46. static inline async_cookie_t async_schedule(async_func_t func, void *data)
  47. {
  48. return async_schedule_node(func, data, NUMA_NO_NODE);
  49. }
  50. /**
  51. * async_schedule_domain - schedule a function for asynchronous execution within a certain domain
  52. * @func: function to execute asynchronously
  53. * @data: data pointer to pass to the function
  54. * @domain: the domain
  55. *
  56. * Returns an async_cookie_t that may be used for checkpointing later.
  57. * @domain may be used in the async_synchronize_*_domain() functions to
  58. * wait within a certain synchronization domain rather than globally.
  59. * Note: This function may be called from atomic or non-atomic contexts.
  60. */
  61. static inline async_cookie_t
  62. async_schedule_domain(async_func_t func, void *data,
  63. struct async_domain *domain)
  64. {
  65. return async_schedule_node_domain(func, data, NUMA_NO_NODE, domain);
  66. }
  67. /**
  68. * async_schedule_dev - A device specific version of async_schedule
  69. * @func: function to execute asynchronously
  70. * @dev: device argument to be passed to function
  71. *
  72. * Returns an async_cookie_t that may be used for checkpointing later.
  73. * @dev is used as both the argument for the function and to provide NUMA
  74. * context for where to run the function. By doing this we can try to
  75. * provide for the best possible outcome by operating on the device on the
  76. * CPUs closest to the device.
  77. * Note: This function may be called from atomic or non-atomic contexts.
  78. */
  79. static inline async_cookie_t
  80. async_schedule_dev(async_func_t func, struct device *dev)
  81. {
  82. return async_schedule_node(func, dev, dev_to_node(dev));
  83. }
  84. /**
  85. * async_schedule_dev_domain - A device specific version of async_schedule_domain
  86. * @func: function to execute asynchronously
  87. * @dev: device argument to be passed to function
  88. * @domain: the domain
  89. *
  90. * Returns an async_cookie_t that may be used for checkpointing later.
  91. * @dev is used as both the argument for the function and to provide NUMA
  92. * context for where to run the function. By doing this we can try to
  93. * provide for the best possible outcome by operating on the device on the
  94. * CPUs closest to the device.
  95. * @domain may be used in the async_synchronize_*_domain() functions to
  96. * wait within a certain synchronization domain rather than globally.
  97. * Note: This function may be called from atomic or non-atomic contexts.
  98. */
  99. static inline async_cookie_t
  100. async_schedule_dev_domain(async_func_t func, struct device *dev,
  101. struct async_domain *domain)
  102. {
  103. return async_schedule_node_domain(func, dev, dev_to_node(dev), domain);
  104. }
  105. void async_unregister_domain(struct async_domain *domain);
  106. extern void async_synchronize_full(void);
  107. extern void async_synchronize_full_domain(struct async_domain *domain);
  108. extern void async_synchronize_cookie(async_cookie_t cookie);
  109. extern void async_synchronize_cookie_domain(async_cookie_t cookie,
  110. struct async_domain *domain);
  111. extern bool current_is_async(void);
  112. #endif