3 # Copyright (c) 2008 Voltaire, Inc. All rights reserved.
4 # Copyright (c) 2006 The Regents of the University of California.
6 # Produced at Lawrence Livermore National Laboratory.
7 # Written by Ira Weiny <weiny2@llnl.gov>.
9 # This software is available to you under a choice of one of two
10 # licenses. You may choose to be licensed under the terms of the GNU
11 # General Public License (GPL) Version 2, available from the file
12 # COPYING in the main directory of this source tree, or the
13 # OpenIB.org BSD license below:
15 # Redistribution and use in source and binary forms, with or
16 # without modification, are permitted provided that the following
19 # - Redistributions of source code must retain the above
20 # copyright notice, this list of conditions and the following
23 # - Redistributions in binary form must reproduce the above
24 # copyright notice, this list of conditions and the following
25 # disclaimer in the documentation and/or other materials
26 # provided with the distribution.
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47 # =========================================================================
56 # =========================================================================
60 if (!$verbose) { return; }
62 print " Counter\t\t\tNew ==> Old\n";
63 foreach my $cnt (@IBswcountlimits::counters) {
65 " $cnt\t\t\t$IBswcountlimits::new_counts{$cnt} ==> $IBswcountlimits::cur_counts{$cnt}\n";
69 # =========================================================================
75 "Usage: $prog [-p <pause_time> -b -v -n <cycles> -G] <guid|lid> <port>\n";
76 print " Attempt to diagnose a problem on a port\n";
78 " Run this on a link while a job is running which utilizes that link.\n";
80 " -p <pause_time> define the ammount of time between counter polls (default $IBswcountlimits::pause_time)\n";
81 print " -v Be verbose\n";
82 print " -n <cycles> run n cycles then exit (default -1 == forever)\n";
83 print " -G Address provided is a GUID\n";
84 print " -b report bytes/second packets/second\n";
88 # =========================================================================
93 foreach my $count (@IBswcountlimits::counters) {
94 $IBswcountlimits::cur_counts{$count} = 0;
95 $IBswcountlimits::new_counts{$count} = 0;
99 # =========================================================================
103 foreach my $count (@IBswcountlimits::counters) {
104 $IBswcountlimits::cur_counts{$count} =
105 $IBswcountlimits::new_counts{$count};
109 # =========================================================================
110 # use perfquery to get the counters.
121 "perfquery $GUID $addr $port > $IBswcountlimits::cache_dir/perfquery.out"
125 die "perfquery failed : \"perfquery $GUID $addr $port\"\n";
127 open PERF_QUERY, "<$IBswcountlimits::cache_dir/perfquery.out"
128 or die "cannot read '$IBswcountlimits::cache_dir/perfquery.out': $!\n";
129 while (my $line = <PERF_QUERY>) {
130 foreach my $count (@IBswcountlimits::counters) {
131 if ($line =~ /^$count:\.+(\d+)/) {
132 $IBswcountlimits::new_counts{$count} = $1;
139 my $cycle = -1; # forever
141 my $bytes_per_second = undef;
142 my $argv0 = `basename $0`;
144 if (!getopts("hbvp:n:G")) { usage_and_exit $argv0; }
145 if (defined $Getopt::Std::opt_h) { usage_and_exit $argv0; }
146 if (defined $Getopt::Std::opt_p) {
147 $IBswcountlimits::pause_time = $Getopt::Std::opt_p;
149 if (defined $Getopt::Std::opt_v) { $verbose = $Getopt::Std::opt_v; }
150 if (defined $Getopt::Std::opt_n) { $cycle = $Getopt::Std::opt_n; }
151 if (defined $Getopt::Std::opt_G) { $GUID = "-G"; }
152 if (defined $Getopt::Std::opt_b) { $bytes_per_second = $Getopt::Std::opt_b; }
154 my $sw_addr = $ARGV[0];
155 my $sw_port = $ARGV[1];
160 get_new_counts($sw_addr, $sw_port);
161 while ($cycle != 0) {
162 print "Checking counts...\n";
163 sleep($IBswcountlimits::pause_time);
164 get_new_counts($sw_addr, $sw_port);
166 if ($bytes_per_second) {
170 if ($cycle != -1) { $cycle = $cycle - 1; }