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 * Copyright (c) 2011, Whamcloud, Inc.
8 * This file is part of Portals
9 * http://sourceforge.net/projects/sandiaportals/
11 * Portals is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Portals is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Portals; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DEBUG_SUBSYSTEM S_LNET
27 #include <libcfs/libcfs.h>
28 #include <lnet/lib-lnet.h>
30 #if defined(__KERNEL__) && defined(LNET_ROUTER)
32 /* This is really lnet_proc.c. You might need to update sanity test 215
33 * if any file format is changed. */
35 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
37 #ifndef HAVE_SYSCTL_UNNUMBERED
38 #define CTL_LNET (0x100)
40 PSDEV_LNET_STATS = 100,
48 #define CTL_LNET CTL_UNNUMBERED
49 #define PSDEV_LNET_STATS CTL_UNNUMBERED
50 #define PSDEV_LNET_ROUTES CTL_UNNUMBERED
51 #define PSDEV_LNET_ROUTERS CTL_UNNUMBERED
52 #define PSDEV_LNET_PEERS CTL_UNNUMBERED
53 #define PSDEV_LNET_BUFFERS CTL_UNNUMBERED
54 #define PSDEV_LNET_NIS CTL_UNNUMBERED
58 * NB: we don't use the highest bit of *ppos because it's signed;
59 * next 9 bits is used to stash idx (assuming that
60 * LNET_PEER_HASHSIZE < 512)
62 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
63 #define LNET_VERSION_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
64 #define LNET_PHASH_IDX_BITS 9
65 #define LNET_PHASH_NUM_BITS (LNET_LOFFT_BITS - 1 -\
66 LNET_VERSION_BITS - LNET_PHASH_IDX_BITS)
67 #define LNET_PHASH_BITS (LNET_PHASH_IDX_BITS + LNET_PHASH_NUM_BITS)
69 #define LNET_VERSION_BITMASK ((1ULL << LNET_VERSION_BITS) - 1)
70 #define LNET_PHASH_IDX_BITMASK ((1ULL << LNET_PHASH_IDX_BITS) - 1)
71 #define LNET_PHASH_NUM_BITMASK ((1ULL << LNET_PHASH_NUM_BITS) - 1)
73 #define LNET_VERSION_MASK (LNET_VERSION_BITMASK << LNET_PHASH_BITS)
74 #define LNET_PHASH_IDX_MASK (LNET_PHASH_IDX_BITMASK << LNET_PHASH_NUM_BITS)
75 #define LNET_PHASH_NUM_MASK (LNET_PHASH_NUM_BITMASK)
77 #define LNET_VERSION_GET(pos) (int)(((pos) & LNET_VERSION_MASK) >> \
79 #define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \
81 #define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK)
82 #define LNET_VERSION_VALID_MASK(ver) \
83 (unsigned int)((ver) & \
85 #define LNET_PHASH_POS_MAKE(ver, idx, num) \
86 (((((loff_t)(ver)) & LNET_VERSION_BITMASK) << \
88 ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\
89 LNET_PHASH_NUM_BITS) | \
90 ((num) & LNET_PHASH_NUM_BITMASK))
92 static int __proc_lnet_stats(void *data, int write,
93 loff_t pos, void *buffer, int nob)
96 lnet_counters_t *ctrs;
99 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
103 memset(&the_lnet.ln_counters, 0, sizeof(the_lnet.ln_counters));
110 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
114 LIBCFS_ALLOC(tmpstr, tmpsiz);
115 if (tmpstr == NULL) {
116 LIBCFS_FREE(ctrs, sizeof(*ctrs));
121 *ctrs = the_lnet.ln_counters;
124 len = snprintf(tmpstr, tmpsiz,
125 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
127 ctrs->msgs_alloc, ctrs->msgs_max,
129 ctrs->send_count, ctrs->recv_count,
130 ctrs->route_count, ctrs->drop_count,
131 ctrs->send_length, ctrs->recv_length,
132 ctrs->route_length, ctrs->drop_length);
134 if (pos >= min_t(int, len, strlen(tmpstr)))
137 rc = cfs_trace_copyout_string(buffer, nob,
140 LIBCFS_FREE(tmpstr, tmpsiz);
141 LIBCFS_FREE(ctrs, sizeof(*ctrs));
145 DECLARE_PROC_HANDLER(proc_lnet_stats);
147 int LL_PROC_PROTO(proc_lnet_routes)
152 const int tmpsiz = 256;
157 DECLARE_LL_PROC_PPOS_DECL;
159 num = LNET_PHASH_NUM_GET(*ppos);
160 ver = LNET_VERSION_GET(*ppos);
167 LIBCFS_ALLOC(tmpstr, tmpsiz);
171 s = tmpstr; /* points to current position in tmpstr[] */
174 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
175 the_lnet.ln_routing ? "enabled" : "disabled");
176 LASSERT (tmpstr + tmpsiz - s > 0);
178 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %7s %s\n",
179 "net", "hops", "state", "router");
180 LASSERT (tmpstr + tmpsiz - s > 0);
183 ver = (unsigned int)the_lnet.ln_remote_nets_version;
185 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
189 lnet_route_t *route = NULL;
190 lnet_remotenet_t *rnet = NULL;
195 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) {
197 LIBCFS_FREE(tmpstr, tmpsiz);
201 n = the_lnet.ln_remote_nets.next;
203 while (n != &the_lnet.ln_remote_nets && route == NULL) {
204 rnet = cfs_list_entry(n, lnet_remotenet_t, lrn_list);
206 r = rnet->lrn_routes.next;
208 while (r != &rnet->lrn_routes) {
210 cfs_list_entry(r, lnet_route_t,
225 __u32 net = rnet->lrn_net;
226 unsigned int hops = route->lr_hops;
227 lnet_nid_t nid = route->lr_gateway->lp_nid;
228 int alive = route->lr_gateway->lp_alive;
230 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4u %7s %s\n",
231 libcfs_net2str(net), hops,
232 alive ? "up" : "down", libcfs_nid2str(nid));
233 LASSERT (tmpstr + tmpsiz - s > 0);
239 len = s - tmpstr; /* how many bytes was written */
241 if (len > *lenp) { /* linux-supplied buffer is too small */
243 } else if (len > 0) { /* wrote something */
244 if (cfs_copy_to_user(buffer, tmpstr, len))
248 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
252 LIBCFS_FREE(tmpstr, tmpsiz);
260 int LL_PROC_PROTO(proc_lnet_routers)
265 const int tmpsiz = 256;
270 DECLARE_LL_PROC_PPOS_DECL;
272 num = LNET_PHASH_NUM_GET(*ppos);
273 ver = LNET_VERSION_GET(*ppos);
280 LIBCFS_ALLOC(tmpstr, tmpsiz);
284 s = tmpstr; /* points to current position in tmpstr[] */
287 s += snprintf(s, tmpstr + tmpsiz - s,
288 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
289 "ref", "rtr_ref", "alive_cnt", "state", "last_ping",
290 "ping_sent", "deadline", "down_ni", "router");
291 LASSERT (tmpstr + tmpsiz - s > 0);
294 ver = (unsigned int)the_lnet.ln_routers_version;
296 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
299 lnet_peer_t *peer = NULL;
304 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_routers_version)) {
306 LIBCFS_FREE(tmpstr, tmpsiz);
310 r = the_lnet.ln_routers.next;
312 while (r != &the_lnet.ln_routers) {
313 lnet_peer_t *lp = cfs_list_entry(r, lnet_peer_t,
326 lnet_nid_t nid = peer->lp_nid;
327 cfs_time_t now = cfs_time_current();
328 cfs_time_t deadline = peer->lp_ping_deadline;
329 int nrefs = peer->lp_refcount;
330 int nrtrrefs = peer->lp_rtr_refcount;
331 int alive_cnt = peer->lp_alive_count;
332 int alive = peer->lp_alive;
333 int pingsent = !peer->lp_ping_notsent;
334 int last_ping = cfs_duration_sec(cfs_time_sub(now,
335 peer->lp_ping_timestamp));
336 int down_ni = lnet_router_down_ni(peer,
337 LNET_NIDNET(LNET_NID_ANY));
340 s += snprintf(s, tmpstr + tmpsiz - s,
341 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
342 nrefs, nrtrrefs, alive_cnt,
343 alive ? "up" : "down", last_ping,
344 pingsent, "NA", down_ni,
345 libcfs_nid2str(nid));
347 s += snprintf(s, tmpstr + tmpsiz - s,
348 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
349 nrefs, nrtrrefs, alive_cnt,
350 alive ? "up" : "down", last_ping,
352 cfs_duration_sec(cfs_time_sub(deadline, now)),
353 down_ni, libcfs_nid2str(nid));
354 LASSERT (tmpstr + tmpsiz - s > 0);
360 len = s - tmpstr; /* how many bytes was written */
362 if (len > *lenp) { /* linux-supplied buffer is too small */
364 } else if (len > 0) { /* wrote something */
365 if (cfs_copy_to_user(buffer, tmpstr, len))
369 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
373 LIBCFS_FREE(tmpstr, tmpsiz);
381 int LL_PROC_PROTO(proc_lnet_peers)
386 const int tmpsiz = 256;
392 DECLARE_LL_PROC_PPOS_DECL;
394 idx = LNET_PHASH_IDX_GET(*ppos);
395 num = LNET_PHASH_NUM_GET(*ppos);
396 ver = LNET_VERSION_GET(*ppos);
398 CLASSERT ((1ULL << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE);
405 LIBCFS_ALLOC(tmpstr, tmpsiz);
409 s = tmpstr; /* points to current position in tmpstr[] */
412 s += snprintf(s, tmpstr + tmpsiz - s,
413 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
414 "nid", "refs", "state", "last", "max",
415 "rtr", "min", "tx", "min", "queue");
416 LASSERT (tmpstr + tmpsiz - s > 0);
419 ver = (unsigned int)the_lnet.ln_peertable_version;
421 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
425 cfs_list_t *p = NULL;
426 lnet_peer_t *peer = NULL;
431 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) {
433 LIBCFS_FREE(tmpstr, tmpsiz);
437 while (idx < LNET_PEER_HASHSIZE) {
439 p = the_lnet.ln_peer_hash[idx].next;
441 while (p != &the_lnet.ln_peer_hash[idx]) {
442 lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
447 /* minor optimization: start from idx+1
448 * on next iteration if we've just
449 * drained lp_hashlist */
450 if (lp->lp_hashlist.next ==
451 &the_lnet.ln_peer_hash[idx]) {
462 p = lp->lp_hashlist.next;
474 lnet_nid_t nid = peer->lp_nid;
475 int nrefs = peer->lp_refcount;
477 char *aliveness = "NA";
478 int maxcr = peer->lp_ni->ni_peertxcredits;
479 int txcr = peer->lp_txcredits;
480 int mintxcr = peer->lp_mintxcredits;
481 int rtrcr = peer->lp_rtrcredits;
482 int minrtrcr = peer->lp_minrtrcredits;
483 int txqnob = peer->lp_txqnob;
485 if (lnet_isrouter(peer) ||
486 lnet_peer_aliveness_enabled(peer))
487 aliveness = peer->lp_alive ? "up" : "down";
489 if (lnet_peer_aliveness_enabled(peer)) {
490 cfs_time_t now = cfs_time_current();
491 cfs_duration_t delta;
493 delta = cfs_time_sub(now, peer->lp_last_alive);
494 lastalive = cfs_duration_sec(delta);
496 /* No need to mess up peers contents with
497 * arbitrarily long integers - it suffices to
498 * know that lastalive is more than 10000s old
500 if (lastalive >= 10000)
504 s += snprintf(s, tmpstr + tmpsiz - s,
505 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
506 libcfs_nid2str(nid), nrefs, aliveness,
507 lastalive, maxcr, rtrcr, minrtrcr, txcr,
509 LASSERT (tmpstr + tmpsiz - s > 0);
515 len = s - tmpstr; /* how many bytes was written */
517 if (len > *lenp) { /* linux-supplied buffer is too small */
519 } else if (len > 0) { /* wrote something */
520 if (cfs_copy_to_user(buffer, tmpstr, len))
523 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
526 LIBCFS_FREE(tmpstr, tmpsiz);
534 static int __proc_lnet_buffers(void *data, int write,
535 loff_t pos, void *buffer, int nob)
542 const int tmpsiz = 64 * (LNET_NRBPOOLS + 1); /* (4 %d) * 4 */
547 LIBCFS_ALLOC(tmpstr, tmpsiz);
551 s = tmpstr; /* points to current position in tmpstr[] */
553 s += snprintf(s, tmpstr + tmpsiz - s,
555 "pages", "count", "credits", "min");
556 LASSERT (tmpstr + tmpsiz - s > 0);
560 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
561 lnet_rtrbufpool_t *rbp = &the_lnet.ln_rtrpools[idx];
563 int npages = rbp->rbp_npages;
564 int nbuf = rbp->rbp_nbuffers;
565 int cr = rbp->rbp_credits;
566 int mincr = rbp->rbp_mincredits;
568 s += snprintf(s, tmpstr + tmpsiz - s,
570 npages, nbuf, cr, mincr);
571 LASSERT (tmpstr + tmpsiz - s > 0);
578 if (pos >= min_t(int, len, strlen(tmpstr)))
581 rc = cfs_trace_copyout_string(buffer, nob,
584 LIBCFS_FREE(tmpstr, tmpsiz);
588 DECLARE_PROC_HANDLER(proc_lnet_buffers);
590 int LL_PROC_PROTO(proc_lnet_nis)
595 const int tmpsiz = 256;
598 DECLARE_LL_PROC_PPOS_DECL;
605 LIBCFS_ALLOC(tmpstr, tmpsiz);
609 s = tmpstr; /* points to current position in tmpstr[] */
612 s += snprintf(s, tmpstr + tmpsiz - s,
613 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
614 "nid", "status", "alive", "refs", "peer",
615 "rtr", "max", "tx", "min");
616 LASSERT (tmpstr + tmpsiz - s > 0);
619 lnet_ni_t *ni = NULL;
620 int skip = *ppos - 1;
624 n = the_lnet.ln_nis.next;
626 while (n != &the_lnet.ln_nis) {
627 lnet_ni_t *a_ni = cfs_list_entry(n, lnet_ni_t, ni_list);
639 cfs_time_t now = cfs_time_current();
641 int maxtxcr = ni->ni_maxtxcredits;
642 int txcr = ni->ni_txcredits;
643 int mintxcr = ni->ni_mintxcredits;
644 int npeertxcr = ni->ni_peertxcredits;
645 int npeerrtrcr = ni->ni_peerrtrcredits;
646 lnet_nid_t nid = ni->ni_nid;
647 int nref = ni->ni_refcount;
650 if (the_lnet.ln_routing)
651 last_alive = cfs_duration_sec(cfs_time_sub(now,
653 if (ni->ni_lnd->lnd_type == LOLND) /* @lo forever alive */
656 LASSERT (ni->ni_status != NULL);
657 stat = (ni->ni_status->ns_status == LNET_NI_STATUS_UP) ?
660 s += snprintf(s, tmpstr + tmpsiz - s,
661 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
662 libcfs_nid2str(nid), stat, last_alive, nref,
663 npeertxcr, npeerrtrcr, maxtxcr,
665 LASSERT (tmpstr + tmpsiz - s > 0);
671 len = s - tmpstr; /* how many bytes was written */
673 if (len > *lenp) { /* linux-supplied buffer is too small */
675 } else if (len > 0) { /* wrote something */
676 if (cfs_copy_to_user(buffer, tmpstr, len))
682 LIBCFS_FREE(tmpstr, tmpsiz);
690 static cfs_sysctl_table_t lnet_table[] = {
692 * NB No .strategy entries have been provided since sysctl(8) prefers
693 * to go via /proc for portability.
696 INIT_CTL_NAME(PSDEV_LNET_STATS)
699 .proc_handler = &proc_lnet_stats,
702 INIT_CTL_NAME(PSDEV_LNET_ROUTES)
703 .procname = "routes",
705 .proc_handler = &proc_lnet_routes,
708 INIT_CTL_NAME(PSDEV_LNET_ROUTERS)
709 .procname = "routers",
711 .proc_handler = &proc_lnet_routers,
714 INIT_CTL_NAME(PSDEV_LNET_PEERS)
717 .proc_handler = &proc_lnet_peers,
720 INIT_CTL_NAME(PSDEV_LNET_PEERS)
721 .procname = "buffers",
723 .proc_handler = &proc_lnet_buffers,
726 INIT_CTL_NAME(PSDEV_LNET_NIS)
729 .proc_handler = &proc_lnet_nis,
736 static cfs_sysctl_table_t top_table[] = {
738 INIT_CTL_NAME(CTL_LNET)
754 if (lnet_table_header == NULL)
755 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
763 if (lnet_table_header != NULL)
764 cfs_unregister_sysctl_table(lnet_table_header);
766 lnet_table_header = NULL;