Whamcloud - gitweb
LU-56 libcfs: CPT affinity workitem scheduler
[fs/lustre-release.git] / lnet / selftest / module.c
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, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #define DEBUG_SUBSYSTEM S_LNET
36
37 #include "selftest.h"
38
39
40 enum {
41         LST_INIT_NONE           = 0,
42         LST_INIT_WI,
43         LST_INIT_RPC,
44         LST_INIT_FW,
45         LST_INIT_CONSOLE
46 };
47
48 extern int lstcon_console_init(void);
49 extern int lstcon_console_fini(void);
50
51 static int lst_init_step = LST_INIT_NONE;
52
53 struct cfs_wi_sched *lst_sched_serial;
54 struct cfs_wi_sched *lst_sched_test;
55
56 void
57 lnet_selftest_fini (void)
58 {
59         switch (lst_init_step) {
60 #ifdef __KERNEL__
61                 case LST_INIT_CONSOLE:
62                         lstcon_console_fini();
63 #endif
64                 case LST_INIT_FW:
65                         sfw_shutdown();
66                 case LST_INIT_RPC:
67                         srpc_shutdown();
68                 case LST_INIT_WI:
69                         cfs_wi_sched_destroy(lst_sched_serial);
70                         cfs_wi_sched_destroy(lst_sched_test);
71                         lst_sched_serial = NULL;
72                         lst_sched_test = NULL;
73                 case LST_INIT_NONE:
74                         break;
75                 default:
76                         LBUG();
77         }
78         return;
79 }
80
81
82 void
83 lnet_selftest_structure_assertion(void)
84 {
85         CLASSERT(sizeof(srpc_msg_t) == 160);
86         CLASSERT(sizeof(srpc_test_reqst_t) == 70);
87         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_concur) == 72);
88         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_ndest) == 78);
89         CLASSERT(sizeof(srpc_stat_reply_t) == 136);
90         CLASSERT(sizeof(srpc_stat_reqst_t) == 28);
91 }
92
93 int
94 lnet_selftest_init (void)
95 {
96         int     nthrs;
97         int     rc;
98
99         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
100                                  1, &lst_sched_serial);
101         if (rc != 0)
102                 return rc;
103
104         nthrs = cfs_cpt_weight(lnet_cpt_table(), CFS_CPT_ANY);
105         rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), CFS_CPT_ANY,
106                                  nthrs, &lst_sched_test);
107         if (rc != 0) {
108                 cfs_wi_sched_destroy(lst_sched_serial);
109                 lst_sched_serial = NULL;
110                 return rc;
111         }
112         lst_init_step = LST_INIT_WI;
113
114         rc = srpc_startup();
115         if (rc != 0) {
116                 CERROR("LST can't startup rpc\n");
117                 goto error;
118         }
119         lst_init_step = LST_INIT_RPC;
120
121         rc = sfw_startup();
122         if (rc != 0) {
123                 CERROR("LST can't startup framework\n");
124                 goto error;
125         }
126         lst_init_step = LST_INIT_FW;
127
128 #ifdef __KERNEL__
129         rc = lstcon_console_init();
130         if (rc != 0) {
131                 CERROR("LST can't startup console\n");
132                 goto error;
133         }
134         lst_init_step = LST_INIT_CONSOLE;  
135 #endif
136
137         return 0;
138 error:
139         lnet_selftest_fini();
140         return rc;
141 }
142
143 #ifdef __KERNEL__
144
145 MODULE_DESCRIPTION("LNet Selftest");
146 MODULE_LICENSE("GPL");
147
148 cfs_module(lnet, "0.9.0", lnet_selftest_init, lnet_selftest_fini);
149
150 #else
151
152 int
153 selftest_wait_events (void)
154 {
155         int evts = 0;
156
157         for (;;) {
158                 /* Consume all pending events */
159                 while (srpc_check_event(0))
160                         evts++;
161                 evts += stt_check_events();
162                 evts += swi_check_events();
163                 if (evts != 0) break;
164
165                 /* Nothing happened, block for events */
166                 evts += srpc_check_event(stt_poll_interval());
167                 /* We may have blocked, check for expired timers */
168                 evts += stt_check_events();
169                 if (evts == 0) /* timed out and still no event */
170                         break;
171         }
172
173         return evts;
174 }
175
176 #endif