4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; If not, see
17 * http://www.gnu.org/licenses/gpl-2.0.html
22 * Copyright (C) 2013 DataDirect Networks, Inc.
24 * Copyright (c) 2014, Intel Corporation.
28 * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
32 #ifndef _LUSTRE_NRS_TBF_H
33 #define _LUSTRE_NRS_TBF_H
45 #define NRS_TBF_MATCH_FULL 0x0000001
46 #define NRS_TBF_MATCH_WILDCARD 0x0000002
48 struct nrs_tbf_jobid {
51 struct list_head tj_linkage;
54 #define NRS_TBF_KEY_LEN (LNET_NIDSTR_SIZE + LUSTRE_JOBID_SIZE + 3 + 2)
55 struct nrs_tbf_client {
56 /** Resource object for policy instance. */
57 struct ptlrpc_nrs_resource tc_res;
58 /** Node in the hash table. */
59 struct hlist_node tc_hnode;
60 /** NID of the client. */
62 /** Jobid of the client. */
63 char tc_jobid[LUSTRE_JOBID_SIZE];
64 /** opcode of the client. */
66 /** Hash key of the client. */
67 char tc_key[NRS_TBF_KEY_LEN];
68 /** Reference number of the client. */
70 /** Lock to protect rule and linkage. */
71 spinlock_t tc_rule_lock;
72 /** Linkage to rule. */
73 struct list_head tc_linkage;
74 /** Pointer to rule. */
75 struct nrs_tbf_rule *tc_rule;
76 /** Generation of the rule matched. */
77 __u64 tc_rule_generation;
78 /** Limit of RPC rate. */
80 /** Time to wait for next token. */
82 /** RPC token number. */
84 /** Token bucket depth. */
86 /** Time check-point. */
88 /** Deadline of a class */
91 * Time residue: the remainder of elapsed time
92 * divided by nsecs when dequeue a request.
95 /** List of queued requests. */
96 struct list_head tc_list;
97 /** Node in binary heap. */
98 struct cfs_binheap_node tc_node;
99 /** Whether the client is in heap. */
101 /** Sequence of the newest rule. */
102 __u32 tc_rule_sequence;
104 * Linkage into LRU list. Protected bucket lock of
105 * nrs_tbf_head::th_cli_hash.
107 struct list_head tc_lru;
110 #define MAX_TBF_NAME (16)
112 enum nrs_rule_flags {
113 NTRS_STOPPING = 0x00000001,
114 NTRS_DEFAULT = 0x00000002,
115 NTRS_REALTIME = 0x00000004,
118 struct nrs_tbf_rule {
119 /** Name of the rule. */
120 char tr_name[MAX_TBF_NAME];
121 /** Head belongs to. */
122 struct nrs_tbf_head *tr_head;
123 /** Likage to head. */
124 struct list_head tr_linkage;
125 /** Nid list of the rule. */
126 struct list_head tr_nids;
127 /** Nid list string of the rule.*/
129 /** Jobid list of the rule. */
130 struct list_head tr_jobids;
131 /** Jobid list string of the rule.*/
133 /** Opcode bitmap of the rule. */
134 struct cfs_bitmap *tr_opcodes;
135 /** Opcode list string of the rule.*/
136 char *tr_opcodes_str;
137 /** Condition list of the rule.*/
138 struct list_head tr_conds;
139 /** Generic condition string of the rule. */
143 /** Time to wait for next token. */
145 /** Token bucket depth. */
147 /** Lock to protect the list of clients. */
148 spinlock_t tr_rule_lock;
149 /** List of client. */
150 struct list_head tr_cli_list;
151 /** Flags of the rule. */
152 enum nrs_rule_flags tr_flags;
153 /** Usage Reference count taken on the rule. */
155 /** Generation of the rule. */
161 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
162 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
163 struct ptlrpc_request *);
164 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
165 struct nrs_tbf_client *);
166 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
167 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
168 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
169 struct nrs_tbf_rule *,
170 struct nrs_tbf_cmd *);
171 int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
172 int (*o_rule_match)(struct nrs_tbf_rule *,
173 struct nrs_tbf_client *);
174 void (*o_rule_fini)(struct nrs_tbf_rule *);
177 #define NRS_TBF_TYPE_JOBID "jobid"
178 #define NRS_TBF_TYPE_NID "nid"
179 #define NRS_TBF_TYPE_OPCODE "opcode"
180 #define NRS_TBF_TYPE_GENERIC "generic"
181 #define NRS_TBF_TYPE_MAX_LEN 20
184 NRS_TBF_FLAG_INVALID = 0x0000000,
185 NRS_TBF_FLAG_JOBID = 0x0000001,
186 NRS_TBF_FLAG_NID = 0x0000002,
187 NRS_TBF_FLAG_OPCODE = 0x0000004,
188 NRS_TBF_FLAG_GENERIC = 0x0000008,
191 struct nrs_tbf_type {
192 const char *ntt_name;
193 enum nrs_tbf_flag ntt_flag;
194 struct nrs_tbf_ops *ntt_ops;
197 struct nrs_tbf_bucket {
199 * LRU list, updated on each access to client. Protected by
200 * bucket lock of nrs_tbf_head::th_cli_hash.
202 struct list_head ntb_lru;
206 * Private data structure for the TBF policy
208 struct nrs_tbf_head {
210 * Resource object for policy instance.
212 struct ptlrpc_nrs_resource th_res;
216 struct list_head th_list;
218 * Lock to protect the list of rules.
220 spinlock_t th_rule_lock;
222 * Generation of rules.
224 atomic_t th_rule_sequence;
228 struct nrs_tbf_rule *th_rule;
230 * Timer for next token.
232 struct hrtimer th_timer;
234 * Deadline of the timer.
238 * Sequence of requests.
244 struct cfs_binheap *th_binheap;
248 struct cfs_hash *th_cli_hash;
250 * Type of TBF policy.
252 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
256 struct nrs_tbf_ops *th_ops;
262 * Index of bucket on hash table while purging.
267 enum nrs_tbf_cmd_type {
268 NRS_CTL_TBF_START_RULE = 0,
269 NRS_CTL_TBF_STOP_RULE,
270 NRS_CTL_TBF_CHANGE_RULE,
274 enum nrs_tbf_cmd_type tc_cmd;
277 struct nrs_tbf_cmd_start {
279 struct list_head ts_nids;
281 struct list_head ts_jobids;
283 struct cfs_bitmap *ts_opcodes;
284 char *ts_opcodes_str;
285 struct list_head ts_conds;
288 enum nrs_rule_flags ts_rule_flags;
291 struct nrs_tbf_cmd_change {
301 NRS_TBF_FIELD_OPCODE,
305 struct nrs_tbf_expression {
306 enum nrs_tbf_field te_field;
307 struct list_head te_cond;
308 struct cfs_bitmap *te_opcodes;
309 struct list_head te_linkage;
312 struct nrs_tbf_conjunction {
314 * link to disjunction.
316 struct list_head tc_linkage;
318 * list of logical conjunction
320 struct list_head tc_expressions;
327 struct list_head tr_list;
329 * Sequence of the request.
335 * TBF policy operations.
339 * Read the the data of a TBF policy.
341 NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
343 * Write the the data of a TBF policy.
347 * Read the TBF policy type preset by proc entry "nrs_policies".
349 NRS_CTL_TBF_RD_TYPE_FLAG,