1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
6 * This file is part of Portals
7 * http://sourceforge.net/projects/sandiaportals/
9 * Portals is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Portals is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Portals; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LNET
25 #include <libcfs/libcfs.h>
26 #include <lnet/lib-lnet.h>
28 #if defined(__KERNEL__) && defined(LNET_ROUTER)
30 /* this is really lnet_proc.c */
32 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
34 #ifndef HAVE_SYSCTL_UNNUMBERED
35 #define CTL_LNET (0x100)
37 PSDEV_LNET_STATS = 100,
45 #define CTL_LNET CTL_UNNUMBERED
46 #define PSDEV_LNET_STATS CTL_UNNUMBERED
47 #define PSDEV_LNET_ROUTES CTL_UNNUMBERED
48 #define PSDEV_LNET_ROUTERS CTL_UNNUMBERED
49 #define PSDEV_LNET_PEERS CTL_UNNUMBERED
50 #define PSDEV_LNET_BUFFERS CTL_UNNUMBERED
51 #define PSDEV_LNET_NIS CTL_UNNUMBERED
55 * NB: we don't use the highest bit of *ppos because it's signed;
56 * next 9 bits is used to stash idx (assuming that
57 * LNET_PEER_HASHSIZE < 512)
59 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
60 #define LNET_VERSION_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
61 #define LNET_PHASH_IDX_BITS 9
62 #define LNET_PHASH_NUM_BITS (LNET_LOFFT_BITS - 1 -\
63 LNET_VERSION_BITS - LNET_PHASH_IDX_BITS)
64 #define LNET_PHASH_BITS (LNET_PHASH_IDX_BITS + LNET_PHASH_NUM_BITS)
66 #define LNET_VERSION_BITMASK ((1ULL << LNET_VERSION_BITS) - 1)
67 #define LNET_PHASH_IDX_BITMASK ((1ULL << LNET_PHASH_IDX_BITS) - 1)
68 #define LNET_PHASH_NUM_BITMASK ((1ULL << LNET_PHASH_NUM_BITS) - 1)
70 #define LNET_VERSION_MASK (LNET_VERSION_BITMASK << LNET_PHASH_BITS)
71 #define LNET_PHASH_IDX_MASK (LNET_PHASH_IDX_BITMASK << LNET_PHASH_NUM_BITS)
72 #define LNET_PHASH_NUM_MASK (LNET_PHASH_NUM_BITMASK)
74 #define LNET_VERSION_GET(pos) (int)(((pos) & LNET_VERSION_MASK) >> \
76 #define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \
78 #define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK)
79 #define LNET_VERSION_VALID_MASK(ver) \
80 (unsigned int)((ver) & \
82 #define LNET_PHASH_POS_MAKE(ver, idx, num) \
83 (((((loff_t)(ver)) & LNET_VERSION_BITMASK) << \
85 ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\
86 LNET_PHASH_NUM_BITS) | \
87 ((num) & LNET_PHASH_NUM_BITMASK))
89 static int __proc_lnet_stats(void *data, int write,
90 loff_t pos, void *buffer, int nob)
93 lnet_counters_t *ctrs;
96 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
100 memset(&the_lnet.ln_counters, 0, sizeof(the_lnet.ln_counters));
107 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
111 LIBCFS_ALLOC(tmpstr, tmpsiz);
112 if (tmpstr == NULL) {
113 LIBCFS_FREE(ctrs, sizeof(*ctrs));
118 *ctrs = the_lnet.ln_counters;
121 len = snprintf(tmpstr, tmpsiz,
122 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
124 ctrs->msgs_alloc, ctrs->msgs_max,
126 ctrs->send_count, ctrs->recv_count,
127 ctrs->route_count, ctrs->drop_count,
128 ctrs->send_length, ctrs->recv_length,
129 ctrs->route_length, ctrs->drop_length);
131 if (pos >= min_t(int, len, strlen(tmpstr)))
134 rc = cfs_trace_copyout_string(buffer, nob,
137 LIBCFS_FREE(tmpstr, tmpsiz);
138 LIBCFS_FREE(ctrs, sizeof(*ctrs));
142 DECLARE_PROC_HANDLER(proc_lnet_stats);
144 int LL_PROC_PROTO(proc_lnet_routes)
149 const int tmpsiz = 256;
154 DECLARE_LL_PROC_PPOS_DECL;
156 num = LNET_PHASH_NUM_GET(*ppos);
157 ver = LNET_VERSION_GET(*ppos);
164 LIBCFS_ALLOC(tmpstr, tmpsiz);
168 s = tmpstr; /* points to current position in tmpstr[] */
171 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
172 the_lnet.ln_routing ? "enabled" : "disabled");
173 LASSERT (tmpstr + tmpsiz - s > 0);
175 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %7s %s\n",
176 "net", "hops", "state", "router");
177 LASSERT (tmpstr + tmpsiz - s > 0);
180 ver = (unsigned int)the_lnet.ln_remote_nets_version;
182 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
186 lnet_route_t *route = NULL;
187 lnet_remotenet_t *rnet = NULL;
192 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) {
194 LIBCFS_FREE(tmpstr, tmpsiz);
198 n = the_lnet.ln_remote_nets.next;
200 while (n != &the_lnet.ln_remote_nets && route == NULL) {
201 rnet = cfs_list_entry(n, lnet_remotenet_t, lrn_list);
203 r = rnet->lrn_routes.next;
205 while (r != &rnet->lrn_routes) {
207 cfs_list_entry(r, lnet_route_t,
222 __u32 net = rnet->lrn_net;
223 unsigned int hops = route->lr_hops;
224 lnet_nid_t nid = route->lr_gateway->lp_nid;
225 int alive = route->lr_gateway->lp_alive;
227 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4u %7s %s\n",
228 libcfs_net2str(net), hops,
229 alive ? "up" : "down", libcfs_nid2str(nid));
230 LASSERT (tmpstr + tmpsiz - s > 0);
236 len = s - tmpstr; /* how many bytes was written */
238 if (len > *lenp) { /* linux-supplied buffer is too small */
240 } else if (len > 0) { /* wrote something */
241 if (cfs_copy_to_user(buffer, tmpstr, len))
245 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
249 LIBCFS_FREE(tmpstr, tmpsiz);
257 int LL_PROC_PROTO(proc_lnet_routers)
262 const int tmpsiz = 256;
267 DECLARE_LL_PROC_PPOS_DECL;
269 num = LNET_PHASH_NUM_GET(*ppos);
270 ver = LNET_VERSION_GET(*ppos);
277 LIBCFS_ALLOC(tmpstr, tmpsiz);
281 s = tmpstr; /* points to current position in tmpstr[] */
284 s += snprintf(s, tmpstr + tmpsiz - s,
285 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
286 "ref", "rtr_ref", "alive_cnt", "state", "last_ping",
287 "ping_sent", "deadline", "down_ni", "router");
288 LASSERT (tmpstr + tmpsiz - s > 0);
291 ver = (unsigned int)the_lnet.ln_routers_version;
293 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
296 lnet_peer_t *peer = NULL;
301 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_routers_version)) {
303 LIBCFS_FREE(tmpstr, tmpsiz);
307 r = the_lnet.ln_routers.next;
309 while (r != &the_lnet.ln_routers) {
310 lnet_peer_t *lp = cfs_list_entry(r, lnet_peer_t,
323 lnet_nid_t nid = peer->lp_nid;
324 cfs_time_t now = cfs_time_current();
325 cfs_time_t deadline = peer->lp_ping_deadline;
326 int nrefs = peer->lp_refcount;
327 int nrtrrefs = peer->lp_rtr_refcount;
328 int alive_cnt = peer->lp_alive_count;
329 int alive = peer->lp_alive;
330 int pingsent = !peer->lp_ping_notsent;
331 int last_ping = cfs_duration_sec(cfs_time_sub(now,
332 peer->lp_ping_timestamp));
333 int down_ni = lnet_router_down_ni(peer,
334 LNET_NIDNET(LNET_NID_ANY));
337 s += snprintf(s, tmpstr + tmpsiz - s,
338 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
339 nrefs, nrtrrefs, alive_cnt,
340 alive ? "up" : "down", last_ping,
341 pingsent, "NA", down_ni,
342 libcfs_nid2str(nid));
344 s += snprintf(s, tmpstr + tmpsiz - s,
345 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
346 nrefs, nrtrrefs, alive_cnt,
347 alive ? "up" : "down", last_ping,
349 cfs_duration_sec(cfs_time_sub(deadline, now)),
350 down_ni, libcfs_nid2str(nid));
351 LASSERT (tmpstr + tmpsiz - s > 0);
357 len = s - tmpstr; /* how many bytes was written */
359 if (len > *lenp) { /* linux-supplied buffer is too small */
361 } else if (len > 0) { /* wrote something */
362 if (cfs_copy_to_user(buffer, tmpstr, len))
366 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
370 LIBCFS_FREE(tmpstr, tmpsiz);
378 int LL_PROC_PROTO(proc_lnet_peers)
383 const int tmpsiz = 256;
389 DECLARE_LL_PROC_PPOS_DECL;
391 idx = LNET_PHASH_IDX_GET(*ppos);
392 num = LNET_PHASH_NUM_GET(*ppos);
393 ver = LNET_VERSION_GET(*ppos);
395 CLASSERT ((1ULL << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE);
402 LIBCFS_ALLOC(tmpstr, tmpsiz);
406 s = tmpstr; /* points to current position in tmpstr[] */
409 s += snprintf(s, tmpstr + tmpsiz - s,
410 "%-24s %4s %5s %5s %5s %5s %5s %5s %s\n",
411 "nid", "refs", "state", "max",
412 "rtr", "min", "tx", "min", "queue");
413 LASSERT (tmpstr + tmpsiz - s > 0);
416 ver = (unsigned int)the_lnet.ln_peertable_version;
418 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
422 cfs_list_t *p = NULL;
423 lnet_peer_t *peer = NULL;
428 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) {
430 LIBCFS_FREE(tmpstr, tmpsiz);
434 while (idx < LNET_PEER_HASHSIZE) {
436 p = the_lnet.ln_peer_hash[idx].next;
438 while (p != &the_lnet.ln_peer_hash[idx]) {
439 lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
444 /* minor optimiztion: start from idx+1
445 * on next iteration if we've just
446 * drained lp_hashlist */
447 if (lp->lp_hashlist.next ==
448 &the_lnet.ln_peer_hash[idx]) {
459 p = lp->lp_hashlist.next;
471 lnet_nid_t nid = peer->lp_nid;
472 int nrefs = peer->lp_refcount;
473 char *aliveness = "NA";
474 int maxcr = peer->lp_ni->ni_peertxcredits;
475 int txcr = peer->lp_txcredits;
476 int mintxcr = peer->lp_mintxcredits;
477 int rtrcr = peer->lp_rtrcredits;
478 int minrtrcr = peer->lp_minrtrcredits;
479 int txqnob = peer->lp_txqnob;
481 if (lnet_isrouter(peer) ||
482 lnet_peer_aliveness_enabled(peer))
483 aliveness = peer->lp_alive ? "up" : "down";
485 s += snprintf(s, tmpstr + tmpsiz - s,
486 "%-24s %4d %5s %5d %5d %5d %5d %5d %d\n",
487 libcfs_nid2str(nid), nrefs, aliveness,
488 maxcr, rtrcr, minrtrcr, txcr,
490 LASSERT (tmpstr + tmpsiz - s > 0);
496 len = s - tmpstr; /* how many bytes was written */
498 if (len > *lenp) { /* linux-supplied buffer is too small */
500 } else if (len > 0) { /* wrote something */
501 if (cfs_copy_to_user(buffer, tmpstr, len))
504 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
507 LIBCFS_FREE(tmpstr, tmpsiz);
515 static int __proc_lnet_buffers(void *data, int write,
516 loff_t pos, void *buffer, int nob)
523 const int tmpsiz = 64 * (LNET_NRBPOOLS + 1); /* (4 %d) * 4 */
528 LIBCFS_ALLOC(tmpstr, tmpsiz);
532 s = tmpstr; /* points to current position in tmpstr[] */
534 s += snprintf(s, tmpstr + tmpsiz - s,
536 "pages", "count", "credits", "min");
537 LASSERT (tmpstr + tmpsiz - s > 0);
541 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
542 lnet_rtrbufpool_t *rbp = &the_lnet.ln_rtrpools[idx];
544 int npages = rbp->rbp_npages;
545 int nbuf = rbp->rbp_nbuffers;
546 int cr = rbp->rbp_credits;
547 int mincr = rbp->rbp_mincredits;
549 s += snprintf(s, tmpstr + tmpsiz - s,
551 npages, nbuf, cr, mincr);
552 LASSERT (tmpstr + tmpsiz - s > 0);
559 if (pos >= min_t(int, len, strlen(tmpstr)))
562 rc = cfs_trace_copyout_string(buffer, nob,
565 LIBCFS_FREE(tmpstr, tmpsiz);
569 DECLARE_PROC_HANDLER(proc_lnet_buffers);
571 int LL_PROC_PROTO(proc_lnet_nis)
576 const int tmpsiz = 256;
579 DECLARE_LL_PROC_PPOS_DECL;
586 LIBCFS_ALLOC(tmpstr, tmpsiz);
590 s = tmpstr; /* points to current position in tmpstr[] */
593 s += snprintf(s, tmpstr + tmpsiz - s,
594 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
595 "nid", "status", "alive", "refs", "peer",
596 "rtr", "max", "tx", "min");
597 LASSERT (tmpstr + tmpsiz - s > 0);
600 lnet_ni_t *ni = NULL;
601 int skip = *ppos - 1;
605 n = the_lnet.ln_nis.next;
607 while (n != &the_lnet.ln_nis) {
608 lnet_ni_t *a_ni = cfs_list_entry(n, lnet_ni_t, ni_list);
620 cfs_time_t now = cfs_time_current();
622 int maxtxcr = ni->ni_maxtxcredits;
623 int txcr = ni->ni_txcredits;
624 int mintxcr = ni->ni_mintxcredits;
625 int npeertxcr = ni->ni_peertxcredits;
626 int npeerrtrcr = ni->ni_peerrtrcredits;
627 lnet_nid_t nid = ni->ni_nid;
628 int nref = ni->ni_refcount;
631 if (the_lnet.ln_routing)
632 last_alive = cfs_duration_sec(cfs_time_sub(now,
634 if (ni->ni_lnd->lnd_type == LOLND) /* @lo forever alive */
637 LASSERT (ni->ni_status != NULL);
638 stat = (ni->ni_status->ns_status == LNET_NI_STATUS_UP) ?
641 s += snprintf(s, tmpstr + tmpsiz - s,
642 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
643 libcfs_nid2str(nid), stat, last_alive, nref,
644 npeertxcr, npeerrtrcr, maxtxcr,
646 LASSERT (tmpstr + tmpsiz - s > 0);
652 len = s - tmpstr; /* how many bytes was written */
654 if (len > *lenp) { /* linux-supplied buffer is too small */
656 } else if (len > 0) { /* wrote something */
657 if (cfs_copy_to_user(buffer, tmpstr, len))
663 LIBCFS_FREE(tmpstr, tmpsiz);
671 static cfs_sysctl_table_t lnet_table[] = {
673 * NB No .strategy entries have been provided since sysctl(8) prefers
674 * to go via /proc for portability.
677 .ctl_name = PSDEV_LNET_STATS,
680 .proc_handler = &proc_lnet_stats,
683 .ctl_name = PSDEV_LNET_ROUTES,
684 .procname = "routes",
686 .proc_handler = &proc_lnet_routes,
689 .ctl_name = PSDEV_LNET_ROUTERS,
690 .procname = "routers",
692 .proc_handler = &proc_lnet_routers,
695 .ctl_name = PSDEV_LNET_PEERS,
698 .proc_handler = &proc_lnet_peers,
701 .ctl_name = PSDEV_LNET_PEERS,
702 .procname = "buffers",
704 .proc_handler = &proc_lnet_buffers,
707 .ctl_name = PSDEV_LNET_NIS,
710 .proc_handler = &proc_lnet_nis,
715 static cfs_sysctl_table_t top_table[] = {
717 .ctl_name = CTL_LNET,
733 if (lnet_table_header == NULL)
734 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
742 if (lnet_table_header != NULL)
743 cfs_unregister_sysctl_table(lnet_table_header);
745 lnet_table_header = NULL;