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 Lustre, https://wiki.hpdd.intel.com/
8 * Portals is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Portals is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Portals; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_LNET
24 #include <libcfs/libcfs.h>
25 #include <lnet/lib-lnet.h>
27 /* This is really lnet_proc.c. You might need to update sanity test 215
28 * if any file format is changed. */
30 static struct ctl_table_header *lnet_table_header = NULL;
32 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
34 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
36 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
37 /* change version, 16 bits or 8 bits */
38 #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
40 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
42 * bits for peer hash offset
43 * NB: we don't use the highest bit of *ppos because it's signed
45 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
46 LNET_PROC_CPT_BITS - \
47 LNET_PROC_VER_BITS - \
48 LNET_PROC_HASH_BITS - 1)
49 /* bits for hash index + position */
50 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
51 /* bits for peer hash table + hash version */
52 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
54 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
55 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
56 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
57 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
59 #define LNET_PROC_CPT_GET(pos) \
60 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
62 #define LNET_PROC_VER_GET(pos) \
63 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
65 #define LNET_PROC_HASH_GET(pos) \
66 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
68 #define LNET_PROC_HOFF_GET(pos) \
69 (int)((pos) & LNET_PROC_HOFF_MASK)
71 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
72 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
73 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
74 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
75 ((off) & LNET_PROC_HOFF_MASK))
77 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
79 static int __proc_lnet_stats(void *data, int write,
80 loff_t pos, void __user *buffer, int nob)
83 lnet_counters_t *ctrs;
86 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
89 lnet_counters_reset();
95 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
99 LIBCFS_ALLOC(tmpstr, tmpsiz);
100 if (tmpstr == NULL) {
101 LIBCFS_FREE(ctrs, sizeof(*ctrs));
105 lnet_counters_get(ctrs);
107 len = snprintf(tmpstr, tmpsiz,
108 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
110 ctrs->msgs_alloc, ctrs->msgs_max,
112 ctrs->send_count, ctrs->recv_count,
113 ctrs->route_count, ctrs->drop_count,
114 ctrs->send_length, ctrs->recv_length,
115 ctrs->route_length, ctrs->drop_length);
117 if (pos >= min_t(int, len, strlen(tmpstr)))
120 rc = cfs_trace_copyout_string(buffer, nob,
123 LIBCFS_FREE(tmpstr, tmpsiz);
124 LIBCFS_FREE(ctrs, sizeof(*ctrs));
129 proc_lnet_stats(struct ctl_table *table, int write, void __user *buffer,
130 size_t *lenp, loff_t *ppos)
132 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
137 proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer,
138 size_t *lenp, loff_t *ppos)
140 const int tmpsiz = 256;
148 CLASSERT(sizeof(loff_t) >= 4);
150 off = LNET_PROC_HOFF_GET(*ppos);
151 ver = LNET_PROC_VER_GET(*ppos);
158 LIBCFS_ALLOC(tmpstr, tmpsiz);
162 s = tmpstr; /* points to current position in tmpstr[] */
165 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
166 the_lnet.ln_routing ? "enabled" : "disabled");
167 LASSERT (tmpstr + tmpsiz - s > 0);
169 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
170 "net", "hops", "priority", "state", "router");
171 LASSERT (tmpstr + tmpsiz - s > 0);
174 ver = (unsigned int)the_lnet.ln_remote_nets_version;
176 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
180 lnet_route_t *route = NULL;
181 lnet_remotenet_t *rnet = NULL;
183 struct list_head *rn_list;
188 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
190 LIBCFS_FREE(tmpstr, tmpsiz);
194 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
196 rn_list = &the_lnet.ln_remote_nets_hash[i];
200 while (n != rn_list && route == NULL) {
201 rnet = list_entry(n, lnet_remotenet_t,
204 r = rnet->lrn_routes.next;
206 while (r != &rnet->lrn_routes) {
208 list_entry(r, lnet_route_t,
224 __u32 net = rnet->lrn_net;
225 unsigned int hops = route->lr_hops;
226 unsigned int priority = route->lr_priority;
227 lnet_nid_t nid = route->lr_gateway->lp_nid;
228 int alive = lnet_is_route_alive(route);
230 s += snprintf(s, tmpstr + tmpsiz - s,
231 "%-8s %4u %8u %7s %s\n",
232 libcfs_net2str(net), hops,
234 alive ? "up" : "down",
235 libcfs_nid2str(nid));
236 LASSERT(tmpstr + tmpsiz - s > 0);
242 len = s - tmpstr; /* how many bytes was written */
244 if (len > *lenp) { /* linux-supplied buffer is too small */
246 } else if (len > 0) { /* wrote something */
247 if (copy_to_user(buffer, tmpstr, len))
251 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
255 LIBCFS_FREE(tmpstr, tmpsiz);
264 proc_lnet_routers(struct ctl_table *table, int write, void __user *buffer,
265 size_t *lenp, loff_t *ppos)
270 const int tmpsiz = 256;
275 off = LNET_PROC_HOFF_GET(*ppos);
276 ver = LNET_PROC_VER_GET(*ppos);
283 LIBCFS_ALLOC(tmpstr, tmpsiz);
287 s = tmpstr; /* points to current position in tmpstr[] */
290 s += snprintf(s, tmpstr + tmpsiz - s,
291 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
292 "ref", "rtr_ref", "alive_cnt", "state",
293 "last_ping", "ping_sent", "deadline",
294 "down_ni", "router");
295 LASSERT(tmpstr + tmpsiz - s > 0);
298 ver = (unsigned int)the_lnet.ln_routers_version;
300 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
303 struct lnet_peer *peer = NULL;
308 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
311 LIBCFS_FREE(tmpstr, tmpsiz);
315 r = the_lnet.ln_routers.next;
317 while (r != &the_lnet.ln_routers) {
318 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
331 lnet_nid_t nid = peer->lp_nid;
332 cfs_time_t now = cfs_time_current();
333 cfs_time_t deadline = peer->lp_ping_deadline;
334 int nrefs = peer->lp_refcount;
335 int nrtrrefs = peer->lp_rtr_refcount;
336 int alive_cnt = peer->lp_alive_count;
337 int alive = peer->lp_alive;
338 int pingsent = !peer->lp_ping_notsent;
339 int last_ping = cfs_duration_sec(cfs_time_sub(now,
340 peer->lp_ping_timestamp));
344 if ((peer->lp_ping_feats &
345 LNET_PING_FEAT_NI_STATUS) != 0) {
346 list_for_each_entry(rtr, &peer->lp_routes,
348 /* downis on any route should be the
349 * number of downis on the gateway */
350 if (rtr->lr_downis != 0) {
351 down_ni = rtr->lr_downis;
358 s += snprintf(s, tmpstr + tmpsiz - s,
359 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
360 nrefs, nrtrrefs, alive_cnt,
361 alive ? "up" : "down", last_ping,
362 pingsent, "NA", down_ni,
363 libcfs_nid2str(nid));
365 s += snprintf(s, tmpstr + tmpsiz - s,
366 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
367 nrefs, nrtrrefs, alive_cnt,
368 alive ? "up" : "down", last_ping,
370 cfs_duration_sec(cfs_time_sub(deadline, now)),
371 down_ni, libcfs_nid2str(nid));
372 LASSERT (tmpstr + tmpsiz - s > 0);
378 len = s - tmpstr; /* how many bytes was written */
380 if (len > *lenp) { /* linux-supplied buffer is too small */
382 } else if (len > 0) { /* wrote something */
383 if (copy_to_user(buffer, tmpstr, len))
387 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
391 LIBCFS_FREE(tmpstr, tmpsiz);
400 proc_lnet_peers(struct ctl_table *table, int write, void __user *buffer,
401 size_t *lenp, loff_t *ppos)
403 const int tmpsiz = 256;
404 struct lnet_peer_table *ptable;
407 int cpt = LNET_PROC_CPT_GET(*ppos);
408 int ver = LNET_PROC_VER_GET(*ppos);
409 int hash = LNET_PROC_HASH_GET(*ppos);
410 int hoff = LNET_PROC_HOFF_GET(*ppos);
414 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
420 if (cpt >= LNET_CPT_NUMBER) {
425 LIBCFS_ALLOC(tmpstr, tmpsiz);
429 s = tmpstr; /* points to current position in tmpstr[] */
432 s += snprintf(s, tmpstr + tmpsiz - s,
433 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
434 "nid", "refs", "state", "last", "max",
435 "rtr", "min", "tx", "min", "queue");
436 LASSERT (tmpstr + tmpsiz - s > 0);
440 struct lnet_peer *peer;
449 ptable = the_lnet.ln_peer_tables[cpt];
451 ver = LNET_PROC_VERSION(ptable->pt_version);
453 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
454 lnet_net_unlock(cpt);
455 LIBCFS_FREE(tmpstr, tmpsiz);
459 while (hash < LNET_PEER_HASH_SIZE) {
461 p = ptable->pt_hash[hash].next;
463 while (p != &ptable->pt_hash[hash]) {
464 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
469 /* minor optimization: start from idx+1
470 * on next iteration if we've just
471 * drained lp_hashlist */
472 if (lp->lp_hashlist.next ==
473 &ptable->pt_hash[hash]) {
484 p = lp->lp_hashlist.next;
496 lnet_nid_t nid = peer->lp_nid;
497 int nrefs = peer->lp_refcount;
499 char *aliveness = "NA";
500 int maxcr = peer->lp_ni->ni_peertxcredits;
501 int txcr = peer->lp_txcredits;
502 int mintxcr = peer->lp_mintxcredits;
503 int rtrcr = peer->lp_rtrcredits;
504 int minrtrcr = peer->lp_minrtrcredits;
505 int txqnob = peer->lp_txqnob;
507 if (lnet_isrouter(peer) ||
508 lnet_peer_aliveness_enabled(peer))
509 aliveness = peer->lp_alive ? "up" : "down";
511 if (lnet_peer_aliveness_enabled(peer)) {
512 cfs_time_t now = cfs_time_current();
513 cfs_duration_t delta;
515 delta = cfs_time_sub(now, peer->lp_last_alive);
516 lastalive = cfs_duration_sec(delta);
518 /* No need to mess up peers contents with
519 * arbitrarily long integers - it suffices to
520 * know that lastalive is more than 10000s old
522 if (lastalive >= 10000)
526 lnet_net_unlock(cpt);
528 s += snprintf(s, tmpstr + tmpsiz - s,
529 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
530 libcfs_nid2str(nid), nrefs, aliveness,
531 lastalive, maxcr, rtrcr, minrtrcr, txcr,
533 LASSERT (tmpstr + tmpsiz - s > 0);
535 } else { /* peer is NULL */
536 lnet_net_unlock(cpt);
539 if (hash == LNET_PEER_HASH_SIZE) {
543 if (peer == NULL && cpt < LNET_CPT_NUMBER)
548 len = s - tmpstr; /* how many bytes was written */
550 if (len > *lenp) { /* linux-supplied buffer is too small */
552 } else if (len > 0) { /* wrote something */
553 if (copy_to_user(buffer, tmpstr, len))
556 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
559 LIBCFS_FREE(tmpstr, tmpsiz);
567 static int __proc_lnet_buffers(void *data, int write,
568 loff_t pos, void __user *buffer, int nob)
580 /* (4 %d) * 4 * LNET_CPT_NUMBER */
581 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
582 LIBCFS_ALLOC(tmpstr, tmpsiz);
586 s = tmpstr; /* points to current position in tmpstr[] */
588 s += snprintf(s, tmpstr + tmpsiz - s,
590 "pages", "count", "credits", "min");
591 LASSERT (tmpstr + tmpsiz - s > 0);
593 if (the_lnet.ln_rtrpools == NULL)
594 goto out; /* I'm not a router */
596 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
597 lnet_rtrbufpool_t *rbp;
599 lnet_net_lock(LNET_LOCK_EX);
600 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
601 s += snprintf(s, tmpstr + tmpsiz - s,
604 rbp[idx].rbp_nbuffers,
605 rbp[idx].rbp_credits,
606 rbp[idx].rbp_mincredits);
607 LASSERT(tmpstr + tmpsiz - s > 0);
609 lnet_net_unlock(LNET_LOCK_EX);
615 if (pos >= min_t(int, len, strlen(tmpstr)))
618 rc = cfs_trace_copyout_string(buffer, nob,
621 LIBCFS_FREE(tmpstr, tmpsiz);
626 proc_lnet_buffers(struct ctl_table *table, int write, void __user *buffer,
627 size_t *lenp, loff_t *ppos)
629 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
630 __proc_lnet_buffers);
634 proc_lnet_nis(struct ctl_table *table, int write, void __user *buffer,
635 size_t *lenp, loff_t *ppos)
637 int tmpsiz = 128 * LNET_CPT_NUMBER;
648 LIBCFS_ALLOC(tmpstr, tmpsiz);
652 s = tmpstr; /* points to current position in tmpstr[] */
655 s += snprintf(s, tmpstr + tmpsiz - s,
656 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
657 "nid", "status", "alive", "refs", "peer",
658 "rtr", "max", "tx", "min");
659 LASSERT (tmpstr + tmpsiz - s > 0);
662 lnet_ni_t *ni = NULL;
663 int skip = *ppos - 1;
667 n = the_lnet.ln_nis.next;
669 while (n != &the_lnet.ln_nis) {
670 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
682 struct lnet_tx_queue *tq;
684 long now = cfs_time_current_sec();
689 if (the_lnet.ln_routing)
690 last_alive = now - ni->ni_last_alive;
692 /* @lo forever alive */
693 if (ni->ni_lnd->lnd_type == LOLND)
697 LASSERT(ni->ni_status != NULL);
698 stat = (ni->ni_status->ns_status ==
699 LNET_NI_STATUS_UP) ? "up" : "down";
702 /* we actually output credits information for
703 * TX queue of each partition */
704 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
705 for (j = 0; ni->ni_cpts != NULL &&
706 j < ni->ni_ncpts; j++) {
707 if (i == ni->ni_cpts[j])
711 if (j == ni->ni_ncpts)
717 s += snprintf(s, tmpstr + tmpsiz - s,
718 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
719 libcfs_nid2str(ni->ni_nid), stat,
720 last_alive, *ni->ni_refs[i],
721 ni->ni_peertxcredits,
722 ni->ni_peerrtrcredits,
724 tq->tq_credits, tq->tq_credits_min);
728 LASSERT(tmpstr + tmpsiz - s > 0);
734 len = s - tmpstr; /* how many bytes was written */
736 if (len > *lenp) { /* linux-supplied buffer is too small */
738 } else if (len > 0) { /* wrote something */
739 if (copy_to_user(buffer, tmpstr, len))
745 LIBCFS_FREE(tmpstr, tmpsiz);
753 struct lnet_portal_rotors {
759 static struct lnet_portal_rotors portal_rotors[] = {
761 .pr_value = LNET_PTL_ROTOR_OFF,
763 .pr_desc = "Turn off message rotor for wildcard portals"
766 .pr_value = LNET_PTL_ROTOR_ON,
768 .pr_desc = "round-robin dispatch all PUT messages for "
772 .pr_value = LNET_PTL_ROTOR_RR_RT,
774 .pr_desc = "round-robin dispatch routed PUT message for "
778 .pr_value = LNET_PTL_ROTOR_HASH_RT,
779 .pr_name = "HASH_RT",
780 .pr_desc = "dispatch routed PUT message by hashing source "
781 "NID for wildcard portals"
790 static int __proc_lnet_portal_rotor(void *data, int write,
791 loff_t pos, void __user *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 (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);
852 proc_lnet_portal_rotor(struct ctl_table *table, int write, void __user *buffer,
853 size_t *lenp, loff_t *ppos)
855 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
856 __proc_lnet_portal_rotor);
860 static struct ctl_table lnet_table[] = {
862 * NB No .strategy entries have been provided since sysctl(8) prefers
863 * to go via /proc for portability.
869 .proc_handler = &proc_lnet_stats,
873 .procname = "routes",
875 .proc_handler = &proc_lnet_routes,
879 .procname = "routers",
881 .proc_handler = &proc_lnet_routers,
887 .proc_handler = &proc_lnet_peers,
891 .procname = "buffers",
893 .proc_handler = &proc_lnet_buffers,
899 .proc_handler = &proc_lnet_nis,
903 .procname = "portal_rotor",
905 .proc_handler = &proc_lnet_portal_rotor,
910 static struct ctl_table top_table[] = {
926 if (lnet_table_header == NULL)
927 lnet_table_header = register_sysctl_table(top_table);
935 if (lnet_table_header != NULL)
936 unregister_sysctl_table(lnet_table_header);
938 lnet_table_header = NULL;