2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2013, Intel Corporation.
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,
47 #define CTL_LNET CTL_UNNUMBERED
48 #define PSDEV_LNET_STATS CTL_UNNUMBERED
49 #define PSDEV_LNET_ROUTES CTL_UNNUMBERED
50 #define PSDEV_LNET_ROUTERS CTL_UNNUMBERED
51 #define PSDEV_LNET_PEERS CTL_UNNUMBERED
52 #define PSDEV_LNET_BUFFERS CTL_UNNUMBERED
53 #define PSDEV_LNET_NIS CTL_UNNUMBERED
54 #define PSDEV_LNET_PTL_ROTOR CTL_UNNUMBERED
57 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
59 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
61 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
62 /* change version, 16 bits or 8 bits */
63 #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
65 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
67 * bits for peer hash offset
68 * NB: we don't use the highest bit of *ppos because it's signed
70 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
71 LNET_PROC_CPT_BITS - \
72 LNET_PROC_VER_BITS - \
73 LNET_PROC_HASH_BITS - 1)
74 /* bits for hash index + position */
75 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
76 /* bits for peer hash table + hash version */
77 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
79 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
80 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
81 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
82 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
84 #define LNET_PROC_CPT_GET(pos) \
85 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
87 #define LNET_PROC_VER_GET(pos) \
88 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
90 #define LNET_PROC_HASH_GET(pos) \
91 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
93 #define LNET_PROC_HOFF_GET(pos) \
94 (int)((pos) & LNET_PROC_HOFF_MASK)
96 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
97 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
98 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
99 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
100 ((off) & LNET_PROC_HOFF_MASK))
102 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
104 static int __proc_lnet_stats(void *data, int write,
105 loff_t pos, void *buffer, int nob)
108 lnet_counters_t *ctrs;
111 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
114 lnet_counters_reset();
120 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
124 LIBCFS_ALLOC(tmpstr, tmpsiz);
125 if (tmpstr == NULL) {
126 LIBCFS_FREE(ctrs, sizeof(*ctrs));
130 lnet_counters_get(ctrs);
132 len = snprintf(tmpstr, tmpsiz,
133 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
135 ctrs->msgs_alloc, ctrs->msgs_max,
137 ctrs->send_count, ctrs->recv_count,
138 ctrs->route_count, ctrs->drop_count,
139 ctrs->send_length, ctrs->recv_length,
140 ctrs->route_length, ctrs->drop_length);
142 if (pos >= min_t(int, len, strlen(tmpstr)))
145 rc = cfs_trace_copyout_string(buffer, nob,
148 LIBCFS_FREE(tmpstr, tmpsiz);
149 LIBCFS_FREE(ctrs, sizeof(*ctrs));
153 DECLARE_PROC_HANDLER(proc_lnet_stats);
155 int LL_PROC_PROTO(proc_lnet_routes)
157 const int tmpsiz = 256;
165 DECLARE_LL_PROC_PPOS_DECL;
167 CLASSERT(sizeof(loff_t) >= 4);
169 off = LNET_PROC_HOFF_GET(*ppos);
170 ver = LNET_PROC_VER_GET(*ppos);
177 LIBCFS_ALLOC(tmpstr, tmpsiz);
181 s = tmpstr; /* points to current position in tmpstr[] */
184 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
185 the_lnet.ln_routing ? "enabled" : "disabled");
186 LASSERT (tmpstr + tmpsiz - s > 0);
188 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
189 "net", "hops", "priority", "state", "router");
190 LASSERT (tmpstr + tmpsiz - s > 0);
193 ver = (unsigned int)the_lnet.ln_remote_nets_version;
195 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
199 lnet_route_t *route = NULL;
200 lnet_remotenet_t *rnet = NULL;
207 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
209 LIBCFS_FREE(tmpstr, tmpsiz);
213 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
215 rn_list = &the_lnet.ln_remote_nets_hash[i];
219 while (n != rn_list && route == NULL) {
220 rnet = cfs_list_entry(n, lnet_remotenet_t,
223 r = rnet->lrn_routes.next;
225 while (r != &rnet->lrn_routes) {
227 cfs_list_entry(r, lnet_route_t,
243 __u32 net = rnet->lrn_net;
244 unsigned int hops = route->lr_hops;
245 unsigned int priority = route->lr_priority;
246 lnet_nid_t nid = route->lr_gateway->lp_nid;
247 int alive = route->lr_gateway->lp_alive;
249 s += snprintf(s, tmpstr + tmpsiz - s,
250 "%-8s %4u %8u %7s %s\n",
251 libcfs_net2str(net), hops,
253 alive ? "up" : "down",
254 libcfs_nid2str(nid));
255 LASSERT(tmpstr + tmpsiz - s > 0);
261 len = s - tmpstr; /* how many bytes was written */
263 if (len > *lenp) { /* linux-supplied buffer is too small */
265 } else if (len > 0) { /* wrote something */
266 if (copy_to_user(buffer, tmpstr, len))
270 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
274 LIBCFS_FREE(tmpstr, tmpsiz);
282 int LL_PROC_PROTO(proc_lnet_routers)
287 const int tmpsiz = 256;
292 DECLARE_LL_PROC_PPOS_DECL;
294 off = LNET_PROC_HOFF_GET(*ppos);
295 ver = LNET_PROC_VER_GET(*ppos);
302 LIBCFS_ALLOC(tmpstr, tmpsiz);
306 s = tmpstr; /* points to current position in tmpstr[] */
309 s += snprintf(s, tmpstr + tmpsiz - s,
310 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
311 "ref", "rtr_ref", "alive_cnt", "state",
312 "last_ping", "ping_sent", "deadline",
313 "down_ni", "router");
314 LASSERT(tmpstr + tmpsiz - s > 0);
317 ver = (unsigned int)the_lnet.ln_routers_version;
319 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
322 struct lnet_peer *peer = NULL;
327 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
330 LIBCFS_FREE(tmpstr, tmpsiz);
334 r = the_lnet.ln_routers.next;
336 while (r != &the_lnet.ln_routers) {
337 lnet_peer_t *lp = cfs_list_entry(r, lnet_peer_t,
350 lnet_nid_t nid = peer->lp_nid;
351 cfs_time_t now = cfs_time_current();
352 cfs_time_t deadline = peer->lp_ping_deadline;
353 int nrefs = peer->lp_refcount;
354 int nrtrrefs = peer->lp_rtr_refcount;
355 int alive_cnt = peer->lp_alive_count;
356 int alive = peer->lp_alive;
357 int pingsent = !peer->lp_ping_notsent;
358 int last_ping = cfs_duration_sec(cfs_time_sub(now,
359 peer->lp_ping_timestamp));
363 if ((peer->lp_ping_feats &
364 LNET_PING_FEAT_NI_STATUS) != 0) {
365 cfs_list_for_each_entry(rtr, &peer->lp_routes,
367 /* downis on any route should be the
368 * number of downis on the gateway */
369 if (rtr->lr_downis != 0) {
370 down_ni = rtr->lr_downis;
377 s += snprintf(s, tmpstr + tmpsiz - s,
378 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
379 nrefs, nrtrrefs, alive_cnt,
380 alive ? "up" : "down", last_ping,
381 pingsent, "NA", down_ni,
382 libcfs_nid2str(nid));
384 s += snprintf(s, tmpstr + tmpsiz - s,
385 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
386 nrefs, nrtrrefs, alive_cnt,
387 alive ? "up" : "down", last_ping,
389 cfs_duration_sec(cfs_time_sub(deadline, now)),
390 down_ni, libcfs_nid2str(nid));
391 LASSERT (tmpstr + tmpsiz - s > 0);
397 len = s - tmpstr; /* how many bytes was written */
399 if (len > *lenp) { /* linux-supplied buffer is too small */
401 } else if (len > 0) { /* wrote something */
402 if (copy_to_user(buffer, tmpstr, len))
406 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
410 LIBCFS_FREE(tmpstr, tmpsiz);
418 int LL_PROC_PROTO(proc_lnet_peers)
420 const int tmpsiz = 256;
421 struct lnet_peer_table *ptable;
424 int cpt = LNET_PROC_CPT_GET(*ppos);
425 int ver = LNET_PROC_VER_GET(*ppos);
426 int hash = LNET_PROC_HASH_GET(*ppos);
427 int hoff = LNET_PROC_HOFF_GET(*ppos);
431 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
437 if (cpt >= LNET_CPT_NUMBER) {
442 LIBCFS_ALLOC(tmpstr, tmpsiz);
446 s = tmpstr; /* points to current position in tmpstr[] */
449 s += snprintf(s, tmpstr + tmpsiz - s,
450 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
451 "nid", "refs", "state", "last", "max",
452 "rtr", "min", "tx", "min", "queue");
453 LASSERT (tmpstr + tmpsiz - s > 0);
457 struct lnet_peer *peer;
466 ptable = the_lnet.ln_peer_tables[cpt];
468 ver = LNET_PROC_VERSION(ptable->pt_version);
470 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
471 lnet_net_unlock(cpt);
472 LIBCFS_FREE(tmpstr, tmpsiz);
476 while (hash < LNET_PEER_HASH_SIZE) {
478 p = ptable->pt_hash[hash].next;
480 while (p != &ptable->pt_hash[hash]) {
481 lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
486 /* minor optimization: start from idx+1
487 * on next iteration if we've just
488 * drained lp_hashlist */
489 if (lp->lp_hashlist.next ==
490 &ptable->pt_hash[hash]) {
501 p = lp->lp_hashlist.next;
513 lnet_nid_t nid = peer->lp_nid;
514 int nrefs = peer->lp_refcount;
516 char *aliveness = "NA";
517 int maxcr = peer->lp_ni->ni_peertxcredits;
518 int txcr = peer->lp_txcredits;
519 int mintxcr = peer->lp_mintxcredits;
520 int rtrcr = peer->lp_rtrcredits;
521 int minrtrcr = peer->lp_minrtrcredits;
522 int txqnob = peer->lp_txqnob;
524 if (lnet_isrouter(peer) ||
525 lnet_peer_aliveness_enabled(peer))
526 aliveness = peer->lp_alive ? "up" : "down";
528 if (lnet_peer_aliveness_enabled(peer)) {
529 cfs_time_t now = cfs_time_current();
530 cfs_duration_t delta;
532 delta = cfs_time_sub(now, peer->lp_last_alive);
533 lastalive = cfs_duration_sec(delta);
535 /* No need to mess up peers contents with
536 * arbitrarily long integers - it suffices to
537 * know that lastalive is more than 10000s old
539 if (lastalive >= 10000)
543 lnet_net_unlock(cpt);
545 s += snprintf(s, tmpstr + tmpsiz - s,
546 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
547 libcfs_nid2str(nid), nrefs, aliveness,
548 lastalive, maxcr, rtrcr, minrtrcr, txcr,
550 LASSERT (tmpstr + tmpsiz - s > 0);
552 } else { /* peer is NULL */
553 lnet_net_unlock(cpt);
556 if (hash == LNET_PEER_HASH_SIZE) {
560 if (peer == NULL && cpt < LNET_CPT_NUMBER)
565 len = s - tmpstr; /* how many bytes was written */
567 if (len > *lenp) { /* linux-supplied buffer is too small */
569 } else if (len > 0) { /* wrote something */
570 if (copy_to_user(buffer, tmpstr, len))
573 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
576 LIBCFS_FREE(tmpstr, tmpsiz);
584 static int __proc_lnet_buffers(void *data, int write,
585 loff_t pos, void *buffer, int nob)
597 /* (4 %d) * 4 * LNET_CPT_NUMBER */
598 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
599 LIBCFS_ALLOC(tmpstr, tmpsiz);
603 s = tmpstr; /* points to current position in tmpstr[] */
605 s += snprintf(s, tmpstr + tmpsiz - s,
607 "pages", "count", "credits", "min");
608 LASSERT (tmpstr + tmpsiz - s > 0);
610 if (the_lnet.ln_rtrpools == NULL)
611 goto out; /* I'm not a router */
613 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
614 lnet_rtrbufpool_t *rbp;
616 lnet_net_lock(LNET_LOCK_EX);
617 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
618 s += snprintf(s, tmpstr + tmpsiz - s,
621 rbp[idx].rbp_nbuffers,
622 rbp[idx].rbp_credits,
623 rbp[idx].rbp_mincredits);
624 LASSERT(tmpstr + tmpsiz - s > 0);
626 lnet_net_unlock(LNET_LOCK_EX);
632 if (pos >= min_t(int, len, strlen(tmpstr)))
635 rc = cfs_trace_copyout_string(buffer, nob,
638 LIBCFS_FREE(tmpstr, tmpsiz);
642 DECLARE_PROC_HANDLER(proc_lnet_buffers);
644 int LL_PROC_PROTO(proc_lnet_nis)
646 int tmpsiz = 128 * LNET_CPT_NUMBER;
652 DECLARE_LL_PROC_PPOS_DECL;
659 LIBCFS_ALLOC(tmpstr, tmpsiz);
663 s = tmpstr; /* points to current position in tmpstr[] */
666 s += snprintf(s, tmpstr + tmpsiz - s,
667 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
668 "nid", "status", "alive", "refs", "peer",
669 "rtr", "max", "tx", "min");
670 LASSERT (tmpstr + tmpsiz - s > 0);
673 lnet_ni_t *ni = NULL;
674 int skip = *ppos - 1;
678 n = the_lnet.ln_nis.next;
680 while (n != &the_lnet.ln_nis) {
681 lnet_ni_t *a_ni = cfs_list_entry(n, lnet_ni_t, ni_list);
693 struct lnet_tx_queue *tq;
695 long now = cfs_time_current_sec();
700 if (the_lnet.ln_routing)
701 last_alive = now - ni->ni_last_alive;
703 /* @lo forever alive */
704 if (ni->ni_lnd->lnd_type == LOLND)
708 LASSERT(ni->ni_status != NULL);
709 stat = (ni->ni_status->ns_status ==
710 LNET_NI_STATUS_UP) ? "up" : "down";
713 /* we actually output credits information for
714 * TX queue of each partition */
715 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
716 for (j = 0; ni->ni_cpts != NULL &&
717 j < ni->ni_ncpts; j++) {
718 if (i == ni->ni_cpts[j])
722 if (j == ni->ni_ncpts)
728 s += snprintf(s, tmpstr + tmpsiz - s,
729 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
730 libcfs_nid2str(ni->ni_nid), stat,
731 last_alive, *ni->ni_refs[i],
732 ni->ni_peertxcredits,
733 ni->ni_peerrtrcredits,
735 tq->tq_credits, tq->tq_credits_min);
739 LASSERT(tmpstr + tmpsiz - s > 0);
745 len = s - tmpstr; /* how many bytes was written */
747 if (len > *lenp) { /* linux-supplied buffer is too small */
749 } else if (len > 0) { /* wrote something */
750 if (copy_to_user(buffer, tmpstr, len))
756 LIBCFS_FREE(tmpstr, tmpsiz);
764 struct lnet_portal_rotors {
770 static struct lnet_portal_rotors portal_rotors[] = {
772 .pr_value = LNET_PTL_ROTOR_OFF,
774 .pr_desc = "Turn off message rotor for wildcard portals"
777 .pr_value = LNET_PTL_ROTOR_ON,
779 .pr_desc = "round-robin dispatch all PUT messages for "
783 .pr_value = LNET_PTL_ROTOR_RR_RT,
785 .pr_desc = "round-robin dispatch routed PUT message for "
789 .pr_value = LNET_PTL_ROTOR_HASH_RT,
790 .pr_name = "HASH_RT",
791 .pr_desc = "dispatch routed PUT message by hashing source "
792 "NID for wildcard portals"
801 extern int portal_rotor;
803 static int __proc_lnet_portal_rotor(void *data, int write,
804 loff_t pos, void *buffer, int nob)
806 const int buf_len = 128;
812 LIBCFS_ALLOC(buf, buf_len);
819 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
820 if (portal_rotors[i].pr_value == portal_rotor)
824 LASSERT(portal_rotors[i].pr_value == portal_rotor);
827 rc = snprintf(buf, buf_len,
828 "{\n\tportals: all\n"
829 "\trotor: %s\n\tdescription: %s\n}",
830 portal_rotors[i].pr_name,
831 portal_rotors[i].pr_desc);
833 if (pos >= min_t(int, rc, buf_len)) {
836 rc = cfs_trace_copyout_string(buffer, nob,
842 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
846 tmp = cfs_trimwhite(buf);
850 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
851 if (cfs_strncasecmp(portal_rotors[i].pr_name, tmp,
852 strlen(portal_rotors[i].pr_name)) == 0) {
853 portal_rotor = portal_rotors[i].pr_value;
860 LIBCFS_FREE(buf, buf_len);
863 DECLARE_PROC_HANDLER(proc_lnet_portal_rotor);
865 static cfs_sysctl_table_t lnet_table[] = {
867 * NB No .strategy entries have been provided since sysctl(8) prefers
868 * to go via /proc for portability.
871 INIT_CTL_NAME(PSDEV_LNET_STATS)
874 .proc_handler = &proc_lnet_stats,
877 INIT_CTL_NAME(PSDEV_LNET_ROUTES)
878 .procname = "routes",
880 .proc_handler = &proc_lnet_routes,
883 INIT_CTL_NAME(PSDEV_LNET_ROUTERS)
884 .procname = "routers",
886 .proc_handler = &proc_lnet_routers,
889 INIT_CTL_NAME(PSDEV_LNET_PEERS)
892 .proc_handler = &proc_lnet_peers,
895 INIT_CTL_NAME(PSDEV_LNET_PEERS)
896 .procname = "buffers",
898 .proc_handler = &proc_lnet_buffers,
901 INIT_CTL_NAME(PSDEV_LNET_NIS)
904 .proc_handler = &proc_lnet_nis,
907 INIT_CTL_NAME(PSDEV_LNET_PTL_ROTOR)
908 .procname = "portal_rotor",
910 .proc_handler = &proc_lnet_portal_rotor,
917 static cfs_sysctl_table_t top_table[] = {
919 INIT_CTL_NAME(CTL_LNET)
935 if (lnet_table_header == NULL)
936 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
944 if (lnet_table_header != NULL)
945 cfs_unregister_sysctl_table(lnet_table_header);
947 lnet_table_header = NULL;