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 #if 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 ctl_table_header_t
*lnet_table_header
;
35 #define CTL_LNET (0x100)
37 PSDEV_LNET_STATS
= 100,
46 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
48 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
50 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
51 /* change version, 16 bits or 8 bits */
52 #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
54 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
56 * bits for peer hash offset
57 * NB: we don't use the highest bit of *ppos because it's signed
59 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
60 LNET_PROC_CPT_BITS - \
61 LNET_PROC_VER_BITS - \
62 LNET_PROC_HASH_BITS - 1)
63 /* bits for hash index + position */
64 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
65 /* bits for peer hash table + hash version */
66 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
68 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
69 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
70 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
71 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
73 #define LNET_PROC_CPT_GET(pos) \
74 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
76 #define LNET_PROC_VER_GET(pos) \
77 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
79 #define LNET_PROC_HASH_GET(pos) \
80 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
82 #define LNET_PROC_HOFF_GET(pos) \
83 (int)((pos) & LNET_PROC_HOFF_MASK)
85 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
86 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
87 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
88 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
89 ((off) & LNET_PROC_HOFF_MASK))
91 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
93 static int __proc_lnet_stats(void *data
, int write
,
94 loff_t pos
, void *buffer
, int nob
)
97 lnet_counters_t
*ctrs
;
100 const int tmpsiz
= 256; /* 7 %u and 4 LPU64 */
103 lnet_counters_reset();
109 LIBCFS_ALLOC(ctrs
, sizeof(*ctrs
));
113 LIBCFS_ALLOC(tmpstr
, tmpsiz
);
114 if (tmpstr
== NULL
) {
115 LIBCFS_FREE(ctrs
, sizeof(*ctrs
));
119 lnet_counters_get(ctrs
);
121 len
= snprintf(tmpstr
, tmpsiz
,
122 "%u %u %u %u %u %u %u "LPU64
" "LPU64
" "
124 ctrs
->msgs_alloc
, ctrs
->msgs_max
,
126 ctrs
->send_count
, ctrs
->recv_count
,
127 ctrs
->route_count
, ctrs
->drop_count
,
128 ctrs
->send_length
, ctrs
->recv_length
,
129 ctrs
->route_length
, ctrs
->drop_length
);
131 if (pos
>= min_t(int, len
, strlen(tmpstr
)))
134 rc
= cfs_trace_copyout_string(buffer
, nob
,
137 LIBCFS_FREE(tmpstr
, tmpsiz
);
138 LIBCFS_FREE(ctrs
, sizeof(*ctrs
));
142 DECLARE_PROC_HANDLER(proc_lnet_stats
);
144 int LL_PROC_PROTO(proc_lnet_routes
)
146 const int tmpsiz
= 256;
154 DECLARE_LL_PROC_PPOS_DECL
;
156 CLASSERT(sizeof(loff_t
) >= 4);
158 off
= LNET_PROC_HOFF_GET(*ppos
);
159 ver
= LNET_PROC_VER_GET(*ppos
);
166 LIBCFS_ALLOC(tmpstr
, tmpsiz
);
170 s
= tmpstr
; /* points to current position in tmpstr[] */
173 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
, "Routing %s\n",
174 the_lnet
.ln_routing
? "enabled" : "disabled");
175 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
177 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
, "%-8s %4s %8s %7s %s\n",
178 "net", "hops", "priority", "state", "router");
179 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
182 ver
= (unsigned int)the_lnet
.ln_remote_nets_version
;
184 *ppos
= LNET_PROC_POS_MAKE(0, ver
, 0, off
);
188 lnet_route_t
*route
= NULL
;
189 lnet_remotenet_t
*rnet
= NULL
;
191 struct list_head
*rn_list
;
196 if (ver
!= LNET_PROC_VERSION(the_lnet
.ln_remote_nets_version
)) {
198 LIBCFS_FREE(tmpstr
, tmpsiz
);
202 for (i
= 0; i
< LNET_REMOTE_NETS_HASH_SIZE
&& route
== NULL
;
204 rn_list
= &the_lnet
.ln_remote_nets_hash
[i
];
208 while (n
!= rn_list
&& route
== NULL
) {
209 rnet
= list_entry(n
, lnet_remotenet_t
,
212 r
= rnet
->lrn_routes
.next
;
214 while (r
!= &rnet
->lrn_routes
) {
216 list_entry(r
, lnet_route_t
,
232 __u32 net
= rnet
->lrn_net
;
233 unsigned int hops
= route
->lr_hops
;
234 unsigned int priority
= route
->lr_priority
;
235 lnet_nid_t nid
= route
->lr_gateway
->lp_nid
;
236 int alive
= route
->lr_gateway
->lp_alive
;
238 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
239 "%-8s %4u %8u %7s %s\n",
240 libcfs_net2str(net
), hops
,
242 alive
? "up" : "down",
243 libcfs_nid2str(nid
));
244 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
250 len
= s
- tmpstr
; /* how many bytes was written */
252 if (len
> *lenp
) { /* linux-supplied buffer is too small */
254 } else if (len
> 0) { /* wrote something */
255 if (copy_to_user(buffer
, tmpstr
, len
))
259 *ppos
= LNET_PROC_POS_MAKE(0, ver
, 0, off
);
263 LIBCFS_FREE(tmpstr
, tmpsiz
);
271 int LL_PROC_PROTO(proc_lnet_routers
)
276 const int tmpsiz
= 256;
281 DECLARE_LL_PROC_PPOS_DECL
;
283 off
= LNET_PROC_HOFF_GET(*ppos
);
284 ver
= LNET_PROC_VER_GET(*ppos
);
291 LIBCFS_ALLOC(tmpstr
, tmpsiz
);
295 s
= tmpstr
; /* points to current position in tmpstr[] */
298 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
299 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
300 "ref", "rtr_ref", "alive_cnt", "state",
301 "last_ping", "ping_sent", "deadline",
302 "down_ni", "router");
303 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
306 ver
= (unsigned int)the_lnet
.ln_routers_version
;
308 *ppos
= LNET_PROC_POS_MAKE(0, ver
, 0, off
);
311 struct lnet_peer
*peer
= NULL
;
316 if (ver
!= LNET_PROC_VERSION(the_lnet
.ln_routers_version
)) {
319 LIBCFS_FREE(tmpstr
, tmpsiz
);
323 r
= the_lnet
.ln_routers
.next
;
325 while (r
!= &the_lnet
.ln_routers
) {
326 lnet_peer_t
*lp
= list_entry(r
, lnet_peer_t
,
339 lnet_nid_t nid
= peer
->lp_nid
;
340 cfs_time_t now
= cfs_time_current();
341 cfs_time_t deadline
= peer
->lp_ping_deadline
;
342 int nrefs
= peer
->lp_refcount
;
343 int nrtrrefs
= peer
->lp_rtr_refcount
;
344 int alive_cnt
= peer
->lp_alive_count
;
345 int alive
= peer
->lp_alive
;
346 int pingsent
= !peer
->lp_ping_notsent
;
347 int last_ping
= cfs_duration_sec(cfs_time_sub(now
,
348 peer
->lp_ping_timestamp
));
352 if ((peer
->lp_ping_feats
&
353 LNET_PING_FEAT_NI_STATUS
) != 0) {
354 list_for_each_entry(rtr
, &peer
->lp_routes
,
356 /* downis on any route should be the
357 * number of downis on the gateway */
358 if (rtr
->lr_downis
!= 0) {
359 down_ni
= rtr
->lr_downis
;
366 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
367 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
368 nrefs
, nrtrrefs
, alive_cnt
,
369 alive
? "up" : "down", last_ping
,
370 pingsent
, "NA", down_ni
,
371 libcfs_nid2str(nid
));
373 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
374 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
375 nrefs
, nrtrrefs
, alive_cnt
,
376 alive
? "up" : "down", last_ping
,
378 cfs_duration_sec(cfs_time_sub(deadline
, now
)),
379 down_ni
, libcfs_nid2str(nid
));
380 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
386 len
= s
- tmpstr
; /* how many bytes was written */
388 if (len
> *lenp
) { /* linux-supplied buffer is too small */
390 } else if (len
> 0) { /* wrote something */
391 if (copy_to_user(buffer
, tmpstr
, len
))
395 *ppos
= LNET_PROC_POS_MAKE(0, ver
, 0, off
);
399 LIBCFS_FREE(tmpstr
, tmpsiz
);
407 int LL_PROC_PROTO(proc_lnet_peers
)
409 const int tmpsiz
= 256;
410 struct lnet_peer_table
*ptable
;
413 int cpt
= LNET_PROC_CPT_GET(*ppos
);
414 int ver
= LNET_PROC_VER_GET(*ppos
);
415 int hash
= LNET_PROC_HASH_GET(*ppos
);
416 int hoff
= LNET_PROC_HOFF_GET(*ppos
);
420 CLASSERT(LNET_PROC_HASH_BITS
>= LNET_PEER_HASH_BITS
);
426 if (cpt
>= LNET_CPT_NUMBER
) {
431 LIBCFS_ALLOC(tmpstr
, tmpsiz
);
435 s
= tmpstr
; /* points to current position in tmpstr[] */
438 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
439 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
440 "nid", "refs", "state", "last", "max",
441 "rtr", "min", "tx", "min", "queue");
442 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
446 struct lnet_peer
*peer
;
455 ptable
= the_lnet
.ln_peer_tables
[cpt
];
457 ver
= LNET_PROC_VERSION(ptable
->pt_version
);
459 if (ver
!= LNET_PROC_VERSION(ptable
->pt_version
)) {
460 lnet_net_unlock(cpt
);
461 LIBCFS_FREE(tmpstr
, tmpsiz
);
465 while (hash
< LNET_PEER_HASH_SIZE
) {
467 p
= ptable
->pt_hash
[hash
].next
;
469 while (p
!= &ptable
->pt_hash
[hash
]) {
470 lnet_peer_t
*lp
= list_entry(p
, lnet_peer_t
,
475 /* minor optimization: start from idx+1
476 * on next iteration if we've just
477 * drained lp_hashlist */
478 if (lp
->lp_hashlist
.next
==
479 &ptable
->pt_hash
[hash
]) {
490 p
= lp
->lp_hashlist
.next
;
502 lnet_nid_t nid
= peer
->lp_nid
;
503 int nrefs
= peer
->lp_refcount
;
505 char *aliveness
= "NA";
506 int maxcr
= peer
->lp_ni
->ni_peertxcredits
;
507 int txcr
= peer
->lp_txcredits
;
508 int mintxcr
= peer
->lp_mintxcredits
;
509 int rtrcr
= peer
->lp_rtrcredits
;
510 int minrtrcr
= peer
->lp_minrtrcredits
;
511 int txqnob
= peer
->lp_txqnob
;
513 if (lnet_isrouter(peer
) ||
514 lnet_peer_aliveness_enabled(peer
))
515 aliveness
= peer
->lp_alive
? "up" : "down";
517 if (lnet_peer_aliveness_enabled(peer
)) {
518 cfs_time_t now
= cfs_time_current();
519 cfs_duration_t delta
;
521 delta
= cfs_time_sub(now
, peer
->lp_last_alive
);
522 lastalive
= cfs_duration_sec(delta
);
524 /* No need to mess up peers contents with
525 * arbitrarily long integers - it suffices to
526 * know that lastalive is more than 10000s old
528 if (lastalive
>= 10000)
532 lnet_net_unlock(cpt
);
534 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
535 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
536 libcfs_nid2str(nid
), nrefs
, aliveness
,
537 lastalive
, maxcr
, rtrcr
, minrtrcr
, txcr
,
539 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
541 } else { /* peer is NULL */
542 lnet_net_unlock(cpt
);
545 if (hash
== LNET_PEER_HASH_SIZE
) {
549 if (peer
== NULL
&& cpt
< LNET_CPT_NUMBER
)
554 len
= s
- tmpstr
; /* how many bytes was written */
556 if (len
> *lenp
) { /* linux-supplied buffer is too small */
558 } else if (len
> 0) { /* wrote something */
559 if (copy_to_user(buffer
, tmpstr
, len
))
562 *ppos
= LNET_PROC_POS_MAKE(cpt
, ver
, hash
, hoff
);
565 LIBCFS_FREE(tmpstr
, tmpsiz
);
573 static int __proc_lnet_buffers(void *data
, int write
,
574 loff_t pos
, void *buffer
, int nob
)
586 /* (4 %d) * 4 * LNET_CPT_NUMBER */
587 tmpsiz
= 64 * (LNET_NRBPOOLS
+ 1) * LNET_CPT_NUMBER
;
588 LIBCFS_ALLOC(tmpstr
, tmpsiz
);
592 s
= tmpstr
; /* points to current position in tmpstr[] */
594 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
596 "pages", "count", "credits", "min");
597 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
599 if (the_lnet
.ln_rtrpools
== NULL
)
600 goto out
; /* I'm not a router */
602 for (idx
= 0; idx
< LNET_NRBPOOLS
; idx
++) {
603 lnet_rtrbufpool_t
*rbp
;
605 lnet_net_lock(LNET_LOCK_EX
);
606 cfs_percpt_for_each(rbp
, i
, the_lnet
.ln_rtrpools
) {
607 s
+= snprintf(s
, tmpstr
+ tmpsiz
- s
,
610 rbp
[idx
].rbp_nbuffers
,
611 rbp
[idx
].rbp_credits
,
612 rbp
[idx
].rbp_mincredits
);
613 LASSERT(tmpstr
+ tmpsiz
- s
> 0);
615 lnet_net_unlock(LNET_LOCK_EX
);
621 if (pos
>= min_t(int, len
, strlen(tmpstr
)))
624 rc
= cfs_trace_copyout_string(buffer
, nob
,
627 LIBCFS_FREE(tmpstr
, tmpsiz
);
631 DECLARE_PROC_HANDLER(proc_lnet_buffers
);
633 int LL_PROC_PROTO(proc_lnet_nis
)
635 int tmpsiz
= 128 * LNET_CPT_NUMBER
;
641 DECLARE_LL_PROC_PPOS_DECL
;
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 extern int portal_rotor
;
792 static int __proc_lnet_portal_rotor(void *data
, int write
,
793 loff_t pos
, void *buffer
, int nob
)
795 const int buf_len
= 128;
801 LIBCFS_ALLOC(buf
, buf_len
);
808 for (i
= 0; portal_rotors
[i
].pr_value
>= 0; i
++) {
809 if (portal_rotors
[i
].pr_value
== portal_rotor
)
813 LASSERT(portal_rotors
[i
].pr_value
== portal_rotor
);
816 rc
= snprintf(buf
, buf_len
,
817 "{\n\tportals: all\n"
818 "\trotor: %s\n\tdescription: %s\n}",
819 portal_rotors
[i
].pr_name
,
820 portal_rotors
[i
].pr_desc
);
822 if (pos
>= min_t(int, rc
, buf_len
)) {
825 rc
= cfs_trace_copyout_string(buffer
, nob
,
831 rc
= cfs_trace_copyin_string(buf
, buf_len
, buffer
, nob
);
835 tmp
= cfs_trimwhite(buf
);
839 for (i
= 0; portal_rotors
[i
].pr_name
!= NULL
; i
++) {
840 if (strncasecmp(portal_rotors
[i
].pr_name
, tmp
,
841 strlen(portal_rotors
[i
].pr_name
)) == 0) {
842 portal_rotor
= portal_rotors
[i
].pr_value
;
849 LIBCFS_FREE(buf
, buf_len
);
852 DECLARE_PROC_HANDLER(proc_lnet_portal_rotor
);
854 static ctl_table_t lnet_table
[] = {
856 * NB No .strategy entries have been provided since sysctl(8) prefers
857 * to go via /proc for portability.
862 .proc_handler
= &proc_lnet_stats
,
865 .procname
= "routes",
867 .proc_handler
= &proc_lnet_routes
,
870 .procname
= "routers",
872 .proc_handler
= &proc_lnet_routers
,
877 .proc_handler
= &proc_lnet_peers
,
880 .procname
= "buffers",
882 .proc_handler
= &proc_lnet_buffers
,
887 .proc_handler
= &proc_lnet_nis
,
890 .procname
= "portal_rotor",
892 .proc_handler
= &proc_lnet_portal_rotor
,
898 static ctl_table_t top_table
[] = {
913 if (lnet_table_header
== NULL
)
914 lnet_table_header
= register_sysctl_table(top_table
);
920 if (lnet_table_header
!= NULL
)
921 unregister_sysctl_table(lnet_table_header
);
923 lnet_table_header
= NULL
;