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) & LNET_VERSION_BITMASK))
81 #define LNET_PHASH_POS_MAKE(ver, idx, num) \
82 (((((loff_t)(ver)) & LNET_VERSION_BITMASK) << \
84 ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\
85 LNET_PHASH_NUM_BITS) | \
86 ((num) & LNET_PHASH_NUM_BITMASK))
88 static int __proc_lnet_stats(void *data, int write,
89 loff_t pos, void *buffer, int nob)
92 lnet_counters_t *ctrs;
95 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
99 memset(&the_lnet.ln_counters, 0, sizeof(the_lnet.ln_counters));
106 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
110 LIBCFS_ALLOC(tmpstr, tmpsiz);
111 if (tmpstr == NULL) {
112 LIBCFS_FREE(ctrs, sizeof(*ctrs));
117 *ctrs = the_lnet.ln_counters;
120 len = snprintf(tmpstr, tmpsiz,
121 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
123 ctrs->msgs_alloc, ctrs->msgs_max,
125 ctrs->send_count, ctrs->recv_count,
126 ctrs->route_count, ctrs->drop_count,
127 ctrs->send_length, ctrs->recv_length,
128 ctrs->route_length, ctrs->drop_length);
130 if (pos >= min_t(int, len, strlen(tmpstr)))
133 rc = trace_copyout_string(buffer, nob,
136 LIBCFS_FREE(tmpstr, tmpsiz);
137 LIBCFS_FREE(ctrs, sizeof(*ctrs));
141 DECLARE_PROC_HANDLER(proc_lnet_stats);
143 int LL_PROC_PROTO(proc_lnet_routes)
148 const int tmpsiz = 256;
153 DECLARE_LL_PROC_PPOS_DECL;
155 num = LNET_PHASH_NUM_GET(*ppos);
156 ver = LNET_VERSION_GET(*ppos);
163 LIBCFS_ALLOC(tmpstr, tmpsiz);
167 s = tmpstr; /* points to current position in tmpstr[] */
170 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
171 the_lnet.ln_routing ? "enabled" : "disabled");
172 LASSERT (tmpstr + tmpsiz - s > 0);
174 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %7s %s\n",
175 "net", "hops", "state", "router");
176 LASSERT (tmpstr + tmpsiz - s > 0);
179 ver = (unsigned int)the_lnet.ln_remote_nets_version;
181 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
185 lnet_route_t *route = NULL;
186 lnet_remotenet_t *rnet = NULL;
191 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) {
193 LIBCFS_FREE(tmpstr, tmpsiz);
197 n = the_lnet.ln_remote_nets.next;
199 while (n != &the_lnet.ln_remote_nets && route == NULL) {
200 rnet = list_entry(n, lnet_remotenet_t, lrn_list);
202 r = rnet->lrn_routes.next;
204 while (r != &rnet->lrn_routes) {
205 lnet_route_t *re = list_entry(r, lnet_route_t,
220 __u32 net = rnet->lrn_net;
221 unsigned int hops = route->lr_hops;
222 lnet_nid_t nid = route->lr_gateway->lp_nid;
223 int alive = route->lr_gateway->lp_alive;
225 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4u %7s %s\n",
226 libcfs_net2str(net), hops,
227 alive ? "up" : "down", libcfs_nid2str(nid));
228 LASSERT (tmpstr + tmpsiz - s > 0);
234 len = s - tmpstr; /* how many bytes was written */
236 if (len > *lenp) { /* linux-supplied buffer is too small */
238 } else if (len > 0) { /* wrote something */
239 if (copy_to_user(buffer, tmpstr, len))
243 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
247 LIBCFS_FREE(tmpstr, tmpsiz);
255 int LL_PROC_PROTO(proc_lnet_routers)
260 const int tmpsiz = 256;
265 DECLARE_LL_PROC_PPOS_DECL;
267 num = LNET_PHASH_NUM_GET(*ppos);
268 ver = LNET_VERSION_GET(*ppos);
275 LIBCFS_ALLOC(tmpstr, tmpsiz);
279 s = tmpstr; /* points to current position in tmpstr[] */
282 s += snprintf(s, tmpstr + tmpsiz - s,
283 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
284 "ref", "rtr_ref", "alive_cnt", "state", "last_ping",
285 "ping_sent", "deadline", "down_ni", "router");
286 LASSERT (tmpstr + tmpsiz - s > 0);
289 ver = (unsigned int)the_lnet.ln_routers_version;
291 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
294 lnet_peer_t *peer = NULL;
299 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_routers_version)) {
301 LIBCFS_FREE(tmpstr, tmpsiz);
305 r = the_lnet.ln_routers.next;
307 while (r != &the_lnet.ln_routers) {
308 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
321 lnet_nid_t nid = peer->lp_nid;
322 cfs_time_t now = cfs_time_current();
323 cfs_time_t deadline = peer->lp_ping_deadline;
324 int nrefs = peer->lp_refcount;
325 int nrtrrefs = peer->lp_rtr_refcount;
326 int alive_cnt = peer->lp_alive_count;
327 int alive = peer->lp_alive;
328 int pingsent = !peer->lp_ping_notsent;
329 int last_ping = cfs_duration_sec(cfs_time_sub(now,
330 peer->lp_ping_timestamp));
331 int down_ni = lnet_router_down_ni(peer,
332 LNET_NIDNET(LNET_NID_ANY));
335 s += snprintf(s, tmpstr + tmpsiz - s,
336 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
337 nrefs, nrtrrefs, alive_cnt,
338 alive ? "up" : "down", last_ping,
339 pingsent, "NA", down_ni,
340 libcfs_nid2str(nid));
342 s += snprintf(s, tmpstr + tmpsiz - s,
343 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
344 nrefs, nrtrrefs, alive_cnt,
345 alive ? "up" : "down", last_ping,
347 cfs_duration_sec(cfs_time_sub(deadline, now)),
348 down_ni, libcfs_nid2str(nid));
349 LASSERT (tmpstr + tmpsiz - s > 0);
355 len = s - tmpstr; /* how many bytes was written */
357 if (len > *lenp) { /* linux-supplied buffer is too small */
359 } else if (len > 0) { /* wrote something */
360 if (copy_to_user(buffer, tmpstr, len))
364 *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
368 LIBCFS_FREE(tmpstr, tmpsiz);
376 int LL_PROC_PROTO(proc_lnet_peers)
381 const int tmpsiz = 256;
387 DECLARE_LL_PROC_PPOS_DECL;
389 idx = LNET_PHASH_IDX_GET(*ppos);
390 num = LNET_PHASH_NUM_GET(*ppos);
391 ver = LNET_VERSION_GET(*ppos);
393 CLASSERT ((1ULL << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE);
400 LIBCFS_ALLOC(tmpstr, tmpsiz);
404 s = tmpstr; /* points to current position in tmpstr[] */
407 s += snprintf(s, tmpstr + tmpsiz - s,
408 "%-24s %4s %5s %5s %5s %5s %5s %5s %s\n",
409 "nid", "refs", "state", "max",
410 "rtr", "min", "tx", "min", "queue");
411 LASSERT (tmpstr + tmpsiz - s > 0);
414 ver = (unsigned int)the_lnet.ln_peertable_version;
416 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
420 struct list_head *p = NULL;
421 lnet_peer_t *peer = NULL;
426 if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) {
428 LIBCFS_FREE(tmpstr, tmpsiz);
432 while (idx < LNET_PEER_HASHSIZE) {
434 p = the_lnet.ln_peer_hash[idx].next;
436 while (p != &the_lnet.ln_peer_hash[idx]) {
437 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
442 /* minor optimiztion: start from idx+1
443 * on next iteration if we've just
444 * drained lp_hashlist */
445 if (lp->lp_hashlist.next ==
446 &the_lnet.ln_peer_hash[idx]) {
457 p = lp->lp_hashlist.next;
469 lnet_nid_t nid = peer->lp_nid;
470 int nrefs = peer->lp_refcount;
471 char *aliveness = "NA";
472 int maxcr = peer->lp_ni->ni_peertxcredits;
473 int txcr = peer->lp_txcredits;
474 int mintxcr = peer->lp_mintxcredits;
475 int rtrcr = peer->lp_rtrcredits;
476 int minrtrcr = peer->lp_minrtrcredits;
477 int txqnob = peer->lp_txqnob;
479 if (lnet_isrouter(peer) ||
480 lnet_peer_aliveness_enabled(peer))
481 aliveness = peer->lp_alive ? "up" : "down";
483 s += snprintf(s, tmpstr + tmpsiz - s,
484 "%-24s %4d %5s %5d %5d %5d %5d %5d %d\n",
485 libcfs_nid2str(nid), nrefs, aliveness,
486 maxcr, rtrcr, minrtrcr, txcr,
488 LASSERT (tmpstr + tmpsiz - s > 0);
494 len = s - tmpstr; /* how many bytes was written */
496 if (len > *lenp) { /* linux-supplied buffer is too small */
498 } else if (len > 0) { /* wrote something */
499 if (copy_to_user(buffer, tmpstr, len))
502 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
505 LIBCFS_FREE(tmpstr, tmpsiz);
513 static int __proc_lnet_buffers(void *data, int write,
514 loff_t pos, void *buffer, int nob)
521 const int tmpsiz = 64 * (LNET_NRBPOOLS + 1); /* (4 %d) * 4 */
526 LIBCFS_ALLOC(tmpstr, tmpsiz);
530 s = tmpstr; /* points to current position in tmpstr[] */
532 s += snprintf(s, tmpstr + tmpsiz - s,
534 "pages", "count", "credits", "min");
535 LASSERT (tmpstr + tmpsiz - s > 0);
539 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
540 lnet_rtrbufpool_t *rbp = &the_lnet.ln_rtrpools[idx];
542 int npages = rbp->rbp_npages;
543 int nbuf = rbp->rbp_nbuffers;
544 int cr = rbp->rbp_credits;
545 int mincr = rbp->rbp_mincredits;
547 s += snprintf(s, tmpstr + tmpsiz - s,
549 npages, nbuf, cr, mincr);
550 LASSERT (tmpstr + tmpsiz - s > 0);
557 if (pos >= min_t(int, len, strlen(tmpstr)))
560 rc = trace_copyout_string(buffer, nob,
563 LIBCFS_FREE(tmpstr, tmpsiz);
567 DECLARE_PROC_HANDLER(proc_lnet_buffers);
569 int LL_PROC_PROTO(proc_lnet_nis)
574 const int tmpsiz = 256;
577 DECLARE_LL_PROC_PPOS_DECL;
584 LIBCFS_ALLOC(tmpstr, tmpsiz);
588 s = tmpstr; /* points to current position in tmpstr[] */
591 s += snprintf(s, tmpstr + tmpsiz - s,
592 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
593 "nid", "status", "alive", "refs", "peer",
594 "rtr", "max", "tx", "min");
595 LASSERT (tmpstr + tmpsiz - s > 0);
598 lnet_ni_t *ni = NULL;
599 int skip = *ppos - 1;
603 n = the_lnet.ln_nis.next;
605 while (n != &the_lnet.ln_nis) {
606 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
618 cfs_time_t now = cfs_time_current();
620 int maxtxcr = ni->ni_maxtxcredits;
621 int txcr = ni->ni_txcredits;
622 int mintxcr = ni->ni_mintxcredits;
623 int npeertxcr = ni->ni_peertxcredits;
624 int npeerrtrcr = ni->ni_peerrtrcredits;
625 lnet_nid_t nid = ni->ni_nid;
626 int nref = ni->ni_refcount;
629 if (the_lnet.ln_routing)
630 last_alive = cfs_duration_sec(cfs_time_sub(now,
632 if (ni->ni_lnd->lnd_type == LOLND) /* @lo forever alive */
635 LASSERT (ni->ni_status != NULL);
636 stat = (ni->ni_status->ns_status == LNET_NI_STATUS_UP) ?
639 s += snprintf(s, tmpstr + tmpsiz - s,
640 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
641 libcfs_nid2str(nid), stat, last_alive, nref,
642 npeertxcr, npeerrtrcr, maxtxcr,
644 LASSERT (tmpstr + tmpsiz - s > 0);
650 len = s - tmpstr; /* how many bytes was written */
652 if (len > *lenp) { /* linux-supplied buffer is too small */
654 } else if (len > 0) { /* wrote something */
655 if (copy_to_user(buffer, tmpstr, len))
661 LIBCFS_FREE(tmpstr, tmpsiz);
669 static cfs_sysctl_table_t lnet_table[] = {
671 * NB No .strategy entries have been provided since sysctl(8) prefers
672 * to go via /proc for portability.
675 .ctl_name = PSDEV_LNET_STATS,
678 .proc_handler = &proc_lnet_stats,
681 .ctl_name = PSDEV_LNET_ROUTES,
682 .procname = "routes",
684 .proc_handler = &proc_lnet_routes,
687 .ctl_name = PSDEV_LNET_ROUTERS,
688 .procname = "routers",
690 .proc_handler = &proc_lnet_routers,
693 .ctl_name = PSDEV_LNET_PEERS,
696 .proc_handler = &proc_lnet_peers,
699 .ctl_name = PSDEV_LNET_PEERS,
700 .procname = "buffers",
702 .proc_handler = &proc_lnet_buffers,
705 .ctl_name = PSDEV_LNET_NIS,
708 .proc_handler = &proc_lnet_nis,
713 static cfs_sysctl_table_t top_table[] = {
715 .ctl_name = CTL_LNET,
731 if (lnet_table_header == NULL)
732 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
740 if (lnet_table_header != NULL)
741 cfs_unregister_sysctl_table(lnet_table_header);
743 lnet_table_header = NULL;