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.
20 #define DEBUG_SUBSYSTEM S_LNET
21 #include "../../include/linux/libcfs/libcfs.h"
22 #include "../../include/linux/lnet/lib-lnet.h"
25 * This is really lnet_proc.c. You might need to update sanity test 215
26 * if any file format is changed.
29 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
31 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
33 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
34 /* change version, 16 bits or 8 bits */
35 #define LNET_PROC_VER_BITS max_t(size_t, min_t(size_t, LNET_LOFFT_BITS, 64) / 4, 8)
37 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
39 * bits for peer hash offset
40 * NB: we don't use the highest bit of *ppos because it's signed
42 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
43 LNET_PROC_CPT_BITS - \
44 LNET_PROC_VER_BITS - \
45 LNET_PROC_HASH_BITS - 1)
46 /* bits for hash index + position */
47 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
48 /* bits for peer hash table + hash version */
49 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
51 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
52 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
53 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
54 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
56 #define LNET_PROC_CPT_GET(pos) \
57 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
59 #define LNET_PROC_VER_GET(pos) \
60 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
62 #define LNET_PROC_HASH_GET(pos) \
63 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
65 #define LNET_PROC_HOFF_GET(pos) \
66 (int)((pos) & LNET_PROC_HOFF_MASK)
68 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
69 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
70 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
71 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
72 ((off) & LNET_PROC_HOFF_MASK))
74 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
76 static int __proc_lnet_stats(void *data, int write,
77 loff_t pos, void __user *buffer, int nob)
80 lnet_counters_t *ctrs;
83 const int tmpsiz = 256; /* 7 %u and 4 %llu */
86 lnet_counters_reset();
92 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
96 LIBCFS_ALLOC(tmpstr, tmpsiz);
98 LIBCFS_FREE(ctrs, sizeof(*ctrs));
102 lnet_counters_get(ctrs);
104 len = snprintf(tmpstr, tmpsiz,
105 "%u %u %u %u %u %u %u %llu %llu %llu %llu",
106 ctrs->msgs_alloc, ctrs->msgs_max,
108 ctrs->send_count, ctrs->recv_count,
109 ctrs->route_count, ctrs->drop_count,
110 ctrs->send_length, ctrs->recv_length,
111 ctrs->route_length, ctrs->drop_length);
113 if (pos >= min_t(int, len, strlen(tmpstr)))
116 rc = cfs_trace_copyout_string(buffer, nob,
119 LIBCFS_FREE(tmpstr, tmpsiz);
120 LIBCFS_FREE(ctrs, sizeof(*ctrs));
124 static int proc_lnet_stats(struct ctl_table *table, int write,
125 void __user *buffer, size_t *lenp, loff_t *ppos)
127 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
131 static int proc_lnet_routes(struct ctl_table *table, int write,
132 void __user *buffer, size_t *lenp, loff_t *ppos)
134 const int tmpsiz = 256;
142 CLASSERT(sizeof(loff_t) >= 4);
144 off = LNET_PROC_HOFF_GET(*ppos);
145 ver = LNET_PROC_VER_GET(*ppos);
152 LIBCFS_ALLOC(tmpstr, tmpsiz);
156 s = tmpstr; /* points to current position in tmpstr[] */
159 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
160 the_lnet.ln_routing ? "enabled" : "disabled");
161 LASSERT(tmpstr + tmpsiz - s > 0);
163 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
164 "net", "hops", "priority", "state", "router");
165 LASSERT(tmpstr + tmpsiz - s > 0);
168 ver = (unsigned int)the_lnet.ln_remote_nets_version;
170 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
174 lnet_route_t *route = NULL;
175 lnet_remotenet_t *rnet = NULL;
177 struct list_head *rn_list;
182 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
184 LIBCFS_FREE(tmpstr, tmpsiz);
188 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && !route; i++) {
189 rn_list = &the_lnet.ln_remote_nets_hash[i];
193 while (n != rn_list && !route) {
194 rnet = list_entry(n, lnet_remotenet_t,
197 r = rnet->lrn_routes.next;
199 while (r != &rnet->lrn_routes) {
201 list_entry(r, lnet_route_t,
217 __u32 net = rnet->lrn_net;
218 __u32 hops = route->lr_hops;
219 unsigned int priority = route->lr_priority;
220 lnet_nid_t nid = route->lr_gateway->lp_nid;
221 int alive = lnet_is_route_alive(route);
223 s += snprintf(s, tmpstr + tmpsiz - s,
224 "%-8s %4u %8u %7s %s\n",
225 libcfs_net2str(net), hops,
227 alive ? "up" : "down",
228 libcfs_nid2str(nid));
229 LASSERT(tmpstr + tmpsiz - s > 0);
235 len = s - tmpstr; /* how many bytes was written */
237 if (len > *lenp) { /* linux-supplied buffer is too small */
239 } else if (len > 0) { /* wrote something */
240 if (copy_to_user(buffer, tmpstr, len)) {
244 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
248 LIBCFS_FREE(tmpstr, tmpsiz);
256 static int proc_lnet_routers(struct ctl_table *table, int write,
257 void __user *buffer, size_t *lenp, loff_t *ppos)
262 const int tmpsiz = 256;
267 off = LNET_PROC_HOFF_GET(*ppos);
268 ver = LNET_PROC_VER_GET(*ppos);
275 LIBCFS_ALLOC(tmpstr, tmpsiz);
279 s = tmpstr; /* points to current position in tmpstr[] */
282 s += snprintf(s, tmpstr + tmpsiz - s,
283 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
284 "ref", "rtr_ref", "alive_cnt", "state",
285 "last_ping", "ping_sent", "deadline",
286 "down_ni", "router");
287 LASSERT(tmpstr + tmpsiz - s > 0);
290 ver = (unsigned int)the_lnet.ln_routers_version;
292 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
295 struct lnet_peer *peer = NULL;
300 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
303 LIBCFS_FREE(tmpstr, tmpsiz);
307 r = the_lnet.ln_routers.next;
309 while (r != &the_lnet.ln_routers) {
310 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
323 lnet_nid_t nid = peer->lp_nid;
324 unsigned long now = cfs_time_current();
325 unsigned long deadline = peer->lp_ping_deadline;
326 int nrefs = peer->lp_refcount;
327 int nrtrrefs = peer->lp_rtr_refcount;
328 int alive_cnt = peer->lp_alive_count;
329 int alive = peer->lp_alive;
330 int pingsent = !peer->lp_ping_notsent;
331 int last_ping = cfs_duration_sec(cfs_time_sub(now,
332 peer->lp_ping_timestamp));
336 if ((peer->lp_ping_feats &
337 LNET_PING_FEAT_NI_STATUS)) {
338 list_for_each_entry(rtr, &peer->lp_routes,
341 * downis on any route should be the
342 * number of downis on the gateway
344 if (rtr->lr_downis) {
345 down_ni = rtr->lr_downis;
352 s += snprintf(s, tmpstr + tmpsiz - s,
353 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
354 nrefs, nrtrrefs, alive_cnt,
355 alive ? "up" : "down", last_ping,
356 pingsent, "NA", down_ni,
357 libcfs_nid2str(nid));
359 s += snprintf(s, tmpstr + tmpsiz - s,
360 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
361 nrefs, nrtrrefs, alive_cnt,
362 alive ? "up" : "down", last_ping,
364 cfs_duration_sec(cfs_time_sub(deadline, now)),
365 down_ni, libcfs_nid2str(nid));
366 LASSERT(tmpstr + tmpsiz - s > 0);
372 len = s - tmpstr; /* how many bytes was written */
374 if (len > *lenp) { /* linux-supplied buffer is too small */
376 } else if (len > 0) { /* wrote something */
377 if (copy_to_user(buffer, tmpstr, len)) {
381 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
385 LIBCFS_FREE(tmpstr, tmpsiz);
393 static int proc_lnet_peers(struct ctl_table *table, int write,
394 void __user *buffer, size_t *lenp, loff_t *ppos)
396 const int tmpsiz = 256;
397 struct lnet_peer_table *ptable;
400 int cpt = LNET_PROC_CPT_GET(*ppos);
401 int ver = LNET_PROC_VER_GET(*ppos);
402 int hash = LNET_PROC_HASH_GET(*ppos);
403 int hoff = LNET_PROC_HOFF_GET(*ppos);
407 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
413 if (cpt >= LNET_CPT_NUMBER) {
418 LIBCFS_ALLOC(tmpstr, tmpsiz);
422 s = tmpstr; /* points to current position in tmpstr[] */
425 s += snprintf(s, tmpstr + tmpsiz - s,
426 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
427 "nid", "refs", "state", "last", "max",
428 "rtr", "min", "tx", "min", "queue");
429 LASSERT(tmpstr + tmpsiz - s > 0);
433 struct lnet_peer *peer;
442 ptable = the_lnet.ln_peer_tables[cpt];
444 ver = LNET_PROC_VERSION(ptable->pt_version);
446 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
447 lnet_net_unlock(cpt);
448 LIBCFS_FREE(tmpstr, tmpsiz);
452 while (hash < LNET_PEER_HASH_SIZE) {
454 p = ptable->pt_hash[hash].next;
456 while (p != &ptable->pt_hash[hash]) {
457 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
463 * minor optimization: start from idx+1
464 * on next iteration if we've just
465 * drained lp_hashlist
467 if (lp->lp_hashlist.next ==
468 &ptable->pt_hash[hash]) {
479 p = lp->lp_hashlist.next;
491 lnet_nid_t nid = peer->lp_nid;
492 int nrefs = peer->lp_refcount;
494 char *aliveness = "NA";
495 int maxcr = peer->lp_ni->ni_peertxcredits;
496 int txcr = peer->lp_txcredits;
497 int mintxcr = peer->lp_mintxcredits;
498 int rtrcr = peer->lp_rtrcredits;
499 int minrtrcr = peer->lp_minrtrcredits;
500 int txqnob = peer->lp_txqnob;
502 if (lnet_isrouter(peer) ||
503 lnet_peer_aliveness_enabled(peer))
504 aliveness = peer->lp_alive ? "up" : "down";
506 if (lnet_peer_aliveness_enabled(peer)) {
507 unsigned long now = cfs_time_current();
510 delta = cfs_time_sub(now, peer->lp_last_alive);
511 lastalive = cfs_duration_sec(delta);
513 /* No need to mess up peers contents with
514 * arbitrarily long integers - it suffices to
515 * know that lastalive is more than 10000s old
517 if (lastalive >= 10000)
521 lnet_net_unlock(cpt);
523 s += snprintf(s, tmpstr + tmpsiz - s,
524 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
525 libcfs_nid2str(nid), nrefs, aliveness,
526 lastalive, maxcr, rtrcr, minrtrcr, txcr,
528 LASSERT(tmpstr + tmpsiz - s > 0);
530 } else { /* peer is NULL */
531 lnet_net_unlock(cpt);
534 if (hash == LNET_PEER_HASH_SIZE) {
538 if (!peer && cpt < LNET_CPT_NUMBER)
543 len = s - tmpstr; /* how many bytes was written */
545 if (len > *lenp) { /* linux-supplied buffer is too small */
547 } else if (len > 0) { /* wrote something */
548 if (copy_to_user(buffer, tmpstr, len))
551 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
554 LIBCFS_FREE(tmpstr, tmpsiz);
562 static int __proc_lnet_buffers(void *data, int write,
563 loff_t pos, void __user *buffer, int nob)
575 /* (4 %d) * 4 * LNET_CPT_NUMBER */
576 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
577 LIBCFS_ALLOC(tmpstr, tmpsiz);
581 s = tmpstr; /* points to current position in tmpstr[] */
583 s += snprintf(s, tmpstr + tmpsiz - s,
585 "pages", "count", "credits", "min");
586 LASSERT(tmpstr + tmpsiz - s > 0);
588 if (!the_lnet.ln_rtrpools)
589 goto out; /* I'm not a router */
591 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
592 lnet_rtrbufpool_t *rbp;
594 lnet_net_lock(LNET_LOCK_EX);
595 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
596 s += snprintf(s, tmpstr + tmpsiz - s,
599 rbp[idx].rbp_nbuffers,
600 rbp[idx].rbp_credits,
601 rbp[idx].rbp_mincredits);
602 LASSERT(tmpstr + tmpsiz - s > 0);
604 lnet_net_unlock(LNET_LOCK_EX);
610 if (pos >= min_t(int, len, strlen(tmpstr)))
613 rc = cfs_trace_copyout_string(buffer, nob,
616 LIBCFS_FREE(tmpstr, tmpsiz);
620 static int proc_lnet_buffers(struct ctl_table *table, int write,
621 void __user *buffer, size_t *lenp, loff_t *ppos)
623 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
624 __proc_lnet_buffers);
627 static int proc_lnet_nis(struct ctl_table *table, int write,
628 void __user *buffer, size_t *lenp, loff_t *ppos)
630 int tmpsiz = 128 * LNET_CPT_NUMBER;
641 LIBCFS_ALLOC(tmpstr, tmpsiz);
645 s = tmpstr; /* points to current position in tmpstr[] */
648 s += snprintf(s, tmpstr + tmpsiz - s,
649 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
650 "nid", "status", "alive", "refs", "peer",
651 "rtr", "max", "tx", "min");
652 LASSERT(tmpstr + tmpsiz - s > 0);
655 lnet_ni_t *ni = NULL;
656 int skip = *ppos - 1;
660 n = the_lnet.ln_nis.next;
662 while (n != &the_lnet.ln_nis) {
663 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
675 struct lnet_tx_queue *tq;
677 time64_t now = ktime_get_real_seconds();
682 if (the_lnet.ln_routing)
683 last_alive = now - ni->ni_last_alive;
685 /* @lo forever alive */
686 if (ni->ni_lnd->lnd_type == LOLND)
690 LASSERT(ni->ni_status);
691 stat = (ni->ni_status->ns_status ==
692 LNET_NI_STATUS_UP) ? "up" : "down";
696 * we actually output credits information for
697 * TX queue of each partition
699 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
700 for (j = 0; ni->ni_cpts &&
701 j < ni->ni_ncpts; j++) {
702 if (i == ni->ni_cpts[j])
706 if (j == ni->ni_ncpts)
712 s += snprintf(s, tmpstr + tmpsiz - s,
713 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
714 libcfs_nid2str(ni->ni_nid), stat,
715 last_alive, *ni->ni_refs[i],
716 ni->ni_peertxcredits,
717 ni->ni_peerrtrcredits,
724 LASSERT(tmpstr + tmpsiz - s > 0);
730 len = s - tmpstr; /* how many bytes was written */
732 if (len > *lenp) { /* linux-supplied buffer is too small */
734 } else if (len > 0) { /* wrote something */
735 if (copy_to_user(buffer, tmpstr, len))
741 LIBCFS_FREE(tmpstr, tmpsiz);
749 struct lnet_portal_rotors {
755 static struct lnet_portal_rotors portal_rotors[] = {
757 .pr_value = LNET_PTL_ROTOR_OFF,
759 .pr_desc = "Turn off message rotor for wildcard portals"
762 .pr_value = LNET_PTL_ROTOR_ON,
764 .pr_desc = "round-robin dispatch all PUT messages for wildcard portals"
767 .pr_value = LNET_PTL_ROTOR_RR_RT,
769 .pr_desc = "round-robin dispatch routed PUT message for wildcard portals"
772 .pr_value = LNET_PTL_ROTOR_HASH_RT,
773 .pr_name = "HASH_RT",
774 .pr_desc = "dispatch routed PUT message by hashing source NID for wildcard portals"
783 static int __proc_lnet_portal_rotor(void *data, int write,
784 loff_t pos, void __user *buffer, int nob)
786 const int buf_len = 128;
792 LIBCFS_ALLOC(buf, buf_len);
799 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
800 if (portal_rotors[i].pr_value == portal_rotor)
804 LASSERT(portal_rotors[i].pr_value == portal_rotor);
807 rc = snprintf(buf, buf_len,
808 "{\n\tportals: all\n"
809 "\trotor: %s\n\tdescription: %s\n}",
810 portal_rotors[i].pr_name,
811 portal_rotors[i].pr_desc);
813 if (pos >= min_t(int, rc, buf_len)) {
816 rc = cfs_trace_copyout_string(buffer, nob,
822 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
826 tmp = cfs_trimwhite(buf);
830 for (i = 0; portal_rotors[i].pr_name; i++) {
831 if (!strncasecmp(portal_rotors[i].pr_name, tmp,
832 strlen(portal_rotors[i].pr_name))) {
833 portal_rotor = portal_rotors[i].pr_value;
840 LIBCFS_FREE(buf, buf_len);
844 static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
845 void __user *buffer, size_t *lenp,
848 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
849 __proc_lnet_portal_rotor);
852 static struct ctl_table lnet_table[] = {
854 * NB No .strategy entries have been provided since sysctl(8) prefers
855 * to go via /proc for portability.
860 .proc_handler = &proc_lnet_stats,
863 .procname = "routes",
865 .proc_handler = &proc_lnet_routes,
868 .procname = "routers",
870 .proc_handler = &proc_lnet_routers,
875 .proc_handler = &proc_lnet_peers,
878 .procname = "buffers",
880 .proc_handler = &proc_lnet_buffers,
885 .proc_handler = &proc_lnet_nis,
888 .procname = "portal_rotor",
890 .proc_handler = &proc_lnet_portal_rotor,
896 void lnet_router_debugfs_init(void)
898 lustre_insert_debugfs(lnet_table, NULL);
901 void lnet_router_debugfs_fini(void)