Whamcloud - gitweb
LU-8964 libcfs: Introduce parallel tasks framework
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_ptask.h
1 #ifndef __LIBCFS_PTASK_H__
2 #define __LIBCFS_PTASK_H__
3
4 #include <linux/types.h>
5 #include <linux/bitops.h>
6 #include <linux/kernel.h>
7 #include <linux/cpumask.h>
8 #include <linux/uaccess.h>
9 #include <linux/notifier.h>
10 #include <linux/workqueue.h>
11 #include <linux/completion.h>
12 #ifdef CONFIG_PADATA
13 #include <linux/padata.h>
14 #else
15 struct padata_priv {};
16 struct padata_instance {};
17 #endif
18
19 #define PTF_COMPLETE    BIT(0)
20 #define PTF_AUTOFREE    BIT(1)
21 #define PTF_ORDERED     BIT(2)
22 #define PTF_USER_MM     BIT(3)
23 #define PTF_ATOMIC      BIT(4)
24 #define PTF_RETRY       BIT(5)
25
26 struct cfs_ptask_engine {
27         struct padata_instance  *pte_pinst;
28         struct workqueue_struct *pte_wq;
29         struct notifier_block    pte_notifier;
30         int                      pte_weight;
31 };
32
33 struct cfs_ptask;
34 typedef int (*cfs_ptask_cb_t)(struct cfs_ptask *);
35
36 struct cfs_ptask {
37         struct padata_priv       pt_padata;
38         struct completion        pt_completion;
39         mm_segment_t             pt_fs;
40         struct mm_struct        *pt_mm;
41         unsigned int             pt_flags;
42         int                      pt_cbcpu;
43         cfs_ptask_cb_t           pt_cbfunc;
44         void                    *pt_cbdata;
45         int                      pt_result;
46 };
47
48 static inline
49 struct padata_priv *cfs_ptask2padata(struct cfs_ptask *ptask)
50 {
51         return &ptask->pt_padata;
52 }
53
54 static inline
55 struct cfs_ptask *cfs_padata2ptask(struct padata_priv *padata)
56 {
57         return container_of(padata, struct cfs_ptask, pt_padata);
58 }
59
60 static inline
61 bool cfs_ptask_need_complete(struct cfs_ptask *ptask)
62 {
63         return ptask->pt_flags & PTF_COMPLETE;
64 }
65
66 static inline
67 bool cfs_ptask_is_autofree(struct cfs_ptask *ptask)
68 {
69         return ptask->pt_flags & PTF_AUTOFREE;
70 }
71
72 static inline
73 bool cfs_ptask_is_ordered(struct cfs_ptask *ptask)
74 {
75         return ptask->pt_flags & PTF_ORDERED;
76 }
77
78 static inline
79 bool cfs_ptask_use_user_mm(struct cfs_ptask *ptask)
80 {
81         return ptask->pt_flags & PTF_USER_MM;
82 }
83
84 static inline
85 bool cfs_ptask_is_atomic(struct cfs_ptask *ptask)
86 {
87         return ptask->pt_flags & PTF_ATOMIC;
88 }
89
90 static inline
91 bool cfs_ptask_is_retry(struct cfs_ptask *ptask)
92 {
93         return ptask->pt_flags & PTF_RETRY;
94 }
95
96 static inline
97 int cfs_ptask_result(struct cfs_ptask *ptask)
98 {
99         return ptask->pt_result;
100 }
101
102 struct cfs_ptask_engine *cfs_ptengine_init(const char *, const struct cpumask *);
103 void cfs_ptengine_fini(struct cfs_ptask_engine *);
104 int  cfs_ptengine_set_cpumask(struct cfs_ptask_engine *, const struct cpumask *);
105 int  cfs_ptengine_weight(struct cfs_ptask_engine *);
106
107 int  cfs_ptask_submit(struct cfs_ptask *, struct cfs_ptask_engine *);
108 int  cfs_ptask_wait_for(struct cfs_ptask *);
109 int  cfs_ptask_init(struct cfs_ptask *, cfs_ptask_cb_t, void *,
110                     unsigned int, int);
111
112 #endif /* __LIBCFS_PTASK_H__ */