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 %7s %s\n",
189 "net", "hops", "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 lnet_nid_t nid = route->lr_gateway->lp_nid;
246 int alive = route->lr_gateway->lp_alive;
248 s += snprintf(s, tmpstr + tmpsiz - s,
250 libcfs_net2str(net), hops,
251 alive ? "up" : "down",
252 libcfs_nid2str(nid));
253 LASSERT(tmpstr + tmpsiz - s > 0);
259 len = s - tmpstr; /* how many bytes was written */
261 if (len > *lenp) { /* linux-supplied buffer is too small */
263 } else if (len > 0) { /* wrote something */
264 if (copy_to_user(buffer, tmpstr, len))
268 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
272 LIBCFS_FREE(tmpstr, tmpsiz);
280 int LL_PROC_PROTO(proc_lnet_routers)
285 const int tmpsiz = 256;
290 DECLARE_LL_PROC_PPOS_DECL;
292 off = LNET_PROC_HOFF_GET(*ppos);
293 ver = LNET_PROC_VER_GET(*ppos);
300 LIBCFS_ALLOC(tmpstr, tmpsiz);
304 s = tmpstr; /* points to current position in tmpstr[] */
307 s += snprintf(s, tmpstr + tmpsiz - s,
308 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
309 "ref", "rtr_ref", "alive_cnt", "state",
310 "last_ping", "ping_sent", "deadline",
311 "down_ni", "router");
312 LASSERT(tmpstr + tmpsiz - s > 0);
315 ver = (unsigned int)the_lnet.ln_routers_version;
317 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
320 struct lnet_peer *peer = NULL;
325 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
328 LIBCFS_FREE(tmpstr, tmpsiz);
332 r = the_lnet.ln_routers.next;
334 while (r != &the_lnet.ln_routers) {
335 lnet_peer_t *lp = cfs_list_entry(r, lnet_peer_t,
348 lnet_nid_t nid = peer->lp_nid;
349 cfs_time_t now = cfs_time_current();
350 cfs_time_t deadline = peer->lp_ping_deadline;
351 int nrefs = peer->lp_refcount;
352 int nrtrrefs = peer->lp_rtr_refcount;
353 int alive_cnt = peer->lp_alive_count;
354 int alive = peer->lp_alive;
355 int pingsent = !peer->lp_ping_notsent;
356 int last_ping = cfs_duration_sec(cfs_time_sub(now,
357 peer->lp_ping_timestamp));
361 if ((peer->lp_ping_feats &
362 LNET_PING_FEAT_NI_STATUS) != 0) {
363 cfs_list_for_each_entry(rtr, &peer->lp_routes,
365 /* downis on any route should be the
366 * number of downis on the gateway */
367 if (rtr->lr_downis != 0) {
368 down_ni = rtr->lr_downis;
375 s += snprintf(s, tmpstr + tmpsiz - s,
376 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
377 nrefs, nrtrrefs, alive_cnt,
378 alive ? "up" : "down", last_ping,
379 pingsent, "NA", down_ni,
380 libcfs_nid2str(nid));
382 s += snprintf(s, tmpstr + tmpsiz - s,
383 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
384 nrefs, nrtrrefs, alive_cnt,
385 alive ? "up" : "down", last_ping,
387 cfs_duration_sec(cfs_time_sub(deadline, now)),
388 down_ni, libcfs_nid2str(nid));
389 LASSERT (tmpstr + tmpsiz - s > 0);
395 len = s - tmpstr; /* how many bytes was written */
397 if (len > *lenp) { /* linux-supplied buffer is too small */
399 } else if (len > 0) { /* wrote something */
400 if (copy_to_user(buffer, tmpstr, len))
404 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
408 LIBCFS_FREE(tmpstr, tmpsiz);
416 int LL_PROC_PROTO(proc_lnet_peers)
418 const int tmpsiz = 256;
419 struct lnet_peer_table *ptable;
422 int cpt = LNET_PROC_CPT_GET(*ppos);
423 int ver = LNET_PROC_VER_GET(*ppos);
424 int hash = LNET_PROC_HASH_GET(*ppos);
425 int hoff = LNET_PROC_HOFF_GET(*ppos);
429 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
435 if (cpt >= LNET_CPT_NUMBER) {
440 LIBCFS_ALLOC(tmpstr, tmpsiz);
444 s = tmpstr; /* points to current position in tmpstr[] */
447 s += snprintf(s, tmpstr + tmpsiz - s,
448 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
449 "nid", "refs", "state", "last", "max",
450 "rtr", "min", "tx", "min", "queue");
451 LASSERT (tmpstr + tmpsiz - s > 0);
455 struct lnet_peer *peer;
464 ptable = the_lnet.ln_peer_tables[cpt];
466 ver = LNET_PROC_VERSION(ptable->pt_version);
468 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
469 lnet_net_unlock(cpt);
470 LIBCFS_FREE(tmpstr, tmpsiz);
474 while (hash < LNET_PEER_HASH_SIZE) {
476 p = ptable->pt_hash[hash].next;
478 while (p != &ptable->pt_hash[hash]) {
479 lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
484 /* minor optimization: start from idx+1
485 * on next iteration if we've just
486 * drained lp_hashlist */
487 if (lp->lp_hashlist.next ==
488 &ptable->pt_hash[hash]) {
499 p = lp->lp_hashlist.next;
511 lnet_nid_t nid = peer->lp_nid;
512 int nrefs = peer->lp_refcount;
514 char *aliveness = "NA";
515 int maxcr = peer->lp_ni->ni_peertxcredits;
516 int txcr = peer->lp_txcredits;
517 int mintxcr = peer->lp_mintxcredits;
518 int rtrcr = peer->lp_rtrcredits;
519 int minrtrcr = peer->lp_minrtrcredits;
520 int txqnob = peer->lp_txqnob;
522 if (lnet_isrouter(peer) ||
523 lnet_peer_aliveness_enabled(peer))
524 aliveness = peer->lp_alive ? "up" : "down";
526 if (lnet_peer_aliveness_enabled(peer)) {
527 cfs_time_t now = cfs_time_current();
528 cfs_duration_t delta;
530 delta = cfs_time_sub(now, peer->lp_last_alive);
531 lastalive = cfs_duration_sec(delta);
533 /* No need to mess up peers contents with
534 * arbitrarily long integers - it suffices to
535 * know that lastalive is more than 10000s old
537 if (lastalive >= 10000)
541 lnet_net_unlock(cpt);
543 s += snprintf(s, tmpstr + tmpsiz - s,
544 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
545 libcfs_nid2str(nid), nrefs, aliveness,
546 lastalive, maxcr, rtrcr, minrtrcr, txcr,
548 LASSERT (tmpstr + tmpsiz - s > 0);
550 } else { /* peer is NULL */
551 lnet_net_unlock(cpt);
554 if (hash == LNET_PEER_HASH_SIZE) {
558 if (peer == NULL && cpt < LNET_CPT_NUMBER)
563 len = s - tmpstr; /* how many bytes was written */
565 if (len > *lenp) { /* linux-supplied buffer is too small */
567 } else if (len > 0) { /* wrote something */
568 if (copy_to_user(buffer, tmpstr, len))
571 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
574 LIBCFS_FREE(tmpstr, tmpsiz);
582 static int __proc_lnet_buffers(void *data, int write,
583 loff_t pos, void *buffer, int nob)
595 /* (4 %d) * 4 * LNET_CPT_NUMBER */
596 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
597 LIBCFS_ALLOC(tmpstr, tmpsiz);
601 s = tmpstr; /* points to current position in tmpstr[] */
603 s += snprintf(s, tmpstr + tmpsiz - s,
605 "pages", "count", "credits", "min");
606 LASSERT (tmpstr + tmpsiz - s > 0);
608 if (the_lnet.ln_rtrpools == NULL)
609 goto out; /* I'm not a router */
611 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
612 lnet_rtrbufpool_t *rbp;
614 lnet_net_lock(LNET_LOCK_EX);
615 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
616 s += snprintf(s, tmpstr + tmpsiz - s,
619 rbp[idx].rbp_nbuffers,
620 rbp[idx].rbp_credits,
621 rbp[idx].rbp_mincredits);
622 LASSERT(tmpstr + tmpsiz - s > 0);
624 lnet_net_unlock(LNET_LOCK_EX);
630 if (pos >= min_t(int, len, strlen(tmpstr)))
633 rc = cfs_trace_copyout_string(buffer, nob,
636 LIBCFS_FREE(tmpstr, tmpsiz);
640 DECLARE_PROC_HANDLER(proc_lnet_buffers);
642 int LL_PROC_PROTO(proc_lnet_nis)
644 int tmpsiz = 128 * LNET_CPT_NUMBER;
650 DECLARE_LL_PROC_PPOS_DECL;
657 LIBCFS_ALLOC(tmpstr, tmpsiz);
661 s = tmpstr; /* points to current position in tmpstr[] */
664 s += snprintf(s, tmpstr + tmpsiz - s,
665 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
666 "nid", "status", "alive", "refs", "peer",
667 "rtr", "max", "tx", "min");
668 LASSERT (tmpstr + tmpsiz - s > 0);
671 lnet_ni_t *ni = NULL;
672 int skip = *ppos - 1;
676 n = the_lnet.ln_nis.next;
678 while (n != &the_lnet.ln_nis) {
679 lnet_ni_t *a_ni = cfs_list_entry(n, lnet_ni_t, ni_list);
691 struct lnet_tx_queue *tq;
693 long now = cfs_time_current_sec();
698 if (the_lnet.ln_routing)
699 last_alive = now - ni->ni_last_alive;
701 /* @lo forever alive */
702 if (ni->ni_lnd->lnd_type == LOLND)
706 LASSERT(ni->ni_status != NULL);
707 stat = (ni->ni_status->ns_status ==
708 LNET_NI_STATUS_UP) ? "up" : "down";
711 /* we actually output credits information for
712 * TX queue of each partition */
713 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
714 for (j = 0; ni->ni_cpts != NULL &&
715 j < ni->ni_ncpts; j++) {
716 if (i == ni->ni_cpts[j])
720 if (j == ni->ni_ncpts)
726 s += snprintf(s, tmpstr + tmpsiz - s,
727 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
728 libcfs_nid2str(ni->ni_nid), stat,
729 last_alive, *ni->ni_refs[i],
730 ni->ni_peertxcredits,
731 ni->ni_peerrtrcredits,
733 tq->tq_credits, tq->tq_credits_min);
737 LASSERT(tmpstr + tmpsiz - s > 0);
743 len = s - tmpstr; /* how many bytes was written */
745 if (len > *lenp) { /* linux-supplied buffer is too small */
747 } else if (len > 0) { /* wrote something */
748 if (copy_to_user(buffer, tmpstr, len))
754 LIBCFS_FREE(tmpstr, tmpsiz);
762 struct lnet_portal_rotors {
768 static struct lnet_portal_rotors portal_rotors[] = {
770 .pr_value = LNET_PTL_ROTOR_OFF,
772 .pr_desc = "Turn off message rotor for wildcard portals"
775 .pr_value = LNET_PTL_ROTOR_ON,
777 .pr_desc = "round-robin dispatch all PUT messages for "
781 .pr_value = LNET_PTL_ROTOR_RR_RT,
783 .pr_desc = "round-robin dispatch routed PUT message for "
787 .pr_value = LNET_PTL_ROTOR_HASH_RT,
788 .pr_name = "HASH_RT",
789 .pr_desc = "dispatch routed PUT message by hashing source "
790 "NID for wildcard portals"
799 extern int portal_rotor;
801 static int __proc_lnet_portal_rotor(void *data, int write,
802 loff_t pos, void *buffer, int nob)
804 const int buf_len = 128;
810 LIBCFS_ALLOC(buf, buf_len);
817 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
818 if (portal_rotors[i].pr_value == portal_rotor)
822 LASSERT(portal_rotors[i].pr_value == portal_rotor);
825 rc = snprintf(buf, buf_len,
826 "{\n\tportals: all\n"
827 "\trotor: %s\n\tdescription: %s\n}",
828 portal_rotors[i].pr_name,
829 portal_rotors[i].pr_desc);
831 if (pos >= min_t(int, rc, buf_len)) {
834 rc = cfs_trace_copyout_string(buffer, nob,
840 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
844 tmp = cfs_trimwhite(buf);
848 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
849 if (cfs_strncasecmp(portal_rotors[i].pr_name, tmp,
850 strlen(portal_rotors[i].pr_name)) == 0) {
851 portal_rotor = portal_rotors[i].pr_value;
858 LIBCFS_FREE(buf, buf_len);
861 DECLARE_PROC_HANDLER(proc_lnet_portal_rotor);
863 static cfs_sysctl_table_t lnet_table[] = {
865 * NB No .strategy entries have been provided since sysctl(8) prefers
866 * to go via /proc for portability.
869 INIT_CTL_NAME(PSDEV_LNET_STATS)
872 .proc_handler = &proc_lnet_stats,
875 INIT_CTL_NAME(PSDEV_LNET_ROUTES)
876 .procname = "routes",
878 .proc_handler = &proc_lnet_routes,
881 INIT_CTL_NAME(PSDEV_LNET_ROUTERS)
882 .procname = "routers",
884 .proc_handler = &proc_lnet_routers,
887 INIT_CTL_NAME(PSDEV_LNET_PEERS)
890 .proc_handler = &proc_lnet_peers,
893 INIT_CTL_NAME(PSDEV_LNET_PEERS)
894 .procname = "buffers",
896 .proc_handler = &proc_lnet_buffers,
899 INIT_CTL_NAME(PSDEV_LNET_NIS)
902 .proc_handler = &proc_lnet_nis,
905 INIT_CTL_NAME(PSDEV_LNET_PTL_ROTOR)
906 .procname = "portal_rotor",
908 .proc_handler = &proc_lnet_portal_rotor,
915 static cfs_sysctl_table_t top_table[] = {
917 INIT_CTL_NAME(CTL_LNET)
933 if (lnet_table_header == NULL)
934 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
942 if (lnet_table_header != NULL)
943 cfs_unregister_sysctl_table(lnet_table_header);
945 lnet_table_header = NULL;