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 struct ctl_table_header *lnet_table_header = NULL;
35 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
37 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
39 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
40 /* change version, 16 bits or 8 bits */
41 #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
43 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
45 * bits for peer hash offset
46 * NB: we don't use the highest bit of *ppos because it's signed
48 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
49 LNET_PROC_CPT_BITS - \
50 LNET_PROC_VER_BITS - \
51 LNET_PROC_HASH_BITS - 1)
52 /* bits for hash index + position */
53 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
54 /* bits for peer hash table + hash version */
55 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
57 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
58 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
59 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
60 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
62 #define LNET_PROC_CPT_GET(pos) \
63 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
65 #define LNET_PROC_VER_GET(pos) \
66 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
68 #define LNET_PROC_HASH_GET(pos) \
69 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
71 #define LNET_PROC_HOFF_GET(pos) \
72 (int)((pos) & LNET_PROC_HOFF_MASK)
74 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
75 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
76 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
77 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
78 ((off) & LNET_PROC_HOFF_MASK))
80 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
82 static int __proc_lnet_stats(void *data, int write,
83 loff_t pos, void *buffer, int nob)
86 lnet_counters_t *ctrs;
89 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
92 lnet_counters_reset();
98 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
102 LIBCFS_ALLOC(tmpstr, tmpsiz);
103 if (tmpstr == NULL) {
104 LIBCFS_FREE(ctrs, sizeof(*ctrs));
108 lnet_counters_get(ctrs);
110 len = snprintf(tmpstr, tmpsiz,
111 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
113 ctrs->msgs_alloc, ctrs->msgs_max,
115 ctrs->send_count, ctrs->recv_count,
116 ctrs->route_count, ctrs->drop_count,
117 ctrs->send_length, ctrs->recv_length,
118 ctrs->route_length, ctrs->drop_length);
120 if (pos >= min_t(int, len, strlen(tmpstr)))
123 rc = cfs_trace_copyout_string(buffer, nob,
126 LIBCFS_FREE(tmpstr, tmpsiz);
127 LIBCFS_FREE(ctrs, sizeof(*ctrs));
131 DECLARE_PROC_HANDLER(proc_lnet_stats);
133 int LL_PROC_PROTO(proc_lnet_routes)
135 const int tmpsiz = 256;
143 CLASSERT(sizeof(loff_t) >= 4);
145 off = LNET_PROC_HOFF_GET(*ppos);
146 ver = LNET_PROC_VER_GET(*ppos);
153 LIBCFS_ALLOC(tmpstr, tmpsiz);
157 s = tmpstr; /* points to current position in tmpstr[] */
160 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
161 the_lnet.ln_routing ? "enabled" : "disabled");
162 LASSERT (tmpstr + tmpsiz - s > 0);
164 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
165 "net", "hops", "priority", "state", "router");
166 LASSERT (tmpstr + tmpsiz - s > 0);
169 ver = (unsigned int)the_lnet.ln_remote_nets_version;
171 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
175 lnet_route_t *route = NULL;
176 lnet_remotenet_t *rnet = NULL;
178 struct list_head *rn_list;
183 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
185 LIBCFS_FREE(tmpstr, tmpsiz);
189 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
191 rn_list = &the_lnet.ln_remote_nets_hash[i];
195 while (n != rn_list && route == NULL) {
196 rnet = list_entry(n, lnet_remotenet_t,
199 r = rnet->lrn_routes.next;
201 while (r != &rnet->lrn_routes) {
203 list_entry(r, lnet_route_t,
219 __u32 net = rnet->lrn_net;
220 unsigned int hops = route->lr_hops;
221 unsigned int priority = route->lr_priority;
222 lnet_nid_t nid = route->lr_gateway->lp_nid;
223 int alive = lnet_is_route_alive(route);
225 s += snprintf(s, tmpstr + tmpsiz - s,
226 "%-8s %4u %8u %7s %s\n",
227 libcfs_net2str(net), hops,
229 alive ? "up" : "down",
230 libcfs_nid2str(nid));
231 LASSERT(tmpstr + tmpsiz - s > 0);
237 len = s - tmpstr; /* how many bytes was written */
239 if (len > *lenp) { /* linux-supplied buffer is too small */
241 } else if (len > 0) { /* wrote something */
242 if (copy_to_user(buffer, tmpstr, len))
246 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
250 LIBCFS_FREE(tmpstr, tmpsiz);
258 int LL_PROC_PROTO(proc_lnet_routers)
263 const int tmpsiz = 256;
268 off = LNET_PROC_HOFF_GET(*ppos);
269 ver = LNET_PROC_VER_GET(*ppos);
276 LIBCFS_ALLOC(tmpstr, tmpsiz);
280 s = tmpstr; /* points to current position in tmpstr[] */
283 s += snprintf(s, tmpstr + tmpsiz - s,
284 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
285 "ref", "rtr_ref", "alive_cnt", "state",
286 "last_ping", "ping_sent", "deadline",
287 "down_ni", "router");
288 LASSERT(tmpstr + tmpsiz - s > 0);
291 ver = (unsigned int)the_lnet.ln_routers_version;
293 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
296 struct lnet_peer *peer = NULL;
301 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
304 LIBCFS_FREE(tmpstr, tmpsiz);
308 r = the_lnet.ln_routers.next;
310 while (r != &the_lnet.ln_routers) {
311 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
324 lnet_nid_t nid = peer->lp_nid;
325 cfs_time_t now = cfs_time_current();
326 cfs_time_t deadline = peer->lp_ping_deadline;
327 int nrefs = peer->lp_refcount;
328 int nrtrrefs = peer->lp_rtr_refcount;
329 int alive_cnt = peer->lp_alive_count;
330 int alive = peer->lp_alive;
331 int pingsent = !peer->lp_ping_notsent;
332 int last_ping = cfs_duration_sec(cfs_time_sub(now,
333 peer->lp_ping_timestamp));
337 if ((peer->lp_ping_feats &
338 LNET_PING_FEAT_NI_STATUS) != 0) {
339 list_for_each_entry(rtr, &peer->lp_routes,
341 /* downis on any route should be the
342 * number of downis on the gateway */
343 if (rtr->lr_downis != 0) {
344 down_ni = rtr->lr_downis;
351 s += snprintf(s, tmpstr + tmpsiz - s,
352 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
353 nrefs, nrtrrefs, alive_cnt,
354 alive ? "up" : "down", last_ping,
355 pingsent, "NA", down_ni,
356 libcfs_nid2str(nid));
358 s += snprintf(s, tmpstr + tmpsiz - s,
359 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
360 nrefs, nrtrrefs, alive_cnt,
361 alive ? "up" : "down", last_ping,
363 cfs_duration_sec(cfs_time_sub(deadline, now)),
364 down_ni, libcfs_nid2str(nid));
365 LASSERT (tmpstr + tmpsiz - s > 0);
371 len = s - tmpstr; /* how many bytes was written */
373 if (len > *lenp) { /* linux-supplied buffer is too small */
375 } else if (len > 0) { /* wrote something */
376 if (copy_to_user(buffer, tmpstr, len))
380 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
384 LIBCFS_FREE(tmpstr, tmpsiz);
392 int LL_PROC_PROTO(proc_lnet_peers)
394 const int tmpsiz = 256;
395 struct lnet_peer_table *ptable;
398 int cpt = LNET_PROC_CPT_GET(*ppos);
399 int ver = LNET_PROC_VER_GET(*ppos);
400 int hash = LNET_PROC_HASH_GET(*ppos);
401 int hoff = LNET_PROC_HOFF_GET(*ppos);
405 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
411 if (cpt >= LNET_CPT_NUMBER) {
416 LIBCFS_ALLOC(tmpstr, tmpsiz);
420 s = tmpstr; /* points to current position in tmpstr[] */
423 s += snprintf(s, tmpstr + tmpsiz - s,
424 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
425 "nid", "refs", "state", "last", "max",
426 "rtr", "min", "tx", "min", "queue");
427 LASSERT (tmpstr + tmpsiz - s > 0);
431 struct lnet_peer *peer;
440 ptable = the_lnet.ln_peer_tables[cpt];
442 ver = LNET_PROC_VERSION(ptable->pt_version);
444 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
445 lnet_net_unlock(cpt);
446 LIBCFS_FREE(tmpstr, tmpsiz);
450 while (hash < LNET_PEER_HASH_SIZE) {
452 p = ptable->pt_hash[hash].next;
454 while (p != &ptable->pt_hash[hash]) {
455 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
460 /* minor optimization: start from idx+1
461 * on next iteration if we've just
462 * drained lp_hashlist */
463 if (lp->lp_hashlist.next ==
464 &ptable->pt_hash[hash]) {
475 p = lp->lp_hashlist.next;
487 lnet_nid_t nid = peer->lp_nid;
488 int nrefs = peer->lp_refcount;
490 char *aliveness = "NA";
491 int maxcr = peer->lp_ni->ni_peertxcredits;
492 int txcr = peer->lp_txcredits;
493 int mintxcr = peer->lp_mintxcredits;
494 int rtrcr = peer->lp_rtrcredits;
495 int minrtrcr = peer->lp_minrtrcredits;
496 int txqnob = peer->lp_txqnob;
498 if (lnet_isrouter(peer) ||
499 lnet_peer_aliveness_enabled(peer))
500 aliveness = peer->lp_alive ? "up" : "down";
502 if (lnet_peer_aliveness_enabled(peer)) {
503 cfs_time_t now = cfs_time_current();
504 cfs_duration_t delta;
506 delta = cfs_time_sub(now, peer->lp_last_alive);
507 lastalive = cfs_duration_sec(delta);
509 /* No need to mess up peers contents with
510 * arbitrarily long integers - it suffices to
511 * know that lastalive is more than 10000s old
513 if (lastalive >= 10000)
517 lnet_net_unlock(cpt);
519 s += snprintf(s, tmpstr + tmpsiz - s,
520 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
521 libcfs_nid2str(nid), nrefs, aliveness,
522 lastalive, maxcr, rtrcr, minrtrcr, txcr,
524 LASSERT (tmpstr + tmpsiz - s > 0);
526 } else { /* peer is NULL */
527 lnet_net_unlock(cpt);
530 if (hash == LNET_PEER_HASH_SIZE) {
534 if (peer == NULL && cpt < LNET_CPT_NUMBER)
539 len = s - tmpstr; /* how many bytes was written */
541 if (len > *lenp) { /* linux-supplied buffer is too small */
543 } else if (len > 0) { /* wrote something */
544 if (copy_to_user(buffer, tmpstr, len))
547 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
550 LIBCFS_FREE(tmpstr, tmpsiz);
558 static int __proc_lnet_buffers(void *data, int write,
559 loff_t pos, void *buffer, int nob)
571 /* (4 %d) * 4 * LNET_CPT_NUMBER */
572 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
573 LIBCFS_ALLOC(tmpstr, tmpsiz);
577 s = tmpstr; /* points to current position in tmpstr[] */
579 s += snprintf(s, tmpstr + tmpsiz - s,
581 "pages", "count", "credits", "min");
582 LASSERT (tmpstr + tmpsiz - s > 0);
584 if (the_lnet.ln_rtrpools == NULL)
585 goto out; /* I'm not a router */
587 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
588 lnet_rtrbufpool_t *rbp;
590 lnet_net_lock(LNET_LOCK_EX);
591 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
592 s += snprintf(s, tmpstr + tmpsiz - s,
595 rbp[idx].rbp_nbuffers,
596 rbp[idx].rbp_credits,
597 rbp[idx].rbp_mincredits);
598 LASSERT(tmpstr + tmpsiz - s > 0);
600 lnet_net_unlock(LNET_LOCK_EX);
606 if (pos >= min_t(int, len, strlen(tmpstr)))
609 rc = cfs_trace_copyout_string(buffer, nob,
612 LIBCFS_FREE(tmpstr, tmpsiz);
616 DECLARE_PROC_HANDLER(proc_lnet_buffers);
618 int LL_PROC_PROTO(proc_lnet_nis)
620 int tmpsiz = 128 * LNET_CPT_NUMBER;
631 LIBCFS_ALLOC(tmpstr, tmpsiz);
635 s = tmpstr; /* points to current position in tmpstr[] */
638 s += snprintf(s, tmpstr + tmpsiz - s,
639 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
640 "nid", "status", "alive", "refs", "peer",
641 "rtr", "max", "tx", "min");
642 LASSERT (tmpstr + tmpsiz - s > 0);
645 lnet_ni_t *ni = NULL;
646 int skip = *ppos - 1;
650 n = the_lnet.ln_nis.next;
652 while (n != &the_lnet.ln_nis) {
653 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
665 struct lnet_tx_queue *tq;
667 long now = cfs_time_current_sec();
672 if (the_lnet.ln_routing)
673 last_alive = now - ni->ni_last_alive;
675 /* @lo forever alive */
676 if (ni->ni_lnd->lnd_type == LOLND)
680 LASSERT(ni->ni_status != NULL);
681 stat = (ni->ni_status->ns_status ==
682 LNET_NI_STATUS_UP) ? "up" : "down";
685 /* we actually output credits information for
686 * TX queue of each partition */
687 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
688 for (j = 0; ni->ni_cpts != NULL &&
689 j < ni->ni_ncpts; j++) {
690 if (i == ni->ni_cpts[j])
694 if (j == ni->ni_ncpts)
700 s += snprintf(s, tmpstr + tmpsiz - s,
701 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
702 libcfs_nid2str(ni->ni_nid), stat,
703 last_alive, *ni->ni_refs[i],
704 ni->ni_peertxcredits,
705 ni->ni_peerrtrcredits,
707 tq->tq_credits, tq->tq_credits_min);
711 LASSERT(tmpstr + tmpsiz - s > 0);
717 len = s - tmpstr; /* how many bytes was written */
719 if (len > *lenp) { /* linux-supplied buffer is too small */
721 } else if (len > 0) { /* wrote something */
722 if (copy_to_user(buffer, tmpstr, len))
728 LIBCFS_FREE(tmpstr, tmpsiz);
736 struct lnet_portal_rotors {
742 static struct lnet_portal_rotors portal_rotors[] = {
744 .pr_value = LNET_PTL_ROTOR_OFF,
746 .pr_desc = "Turn off message rotor for wildcard portals"
749 .pr_value = LNET_PTL_ROTOR_ON,
751 .pr_desc = "round-robin dispatch all PUT messages for "
755 .pr_value = LNET_PTL_ROTOR_RR_RT,
757 .pr_desc = "round-robin dispatch routed PUT message for "
761 .pr_value = LNET_PTL_ROTOR_HASH_RT,
762 .pr_name = "HASH_RT",
763 .pr_desc = "dispatch routed PUT message by hashing source "
764 "NID for wildcard portals"
773 extern int portal_rotor;
775 static int __proc_lnet_portal_rotor(void *data, int write,
776 loff_t pos, void *buffer, int nob)
778 const int buf_len = 128;
784 LIBCFS_ALLOC(buf, buf_len);
791 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
792 if (portal_rotors[i].pr_value == portal_rotor)
796 LASSERT(portal_rotors[i].pr_value == portal_rotor);
799 rc = snprintf(buf, buf_len,
800 "{\n\tportals: all\n"
801 "\trotor: %s\n\tdescription: %s\n}",
802 portal_rotors[i].pr_name,
803 portal_rotors[i].pr_desc);
805 if (pos >= min_t(int, rc, buf_len)) {
808 rc = cfs_trace_copyout_string(buffer, nob,
814 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
818 tmp = cfs_trimwhite(buf);
822 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
823 if (cfs_strncasecmp(portal_rotors[i].pr_name, tmp,
824 strlen(portal_rotors[i].pr_name)) == 0) {
825 portal_rotor = portal_rotors[i].pr_value;
832 LIBCFS_FREE(buf, buf_len);
835 DECLARE_PROC_HANDLER(proc_lnet_portal_rotor);
837 static struct ctl_table lnet_table[] = {
839 * NB No .strategy entries have been provided since sysctl(8) prefers
840 * to go via /proc for portability.
846 .proc_handler = &proc_lnet_stats,
850 .procname = "routes",
852 .proc_handler = &proc_lnet_routes,
856 .procname = "routers",
858 .proc_handler = &proc_lnet_routers,
864 .proc_handler = &proc_lnet_peers,
868 .procname = "buffers",
870 .proc_handler = &proc_lnet_buffers,
876 .proc_handler = &proc_lnet_nis,
880 .procname = "portal_rotor",
882 .proc_handler = &proc_lnet_portal_rotor,
887 static struct ctl_table top_table[] = {
903 if (lnet_table_header == NULL)
904 lnet_table_header = register_sysctl_table(top_table);
912 if (lnet_table_header != NULL)
913 unregister_sysctl_table(lnet_table_header);
915 lnet_table_header = NULL;