Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * async.h: Asynchronous function calls for boot performance
0004  *
0005  * (C) Copyright 2009 Intel Corporation
0006  * Author: Arjan van de Ven <arjan@linux.intel.com>
0007  */
0008 #ifndef __ASYNC_H__
0009 #define __ASYNC_H__
0010 
0011 #include <linux/types.h>
0012 #include <linux/list.h>
0013 #include <linux/numa.h>
0014 #include <linux/device.h>
0015 
0016 typedef u64 async_cookie_t;
0017 typedef void (*async_func_t) (void *data, async_cookie_t cookie);
0018 struct async_domain {
0019     struct list_head pending;
0020     unsigned registered:1;
0021 };
0022 
0023 /*
0024  * domain participates in global async_synchronize_full
0025  */
0026 #define ASYNC_DOMAIN(_name) \
0027     struct async_domain _name = { .pending = LIST_HEAD_INIT(_name.pending), \
0028                       .registered = 1 }
0029 
0030 /*
0031  * domain is free to go out of scope as soon as all pending work is
0032  * complete, this domain does not participate in async_synchronize_full
0033  */
0034 #define ASYNC_DOMAIN_EXCLUSIVE(_name) \
0035     struct async_domain _name = { .pending = LIST_HEAD_INIT(_name.pending), \
0036                       .registered = 0 }
0037 
0038 async_cookie_t async_schedule_node(async_func_t func, void *data,
0039                    int node);
0040 async_cookie_t async_schedule_node_domain(async_func_t func, void *data,
0041                       int node,
0042                       struct async_domain *domain);
0043 
0044 /**
0045  * async_schedule - schedule a function for asynchronous execution
0046  * @func: function to execute asynchronously
0047  * @data: data pointer to pass to the function
0048  *
0049  * Returns an async_cookie_t that may be used for checkpointing later.
0050  * Note: This function may be called from atomic or non-atomic contexts.
0051  */
0052 static inline async_cookie_t async_schedule(async_func_t func, void *data)
0053 {
0054     return async_schedule_node(func, data, NUMA_NO_NODE);
0055 }
0056 
0057 /**
0058  * async_schedule_domain - schedule a function for asynchronous execution within a certain domain
0059  * @func: function to execute asynchronously
0060  * @data: data pointer to pass to the function
0061  * @domain: the domain
0062  *
0063  * Returns an async_cookie_t that may be used for checkpointing later.
0064  * @domain may be used in the async_synchronize_*_domain() functions to
0065  * wait within a certain synchronization domain rather than globally.
0066  * Note: This function may be called from atomic or non-atomic contexts.
0067  */
0068 static inline async_cookie_t
0069 async_schedule_domain(async_func_t func, void *data,
0070               struct async_domain *domain)
0071 {
0072     return async_schedule_node_domain(func, data, NUMA_NO_NODE, domain);
0073 }
0074 
0075 /**
0076  * async_schedule_dev - A device specific version of async_schedule
0077  * @func: function to execute asynchronously
0078  * @dev: device argument to be passed to function
0079  *
0080  * Returns an async_cookie_t that may be used for checkpointing later.
0081  * @dev is used as both the argument for the function and to provide NUMA
0082  * context for where to run the function. By doing this we can try to
0083  * provide for the best possible outcome by operating on the device on the
0084  * CPUs closest to the device.
0085  * Note: This function may be called from atomic or non-atomic contexts.
0086  */
0087 static inline async_cookie_t
0088 async_schedule_dev(async_func_t func, struct device *dev)
0089 {
0090     return async_schedule_node(func, dev, dev_to_node(dev));
0091 }
0092 
0093 /**
0094  * async_schedule_dev_domain - A device specific version of async_schedule_domain
0095  * @func: function to execute asynchronously
0096  * @dev: device argument to be passed to function
0097  * @domain: the domain
0098  *
0099  * Returns an async_cookie_t that may be used for checkpointing later.
0100  * @dev is used as both the argument for the function and to provide NUMA
0101  * context for where to run the function. By doing this we can try to
0102  * provide for the best possible outcome by operating on the device on the
0103  * CPUs closest to the device.
0104  * @domain may be used in the async_synchronize_*_domain() functions to
0105  * wait within a certain synchronization domain rather than globally.
0106  * Note: This function may be called from atomic or non-atomic contexts.
0107  */
0108 static inline async_cookie_t
0109 async_schedule_dev_domain(async_func_t func, struct device *dev,
0110               struct async_domain *domain)
0111 {
0112     return async_schedule_node_domain(func, dev, dev_to_node(dev), domain);
0113 }
0114 
0115 extern void async_synchronize_full(void);
0116 extern void async_synchronize_full_domain(struct async_domain *domain);
0117 extern void async_synchronize_cookie(async_cookie_t cookie);
0118 extern void async_synchronize_cookie_domain(async_cookie_t cookie,
0119                         struct async_domain *domain);
0120 extern bool current_is_async(void);
0121 #endif