Whamcloud - gitweb
LU-5557 mdt: track reint operations in MDS service stats
[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  */
26 /*
27  *
28  * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
29  *
30  */
31
32 #ifndef _LUSTRE_NRS_TBF_H
33 #define _LUSTRE_NRS_TBF_H
34 #include <lustre_net.h>
35
36 /* \name tbf
37  *
38  * TBF policy
39  *
40  * @{
41  */
42
43 struct nrs_tbf_head;
44 struct nrs_tbf_cmd;
45
46 struct nrs_tbf_jobid {
47         char            *tj_id;
48         struct list_head tj_linkage;
49 };
50
51 struct nrs_tbf_client {
52         /** Resource object for policy instance. */
53         struct ptlrpc_nrs_resource       tc_res;
54         /** Node in the hash table. */
55         struct hlist_node                tc_hnode;
56         /** NID of the client. */
57         lnet_nid_t                       tc_nid;
58         /** Jobid of the client. */
59         char                             tc_jobid[JOBSTATS_JOBID_SIZE];
60         /** Reference number of the client. */
61         atomic_t                         tc_ref;
62         /** Likage to rule. */
63         struct list_head                 tc_linkage;
64         /** Pointer to rule. */
65         struct nrs_tbf_rule             *tc_rule;
66         /** Generation of the rule matched. */
67         __u64                            tc_rule_generation;
68         /** Limit of RPC rate. */
69         __u64                            tc_rpc_rate;
70         /** Time to wait for next token. */
71         __u64                            tc_nsecs;
72         /** RPC token number. */
73         __u64                            tc_ntoken;
74         /** Token bucket depth. */
75         __u64                            tc_depth;
76         /** Time check-point. */
77         __u64                            tc_check_time;
78         /** List of queued requests. */
79         struct list_head                 tc_list;
80         /** Node in binary heap. */
81         cfs_binheap_node_t               tc_node;
82         /** Whether the client is in heap. */
83         bool                             tc_in_heap;
84         /** Sequence of the newest rule. */
85         __u32                            tc_rule_sequence;
86         /**
87          * Linkage into LRU list. Protected bucket lock of
88          * nrs_tbf_head::th_cli_hash.
89          */
90         struct list_head                 tc_lru;
91 };
92
93 #define MAX_TBF_NAME (16)
94
95 #define NTRS_STOPPING   0x0000001
96 #define NTRS_DEFAULT    0x0000002
97
98 struct nrs_tbf_rule {
99         /** Name of the rule. */
100         char                             tr_name[MAX_TBF_NAME];
101         /** Head belongs to. */
102         struct nrs_tbf_head             *tr_head;
103         /** Likage to head. */
104         struct list_head                 tr_linkage;
105         /** Nid list of the rule. */
106         struct list_head                 tr_nids;
107         /** Nid list string of the rule.*/
108         char                            *tr_nids_str;
109         /** Jobid list of the rule. */
110         struct list_head                 tr_jobids;
111         /** Jobid list string of the rule.*/
112         char                            *tr_jobids_str;
113         /** RPC/s limit. */
114         __u64                            tr_rpc_rate;
115         /** Time to wait for next token. */
116         __u64                            tr_nsecs;
117         /** Token bucket depth. */
118         __u64                            tr_depth;
119         /** List of client. */
120         struct list_head                 tr_cli_list;
121         /** Flags of the rule. */
122         __u32                            tr_flags;
123         /** Usage Reference count taken on the rule. */
124         atomic_t                         tr_ref;
125         /** Generation of the rule. */
126         __u64                            tr_generation;
127 };
128
129 struct nrs_tbf_ops {
130         char *o_name;
131         int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
132         struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
133                                              struct ptlrpc_request *);
134         struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
135                                                 struct nrs_tbf_client *);
136         void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
137         void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
138         int (*o_rule_init)(struct ptlrpc_nrs_policy *,
139                            struct nrs_tbf_rule *,
140                            struct nrs_tbf_cmd *);
141         int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
142         int (*o_rule_match)(struct nrs_tbf_rule *,
143                             struct nrs_tbf_client *);
144         void (*o_rule_fini)(struct nrs_tbf_rule *);
145 };
146
147 #define NRS_TBF_TYPE_JOBID      "jobid"
148 #define NRS_TBF_TYPE_NID        "nid"
149 #define NRS_TBF_TYPE_MAX_LEN    20
150 #define NRS_TBF_FLAG_JOBID      0x0000001
151 #define NRS_TBF_FLAG_NID        0x0000002
152
153 struct nrs_tbf_bucket {
154         /**
155          * LRU list, updated on each access to client. Protected by
156          * bucket lock of nrs_tbf_head::th_cli_hash.
157          */
158         struct list_head        ntb_lru;
159 };
160
161 /**
162  * Private data structure for the TBF policy
163  */
164 struct nrs_tbf_head {
165         /**
166          * Resource object for policy instance.
167          */
168         struct ptlrpc_nrs_resource       th_res;
169         /**
170          * List of rules.
171          */
172         struct list_head                 th_list;
173         /**
174          * Lock to protect the list of rules.
175          */
176         spinlock_t                       th_rule_lock;
177         /**
178          * Generation of rules.
179          */
180         atomic_t                         th_rule_sequence;
181         /**
182          * Default rule.
183          */
184         struct nrs_tbf_rule             *th_rule;
185         /**
186          * Timer for next token.
187          */
188         struct hrtimer                   th_timer;
189         /**
190          * Deadline of the timer.
191          */
192         __u64                            th_deadline;
193         /**
194          * Sequence of requests.
195          */
196         __u64                            th_sequence;
197         /**
198          * Heap of queues.
199          */
200         cfs_binheap_t                   *th_binheap;
201         /**
202          * Hash of clients.
203          */
204         cfs_hash_t                      *th_cli_hash;
205         /**
206          * Type of TBF policy.
207          */
208         char                             th_type[NRS_TBF_TYPE_MAX_LEN + 1];
209         /**
210          * Rule operations.
211          */
212         struct nrs_tbf_ops              *th_ops;
213         /**
214          * Flag of type.
215          */
216         __u32                            th_type_flag;
217         /**
218          * Index of bucket on hash table while purging.
219          */
220         int                              th_purge_start;
221 };
222
223 enum nrs_tbf_cmd_type {
224         NRS_CTL_TBF_START_RULE = 0,
225         NRS_CTL_TBF_STOP_RULE,
226         NRS_CTL_TBF_CHANGE_RATE,
227 };
228
229 struct nrs_tbf_cmd {
230         enum nrs_tbf_cmd_type    tc_cmd;
231         char                    *tc_name;
232         __u64                    tc_rpc_rate;
233         struct list_head         tc_nids;
234         char                    *tc_nids_str;
235         struct list_head         tc_jobids;
236         char                    *tc_jobids_str;
237         __u32                    tc_valid_types;
238         __u32                    tc_rule_flags;
239 };
240
241 struct nrs_tbf_req {
242         /**
243          * Linkage to queue.
244          */
245         struct list_head        tr_list;
246         /**
247          * Sequence of the request.
248          */
249         __u64                   tr_sequence;
250 };
251
252 /**
253  * TBF policy operations.
254  */
255 enum nrs_ctl_tbf {
256         /**
257          * Read the the data of a TBF policy.
258          */
259         NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
260         /**
261          * Write the the data of a TBF policy.
262          */
263         NRS_CTL_TBF_WR_RULE,
264 };
265
266 /** @} tbf */
267 #endif