blob: 0a17cd27f34851c0e3d19f259eb0b5b2ccd82a14 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Arjan van de Ven22a9d642009-01-07 08:45:46 -08002/*
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>
Arjan van de Ven22a9d642009-01-07 08:45:46 -08007 */
Dan Williams2955b472012-07-09 19:33:25 -07008#ifndef __ASYNC_H__
9#define __ASYNC_H__
Arjan van de Ven22a9d642009-01-07 08:45:46 -080010
11#include <linux/types.h>
12#include <linux/list.h>
Alexander Duyck6be92382019-01-22 10:39:31 -080013#include <linux/numa.h>
14#include <linux/device.h>
Arjan van de Ven22a9d642009-01-07 08:45:46 -080015
16typedef u64 async_cookie_t;
Lai Jiangshan362f2b02013-03-12 13:59:14 -070017typedef void (*async_func_t) (void *data, async_cookie_t cookie);
Dan Williams2955b472012-07-09 19:33:25 -070018struct async_domain {
Tejun Heo52722792013-01-23 09:32:30 -080019 struct list_head pending;
Dan Williams2955b472012-07-09 19:33:25 -070020 unsigned registered:1;
21};
22
23/*
24 * domain participates in global async_synchronize_full
25 */
26#define ASYNC_DOMAIN(_name) \
Lai Jiangshancc2a8b12013-03-12 13:59:14 -070027 struct async_domain _name = { .pending = LIST_HEAD_INIT(_name.pending), \
Dan Williams2955b472012-07-09 19:33:25 -070028 .registered = 1 }
29
30/*
31 * domain is free to go out of scope as soon as all pending work is
32 * complete, this domain does not participate in async_synchronize_full
33 */
34#define ASYNC_DOMAIN_EXCLUSIVE(_name) \
Lai Jiangshancc2a8b12013-03-12 13:59:14 -070035 struct async_domain _name = { .pending = LIST_HEAD_INIT(_name.pending), \
Dan Williams2955b472012-07-09 19:33:25 -070036 .registered = 0 }
Arjan van de Ven22a9d642009-01-07 08:45:46 -080037
Alexander Duyck6be92382019-01-22 10:39:31 -080038async_cookie_t async_schedule_node(async_func_t func, void *data,
39 int node);
40async_cookie_t async_schedule_node_domain(async_func_t func, void *data,
41 int node,
42 struct async_domain *domain);
43
44/**
45 * async_schedule - schedule a function for asynchronous execution
46 * @func: function to execute asynchronously
47 * @data: data pointer to pass to the function
48 *
49 * Returns an async_cookie_t that may be used for checkpointing later.
50 * Note: This function may be called from atomic or non-atomic contexts.
51 */
52static inline async_cookie_t async_schedule(async_func_t func, void *data)
53{
54 return async_schedule_node(func, data, NUMA_NO_NODE);
55}
56
57/**
58 * async_schedule_domain - schedule a function for asynchronous execution within a certain domain
59 * @func: function to execute asynchronously
60 * @data: data pointer to pass to the function
61 * @domain: the domain
62 *
63 * Returns an async_cookie_t that may be used for checkpointing later.
64 * @domain may be used in the async_synchronize_*_domain() functions to
65 * wait within a certain synchronization domain rather than globally.
66 * Note: This function may be called from atomic or non-atomic contexts.
67 */
68static inline async_cookie_t
69async_schedule_domain(async_func_t func, void *data,
70 struct async_domain *domain)
71{
72 return async_schedule_node_domain(func, data, NUMA_NO_NODE, domain);
73}
74
75/**
76 * async_schedule_dev - A device specific version of async_schedule
77 * @func: function to execute asynchronously
78 * @dev: device argument to be passed to function
79 *
80 * Returns an async_cookie_t that may be used for checkpointing later.
81 * @dev is used as both the argument for the function and to provide NUMA
82 * context for where to run the function. By doing this we can try to
83 * provide for the best possible outcome by operating on the device on the
84 * CPUs closest to the device.
85 * Note: This function may be called from atomic or non-atomic contexts.
86 */
87static inline async_cookie_t
88async_schedule_dev(async_func_t func, struct device *dev)
89{
90 return async_schedule_node(func, dev, dev_to_node(dev));
91}
92
93/**
94 * async_schedule_dev_domain - A device specific version of async_schedule_domain
95 * @func: function to execute asynchronously
96 * @dev: device argument to be passed to function
97 * @domain: the domain
98 *
99 * Returns an async_cookie_t that may be used for checkpointing later.
100 * @dev is used as both the argument for the function and to provide NUMA
101 * context for where to run the function. By doing this we can try to
102 * provide for the best possible outcome by operating on the device on the
103 * CPUs closest to the device.
104 * @domain may be used in the async_synchronize_*_domain() functions to
105 * wait within a certain synchronization domain rather than globally.
106 * Note: This function may be called from atomic or non-atomic contexts.
107 */
108static inline async_cookie_t
109async_schedule_dev_domain(async_func_t func, struct device *dev,
110 struct async_domain *domain)
111{
112 return async_schedule_node_domain(func, dev, dev_to_node(dev), domain);
113}
114
Dan Williamsa46834872012-07-09 19:33:30 -0700115void async_unregister_domain(struct async_domain *domain);
Arjan van de Ven22a9d642009-01-07 08:45:46 -0800116extern void async_synchronize_full(void);
Dan Williams2955b472012-07-09 19:33:25 -0700117extern void async_synchronize_full_domain(struct async_domain *domain);
Arjan van de Ven22a9d642009-01-07 08:45:46 -0800118extern void async_synchronize_cookie(async_cookie_t cookie);
Cornelia Huck766ccb92009-01-20 15:31:31 +0100119extern void async_synchronize_cookie_domain(async_cookie_t cookie,
Dan Williams2955b472012-07-09 19:33:25 -0700120 struct async_domain *domain);
Tejun Heo84b233a2013-01-18 14:05:56 -0800121extern bool current_is_async(void);
Dan Williams2955b472012-07-09 19:33:25 -0700122#endif