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 "../../include/linux/libcfs/libcfs.h"
26 #include "../../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 struct ctl_table_header *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_t(size_t, min_t(size_t, 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_call_handler(void *data, int write, loff_t *ppos,
94 void __user *buffer, size_t *lenp,
95 int (*handler)(void *data, int write,
96 loff_t pos, void __user *buffer, int len))
98 int rc = handler(data, write, *ppos, buffer, *lenp);
112 static int __proc_lnet_stats(void *data, int write,
113 loff_t pos, void __user *buffer, int nob)
116 lnet_counters_t *ctrs;
119 const int tmpsiz = 256; /* 7 %u and 4 %llu */
122 lnet_counters_reset();
128 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
132 LIBCFS_ALLOC(tmpstr, tmpsiz);
133 if (tmpstr == NULL) {
134 LIBCFS_FREE(ctrs, sizeof(*ctrs));
138 lnet_counters_get(ctrs);
140 len = snprintf(tmpstr, tmpsiz,
141 "%u %u %u %u %u %u %u %llu %llu %llu %llu",
142 ctrs->msgs_alloc, ctrs->msgs_max,
144 ctrs->send_count, ctrs->recv_count,
145 ctrs->route_count, ctrs->drop_count,
146 ctrs->send_length, ctrs->recv_length,
147 ctrs->route_length, ctrs->drop_length);
149 if (pos >= min_t(int, len, strlen(tmpstr)))
152 rc = cfs_trace_copyout_string(buffer, nob,
155 LIBCFS_FREE(tmpstr, tmpsiz);
156 LIBCFS_FREE(ctrs, sizeof(*ctrs));
160 static int proc_lnet_stats(struct ctl_table *table, int write,
161 void __user *buffer, size_t *lenp, loff_t *ppos)
163 return proc_call_handler(table->data, write, ppos, buffer, lenp,
167 static int proc_lnet_routes(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos)
170 const int tmpsiz = 256;
178 CLASSERT(sizeof(loff_t) >= 4);
180 off = LNET_PROC_HOFF_GET(*ppos);
181 ver = LNET_PROC_VER_GET(*ppos);
188 LIBCFS_ALLOC(tmpstr, tmpsiz);
192 s = tmpstr; /* points to current position in tmpstr[] */
195 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
196 the_lnet.ln_routing ? "enabled" : "disabled");
197 LASSERT(tmpstr + tmpsiz - s > 0);
199 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
200 "net", "hops", "priority", "state", "router");
201 LASSERT(tmpstr + tmpsiz - s > 0);
204 ver = (unsigned int)the_lnet.ln_remote_nets_version;
206 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
210 lnet_route_t *route = NULL;
211 lnet_remotenet_t *rnet = NULL;
213 struct list_head *rn_list;
218 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
220 LIBCFS_FREE(tmpstr, tmpsiz);
224 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
226 rn_list = &the_lnet.ln_remote_nets_hash[i];
230 while (n != rn_list && route == NULL) {
231 rnet = list_entry(n, lnet_remotenet_t,
234 r = rnet->lrn_routes.next;
236 while (r != &rnet->lrn_routes) {
238 list_entry(r, lnet_route_t,
254 __u32 net = rnet->lrn_net;
255 unsigned int hops = route->lr_hops;
256 unsigned int priority = route->lr_priority;
257 lnet_nid_t nid = route->lr_gateway->lp_nid;
258 int alive = route->lr_gateway->lp_alive;
260 s += snprintf(s, tmpstr + tmpsiz - s,
261 "%-8s %4u %8u %7s %s\n",
262 libcfs_net2str(net), hops,
264 alive ? "up" : "down",
265 libcfs_nid2str(nid));
266 LASSERT(tmpstr + tmpsiz - s > 0);
272 len = s - tmpstr; /* how many bytes was written */
274 if (len > *lenp) { /* linux-supplied buffer is too small */
276 } else if (len > 0) { /* wrote something */
277 if (copy_to_user(buffer, tmpstr, len))
281 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
285 LIBCFS_FREE(tmpstr, tmpsiz);
293 static int proc_lnet_routers(struct ctl_table *table, int write,
294 void __user *buffer, size_t *lenp, loff_t *ppos)
299 const int tmpsiz = 256;
304 off = LNET_PROC_HOFF_GET(*ppos);
305 ver = LNET_PROC_VER_GET(*ppos);
312 LIBCFS_ALLOC(tmpstr, tmpsiz);
316 s = tmpstr; /* points to current position in tmpstr[] */
319 s += snprintf(s, tmpstr + tmpsiz - s,
320 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
321 "ref", "rtr_ref", "alive_cnt", "state",
322 "last_ping", "ping_sent", "deadline",
323 "down_ni", "router");
324 LASSERT(tmpstr + tmpsiz - s > 0);
327 ver = (unsigned int)the_lnet.ln_routers_version;
329 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
332 struct lnet_peer *peer = NULL;
337 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
340 LIBCFS_FREE(tmpstr, tmpsiz);
344 r = the_lnet.ln_routers.next;
346 while (r != &the_lnet.ln_routers) {
347 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
360 lnet_nid_t nid = peer->lp_nid;
361 unsigned long now = cfs_time_current();
362 unsigned long deadline = peer->lp_ping_deadline;
363 int nrefs = peer->lp_refcount;
364 int nrtrrefs = peer->lp_rtr_refcount;
365 int alive_cnt = peer->lp_alive_count;
366 int alive = peer->lp_alive;
367 int pingsent = !peer->lp_ping_notsent;
368 int last_ping = cfs_duration_sec(cfs_time_sub(now,
369 peer->lp_ping_timestamp));
373 if ((peer->lp_ping_feats &
374 LNET_PING_FEAT_NI_STATUS) != 0) {
375 list_for_each_entry(rtr, &peer->lp_routes,
377 /* downis on any route should be the
378 * number of downis on the gateway */
379 if (rtr->lr_downis != 0) {
380 down_ni = rtr->lr_downis;
387 s += snprintf(s, tmpstr + tmpsiz - s,
388 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
389 nrefs, nrtrrefs, alive_cnt,
390 alive ? "up" : "down", last_ping,
391 pingsent, "NA", down_ni,
392 libcfs_nid2str(nid));
394 s += snprintf(s, tmpstr + tmpsiz - s,
395 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
396 nrefs, nrtrrefs, alive_cnt,
397 alive ? "up" : "down", last_ping,
399 cfs_duration_sec(cfs_time_sub(deadline, now)),
400 down_ni, libcfs_nid2str(nid));
401 LASSERT(tmpstr + tmpsiz - s > 0);
407 len = s - tmpstr; /* how many bytes was written */
409 if (len > *lenp) { /* linux-supplied buffer is too small */
411 } else if (len > 0) { /* wrote something */
412 if (copy_to_user(buffer, tmpstr, len))
416 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
420 LIBCFS_FREE(tmpstr, tmpsiz);
428 static int proc_lnet_peers(struct ctl_table *table, int write,
429 void __user *buffer, size_t *lenp, loff_t *ppos)
431 const int tmpsiz = 256;
432 struct lnet_peer_table *ptable;
435 int cpt = LNET_PROC_CPT_GET(*ppos);
436 int ver = LNET_PROC_VER_GET(*ppos);
437 int hash = LNET_PROC_HASH_GET(*ppos);
438 int hoff = LNET_PROC_HOFF_GET(*ppos);
442 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
448 if (cpt >= LNET_CPT_NUMBER) {
453 LIBCFS_ALLOC(tmpstr, tmpsiz);
457 s = tmpstr; /* points to current position in tmpstr[] */
460 s += snprintf(s, tmpstr + tmpsiz - s,
461 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
462 "nid", "refs", "state", "last", "max",
463 "rtr", "min", "tx", "min", "queue");
464 LASSERT(tmpstr + tmpsiz - s > 0);
468 struct lnet_peer *peer;
477 ptable = the_lnet.ln_peer_tables[cpt];
479 ver = LNET_PROC_VERSION(ptable->pt_version);
481 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
482 lnet_net_unlock(cpt);
483 LIBCFS_FREE(tmpstr, tmpsiz);
487 while (hash < LNET_PEER_HASH_SIZE) {
489 p = ptable->pt_hash[hash].next;
491 while (p != &ptable->pt_hash[hash]) {
492 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
497 /* minor optimization: start from idx+1
498 * on next iteration if we've just
499 * drained lp_hashlist */
500 if (lp->lp_hashlist.next ==
501 &ptable->pt_hash[hash]) {
512 p = lp->lp_hashlist.next;
524 lnet_nid_t nid = peer->lp_nid;
525 int nrefs = peer->lp_refcount;
527 char *aliveness = "NA";
528 int maxcr = peer->lp_ni->ni_peertxcredits;
529 int txcr = peer->lp_txcredits;
530 int mintxcr = peer->lp_mintxcredits;
531 int rtrcr = peer->lp_rtrcredits;
532 int minrtrcr = peer->lp_minrtrcredits;
533 int txqnob = peer->lp_txqnob;
535 if (lnet_isrouter(peer) ||
536 lnet_peer_aliveness_enabled(peer))
537 aliveness = peer->lp_alive ? "up" : "down";
539 if (lnet_peer_aliveness_enabled(peer)) {
540 unsigned long now = cfs_time_current();
543 delta = cfs_time_sub(now, peer->lp_last_alive);
544 lastalive = cfs_duration_sec(delta);
546 /* No need to mess up peers contents with
547 * arbitrarily long integers - it suffices to
548 * know that lastalive is more than 10000s old
550 if (lastalive >= 10000)
554 lnet_net_unlock(cpt);
556 s += snprintf(s, tmpstr + tmpsiz - s,
557 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
558 libcfs_nid2str(nid), nrefs, aliveness,
559 lastalive, maxcr, rtrcr, minrtrcr, txcr,
561 LASSERT(tmpstr + tmpsiz - s > 0);
563 } else { /* peer is NULL */
564 lnet_net_unlock(cpt);
567 if (hash == LNET_PEER_HASH_SIZE) {
571 if (peer == NULL && cpt < LNET_CPT_NUMBER)
576 len = s - tmpstr; /* how many bytes was written */
578 if (len > *lenp) { /* linux-supplied buffer is too small */
580 } else if (len > 0) { /* wrote something */
581 if (copy_to_user(buffer, tmpstr, len))
584 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
587 LIBCFS_FREE(tmpstr, tmpsiz);
595 static int __proc_lnet_buffers(void *data, int write,
596 loff_t pos, void __user *buffer, int nob)
608 /* (4 %d) * 4 * LNET_CPT_NUMBER */
609 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
610 LIBCFS_ALLOC(tmpstr, tmpsiz);
614 s = tmpstr; /* points to current position in tmpstr[] */
616 s += snprintf(s, tmpstr + tmpsiz - s,
618 "pages", "count", "credits", "min");
619 LASSERT(tmpstr + tmpsiz - s > 0);
621 if (the_lnet.ln_rtrpools == NULL)
622 goto out; /* I'm not a router */
624 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
625 lnet_rtrbufpool_t *rbp;
627 lnet_net_lock(LNET_LOCK_EX);
628 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
629 s += snprintf(s, tmpstr + tmpsiz - s,
632 rbp[idx].rbp_nbuffers,
633 rbp[idx].rbp_credits,
634 rbp[idx].rbp_mincredits);
635 LASSERT(tmpstr + tmpsiz - s > 0);
637 lnet_net_unlock(LNET_LOCK_EX);
643 if (pos >= min_t(int, len, strlen(tmpstr)))
646 rc = cfs_trace_copyout_string(buffer, nob,
649 LIBCFS_FREE(tmpstr, tmpsiz);
653 static int proc_lnet_buffers(struct ctl_table *table, int write,
654 void __user *buffer, size_t *lenp, loff_t *ppos)
656 return proc_call_handler(table->data, write, ppos, buffer, lenp,
657 __proc_lnet_buffers);
660 static int proc_lnet_nis(struct ctl_table *table, int write,
661 void __user *buffer, size_t *lenp, loff_t *ppos)
663 int tmpsiz = 128 * LNET_CPT_NUMBER;
674 LIBCFS_ALLOC(tmpstr, tmpsiz);
678 s = tmpstr; /* points to current position in tmpstr[] */
681 s += snprintf(s, tmpstr + tmpsiz - s,
682 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
683 "nid", "status", "alive", "refs", "peer",
684 "rtr", "max", "tx", "min");
685 LASSERT(tmpstr + tmpsiz - s > 0);
688 lnet_ni_t *ni = NULL;
689 int skip = *ppos - 1;
693 n = the_lnet.ln_nis.next;
695 while (n != &the_lnet.ln_nis) {
696 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
708 struct lnet_tx_queue *tq;
710 long now = get_seconds();
715 if (the_lnet.ln_routing)
716 last_alive = now - ni->ni_last_alive;
718 /* @lo forever alive */
719 if (ni->ni_lnd->lnd_type == LOLND)
723 LASSERT(ni->ni_status != NULL);
724 stat = (ni->ni_status->ns_status ==
725 LNET_NI_STATUS_UP) ? "up" : "down";
728 /* we actually output credits information for
729 * TX queue of each partition */
730 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
731 for (j = 0; ni->ni_cpts != NULL &&
732 j < ni->ni_ncpts; j++) {
733 if (i == ni->ni_cpts[j])
737 if (j == ni->ni_ncpts)
743 s += snprintf(s, tmpstr + tmpsiz - s,
744 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
745 libcfs_nid2str(ni->ni_nid), stat,
746 last_alive, *ni->ni_refs[i],
747 ni->ni_peertxcredits,
748 ni->ni_peerrtrcredits,
750 tq->tq_credits, tq->tq_credits_min);
754 LASSERT(tmpstr + tmpsiz - s > 0);
760 len = s - tmpstr; /* how many bytes was written */
762 if (len > *lenp) { /* linux-supplied buffer is too small */
764 } else if (len > 0) { /* wrote something */
765 if (copy_to_user(buffer, tmpstr, len))
771 LIBCFS_FREE(tmpstr, tmpsiz);
779 struct lnet_portal_rotors {
785 static struct lnet_portal_rotors portal_rotors[] = {
787 .pr_value = LNET_PTL_ROTOR_OFF,
789 .pr_desc = "Turn off message rotor for wildcard portals"
792 .pr_value = LNET_PTL_ROTOR_ON,
794 .pr_desc = "round-robin dispatch all PUT messages for wildcard portals"
797 .pr_value = LNET_PTL_ROTOR_RR_RT,
799 .pr_desc = "round-robin dispatch routed PUT message for wildcard portals"
802 .pr_value = LNET_PTL_ROTOR_HASH_RT,
803 .pr_name = "HASH_RT",
804 .pr_desc = "dispatch routed PUT message by hashing source NID for wildcard portals"
813 extern int portal_rotor;
815 static int __proc_lnet_portal_rotor(void *data, int write,
816 loff_t pos, void __user *buffer, int nob)
818 const int buf_len = 128;
824 LIBCFS_ALLOC(buf, buf_len);
831 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
832 if (portal_rotors[i].pr_value == portal_rotor)
836 LASSERT(portal_rotors[i].pr_value == portal_rotor);
839 rc = snprintf(buf, buf_len,
840 "{\n\tportals: all\n"
841 "\trotor: %s\n\tdescription: %s\n}",
842 portal_rotors[i].pr_name,
843 portal_rotors[i].pr_desc);
845 if (pos >= min_t(int, rc, buf_len)) {
848 rc = cfs_trace_copyout_string(buffer, nob,
854 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
858 tmp = cfs_trimwhite(buf);
862 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
863 if (strncasecmp(portal_rotors[i].pr_name, tmp,
864 strlen(portal_rotors[i].pr_name)) == 0) {
865 portal_rotor = portal_rotors[i].pr_value;
872 LIBCFS_FREE(buf, buf_len);
876 static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
877 void __user *buffer, size_t *lenp,
880 return proc_call_handler(table->data, write, ppos, buffer, lenp,
881 __proc_lnet_portal_rotor);
884 static struct ctl_table lnet_table[] = {
886 * NB No .strategy entries have been provided since sysctl(8) prefers
887 * to go via /proc for portability.
892 .proc_handler = &proc_lnet_stats,
895 .procname = "routes",
897 .proc_handler = &proc_lnet_routes,
900 .procname = "routers",
902 .proc_handler = &proc_lnet_routers,
907 .proc_handler = &proc_lnet_peers,
910 .procname = "buffers",
912 .proc_handler = &proc_lnet_buffers,
917 .proc_handler = &proc_lnet_nis,
920 .procname = "portal_rotor",
922 .proc_handler = &proc_lnet_portal_rotor,
928 static struct ctl_table top_table[] = {
943 if (lnet_table_header == NULL)
944 lnet_table_header = register_sysctl_table(top_table);
950 if (lnet_table_header != NULL)
951 unregister_sysctl_table(lnet_table_header);
953 lnet_table_header = NULL;