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
22 #include <linux/libcfs/libcfs.h>
23 #include <linux/lnet/lib-lnet.h>
26 * This is really lnet_proc.c. You might need to update sanity test 215
27 * if any file format is changed.
30 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
32 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
34 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
35 /* change version, 16 bits or 8 bits */
36 #define LNET_PROC_VER_BITS max_t(size_t, min_t(size_t, LNET_LOFFT_BITS, 64) / 4, 8)
38 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
40 * bits for peer hash offset
41 * NB: we don't use the highest bit of *ppos because it's signed
43 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
44 LNET_PROC_CPT_BITS - \
45 LNET_PROC_VER_BITS - \
46 LNET_PROC_HASH_BITS - 1)
47 /* bits for hash index + position */
48 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
49 /* bits for peer hash table + hash version */
50 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
52 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
53 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
54 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
55 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
57 #define LNET_PROC_CPT_GET(pos) \
58 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
60 #define LNET_PROC_VER_GET(pos) \
61 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
63 #define LNET_PROC_HASH_GET(pos) \
64 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
66 #define LNET_PROC_HOFF_GET(pos) \
67 (int)((pos) & LNET_PROC_HOFF_MASK)
69 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
70 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
71 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
72 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
73 ((off) & LNET_PROC_HOFF_MASK))
75 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
77 static int __proc_lnet_stats(void *data, int write,
78 loff_t pos, void __user *buffer, int nob)
81 struct lnet_counters *ctrs;
84 const int tmpsiz = 256; /* 7 %u and 4 %llu */
87 lnet_counters_reset();
93 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
97 LIBCFS_ALLOC(tmpstr, tmpsiz);
99 LIBCFS_FREE(ctrs, sizeof(*ctrs));
103 lnet_counters_get(ctrs);
105 len = snprintf(tmpstr, tmpsiz,
106 "%u %u %u %u %u %u %u %llu %llu %llu %llu",
107 ctrs->msgs_alloc, ctrs->msgs_max,
109 ctrs->send_count, ctrs->recv_count,
110 ctrs->route_count, ctrs->drop_count,
111 ctrs->send_length, ctrs->recv_length,
112 ctrs->route_length, ctrs->drop_length);
114 if (pos >= min_t(int, len, strlen(tmpstr)))
117 rc = cfs_trace_copyout_string(buffer, nob,
120 LIBCFS_FREE(tmpstr, tmpsiz);
121 LIBCFS_FREE(ctrs, sizeof(*ctrs));
125 static int proc_lnet_stats(struct ctl_table *table, int write,
126 void __user *buffer, size_t *lenp, loff_t *ppos)
128 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
132 static int proc_lnet_routes(struct ctl_table *table, int write,
133 void __user *buffer, size_t *lenp, loff_t *ppos)
135 const int tmpsiz = 256;
143 BUILD_BUG_ON(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 struct lnet_route *route = NULL;
176 struct lnet_remotenet *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; i++) {
190 rn_list = &the_lnet.ln_remote_nets_hash[i];
194 while (n != rn_list && !route) {
195 rnet = list_entry(n, struct lnet_remotenet,
198 r = rnet->lrn_routes.next;
200 while (r != &rnet->lrn_routes) {
201 struct lnet_route *re;
203 re = list_entry(r, struct lnet_route,
219 __u32 net = rnet->lrn_net;
220 __u32 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 static int proc_lnet_routers(struct ctl_table *table, int write,
259 void __user *buffer, size_t *lenp, loff_t *ppos)
264 const int tmpsiz = 256;
269 off = LNET_PROC_HOFF_GET(*ppos);
270 ver = LNET_PROC_VER_GET(*ppos);
277 LIBCFS_ALLOC(tmpstr, tmpsiz);
281 s = tmpstr; /* points to current position in tmpstr[] */
284 s += snprintf(s, tmpstr + tmpsiz - s,
285 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
286 "ref", "rtr_ref", "alive_cnt", "state",
287 "last_ping", "ping_sent", "deadline",
288 "down_ni", "router");
289 LASSERT(tmpstr + tmpsiz - s > 0);
292 ver = (unsigned int)the_lnet.ln_routers_version;
294 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
297 struct lnet_peer *peer = NULL;
302 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
305 LIBCFS_FREE(tmpstr, tmpsiz);
309 r = the_lnet.ln_routers.next;
311 while (r != &the_lnet.ln_routers) {
312 struct lnet_peer *lp;
314 lp = list_entry(r, struct lnet_peer, lp_rtr_list);
325 lnet_nid_t nid = peer->lp_nid;
326 unsigned long now = cfs_time_current();
327 unsigned long deadline = peer->lp_ping_deadline;
328 int nrefs = peer->lp_refcount;
329 int nrtrrefs = peer->lp_rtr_refcount;
330 int alive_cnt = peer->lp_alive_count;
331 int alive = peer->lp_alive;
332 int pingsent = !peer->lp_ping_notsent;
333 int last_ping = cfs_duration_sec(cfs_time_sub(now,
334 peer->lp_ping_timestamp));
336 struct lnet_route *rtr;
338 if ((peer->lp_ping_feats &
339 LNET_PING_FEAT_NI_STATUS)) {
340 list_for_each_entry(rtr, &peer->lp_routes,
343 * downis on any route should be the
344 * number of downis on the gateway
346 if (rtr->lr_downis) {
347 down_ni = rtr->lr_downis;
354 s += snprintf(s, tmpstr + tmpsiz - s,
355 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
356 nrefs, nrtrrefs, alive_cnt,
357 alive ? "up" : "down", last_ping,
358 pingsent, "NA", down_ni,
359 libcfs_nid2str(nid));
361 s += snprintf(s, tmpstr + tmpsiz - s,
362 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
363 nrefs, nrtrrefs, alive_cnt,
364 alive ? "up" : "down", last_ping,
366 cfs_duration_sec(cfs_time_sub(deadline, now)),
367 down_ni, libcfs_nid2str(nid));
368 LASSERT(tmpstr + tmpsiz - s > 0);
374 len = s - tmpstr; /* how many bytes was written */
376 if (len > *lenp) { /* linux-supplied buffer is too small */
378 } else if (len > 0) { /* wrote something */
379 if (copy_to_user(buffer, tmpstr, len)) {
383 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
387 LIBCFS_FREE(tmpstr, tmpsiz);
395 static int proc_lnet_peers(struct ctl_table *table, int write,
396 void __user *buffer, size_t *lenp, loff_t *ppos)
398 const int tmpsiz = 256;
399 struct lnet_peer_table *ptable;
402 int cpt = LNET_PROC_CPT_GET(*ppos);
403 int ver = LNET_PROC_VER_GET(*ppos);
404 int hash = LNET_PROC_HASH_GET(*ppos);
405 int hoff = LNET_PROC_HOFF_GET(*ppos);
409 BUILD_BUG_ON(LNET_PROC_HASH_BITS < LNET_PEER_HASH_BITS);
415 if (cpt >= LNET_CPT_NUMBER) {
420 LIBCFS_ALLOC(tmpstr, tmpsiz);
424 s = tmpstr; /* points to current position in tmpstr[] */
427 s += snprintf(s, tmpstr + tmpsiz - s,
428 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
429 "nid", "refs", "state", "last", "max",
430 "rtr", "min", "tx", "min", "queue");
431 LASSERT(tmpstr + tmpsiz - s > 0);
435 struct lnet_peer *peer;
444 ptable = the_lnet.ln_peer_tables[cpt];
446 ver = LNET_PROC_VERSION(ptable->pt_version);
448 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
449 lnet_net_unlock(cpt);
450 LIBCFS_FREE(tmpstr, tmpsiz);
454 while (hash < LNET_PEER_HASH_SIZE) {
456 p = ptable->pt_hash[hash].next;
458 while (p != &ptable->pt_hash[hash]) {
459 struct lnet_peer *lp;
461 lp = list_entry(p, struct lnet_peer,
467 * minor optimization: start from idx+1
468 * on next iteration if we've just
469 * drained lp_hashlist
471 if (lp->lp_hashlist.next ==
472 &ptable->pt_hash[hash]) {
483 p = lp->lp_hashlist.next;
495 lnet_nid_t nid = peer->lp_nid;
496 int nrefs = peer->lp_refcount;
498 char *aliveness = "NA";
499 int maxcr = peer->lp_ni->ni_peertxcredits;
500 int txcr = peer->lp_txcredits;
501 int mintxcr = peer->lp_mintxcredits;
502 int rtrcr = peer->lp_rtrcredits;
503 int minrtrcr = peer->lp_minrtrcredits;
504 int txqnob = peer->lp_txqnob;
506 if (lnet_isrouter(peer) ||
507 lnet_peer_aliveness_enabled(peer))
508 aliveness = peer->lp_alive ? "up" : "down";
510 if (lnet_peer_aliveness_enabled(peer)) {
511 unsigned long now = cfs_time_current();
514 delta = cfs_time_sub(now, peer->lp_last_alive);
515 lastalive = cfs_duration_sec(delta);
517 /* No need to mess up peers contents with
518 * arbitrarily long integers - it suffices to
519 * know that lastalive is more than 10000s old
521 if (lastalive >= 10000)
525 lnet_net_unlock(cpt);
527 s += snprintf(s, tmpstr + tmpsiz - s,
528 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
529 libcfs_nid2str(nid), nrefs, aliveness,
530 lastalive, maxcr, rtrcr, minrtrcr, txcr,
532 LASSERT(tmpstr + tmpsiz - s > 0);
534 } else { /* peer is NULL */
535 lnet_net_unlock(cpt);
538 if (hash == LNET_PEER_HASH_SIZE) {
542 if (!peer && cpt < LNET_CPT_NUMBER)
547 len = s - tmpstr; /* how many bytes was written */
549 if (len > *lenp) { /* linux-supplied buffer is too small */
551 } else if (len > 0) { /* wrote something */
552 if (copy_to_user(buffer, tmpstr, len))
555 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
558 LIBCFS_FREE(tmpstr, tmpsiz);
566 static int __proc_lnet_buffers(void *data, int write,
567 loff_t pos, void __user *buffer, int nob)
579 /* (4 %d) * 4 * LNET_CPT_NUMBER */
580 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
581 LIBCFS_ALLOC(tmpstr, tmpsiz);
585 s = tmpstr; /* points to current position in tmpstr[] */
587 s += snprintf(s, tmpstr + tmpsiz - s,
589 "pages", "count", "credits", "min");
590 LASSERT(tmpstr + tmpsiz - s > 0);
592 if (!the_lnet.ln_rtrpools)
593 goto out; /* I'm not a router */
595 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
596 struct lnet_rtrbufpool *rbp;
598 lnet_net_lock(LNET_LOCK_EX);
599 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
600 s += snprintf(s, tmpstr + tmpsiz - s,
603 rbp[idx].rbp_nbuffers,
604 rbp[idx].rbp_credits,
605 rbp[idx].rbp_mincredits);
606 LASSERT(tmpstr + tmpsiz - s > 0);
608 lnet_net_unlock(LNET_LOCK_EX);
614 if (pos >= min_t(int, len, strlen(tmpstr)))
617 rc = cfs_trace_copyout_string(buffer, nob,
620 LIBCFS_FREE(tmpstr, tmpsiz);
624 static int proc_lnet_buffers(struct ctl_table *table, int write,
625 void __user *buffer, size_t *lenp, loff_t *ppos)
627 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
628 __proc_lnet_buffers);
631 static int proc_lnet_nis(struct ctl_table *table, int write,
632 void __user *buffer, size_t *lenp, loff_t *ppos)
634 int tmpsiz = 128 * LNET_CPT_NUMBER;
645 LIBCFS_ALLOC(tmpstr, tmpsiz);
649 s = tmpstr; /* points to current position in tmpstr[] */
652 s += snprintf(s, tmpstr + tmpsiz - s,
653 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
654 "nid", "status", "alive", "refs", "peer",
655 "rtr", "max", "tx", "min");
656 LASSERT(tmpstr + tmpsiz - s > 0);
659 struct lnet_ni *ni = NULL;
660 int skip = *ppos - 1;
664 n = the_lnet.ln_nis.next;
666 while (n != &the_lnet.ln_nis) {
667 struct lnet_ni *a_ni;
669 a_ni = list_entry(n, struct lnet_ni, ni_list);
680 struct lnet_tx_queue *tq;
682 time64_t now = ktime_get_real_seconds();
687 if (the_lnet.ln_routing)
688 last_alive = now - ni->ni_last_alive;
690 /* @lo forever alive */
691 if (ni->ni_lnd->lnd_type == LOLND)
695 LASSERT(ni->ni_status);
696 stat = (ni->ni_status->ns_status ==
697 LNET_NI_STATUS_UP) ? "up" : "down";
701 * we actually output credits information for
702 * TX queue of each partition
704 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
705 for (j = 0; ni->ni_cpts &&
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,
729 LASSERT(tmpstr + tmpsiz - s > 0);
735 len = s - tmpstr; /* how many bytes was written */
737 if (len > *lenp) { /* linux-supplied buffer is too small */
739 } else if (len > 0) { /* wrote something */
740 if (copy_to_user(buffer, tmpstr, len))
746 LIBCFS_FREE(tmpstr, tmpsiz);
754 struct lnet_portal_rotors {
760 static struct lnet_portal_rotors portal_rotors[] = {
762 .pr_value = LNET_PTL_ROTOR_OFF,
764 .pr_desc = "Turn off message rotor for wildcard portals"
767 .pr_value = LNET_PTL_ROTOR_ON,
769 .pr_desc = "round-robin dispatch all PUT messages for wildcard portals"
772 .pr_value = LNET_PTL_ROTOR_RR_RT,
774 .pr_desc = "round-robin dispatch routed PUT message for wildcard portals"
777 .pr_value = LNET_PTL_ROTOR_HASH_RT,
778 .pr_name = "HASH_RT",
779 .pr_desc = "dispatch routed PUT message by hashing source NID for wildcard portals"
788 static int __proc_lnet_portal_rotor(void *data, int write,
789 loff_t pos, void __user *buffer, int nob)
791 const int buf_len = 128;
797 LIBCFS_ALLOC(buf, buf_len);
804 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
805 if (portal_rotors[i].pr_value == portal_rotor)
809 LASSERT(portal_rotors[i].pr_value == portal_rotor);
812 rc = snprintf(buf, buf_len,
813 "{\n\tportals: all\n"
814 "\trotor: %s\n\tdescription: %s\n}",
815 portal_rotors[i].pr_name,
816 portal_rotors[i].pr_desc);
818 if (pos >= min_t(int, rc, buf_len)) {
821 rc = cfs_trace_copyout_string(buffer, nob,
827 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
831 tmp = cfs_trimwhite(buf);
835 for (i = 0; portal_rotors[i].pr_name; i++) {
836 if (!strncasecmp(portal_rotors[i].pr_name, tmp,
837 strlen(portal_rotors[i].pr_name))) {
838 portal_rotor = portal_rotors[i].pr_value;
845 LIBCFS_FREE(buf, buf_len);
849 static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
850 void __user *buffer, size_t *lenp,
853 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
854 __proc_lnet_portal_rotor);
857 static struct ctl_table lnet_table[] = {
859 * NB No .strategy entries have been provided since sysctl(8) prefers
860 * to go via /proc for portability.
865 .proc_handler = &proc_lnet_stats,
868 .procname = "routes",
870 .proc_handler = &proc_lnet_routes,
873 .procname = "routers",
875 .proc_handler = &proc_lnet_routers,
880 .proc_handler = &proc_lnet_peers,
883 .procname = "buffers",
885 .proc_handler = &proc_lnet_buffers,
890 .proc_handler = &proc_lnet_nis,
893 .procname = "portal_rotor",
895 .proc_handler = &proc_lnet_portal_rotor,
901 void lnet_router_debugfs_init(void)
903 lustre_insert_debugfs(lnet_table, NULL);
906 void lnet_router_debugfs_fini(void)