Whamcloud - gitweb
LU-5319 ptlrpc: Add OBD_CONNECT_MULTIMODRPCS flag
[fs/lustre-release.git] / lustre / include / lustre_nrs_tbf.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (C) 2013 DataDirect Networks, Inc.
24  *
25  * Copyright (c) 2014, Intel Corporation.
26  */
27 /*
28  *
29  * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
30  *
31  */
32
33 #ifndef _LUSTRE_NRS_TBF_H
34 #define _LUSTRE_NRS_TBF_H
35 #include <lustre_net.h>
36
37 /* \name tbf
38  *
39  * TBF policy
40  *
41  * @{
42  */
43
44 struct nrs_tbf_head;
45 struct nrs_tbf_cmd;
46
47 struct nrs_tbf_jobid {
48         char            *tj_id;
49         struct list_head tj_linkage;
50 };
51
52 struct nrs_tbf_client {
53         /** Resource object for policy instance. */
54         struct ptlrpc_nrs_resource       tc_res;
55         /** Node in the hash table. */
56         struct hlist_node                tc_hnode;
57         /** NID of the client. */
58         lnet_nid_t                       tc_nid;
59         /** Jobid of the client. */
60         char                             tc_jobid[LUSTRE_JOBID_SIZE];
61         /** Reference number of the client. */
62         atomic_t                         tc_ref;
63         /** Likage to rule. */
64         struct list_head                 tc_linkage;
65         /** Pointer to rule. */
66         struct nrs_tbf_rule             *tc_rule;
67         /** Generation of the rule matched. */
68         __u64                            tc_rule_generation;
69         /** Limit of RPC rate. */
70         __u64                            tc_rpc_rate;
71         /** Time to wait for next token. */
72         __u64                            tc_nsecs;
73         /** RPC token number. */
74         __u64                            tc_ntoken;
75         /** Token bucket depth. */
76         __u64                            tc_depth;
77         /** Time check-point. */
78         __u64                            tc_check_time;
79         /** List of queued requests. */
80         struct list_head                 tc_list;
81         /** Node in binary heap. */
82         cfs_binheap_node_t               tc_node;
83         /** Whether the client is in heap. */
84         bool                             tc_in_heap;
85         /** Sequence of the newest rule. */
86         __u32                            tc_rule_sequence;
87         /**
88          * Linkage into LRU list. Protected bucket lock of
89          * nrs_tbf_head::th_cli_hash.
90          */
91         struct list_head                 tc_lru;
92 };
93
94 #define MAX_TBF_NAME (16)
95
96 #define NTRS_STOPPING   0x0000001
97 #define NTRS_DEFAULT    0x0000002
98
99 struct nrs_tbf_rule {
100         /** Name of the rule. */
101         char                             tr_name[MAX_TBF_NAME];
102         /** Head belongs to. */
103         struct nrs_tbf_head             *tr_head;
104         /** Likage to head. */
105         struct list_head                 tr_linkage;
106         /** Nid list of the rule. */
107         struct list_head                 tr_nids;
108         /** Nid list string of the rule.*/
109         char                            *tr_nids_str;
110         /** Jobid list of the rule. */
111         struct list_head                 tr_jobids;
112         /** Jobid list string of the rule.*/
113         char                            *tr_jobids_str;
114         /** RPC/s limit. */
115         __u64                            tr_rpc_rate;
116         /** Time to wait for next token. */
117         __u64                            tr_nsecs;
118         /** Token bucket depth. */
119         __u64                            tr_depth;
120         /** List of client. */
121         struct list_head                 tr_cli_list;
122         /** Flags of the rule. */
123         __u32                            tr_flags;
124         /** Usage Reference count taken on the rule. */
125         atomic_t                         tr_ref;
126         /** Generation of the rule. */
127         __u64                            tr_generation;
128 };
129
130 struct nrs_tbf_ops {
131         char *o_name;
132         int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
133         struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
134                                              struct ptlrpc_request *);
135         struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
136                                                 struct nrs_tbf_client *);
137         void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
138         void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
139         int (*o_rule_init)(struct ptlrpc_nrs_policy *,
140                            struct nrs_tbf_rule *,
141                            struct nrs_tbf_cmd *);
142         int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
143         int (*o_rule_match)(struct nrs_tbf_rule *,
144                             struct nrs_tbf_client *);
145         void (*o_rule_fini)(struct nrs_tbf_rule *);
146 };
147
148 #define NRS_TBF_TYPE_JOBID      "jobid"
149 #define NRS_TBF_TYPE_NID        "nid"
150 #define NRS_TBF_TYPE_MAX_LEN    20
151 #define NRS_TBF_FLAG_JOBID      0x0000001
152 #define NRS_TBF_FLAG_NID        0x0000002
153
154 struct nrs_tbf_bucket {
155         /**
156          * LRU list, updated on each access to client. Protected by
157          * bucket lock of nrs_tbf_head::th_cli_hash.
158          */
159         struct list_head        ntb_lru;
160 };
161
162 /**
163  * Private data structure for the TBF policy
164  */
165 struct nrs_tbf_head {
166         /**
167          * Resource object for policy instance.
168          */
169         struct ptlrpc_nrs_resource       th_res;
170         /**
171          * List of rules.
172          */
173         struct list_head                 th_list;
174         /**
175          * Lock to protect the list of rules.
176          */
177         spinlock_t                       th_rule_lock;
178         /**
179          * Generation of rules.
180          */
181         atomic_t                         th_rule_sequence;
182         /**
183          * Default rule.
184          */
185         struct nrs_tbf_rule             *th_rule;
186         /**
187          * Timer for next token.
188          */
189         struct hrtimer                   th_timer;
190         /**
191          * Deadline of the timer.
192          */
193         __u64                            th_deadline;
194         /**
195          * Sequence of requests.
196          */
197         __u64                            th_sequence;
198         /**
199          * Heap of queues.
200          */
201         cfs_binheap_t                   *th_binheap;
202         /**
203          * Hash of clients.
204          */
205         cfs_hash_t                      *th_cli_hash;
206         /**
207          * Type of TBF policy.
208          */
209         char                             th_type[NRS_TBF_TYPE_MAX_LEN + 1];
210         /**
211          * Rule operations.
212          */
213         struct nrs_tbf_ops              *th_ops;
214         /**
215          * Flag of type.
216          */
217         __u32                            th_type_flag;
218         /**
219          * Index of bucket on hash table while purging.
220          */
221         int                              th_purge_start;
222 };
223
224 enum nrs_tbf_cmd_type {
225         NRS_CTL_TBF_START_RULE = 0,
226         NRS_CTL_TBF_STOP_RULE,
227         NRS_CTL_TBF_CHANGE_RATE,
228 };
229
230 struct nrs_tbf_cmd {
231         enum nrs_tbf_cmd_type    tc_cmd;
232         char                    *tc_name;
233         __u64                    tc_rpc_rate;
234         struct list_head         tc_nids;
235         char                    *tc_nids_str;
236         struct list_head         tc_jobids;
237         char                    *tc_jobids_str;
238         __u32                    tc_valid_types;
239         __u32                    tc_rule_flags;
240 };
241
242 struct nrs_tbf_req {
243         /**
244          * Linkage to queue.
245          */
246         struct list_head        tr_list;
247         /**
248          * Sequence of the request.
249          */
250         __u64                   tr_sequence;
251 };
252
253 /**
254  * TBF policy operations.
255  */
256 enum nrs_ctl_tbf {
257         /**
258          * Read the the data of a TBF policy.
259          */
260         NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
261         /**
262          * Write the the data of a TBF policy.
263          */
264         NRS_CTL_TBF_WR_RULE,
265 };
266
267 /** @} tbf */
268 #endif