2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2012, 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 <linux/libcfs/libcfs.h>
26 #include <linux/lnet/lib-lnet.h>
28 #if 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 ctl_table_header_t *lnet_table_header;
35 #define CTL_LNET (0x100)
37 PSDEV_LNET_STATS = 100,
46 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
48 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
50 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
51 /* change version, 16 bits or 8 bits */
52 #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
54 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
56 * bits for peer hash offset
57 * NB: we don't use the highest bit of *ppos because it's signed
59 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
60 LNET_PROC_CPT_BITS - \
61 LNET_PROC_VER_BITS - \
62 LNET_PROC_HASH_BITS - 1)
63 /* bits for hash index + position */
64 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
65 /* bits for peer hash table + hash version */
66 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
68 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
69 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
70 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
71 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
73 #define LNET_PROC_CPT_GET(pos) \
74 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
76 #define LNET_PROC_VER_GET(pos) \
77 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
79 #define LNET_PROC_HASH_GET(pos) \
80 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
82 #define LNET_PROC_HOFF_GET(pos) \
83 (int)((pos) & LNET_PROC_HOFF_MASK)
85 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
86 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
87 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
88 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
89 ((off) & LNET_PROC_HOFF_MASK))
91 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
93 static int __proc_lnet_stats(void *data, int write,
94 loff_t pos, void *buffer, int nob)
97 lnet_counters_t *ctrs;
100 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
103 lnet_counters_reset();
109 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
113 LIBCFS_ALLOC(tmpstr, tmpsiz);
114 if (tmpstr == NULL) {
115 LIBCFS_FREE(ctrs, sizeof(*ctrs));
119 lnet_counters_get(ctrs);
121 len = snprintf(tmpstr, tmpsiz,
122 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
124 ctrs->msgs_alloc, ctrs->msgs_max,
126 ctrs->send_count, ctrs->recv_count,
127 ctrs->route_count, ctrs->drop_count,
128 ctrs->send_length, ctrs->recv_length,
129 ctrs->route_length, ctrs->drop_length);
131 if (pos >= min_t(int, len, strlen(tmpstr)))
134 rc = cfs_trace_copyout_string(buffer, nob,
137 LIBCFS_FREE(tmpstr, tmpsiz);
138 LIBCFS_FREE(ctrs, sizeof(*ctrs));
142 DECLARE_PROC_HANDLER(proc_lnet_stats);
144 int LL_PROC_PROTO(proc_lnet_routes)
146 const int tmpsiz = 256;
154 DECLARE_LL_PROC_PPOS_DECL;
156 CLASSERT(sizeof(loff_t) >= 4);
158 off = LNET_PROC_HOFF_GET(*ppos);
159 ver = LNET_PROC_VER_GET(*ppos);
166 LIBCFS_ALLOC(tmpstr, tmpsiz);
170 s = tmpstr; /* points to current position in tmpstr[] */
173 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
174 the_lnet.ln_routing ? "enabled" : "disabled");
175 LASSERT(tmpstr + tmpsiz - s > 0);
177 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %7s %s\n",
178 "net", "hops", "state", "router");
179 LASSERT(tmpstr + tmpsiz - s > 0);
182 ver = (unsigned int)the_lnet.ln_remote_nets_version;
184 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
188 lnet_route_t *route = NULL;
189 lnet_remotenet_t *rnet = NULL;
191 struct list_head *rn_list;
196 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
198 LIBCFS_FREE(tmpstr, tmpsiz);
202 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
204 rn_list = &the_lnet.ln_remote_nets_hash[i];
208 while (n != rn_list && route == NULL) {
209 rnet = list_entry(n, lnet_remotenet_t,
212 r = rnet->lrn_routes.next;
214 while (r != &rnet->lrn_routes) {
216 list_entry(r, lnet_route_t,
232 __u32 net = rnet->lrn_net;
233 unsigned int hops = route->lr_hops;
234 lnet_nid_t nid = route->lr_gateway->lp_nid;
235 int alive = route->lr_gateway->lp_alive;
237 s += snprintf(s, tmpstr + tmpsiz - s,
239 libcfs_net2str(net), hops,
240 alive ? "up" : "down",
241 libcfs_nid2str(nid));
242 LASSERT(tmpstr + tmpsiz - s > 0);
248 len = s - tmpstr; /* how many bytes was written */
250 if (len > *lenp) { /* linux-supplied buffer is too small */
252 } else if (len > 0) { /* wrote something */
253 if (copy_to_user(buffer, tmpstr, len))
257 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
261 LIBCFS_FREE(tmpstr, tmpsiz);
269 int LL_PROC_PROTO(proc_lnet_routers)
274 const int tmpsiz = 256;
279 DECLARE_LL_PROC_PPOS_DECL;
281 off = LNET_PROC_HOFF_GET(*ppos);
282 ver = LNET_PROC_VER_GET(*ppos);
289 LIBCFS_ALLOC(tmpstr, tmpsiz);
293 s = tmpstr; /* points to current position in tmpstr[] */
296 s += snprintf(s, tmpstr + tmpsiz - s,
297 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
298 "ref", "rtr_ref", "alive_cnt", "state",
299 "last_ping", "ping_sent", "deadline",
300 "down_ni", "router");
301 LASSERT(tmpstr + tmpsiz - s > 0);
304 ver = (unsigned int)the_lnet.ln_routers_version;
306 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
309 struct lnet_peer *peer = NULL;
314 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
317 LIBCFS_FREE(tmpstr, tmpsiz);
321 r = the_lnet.ln_routers.next;
323 while (r != &the_lnet.ln_routers) {
324 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
337 lnet_nid_t nid = peer->lp_nid;
338 cfs_time_t now = cfs_time_current();
339 cfs_time_t deadline = peer->lp_ping_deadline;
340 int nrefs = peer->lp_refcount;
341 int nrtrrefs = peer->lp_rtr_refcount;
342 int alive_cnt = peer->lp_alive_count;
343 int alive = peer->lp_alive;
344 int pingsent = !peer->lp_ping_notsent;
345 int last_ping = cfs_duration_sec(cfs_time_sub(now,
346 peer->lp_ping_timestamp));
350 if ((peer->lp_ping_feats &
351 LNET_PING_FEAT_NI_STATUS) != 0) {
352 list_for_each_entry(rtr, &peer->lp_routes,
354 /* downis on any route should be the
355 * number of downis on the gateway */
356 if (rtr->lr_downis != 0) {
357 down_ni = rtr->lr_downis;
364 s += snprintf(s, tmpstr + tmpsiz - s,
365 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
366 nrefs, nrtrrefs, alive_cnt,
367 alive ? "up" : "down", last_ping,
368 pingsent, "NA", down_ni,
369 libcfs_nid2str(nid));
371 s += snprintf(s, tmpstr + tmpsiz - s,
372 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
373 nrefs, nrtrrefs, alive_cnt,
374 alive ? "up" : "down", last_ping,
376 cfs_duration_sec(cfs_time_sub(deadline, now)),
377 down_ni, libcfs_nid2str(nid));
378 LASSERT(tmpstr + tmpsiz - s > 0);
384 len = s - tmpstr; /* how many bytes was written */
386 if (len > *lenp) { /* linux-supplied buffer is too small */
388 } else if (len > 0) { /* wrote something */
389 if (copy_to_user(buffer, tmpstr, len))
393 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
397 LIBCFS_FREE(tmpstr, tmpsiz);
405 int LL_PROC_PROTO(proc_lnet_peers)
407 const int tmpsiz = 256;
408 struct lnet_peer_table *ptable;
411 int cpt = LNET_PROC_CPT_GET(*ppos);
412 int ver = LNET_PROC_VER_GET(*ppos);
413 int hash = LNET_PROC_HASH_GET(*ppos);
414 int hoff = LNET_PROC_HOFF_GET(*ppos);
418 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
424 if (cpt >= LNET_CPT_NUMBER) {
429 LIBCFS_ALLOC(tmpstr, tmpsiz);
433 s = tmpstr; /* points to current position in tmpstr[] */
436 s += snprintf(s, tmpstr + tmpsiz - s,
437 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
438 "nid", "refs", "state", "last", "max",
439 "rtr", "min", "tx", "min", "queue");
440 LASSERT(tmpstr + tmpsiz - s > 0);
444 struct lnet_peer *peer;
453 ptable = the_lnet.ln_peer_tables[cpt];
455 ver = LNET_PROC_VERSION(ptable->pt_version);
457 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
458 lnet_net_unlock(cpt);
459 LIBCFS_FREE(tmpstr, tmpsiz);
463 while (hash < LNET_PEER_HASH_SIZE) {
465 p = ptable->pt_hash[hash].next;
467 while (p != &ptable->pt_hash[hash]) {
468 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
473 /* minor optimization: start from idx+1
474 * on next iteration if we've just
475 * drained lp_hashlist */
476 if (lp->lp_hashlist.next ==
477 &ptable->pt_hash[hash]) {
488 p = lp->lp_hashlist.next;
500 lnet_nid_t nid = peer->lp_nid;
501 int nrefs = peer->lp_refcount;
503 char *aliveness = "NA";
504 int maxcr = peer->lp_ni->ni_peertxcredits;
505 int txcr = peer->lp_txcredits;
506 int mintxcr = peer->lp_mintxcredits;
507 int rtrcr = peer->lp_rtrcredits;
508 int minrtrcr = peer->lp_minrtrcredits;
509 int txqnob = peer->lp_txqnob;
511 if (lnet_isrouter(peer) ||
512 lnet_peer_aliveness_enabled(peer))
513 aliveness = peer->lp_alive ? "up" : "down";
515 if (lnet_peer_aliveness_enabled(peer)) {
516 cfs_time_t now = cfs_time_current();
517 cfs_duration_t delta;
519 delta = cfs_time_sub(now, peer->lp_last_alive);
520 lastalive = cfs_duration_sec(delta);
522 /* No need to mess up peers contents with
523 * arbitrarily long integers - it suffices to
524 * know that lastalive is more than 10000s old
526 if (lastalive >= 10000)
530 lnet_net_unlock(cpt);
532 s += snprintf(s, tmpstr + tmpsiz - s,
533 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
534 libcfs_nid2str(nid), nrefs, aliveness,
535 lastalive, maxcr, rtrcr, minrtrcr, txcr,
537 LASSERT(tmpstr + tmpsiz - s > 0);
539 } else { /* peer is NULL */
540 lnet_net_unlock(cpt);
543 if (hash == LNET_PEER_HASH_SIZE) {
547 if (peer == NULL && cpt < LNET_CPT_NUMBER)
552 len = s - tmpstr; /* how many bytes was written */
554 if (len > *lenp) { /* linux-supplied buffer is too small */
556 } else if (len > 0) { /* wrote something */
557 if (copy_to_user(buffer, tmpstr, len))
560 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
563 LIBCFS_FREE(tmpstr, tmpsiz);
571 static int __proc_lnet_buffers(void *data, int write,
572 loff_t pos, void *buffer, int nob)
584 /* (4 %d) * 4 * LNET_CPT_NUMBER */
585 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
586 LIBCFS_ALLOC(tmpstr, tmpsiz);
590 s = tmpstr; /* points to current position in tmpstr[] */
592 s += snprintf(s, tmpstr + tmpsiz - s,
594 "pages", "count", "credits", "min");
595 LASSERT(tmpstr + tmpsiz - s > 0);
597 if (the_lnet.ln_rtrpools == NULL)
598 goto out; /* I'm not a router */
600 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
601 lnet_rtrbufpool_t *rbp;
603 lnet_net_lock(LNET_LOCK_EX);
604 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
605 s += snprintf(s, tmpstr + tmpsiz - s,
608 rbp[idx].rbp_nbuffers,
609 rbp[idx].rbp_credits,
610 rbp[idx].rbp_mincredits);
611 LASSERT(tmpstr + tmpsiz - s > 0);
613 lnet_net_unlock(LNET_LOCK_EX);
619 if (pos >= min_t(int, len, strlen(tmpstr)))
622 rc = cfs_trace_copyout_string(buffer, nob,
625 LIBCFS_FREE(tmpstr, tmpsiz);
629 DECLARE_PROC_HANDLER(proc_lnet_buffers);
631 int LL_PROC_PROTO(proc_lnet_nis)
633 int tmpsiz = 128 * LNET_CPT_NUMBER;
639 DECLARE_LL_PROC_PPOS_DECL;
646 LIBCFS_ALLOC(tmpstr, tmpsiz);
650 s = tmpstr; /* points to current position in tmpstr[] */
653 s += snprintf(s, tmpstr + tmpsiz - s,
654 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
655 "nid", "status", "alive", "refs", "peer",
656 "rtr", "max", "tx", "min");
657 LASSERT(tmpstr + tmpsiz - s > 0);
660 lnet_ni_t *ni = NULL;
661 int skip = *ppos - 1;
665 n = the_lnet.ln_nis.next;
667 while (n != &the_lnet.ln_nis) {
668 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
680 struct lnet_tx_queue *tq;
682 long now = cfs_time_current_sec();
687 if (the_lnet.ln_routing)
688 last_alive = now - ni->ni_last_alive;
690 /* @lo forever alive */
691 if (ni->ni_lnd->lnd_type == LOLND)
695 LASSERT(ni->ni_status != NULL);
696 stat = (ni->ni_status->ns_status ==
697 LNET_NI_STATUS_UP) ? "up" : "down";
700 /* we actually output credits information for
701 * TX queue of each partition */
702 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
703 for (j = 0; ni->ni_cpts != NULL &&
704 j < ni->ni_ncpts; j++) {
705 if (i == ni->ni_cpts[j])
709 if (j == ni->ni_ncpts)
715 s += snprintf(s, tmpstr + tmpsiz - s,
716 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
717 libcfs_nid2str(ni->ni_nid), stat,
718 last_alive, *ni->ni_refs[i],
719 ni->ni_peertxcredits,
720 ni->ni_peerrtrcredits,
722 tq->tq_credits, tq->tq_credits_min);
726 LASSERT(tmpstr + tmpsiz - s > 0);
732 len = s - tmpstr; /* how many bytes was written */
734 if (len > *lenp) { /* linux-supplied buffer is too small */
736 } else if (len > 0) { /* wrote something */
737 if (copy_to_user(buffer, tmpstr, len))
743 LIBCFS_FREE(tmpstr, tmpsiz);
751 struct lnet_portal_rotors {
757 static struct lnet_portal_rotors portal_rotors[] = {
759 .pr_value = LNET_PTL_ROTOR_OFF,
761 .pr_desc = "Turn off message rotor for wildcard portals"
764 .pr_value = LNET_PTL_ROTOR_ON,
766 .pr_desc = "round-robin dispatch all PUT messages for "
770 .pr_value = LNET_PTL_ROTOR_RR_RT,
772 .pr_desc = "round-robin dispatch routed PUT message for "
776 .pr_value = LNET_PTL_ROTOR_HASH_RT,
777 .pr_name = "HASH_RT",
778 .pr_desc = "dispatch routed PUT message by hashing source "
779 "NID for wildcard portals"
788 extern int portal_rotor;
790 static int __proc_lnet_portal_rotor(void *data, int write,
791 loff_t pos, void *buffer, int nob)
793 const int buf_len = 128;
799 LIBCFS_ALLOC(buf, buf_len);
806 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
807 if (portal_rotors[i].pr_value == portal_rotor)
811 LASSERT(portal_rotors[i].pr_value == portal_rotor);
814 rc = snprintf(buf, buf_len,
815 "{\n\tportals: all\n"
816 "\trotor: %s\n\tdescription: %s\n}",
817 portal_rotors[i].pr_name,
818 portal_rotors[i].pr_desc);
820 if (pos >= min_t(int, rc, buf_len)) {
823 rc = cfs_trace_copyout_string(buffer, nob,
829 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
833 tmp = cfs_trimwhite(buf);
837 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
838 if (cfs_strncasecmp(portal_rotors[i].pr_name, tmp,
839 strlen(portal_rotors[i].pr_name)) == 0) {
840 portal_rotor = portal_rotors[i].pr_value;
847 LIBCFS_FREE(buf, buf_len);
850 DECLARE_PROC_HANDLER(proc_lnet_portal_rotor);
852 static ctl_table_t lnet_table[] = {
854 * NB No .strategy entries have been provided since sysctl(8) prefers
855 * to go via /proc for portability.
858 INIT_CTL_NAME(PSDEV_LNET_STATS)
861 .proc_handler = &proc_lnet_stats,
864 INIT_CTL_NAME(PSDEV_LNET_ROUTES)
865 .procname = "routes",
867 .proc_handler = &proc_lnet_routes,
870 INIT_CTL_NAME(PSDEV_LNET_ROUTERS)
871 .procname = "routers",
873 .proc_handler = &proc_lnet_routers,
876 INIT_CTL_NAME(PSDEV_LNET_PEERS)
879 .proc_handler = &proc_lnet_peers,
882 INIT_CTL_NAME(PSDEV_LNET_PEERS)
883 .procname = "buffers",
885 .proc_handler = &proc_lnet_buffers,
888 INIT_CTL_NAME(PSDEV_LNET_NIS)
891 .proc_handler = &proc_lnet_nis,
894 INIT_CTL_NAME(PSDEV_LNET_PTL_ROTOR)
895 .procname = "portal_rotor",
897 .proc_handler = &proc_lnet_portal_rotor,
904 static ctl_table_t top_table[] = {
906 INIT_CTL_NAME(CTL_LNET)
922 if (lnet_table_header == NULL)
923 lnet_table_header = register_sysctl_table(top_table);
931 if (lnet_table_header != NULL)
932 unregister_sysctl_table(lnet_table_header);
934 lnet_table_header = NULL;