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 /* This is really lnet_proc.c. You might need to update sanity test 215
29 * if any file format is changed. */
31 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
33 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
35 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
36 /* change version, 16 bits or 8 bits */
37 #define LNET_PROC_VER_BITS max_t(size_t, min_t(size_t, LNET_LOFFT_BITS, 64) / 4, 8)
39 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
41 * bits for peer hash offset
42 * NB: we don't use the highest bit of *ppos because it's signed
44 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
45 LNET_PROC_CPT_BITS - \
46 LNET_PROC_VER_BITS - \
47 LNET_PROC_HASH_BITS - 1)
48 /* bits for hash index + position */
49 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
50 /* bits for peer hash table + hash version */
51 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
53 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
54 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
55 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
56 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
58 #define LNET_PROC_CPT_GET(pos) \
59 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
61 #define LNET_PROC_VER_GET(pos) \
62 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
64 #define LNET_PROC_HASH_GET(pos) \
65 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
67 #define LNET_PROC_HOFF_GET(pos) \
68 (int)((pos) & LNET_PROC_HOFF_MASK)
70 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
71 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
72 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
73 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
74 ((off) & LNET_PROC_HOFF_MASK))
76 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
78 static int proc_call_handler(void *data, int write, loff_t *ppos,
79 void __user *buffer, size_t *lenp,
80 int (*handler)(void *data, int write,
81 loff_t pos, void __user *buffer, int len))
83 int rc = handler(data, write, *ppos, buffer, *lenp);
97 static int __proc_lnet_stats(void *data, int write,
98 loff_t pos, void __user *buffer, int nob)
101 lnet_counters_t *ctrs;
104 const int tmpsiz = 256; /* 7 %u and 4 %llu */
107 lnet_counters_reset();
113 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
117 LIBCFS_ALLOC(tmpstr, tmpsiz);
118 if (tmpstr == NULL) {
119 LIBCFS_FREE(ctrs, sizeof(*ctrs));
123 lnet_counters_get(ctrs);
125 len = snprintf(tmpstr, tmpsiz,
126 "%u %u %u %u %u %u %u %llu %llu %llu %llu",
127 ctrs->msgs_alloc, ctrs->msgs_max,
129 ctrs->send_count, ctrs->recv_count,
130 ctrs->route_count, ctrs->drop_count,
131 ctrs->send_length, ctrs->recv_length,
132 ctrs->route_length, ctrs->drop_length);
134 if (pos >= min_t(int, len, strlen(tmpstr)))
137 rc = cfs_trace_copyout_string(buffer, nob,
140 LIBCFS_FREE(tmpstr, tmpsiz);
141 LIBCFS_FREE(ctrs, sizeof(*ctrs));
145 static int proc_lnet_stats(struct ctl_table *table, int write,
146 void __user *buffer, size_t *lenp, loff_t *ppos)
148 return proc_call_handler(table->data, write, ppos, buffer, lenp,
152 static int proc_lnet_routes(struct ctl_table *table, int write,
153 void __user *buffer, size_t *lenp, loff_t *ppos)
155 const int tmpsiz = 256;
163 CLASSERT(sizeof(loff_t) >= 4);
165 off = LNET_PROC_HOFF_GET(*ppos);
166 ver = LNET_PROC_VER_GET(*ppos);
173 LIBCFS_ALLOC(tmpstr, tmpsiz);
177 s = tmpstr; /* points to current position in tmpstr[] */
180 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
181 the_lnet.ln_routing ? "enabled" : "disabled");
182 LASSERT(tmpstr + tmpsiz - s > 0);
184 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
185 "net", "hops", "priority", "state", "router");
186 LASSERT(tmpstr + tmpsiz - s > 0);
189 ver = (unsigned int)the_lnet.ln_remote_nets_version;
191 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
195 lnet_route_t *route = NULL;
196 lnet_remotenet_t *rnet = NULL;
198 struct list_head *rn_list;
203 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
205 LIBCFS_FREE(tmpstr, tmpsiz);
209 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
211 rn_list = &the_lnet.ln_remote_nets_hash[i];
215 while (n != rn_list && route == NULL) {
216 rnet = list_entry(n, lnet_remotenet_t,
219 r = rnet->lrn_routes.next;
221 while (r != &rnet->lrn_routes) {
223 list_entry(r, lnet_route_t,
239 __u32 net = rnet->lrn_net;
240 unsigned int hops = route->lr_hops;
241 unsigned int priority = route->lr_priority;
242 lnet_nid_t nid = route->lr_gateway->lp_nid;
243 int alive = route->lr_gateway->lp_alive;
245 s += snprintf(s, tmpstr + tmpsiz - s,
246 "%-8s %4u %8u %7s %s\n",
247 libcfs_net2str(net), hops,
249 alive ? "up" : "down",
250 libcfs_nid2str(nid));
251 LASSERT(tmpstr + tmpsiz - s > 0);
257 len = s - tmpstr; /* how many bytes was written */
259 if (len > *lenp) { /* linux-supplied buffer is too small */
261 } else if (len > 0) { /* wrote something */
262 if (copy_to_user(buffer, tmpstr, len))
266 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
270 LIBCFS_FREE(tmpstr, tmpsiz);
278 static int proc_lnet_routers(struct ctl_table *table, int write,
279 void __user *buffer, size_t *lenp, loff_t *ppos)
284 const int tmpsiz = 256;
289 off = LNET_PROC_HOFF_GET(*ppos);
290 ver = LNET_PROC_VER_GET(*ppos);
297 LIBCFS_ALLOC(tmpstr, tmpsiz);
301 s = tmpstr; /* points to current position in tmpstr[] */
304 s += snprintf(s, tmpstr + tmpsiz - s,
305 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
306 "ref", "rtr_ref", "alive_cnt", "state",
307 "last_ping", "ping_sent", "deadline",
308 "down_ni", "router");
309 LASSERT(tmpstr + tmpsiz - s > 0);
312 ver = (unsigned int)the_lnet.ln_routers_version;
314 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
317 struct lnet_peer *peer = NULL;
322 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
325 LIBCFS_FREE(tmpstr, tmpsiz);
329 r = the_lnet.ln_routers.next;
331 while (r != &the_lnet.ln_routers) {
332 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
345 lnet_nid_t nid = peer->lp_nid;
346 unsigned long now = cfs_time_current();
347 unsigned long deadline = peer->lp_ping_deadline;
348 int nrefs = peer->lp_refcount;
349 int nrtrrefs = peer->lp_rtr_refcount;
350 int alive_cnt = peer->lp_alive_count;
351 int alive = peer->lp_alive;
352 int pingsent = !peer->lp_ping_notsent;
353 int last_ping = cfs_duration_sec(cfs_time_sub(now,
354 peer->lp_ping_timestamp));
358 if ((peer->lp_ping_feats &
359 LNET_PING_FEAT_NI_STATUS) != 0) {
360 list_for_each_entry(rtr, &peer->lp_routes,
362 /* downis on any route should be the
363 * number of downis on the gateway */
364 if (rtr->lr_downis != 0) {
365 down_ni = rtr->lr_downis;
372 s += snprintf(s, tmpstr + tmpsiz - s,
373 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
374 nrefs, nrtrrefs, alive_cnt,
375 alive ? "up" : "down", last_ping,
376 pingsent, "NA", down_ni,
377 libcfs_nid2str(nid));
379 s += snprintf(s, tmpstr + tmpsiz - s,
380 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
381 nrefs, nrtrrefs, alive_cnt,
382 alive ? "up" : "down", last_ping,
384 cfs_duration_sec(cfs_time_sub(deadline, now)),
385 down_ni, libcfs_nid2str(nid));
386 LASSERT(tmpstr + tmpsiz - s > 0);
392 len = s - tmpstr; /* how many bytes was written */
394 if (len > *lenp) { /* linux-supplied buffer is too small */
396 } else if (len > 0) { /* wrote something */
397 if (copy_to_user(buffer, tmpstr, len))
401 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
405 LIBCFS_FREE(tmpstr, tmpsiz);
413 static int proc_lnet_peers(struct ctl_table *table, int write,
414 void __user *buffer, size_t *lenp, loff_t *ppos)
416 const int tmpsiz = 256;
417 struct lnet_peer_table *ptable;
420 int cpt = LNET_PROC_CPT_GET(*ppos);
421 int ver = LNET_PROC_VER_GET(*ppos);
422 int hash = LNET_PROC_HASH_GET(*ppos);
423 int hoff = LNET_PROC_HOFF_GET(*ppos);
427 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
433 if (cpt >= LNET_CPT_NUMBER) {
438 LIBCFS_ALLOC(tmpstr, tmpsiz);
442 s = tmpstr; /* points to current position in tmpstr[] */
445 s += snprintf(s, tmpstr + tmpsiz - s,
446 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
447 "nid", "refs", "state", "last", "max",
448 "rtr", "min", "tx", "min", "queue");
449 LASSERT(tmpstr + tmpsiz - s > 0);
453 struct lnet_peer *peer;
462 ptable = the_lnet.ln_peer_tables[cpt];
464 ver = LNET_PROC_VERSION(ptable->pt_version);
466 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
467 lnet_net_unlock(cpt);
468 LIBCFS_FREE(tmpstr, tmpsiz);
472 while (hash < LNET_PEER_HASH_SIZE) {
474 p = ptable->pt_hash[hash].next;
476 while (p != &ptable->pt_hash[hash]) {
477 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
482 /* minor optimization: start from idx+1
483 * on next iteration if we've just
484 * drained lp_hashlist */
485 if (lp->lp_hashlist.next ==
486 &ptable->pt_hash[hash]) {
497 p = lp->lp_hashlist.next;
509 lnet_nid_t nid = peer->lp_nid;
510 int nrefs = peer->lp_refcount;
512 char *aliveness = "NA";
513 int maxcr = peer->lp_ni->ni_peertxcredits;
514 int txcr = peer->lp_txcredits;
515 int mintxcr = peer->lp_mintxcredits;
516 int rtrcr = peer->lp_rtrcredits;
517 int minrtrcr = peer->lp_minrtrcredits;
518 int txqnob = peer->lp_txqnob;
520 if (lnet_isrouter(peer) ||
521 lnet_peer_aliveness_enabled(peer))
522 aliveness = peer->lp_alive ? "up" : "down";
524 if (lnet_peer_aliveness_enabled(peer)) {
525 unsigned long now = cfs_time_current();
528 delta = cfs_time_sub(now, peer->lp_last_alive);
529 lastalive = cfs_duration_sec(delta);
531 /* No need to mess up peers contents with
532 * arbitrarily long integers - it suffices to
533 * know that lastalive is more than 10000s old
535 if (lastalive >= 10000)
539 lnet_net_unlock(cpt);
541 s += snprintf(s, tmpstr + tmpsiz - s,
542 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
543 libcfs_nid2str(nid), nrefs, aliveness,
544 lastalive, maxcr, rtrcr, minrtrcr, txcr,
546 LASSERT(tmpstr + tmpsiz - s > 0);
548 } else { /* peer is NULL */
549 lnet_net_unlock(cpt);
552 if (hash == LNET_PEER_HASH_SIZE) {
556 if (peer == NULL && cpt < LNET_CPT_NUMBER)
561 len = s - tmpstr; /* how many bytes was written */
563 if (len > *lenp) { /* linux-supplied buffer is too small */
565 } else if (len > 0) { /* wrote something */
566 if (copy_to_user(buffer, tmpstr, len))
569 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
572 LIBCFS_FREE(tmpstr, tmpsiz);
580 static int __proc_lnet_buffers(void *data, int write,
581 loff_t pos, void __user *buffer, int nob)
593 /* (4 %d) * 4 * LNET_CPT_NUMBER */
594 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
595 LIBCFS_ALLOC(tmpstr, tmpsiz);
599 s = tmpstr; /* points to current position in tmpstr[] */
601 s += snprintf(s, tmpstr + tmpsiz - s,
603 "pages", "count", "credits", "min");
604 LASSERT(tmpstr + tmpsiz - s > 0);
606 if (the_lnet.ln_rtrpools == NULL)
607 goto out; /* I'm not a router */
609 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
610 lnet_rtrbufpool_t *rbp;
612 lnet_net_lock(LNET_LOCK_EX);
613 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
614 s += snprintf(s, tmpstr + tmpsiz - s,
617 rbp[idx].rbp_nbuffers,
618 rbp[idx].rbp_credits,
619 rbp[idx].rbp_mincredits);
620 LASSERT(tmpstr + tmpsiz - s > 0);
622 lnet_net_unlock(LNET_LOCK_EX);
628 if (pos >= min_t(int, len, strlen(tmpstr)))
631 rc = cfs_trace_copyout_string(buffer, nob,
634 LIBCFS_FREE(tmpstr, tmpsiz);
638 static int proc_lnet_buffers(struct ctl_table *table, int write,
639 void __user *buffer, size_t *lenp, loff_t *ppos)
641 return proc_call_handler(table->data, write, ppos, buffer, lenp,
642 __proc_lnet_buffers);
645 static int proc_lnet_nis(struct ctl_table *table, int write,
646 void __user *buffer, size_t *lenp, loff_t *ppos)
648 int tmpsiz = 128 * LNET_CPT_NUMBER;
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 = list_entry(n, lnet_ni_t, ni_list);
693 struct lnet_tx_queue *tq;
695 time64_t now = ktime_get_real_seconds();
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 wildcard portals"
782 .pr_value = LNET_PTL_ROTOR_RR_RT,
784 .pr_desc = "round-robin dispatch routed PUT message for wildcard portals"
787 .pr_value = LNET_PTL_ROTOR_HASH_RT,
788 .pr_name = "HASH_RT",
789 .pr_desc = "dispatch routed PUT message by hashing source NID for wildcard portals"
798 extern int portal_rotor;
800 static int __proc_lnet_portal_rotor(void *data, int write,
801 loff_t pos, void __user *buffer, int nob)
803 const int buf_len = 128;
809 LIBCFS_ALLOC(buf, buf_len);
816 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
817 if (portal_rotors[i].pr_value == portal_rotor)
821 LASSERT(portal_rotors[i].pr_value == portal_rotor);
824 rc = snprintf(buf, buf_len,
825 "{\n\tportals: all\n"
826 "\trotor: %s\n\tdescription: %s\n}",
827 portal_rotors[i].pr_name,
828 portal_rotors[i].pr_desc);
830 if (pos >= min_t(int, rc, buf_len)) {
833 rc = cfs_trace_copyout_string(buffer, nob,
839 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
843 tmp = cfs_trimwhite(buf);
847 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
848 if (strncasecmp(portal_rotors[i].pr_name, tmp,
849 strlen(portal_rotors[i].pr_name)) == 0) {
850 portal_rotor = portal_rotors[i].pr_value;
857 LIBCFS_FREE(buf, buf_len);
861 static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
862 void __user *buffer, size_t *lenp,
865 return proc_call_handler(table->data, write, ppos, buffer, lenp,
866 __proc_lnet_portal_rotor);
869 static struct ctl_table lnet_table[] = {
871 * NB No .strategy entries have been provided since sysctl(8) prefers
872 * to go via /proc for portability.
877 .proc_handler = &proc_lnet_stats,
880 .procname = "routes",
882 .proc_handler = &proc_lnet_routes,
885 .procname = "routers",
887 .proc_handler = &proc_lnet_routers,
892 .proc_handler = &proc_lnet_peers,
895 .procname = "buffers",
897 .proc_handler = &proc_lnet_buffers,
902 .proc_handler = &proc_lnet_nis,
905 .procname = "portal_rotor",
907 .proc_handler = &proc_lnet_portal_rotor,
913 void lnet_router_debugfs_init(void)
915 lustre_insert_debugfs(lnet_table, NULL);
918 void lnet_router_debugfs_fini(void)