1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#ifndef __SELFTEST_SELFTEST_H__
42#define __SELFTEST_SELFTEST_H__
43
44#define LNET_ONLY
45
46#include "../../include/linux/libcfs/libcfs.h"
47#include "../../include/linux/lnet/lnet.h"
48#include "../../include/linux/lnet/lib-lnet.h"
49#include "../../include/linux/lnet/lib-types.h"
50#include "../../include/linux/lnet/lnetst.h"
51
52#include "rpc.h"
53#include "timer.h"
54
55#ifndef MADE_WITHOUT_COMPROMISE
56#define MADE_WITHOUT_COMPROMISE
57#endif
58
59
60#define SWI_STATE_NEWBORN 0
61#define SWI_STATE_REPLY_SUBMITTED 1
62#define SWI_STATE_REPLY_SENT 2
63#define SWI_STATE_REQUEST_SUBMITTED 3
64#define SWI_STATE_REQUEST_SENT 4
65#define SWI_STATE_REPLY_RECEIVED 5
66#define SWI_STATE_BULK_STARTED 6
67#define SWI_STATE_DONE 10
68
69
70struct srpc_service;
71struct srpc_service_cd;
72struct sfw_test_unit;
73struct sfw_test_instance;
74
75
76
77
78#define SRPC_SERVICE_DEBUG 0
79#define SRPC_SERVICE_MAKE_SESSION 1
80#define SRPC_SERVICE_REMOVE_SESSION 2
81#define SRPC_SERVICE_BATCH 3
82#define SRPC_SERVICE_TEST 4
83#define SRPC_SERVICE_QUERY_STAT 5
84#define SRPC_SERVICE_JOIN 6
85#define SRPC_FRAMEWORK_SERVICE_MAX_ID 10
86
87#define SRPC_SERVICE_BRW 11
88#define SRPC_SERVICE_PING 12
89#define SRPC_SERVICE_MAX_ID 12
90
91#define SRPC_REQUEST_PORTAL 50
92
93#define SRPC_FRAMEWORK_REQUEST_PORTAL 51
94
95#define SRPC_RDMA_PORTAL 52
96
97static inline srpc_msg_type_t
98srpc_service2request (int service)
99{
100 switch (service) {
101 default:
102 LBUG ();
103 case SRPC_SERVICE_DEBUG:
104 return SRPC_MSG_DEBUG_REQST;
105
106 case SRPC_SERVICE_MAKE_SESSION:
107 return SRPC_MSG_MKSN_REQST;
108
109 case SRPC_SERVICE_REMOVE_SESSION:
110 return SRPC_MSG_RMSN_REQST;
111
112 case SRPC_SERVICE_BATCH:
113 return SRPC_MSG_BATCH_REQST;
114
115 case SRPC_SERVICE_TEST:
116 return SRPC_MSG_TEST_REQST;
117
118 case SRPC_SERVICE_QUERY_STAT:
119 return SRPC_MSG_STAT_REQST;
120
121 case SRPC_SERVICE_BRW:
122 return SRPC_MSG_BRW_REQST;
123
124 case SRPC_SERVICE_PING:
125 return SRPC_MSG_PING_REQST;
126
127 case SRPC_SERVICE_JOIN:
128 return SRPC_MSG_JOIN_REQST;
129 }
130}
131
132static inline srpc_msg_type_t
133srpc_service2reply (int service)
134{
135 return srpc_service2request(service) + 1;
136}
137
138typedef enum {
139 SRPC_BULK_REQ_RCVD = 1,
140
141 SRPC_BULK_PUT_SENT = 2,
142 SRPC_BULK_GET_RPLD = 3,
143 SRPC_REPLY_RCVD = 4,
144 SRPC_REPLY_SENT = 5,
145 SRPC_REQUEST_RCVD = 6,
146 SRPC_REQUEST_SENT = 7,
147} srpc_event_type_t;
148
149
150typedef struct {
151 srpc_event_type_t ev_type;
152 lnet_event_kind_t ev_lnet;
153 int ev_fired;
154 int ev_status;
155 void *ev_data;
156} srpc_event_t;
157
158typedef struct {
159 int bk_len;
160 lnet_handle_md_t bk_mdh;
161 int bk_sink;
162 int bk_niov;
163 lnet_kiov_t bk_iovs[0];
164} srpc_bulk_t;
165
166
167typedef struct srpc_buffer {
168 struct list_head buf_list;
169 srpc_msg_t buf_msg;
170 lnet_handle_md_t buf_mdh;
171 lnet_nid_t buf_self;
172 lnet_process_id_t buf_peer;
173} srpc_buffer_t;
174
175struct swi_workitem;
176typedef int (*swi_action_t) (struct swi_workitem *);
177
178typedef struct swi_workitem {
179 struct cfs_wi_sched *swi_sched;
180 cfs_workitem_t swi_workitem;
181 swi_action_t swi_action;
182 int swi_state;
183} swi_workitem_t;
184
185
186typedef struct srpc_server_rpc {
187
188 struct list_head srpc_list;
189 struct srpc_service_cd *srpc_scd;
190 swi_workitem_t srpc_wi;
191 srpc_event_t srpc_ev;
192 lnet_nid_t srpc_self;
193 lnet_process_id_t srpc_peer;
194 srpc_msg_t srpc_replymsg;
195 lnet_handle_md_t srpc_replymdh;
196 srpc_buffer_t *srpc_reqstbuf;
197 srpc_bulk_t *srpc_bulk;
198
199 unsigned int srpc_aborted;
200 int srpc_status;
201 void (*srpc_done)(struct srpc_server_rpc *);
202} srpc_server_rpc_t;
203
204
205typedef struct srpc_client_rpc {
206 struct list_head crpc_list;
207 spinlock_t crpc_lock;
208 int crpc_service;
209 atomic_t crpc_refcount;
210 int crpc_timeout;
211 stt_timer_t crpc_timer;
212 swi_workitem_t crpc_wi;
213 lnet_process_id_t crpc_dest;
214
215 void (*crpc_done)(struct srpc_client_rpc *);
216 void (*crpc_fini)(struct srpc_client_rpc *);
217 int crpc_status;
218 void *crpc_priv;
219
220
221 unsigned int crpc_aborted:1;
222 unsigned int crpc_closed:1;
223
224
225 srpc_event_t crpc_bulkev;
226 srpc_event_t crpc_reqstev;
227 srpc_event_t crpc_replyev;
228
229
230 srpc_msg_t crpc_reqstmsg;
231 srpc_msg_t crpc_replymsg;
232 lnet_handle_md_t crpc_reqstmdh;
233 lnet_handle_md_t crpc_replymdh;
234 srpc_bulk_t crpc_bulk;
235} srpc_client_rpc_t;
236
237#define srpc_client_rpc_size(rpc) \
238offsetof(srpc_client_rpc_t, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
239
240#define srpc_client_rpc_addref(rpc) \
241do { \
242 CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n", \
243 (rpc), libcfs_id2str((rpc)->crpc_dest), \
244 atomic_read(&(rpc)->crpc_refcount)); \
245 LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0); \
246 atomic_inc(&(rpc)->crpc_refcount); \
247} while (0)
248
249#define srpc_client_rpc_decref(rpc) \
250do { \
251 CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n", \
252 (rpc), libcfs_id2str((rpc)->crpc_dest), \
253 atomic_read(&(rpc)->crpc_refcount)); \
254 LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0); \
255 if (atomic_dec_and_test(&(rpc)->crpc_refcount)) \
256 srpc_destroy_client_rpc(rpc); \
257} while (0)
258
259#define srpc_event_pending(rpc) ((rpc)->crpc_bulkev.ev_fired == 0 || \
260 (rpc)->crpc_reqstev.ev_fired == 0 || \
261 (rpc)->crpc_replyev.ev_fired == 0)
262
263
264struct srpc_service_cd {
265
266 spinlock_t scd_lock;
267
268 struct srpc_service *scd_svc;
269
270 srpc_event_t scd_ev;
271
272 struct list_head scd_rpc_free;
273
274 struct list_head scd_rpc_active;
275
276 swi_workitem_t scd_buf_wi;
277
278 int scd_cpt;
279
280 int scd_buf_err;
281
282 unsigned long scd_buf_err_stamp;
283
284 int scd_buf_total;
285
286 int scd_buf_nposted;
287
288 int scd_buf_posting;
289
290 int scd_buf_low;
291
292 int scd_buf_adjust;
293
294 struct list_head scd_buf_posted;
295
296 struct list_head scd_buf_blocked;
297};
298
299
300#define SFW_TEST_WI_MIN 256
301#define SFW_TEST_WI_MAX 2048
302
303
304#define SFW_TEST_WI_EXTRA 64
305
306
307#define SFW_FRWK_WI_MIN 16
308#define SFW_FRWK_WI_MAX 256
309
310typedef struct srpc_service {
311 int sv_id;
312 const char *sv_name;
313 int sv_wi_total;
314 int sv_shuttingdown;
315 int sv_ncpts;
316
317 struct srpc_service_cd **sv_cpt_data;
318
319
320
321
322 int (*sv_handler) (srpc_server_rpc_t *);
323 int (*sv_bulk_ready) (srpc_server_rpc_t *, int);
324} srpc_service_t;
325
326typedef struct {
327 struct list_head sn_list;
328 lst_sid_t sn_id;
329 unsigned int sn_timeout;
330 int sn_timer_active;
331 unsigned int sn_features;
332 stt_timer_t sn_timer;
333 struct list_head sn_batches;
334 char sn_name[LST_NAME_SIZE];
335 atomic_t sn_refcount;
336 atomic_t sn_brw_errors;
337 atomic_t sn_ping_errors;
338 unsigned long sn_started;
339} sfw_session_t;
340
341#define sfw_sid_equal(sid0, sid1) ((sid0).ses_nid == (sid1).ses_nid && \
342 (sid0).ses_stamp == (sid1).ses_stamp)
343
344typedef struct {
345 struct list_head bat_list;
346 lst_bid_t bat_id;
347 int bat_error;
348 sfw_session_t *bat_session;
349 atomic_t bat_nactive;
350 struct list_head bat_tests;
351} sfw_batch_t;
352
353typedef struct {
354 int (*tso_init)(struct sfw_test_instance *tsi);
355
356 void (*tso_fini)(struct sfw_test_instance *tsi);
357
358 int (*tso_prep_rpc)(struct sfw_test_unit *tsu,
359 lnet_process_id_t dest,
360 srpc_client_rpc_t **rpc);
361 void (*tso_done_rpc)(struct sfw_test_unit *tsu,
362 srpc_client_rpc_t *rpc);
363} sfw_test_client_ops_t;
364
365typedef struct sfw_test_instance {
366 struct list_head tsi_list;
367 int tsi_service;
368 sfw_batch_t *tsi_batch;
369 sfw_test_client_ops_t *tsi_ops;
370
371
372
373 unsigned int tsi_is_client:1;
374 unsigned int tsi_stoptsu_onerr:1;
375 int tsi_concur;
376 int tsi_loop;
377
378
379 spinlock_t tsi_lock;
380 unsigned int tsi_stopping:1;
381 atomic_t tsi_nactive;
382
383 struct list_head tsi_units;
384 struct list_head tsi_free_rpcs;
385 struct list_head tsi_active_rpcs;
386
387 union {
388 test_ping_req_t ping;
389 test_bulk_req_t bulk_v0;
390 test_bulk_req_v1_t bulk_v1;
391 } tsi_u;
392} sfw_test_instance_t;
393
394
395
396#define SFW_MAX_CONCUR LST_MAX_CONCUR
397#define SFW_ID_PER_PAGE (PAGE_CACHE_SIZE / sizeof(lnet_process_id_packed_t))
398#define SFW_MAX_NDESTS (LNET_MAX_IOV * SFW_ID_PER_PAGE)
399#define sfw_id_pages(n) (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
400
401typedef struct sfw_test_unit {
402 struct list_head tsu_list;
403 lnet_process_id_t tsu_dest;
404 int tsu_loop;
405 sfw_test_instance_t *tsu_instance;
406 void *tsu_private;
407 swi_workitem_t tsu_worker;
408} sfw_test_unit_t;
409
410typedef struct sfw_test_case {
411 struct list_head tsc_list;
412 srpc_service_t *tsc_srv_service;
413 sfw_test_client_ops_t *tsc_cli_ops;
414} sfw_test_case_t;
415
416srpc_client_rpc_t *
417sfw_create_rpc(lnet_process_id_t peer, int service,
418 unsigned features, int nbulkiov, int bulklen,
419 void (*done) (srpc_client_rpc_t *), void *priv);
420int sfw_create_test_rpc(sfw_test_unit_t *tsu,
421 lnet_process_id_t peer, unsigned features,
422 int nblk, int blklen, srpc_client_rpc_t **rpc);
423void sfw_abort_rpc(srpc_client_rpc_t *rpc);
424void sfw_post_rpc(srpc_client_rpc_t *rpc);
425void sfw_client_rpc_done(srpc_client_rpc_t *rpc);
426void sfw_unpack_message(srpc_msg_t *msg);
427void sfw_free_pages(srpc_server_rpc_t *rpc);
428void sfw_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i);
429int sfw_alloc_pages(srpc_server_rpc_t *rpc, int cpt, int npages, int len,
430 int sink);
431int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply);
432
433srpc_client_rpc_t *
434srpc_create_client_rpc(lnet_process_id_t peer, int service,
435 int nbulkiov, int bulklen,
436 void (*rpc_done)(srpc_client_rpc_t *),
437 void (*rpc_fini)(srpc_client_rpc_t *), void *priv);
438void srpc_post_rpc(srpc_client_rpc_t *rpc);
439void srpc_abort_rpc(srpc_client_rpc_t *rpc, int why);
440void srpc_free_bulk(srpc_bulk_t *bk);
441srpc_bulk_t *srpc_alloc_bulk(int cpt, unsigned bulk_npg, unsigned bulk_len,
442 int sink);
443int srpc_send_rpc(swi_workitem_t *wi);
444int srpc_send_reply(srpc_server_rpc_t *rpc);
445int srpc_add_service(srpc_service_t *sv);
446int srpc_remove_service(srpc_service_t *sv);
447void srpc_shutdown_service(srpc_service_t *sv);
448void srpc_abort_service(srpc_service_t *sv);
449int srpc_finish_service(srpc_service_t *sv);
450int srpc_service_add_buffers(srpc_service_t *sv, int nbuffer);
451void srpc_service_remove_buffers(srpc_service_t *sv, int nbuffer);
452void srpc_get_counters(srpc_counters_t *cnt);
453void srpc_set_counters(const srpc_counters_t *cnt);
454
455extern struct cfs_wi_sched *lst_sched_serial;
456extern struct cfs_wi_sched **lst_sched_test;
457
458static inline int
459srpc_serv_is_framework(struct srpc_service *svc)
460{
461 return svc->sv_id < SRPC_FRAMEWORK_SERVICE_MAX_ID;
462}
463
464static inline int
465swi_wi_action(cfs_workitem_t *wi)
466{
467 swi_workitem_t *swi = container_of(wi, swi_workitem_t, swi_workitem);
468
469 return swi->swi_action(swi);
470}
471
472static inline void
473swi_init_workitem(swi_workitem_t *swi, void *data,
474 swi_action_t action, struct cfs_wi_sched *sched)
475{
476 swi->swi_sched = sched;
477 swi->swi_action = action;
478 swi->swi_state = SWI_STATE_NEWBORN;
479 cfs_wi_init(&swi->swi_workitem, data, swi_wi_action);
480}
481
482static inline void
483swi_schedule_workitem(swi_workitem_t *wi)
484{
485 cfs_wi_schedule(wi->swi_sched, &wi->swi_workitem);
486}
487
488static inline void
489swi_exit_workitem(swi_workitem_t *swi)
490{
491 cfs_wi_exit(swi->swi_sched, &swi->swi_workitem);
492}
493
494static inline int
495swi_deschedule_workitem(swi_workitem_t *swi)
496{
497 return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem);
498}
499
500
501int sfw_startup(void);
502int srpc_startup(void);
503void sfw_shutdown(void);
504void srpc_shutdown(void);
505
506static inline void
507srpc_destroy_client_rpc (srpc_client_rpc_t *rpc)
508{
509 LASSERT(rpc != NULL);
510 LASSERT(!srpc_event_pending(rpc));
511 LASSERT(atomic_read(&rpc->crpc_refcount) == 0);
512
513 if (rpc->crpc_fini == NULL) {
514 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
515 } else {
516 (*rpc->crpc_fini) (rpc);
517 }
518
519 return;
520}
521
522static inline void
523srpc_init_client_rpc (srpc_client_rpc_t *rpc, lnet_process_id_t peer,
524 int service, int nbulkiov, int bulklen,
525 void (*rpc_done)(srpc_client_rpc_t *),
526 void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
527{
528 LASSERT(nbulkiov <= LNET_MAX_IOV);
529
530 memset(rpc, 0, offsetof(srpc_client_rpc_t,
531 crpc_bulk.bk_iovs[nbulkiov]));
532
533 INIT_LIST_HEAD(&rpc->crpc_list);
534 swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc,
535 lst_sched_test[lnet_cpt_of_nid(peer.nid)]);
536 spin_lock_init(&rpc->crpc_lock);
537 atomic_set(&rpc->crpc_refcount, 1);
538
539 rpc->crpc_dest = peer;
540 rpc->crpc_priv = priv;
541 rpc->crpc_service = service;
542 rpc->crpc_bulk.bk_len = bulklen;
543 rpc->crpc_bulk.bk_niov = nbulkiov;
544 rpc->crpc_done = rpc_done;
545 rpc->crpc_fini = rpc_fini;
546 LNetInvalidateHandle(&rpc->crpc_reqstmdh);
547 LNetInvalidateHandle(&rpc->crpc_replymdh);
548 LNetInvalidateHandle(&rpc->crpc_bulk.bk_mdh);
549
550
551 rpc->crpc_bulkev.ev_fired =
552 rpc->crpc_reqstev.ev_fired =
553 rpc->crpc_replyev.ev_fired = 1;
554
555 rpc->crpc_reqstmsg.msg_magic = SRPC_MSG_MAGIC;
556 rpc->crpc_reqstmsg.msg_version = SRPC_MSG_VERSION;
557 rpc->crpc_reqstmsg.msg_type = srpc_service2request(service);
558 return;
559}
560
561static inline const char *
562swi_state2str (int state)
563{
564#define STATE2STR(x) case x: return #x
565 switch(state) {
566 default:
567 LBUG();
568 STATE2STR(SWI_STATE_NEWBORN);
569 STATE2STR(SWI_STATE_REPLY_SUBMITTED);
570 STATE2STR(SWI_STATE_REPLY_SENT);
571 STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
572 STATE2STR(SWI_STATE_REQUEST_SENT);
573 STATE2STR(SWI_STATE_REPLY_RECEIVED);
574 STATE2STR(SWI_STATE_BULK_STARTED);
575 STATE2STR(SWI_STATE_DONE);
576 }
577#undef STATE2STR
578}
579
580#define selftest_wait_events() \
581 do { \
582 set_current_state(TASK_UNINTERRUPTIBLE); \
583 schedule_timeout(cfs_time_seconds(1) / 10); \
584 } while (0)
585
586
587#define lst_wait_until(cond, lock, fmt, ...) \
588do { \
589 int __I = 2; \
590 while (!(cond)) { \
591 CDEBUG(IS_PO2(++__I) ? D_WARNING : D_NET, \
592 fmt, ## __VA_ARGS__); \
593 spin_unlock(&(lock)); \
594 \
595 selftest_wait_events(); \
596 \
597 spin_lock(&(lock)); \
598 } \
599} while (0)
600
601static inline void
602srpc_wait_service_shutdown(srpc_service_t *sv)
603{
604 int i = 2;
605
606 LASSERT(sv->sv_shuttingdown);
607
608 while (srpc_finish_service(sv) == 0) {
609 i++;
610 CDEBUG (((i & -i) == i) ? D_WARNING : D_NET,
611 "Waiting for %s service to shutdown...\n",
612 sv->sv_name);
613 selftest_wait_events();
614 }
615}
616
617extern sfw_test_client_ops_t brw_test_client;
618void brw_init_test_client(void);
619
620extern srpc_service_t brw_test_service;
621void brw_init_test_service(void);
622
623extern sfw_test_client_ops_t ping_test_client;
624void ping_init_test_client(void);
625
626extern srpc_service_t ping_test_service;
627void ping_init_test_service(void);
628
629#endif
630