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. You might need to update sanity test 215
31 * if any file format is changed. */
33 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
35 #ifndef HAVE_SYSCTL_UNNUMBERED
36 #define CTL_LNET (0x100)
38 PSDEV_LNET_STATS = 100,
46 #define CTL_LNET CTL_UNNUMBERED
47 #define PSDEV_LNET_STATS CTL_UNNUMBERED
48 #define PSDEV_LNET_ROUTES CTL_UNNUMBERED
49 #define PSDEV_LNET_ROUTERS CTL_UNNUMBERED
50 #define PSDEV_LNET_PEERS CTL_UNNUMBERED
51 #define PSDEV_LNET_BUFFERS CTL_UNNUMBERED
52 #define PSDEV_LNET_NIS CTL_UNNUMBERED
56 * NB: we don't use the highest bit of *ppos because it's signed;
57 * next 9 bits is used to stash idx (assuming that
58 * LNET_PEER_HASHSIZE < 512)
60 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
61 #define LNET_VERSION_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
62 #define LNET_PHASH_IDX_BITS 9
63 #define LNET_PHASH_NUM_BITS (LNET_LOFFT_BITS - 1 -\
64 LNET_VERSION_BITS - LNET_PHASH_IDX_BITS)
65 #define LNET_PHASH_BITS (LNET_PHASH_IDX_BITS + LNET_PHASH_NUM_BITS)
67 #define LNET_VERSION_BITMASK ((1ULL << LNET_VERSION_BITS) - 1)
68 #define LNET_PHASH_IDX_BITMASK ((1ULL << LNET_PHASH_IDX_BITS) - 1)
69 #define LNET_PHASH_NUM_BITMASK ((1ULL << LNET_PHASH_NUM_BITS) - 1)
71 #define LNET_VERSION_MASK (LNET_VERSION_BITMASK << LNET_PHASH_BITS)
72 #define LNET_PHASH_IDX_MASK (LNET_PHASH_IDX_BITMASK << LNET_PHASH_NUM_BITS)
73 #define LNET_PHASH_NUM_MASK (LNET_PHASH_NUM_BITMASK)
75 #define LNET_VERSION_GET(pos) (int)(((pos) & LNET_VERSION_MASK) >> \
77 #define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \
79 #define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK)
80 #define LNET_VERSION_VALID_MASK(ver) \
81 (unsigned int)((ver) & \
83 #define LNET_PHASH_POS_MAKE(ver, idx, num) \
84 (((((loff_t)(ver)) & LNET_VERSION_BITMASK) << \
86 ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\
87 LNET_PHASH_NUM_BITS) | \
88 ((num) & LNET_PHASH_NUM_BITMASK))
90 static int __proc_lnet_stats(void *data, int write,
91 loff_t pos, void *buffer, int nob)
94 lnet_counters_t *ctrs;
97 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
101 memset(&the_lnet.ln_counters, 0, sizeof(the_lnet.ln_counters));
108 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
112 LIBCFS_ALLOC(tmpstr, tmpsiz);
113 if (tmpstr == NULL) {
114 LIBCFS_FREE(ctrs, sizeof(*ctrs));
119 *ctrs = the_lnet.ln_counters;
122 len = snprintf(tmpstr, tmpsiz,
123 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
125 ctrs->msgs_alloc, ctrs->msgs_max,
127 ctrs->send_count, ctrs->recv_count,
128 ctrs->route_count, ctrs->drop_count,
129 ctrs->send_length, ctrs->recv_length,
130 ctrs->route_length, ctrs->drop_length);
132 if (pos >= min_t(int, len, strlen(tmpstr)))
135 rc = cfs_trace_copyout_string(buffer, nob,
138 LIBCFS_FREE(tmpstr, tmpsiz);
139 LIBCFS_FREE(ctrs, sizeof(*ctrs));
143 DECLARE_PROC_HANDLER(proc_lnet_stats);
145 int LL_PROC_PROTO(proc_lnet_routes)
150 const int tmpsiz = 256;
155 DECLARE_LL_PROC_PPOS_DECL;
157 num = LNET_PHASH_NUM_GET(*ppos);
158 ver = LNET_VERSION_GET(*ppos);
165 LIBCFS_ALLOC(tmpstr, tmpsiz);
169 s = tmpstr; /* points to current position in tmpstr[] */
172 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
173 the_lnet.ln_routing ? "enabled" : "disabled");
174 LASSERT (tmpstr + tmpsiz - s > 0);
176 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %7s %s\n",
177 "net", "hops", "state", "router");
178 LASSERT (tmpstr + tmpsiz - s > 0);
181 ver = (unsigned int)the_lnet.ln_remote_nets_version;
183 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
187 lnet_route_t *route = NULL;
188 lnet_remotenet_t *rnet = NULL;
193 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) {
195 LIBCFS_FREE(tmpstr, tmpsiz);
199 n = the_lnet.ln_remote_nets.next;
201 while (n != &the_lnet.ln_remote_nets && route == NULL) {
202 rnet = cfs_list_entry(n, lnet_remotenet_t, lrn_list);
204 r = rnet->lrn_routes.next;
206 while (r != &rnet->lrn_routes) {
208 cfs_list_entry(r, lnet_route_t,
223 __u32 net = rnet->lrn_net;
224 unsigned int hops = route->lr_hops;
225 lnet_nid_t nid = route->lr_gateway->lp_nid;
226 int alive = route->lr_gateway->lp_alive;
228 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4u %7s %s\n",
229 libcfs_net2str(net), hops,
230 alive ? "up" : "down", libcfs_nid2str(nid));
231 LASSERT (tmpstr + tmpsiz - s > 0);
237 len = s - tmpstr; /* how many bytes was written */
239 if (len > *lenp) { /* linux-supplied buffer is too small */
241 } else if (len > 0) { /* wrote something */
242 if (cfs_copy_to_user(buffer, tmpstr, len))
246 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
250 LIBCFS_FREE(tmpstr, tmpsiz);
258 int LL_PROC_PROTO(proc_lnet_routers)
263 const int tmpsiz = 256;
268 DECLARE_LL_PROC_PPOS_DECL;
270 num = LNET_PHASH_NUM_GET(*ppos);
271 ver = LNET_VERSION_GET(*ppos);
278 LIBCFS_ALLOC(tmpstr, tmpsiz);
282 s = tmpstr; /* points to current position in tmpstr[] */
285 s += snprintf(s, tmpstr + tmpsiz - s,
286 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
287 "ref", "rtr_ref", "alive_cnt", "state", "last_ping",
288 "ping_sent", "deadline", "down_ni", "router");
289 LASSERT (tmpstr + tmpsiz - s > 0);
292 ver = (unsigned int)the_lnet.ln_routers_version;
294 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
297 lnet_peer_t *peer = NULL;
302 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_routers_version)) {
304 LIBCFS_FREE(tmpstr, tmpsiz);
308 r = the_lnet.ln_routers.next;
310 while (r != &the_lnet.ln_routers) {
311 lnet_peer_t *lp = cfs_list_entry(r, lnet_peer_t,
324 lnet_nid_t nid = peer->lp_nid;
325 cfs_time_t now = cfs_time_current();
326 cfs_time_t deadline = peer->lp_ping_deadline;
327 int nrefs = peer->lp_refcount;
328 int nrtrrefs = peer->lp_rtr_refcount;
329 int alive_cnt = peer->lp_alive_count;
330 int alive = peer->lp_alive;
331 int pingsent = !peer->lp_ping_notsent;
332 int last_ping = cfs_duration_sec(cfs_time_sub(now,
333 peer->lp_ping_timestamp));
334 int down_ni = lnet_router_down_ni(peer,
335 LNET_NIDNET(LNET_NID_ANY));
338 s += snprintf(s, tmpstr + tmpsiz - s,
339 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
340 nrefs, nrtrrefs, alive_cnt,
341 alive ? "up" : "down", last_ping,
342 pingsent, "NA", down_ni,
343 libcfs_nid2str(nid));
345 s += snprintf(s, tmpstr + tmpsiz - s,
346 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
347 nrefs, nrtrrefs, alive_cnt,
348 alive ? "up" : "down", last_ping,
350 cfs_duration_sec(cfs_time_sub(deadline, now)),
351 down_ni, libcfs_nid2str(nid));
352 LASSERT (tmpstr + tmpsiz - s > 0);
358 len = s - tmpstr; /* how many bytes was written */
360 if (len > *lenp) { /* linux-supplied buffer is too small */
362 } else if (len > 0) { /* wrote something */
363 if (cfs_copy_to_user(buffer, tmpstr, len))
367 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
371 LIBCFS_FREE(tmpstr, tmpsiz);
379 int LL_PROC_PROTO(proc_lnet_peers)
384 const int tmpsiz = 256;
390 DECLARE_LL_PROC_PPOS_DECL;
392 idx = LNET_PHASH_IDX_GET(*ppos);
393 num = LNET_PHASH_NUM_GET(*ppos);
394 ver = LNET_VERSION_GET(*ppos);
396 CLASSERT ((1ULL << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE);
403 LIBCFS_ALLOC(tmpstr, tmpsiz);
407 s = tmpstr; /* points to current position in tmpstr[] */
410 s += snprintf(s, tmpstr + tmpsiz - s,
411 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
412 "nid", "refs", "state", "last", "max",
413 "rtr", "min", "tx", "min", "queue");
414 LASSERT (tmpstr + tmpsiz - s > 0);
417 ver = (unsigned int)the_lnet.ln_peertable_version;
419 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
423 cfs_list_t *p = NULL;
424 lnet_peer_t *peer = NULL;
429 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) {
431 LIBCFS_FREE(tmpstr, tmpsiz);
435 while (idx < LNET_PEER_HASHSIZE) {
437 p = the_lnet.ln_peer_hash[idx].next;
439 while (p != &the_lnet.ln_peer_hash[idx]) {
440 lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
445 /* minor optimization: start from idx+1
446 * on next iteration if we've just
447 * drained lp_hashlist */
448 if (lp->lp_hashlist.next ==
449 &the_lnet.ln_peer_hash[idx]) {
460 p = lp->lp_hashlist.next;
472 lnet_nid_t nid = peer->lp_nid;
473 int nrefs = peer->lp_refcount;
475 char *aliveness = "NA";
476 int maxcr = peer->lp_ni->ni_peertxcredits;
477 int txcr = peer->lp_txcredits;
478 int mintxcr = peer->lp_mintxcredits;
479 int rtrcr = peer->lp_rtrcredits;
480 int minrtrcr = peer->lp_minrtrcredits;
481 int txqnob = peer->lp_txqnob;
483 if (lnet_isrouter(peer) ||
484 lnet_peer_aliveness_enabled(peer))
485 aliveness = peer->lp_alive ? "up" : "down";
487 if (lnet_peer_aliveness_enabled(peer)) {
488 cfs_time_t now = cfs_time_current();
489 cfs_duration_t delta;
491 delta = cfs_time_sub(now, peer->lp_last_alive);
492 lastalive = cfs_duration_sec(delta);
494 /* No need to mess up peers contents with
495 * arbitrarily long integers - it suffices to
496 * know that lastalive is more than 10000s old
498 if (lastalive >= 10000)
502 s += snprintf(s, tmpstr + tmpsiz - s,
503 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
504 libcfs_nid2str(nid), nrefs, aliveness,
505 lastalive, maxcr, rtrcr, minrtrcr, txcr,
507 LASSERT (tmpstr + tmpsiz - s > 0);
513 len = s - tmpstr; /* how many bytes was written */
515 if (len > *lenp) { /* linux-supplied buffer is too small */
517 } else if (len > 0) { /* wrote something */
518 if (cfs_copy_to_user(buffer, tmpstr, len))
521 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
524 LIBCFS_FREE(tmpstr, tmpsiz);
532 static int __proc_lnet_buffers(void *data, int write,
533 loff_t pos, void *buffer, int nob)
540 const int tmpsiz = 64 * (LNET_NRBPOOLS + 1); /* (4 %d) * 4 */
545 LIBCFS_ALLOC(tmpstr, tmpsiz);
549 s = tmpstr; /* points to current position in tmpstr[] */
551 s += snprintf(s, tmpstr + tmpsiz - s,
553 "pages", "count", "credits", "min");
554 LASSERT (tmpstr + tmpsiz - s > 0);
558 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
559 lnet_rtrbufpool_t *rbp = &the_lnet.ln_rtrpools[idx];
561 int npages = rbp->rbp_npages;
562 int nbuf = rbp->rbp_nbuffers;
563 int cr = rbp->rbp_credits;
564 int mincr = rbp->rbp_mincredits;
566 s += snprintf(s, tmpstr + tmpsiz - s,
568 npages, nbuf, cr, mincr);
569 LASSERT (tmpstr + tmpsiz - s > 0);
576 if (pos >= min_t(int, len, strlen(tmpstr)))
579 rc = cfs_trace_copyout_string(buffer, nob,
582 LIBCFS_FREE(tmpstr, tmpsiz);
586 DECLARE_PROC_HANDLER(proc_lnet_buffers);
588 int LL_PROC_PROTO(proc_lnet_nis)
593 const int tmpsiz = 256;
596 DECLARE_LL_PROC_PPOS_DECL;
603 LIBCFS_ALLOC(tmpstr, tmpsiz);
607 s = tmpstr; /* points to current position in tmpstr[] */
610 s += snprintf(s, tmpstr + tmpsiz - s,
611 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
612 "nid", "status", "alive", "refs", "peer",
613 "rtr", "max", "tx", "min");
614 LASSERT (tmpstr + tmpsiz - s > 0);
617 lnet_ni_t *ni = NULL;
618 int skip = *ppos - 1;
622 n = the_lnet.ln_nis.next;
624 while (n != &the_lnet.ln_nis) {
625 lnet_ni_t *a_ni = cfs_list_entry(n, lnet_ni_t, ni_list);
637 cfs_time_t now = cfs_time_current();
639 int maxtxcr = ni->ni_maxtxcredits;
640 int txcr = ni->ni_txcredits;
641 int mintxcr = ni->ni_mintxcredits;
642 int npeertxcr = ni->ni_peertxcredits;
643 int npeerrtrcr = ni->ni_peerrtrcredits;
644 lnet_nid_t nid = ni->ni_nid;
645 int nref = ni->ni_refcount;
648 if (the_lnet.ln_routing)
649 last_alive = cfs_duration_sec(cfs_time_sub(now,
651 if (ni->ni_lnd->lnd_type == LOLND) /* @lo forever alive */
654 LASSERT (ni->ni_status != NULL);
655 stat = (ni->ni_status->ns_status == LNET_NI_STATUS_UP) ?
658 s += snprintf(s, tmpstr + tmpsiz - s,
659 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
660 libcfs_nid2str(nid), stat, last_alive, nref,
661 npeertxcr, npeerrtrcr, maxtxcr,
663 LASSERT (tmpstr + tmpsiz - s > 0);
669 len = s - tmpstr; /* how many bytes was written */
671 if (len > *lenp) { /* linux-supplied buffer is too small */
673 } else if (len > 0) { /* wrote something */
674 if (cfs_copy_to_user(buffer, tmpstr, len))
680 LIBCFS_FREE(tmpstr, tmpsiz);
688 static cfs_sysctl_table_t lnet_table[] = {
690 * NB No .strategy entries have been provided since sysctl(8) prefers
691 * to go via /proc for portability.
694 INIT_CTL_NAME(PSDEV_LNET_STATS)
697 .proc_handler = &proc_lnet_stats,
700 INIT_CTL_NAME(PSDEV_LNET_ROUTES)
701 .procname = "routes",
703 .proc_handler = &proc_lnet_routes,
706 INIT_CTL_NAME(PSDEV_LNET_ROUTERS)
707 .procname = "routers",
709 .proc_handler = &proc_lnet_routers,
712 INIT_CTL_NAME(PSDEV_LNET_PEERS)
715 .proc_handler = &proc_lnet_peers,
718 INIT_CTL_NAME(PSDEV_LNET_PEERS)
719 .procname = "buffers",
721 .proc_handler = &proc_lnet_buffers,
724 INIT_CTL_NAME(PSDEV_LNET_NIS)
727 .proc_handler = &proc_lnet_nis,
734 static cfs_sysctl_table_t top_table[] = {
736 INIT_CTL_NAME(CTL_LNET)
752 if (lnet_table_header == NULL)
753 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
761 if (lnet_table_header != NULL)
762 cfs_unregister_sysctl_table(lnet_table_header);
764 lnet_table_header = NULL;