1828038 Members
1979 Online
109973 Solutions
New Discussion

script to find logic

 
IT_2007
Honored Contributor

script to find logic

create a common script to find and transfer CPU ID's for interrupts.

Ex: lanscan |grep -v -E "Hardware|Path" |awk '{print $1}' shows lan card Hardware paths.

then putting into a loop will get all corresponding CPU ID's.

for i in `lanscan |grep -v -E "Hardware|Path" |awk '{print $1}'`
do
intctl -H $i | grep -v -E "cpu|ID" |awk '{print $5}'
done

My Question: Want to make sure they are not using same CPU ID's. If it is using then change to different CPU ID for that path using following command.

intctl -M -H -I 1 -c

The above command performs to transfer interrupts from one CPU to another one for the path specified.

Thanks in Advance.
5 REPLIES 5
Hein van den Heuvel
Honored Contributor

Re: script to find logic

How about something along the lines of
(UNTESTED. Need to check for some max-cpu!)

Hein.

use strict;
use warnings;
my ($cpu, $hw, @hw_to_reassign, %cpu_assigned_to, %hw_assigned_to);

foreach (`lanscan`) {
next if /Hardware|Path/;
chomp;
$hw = $_;
foreach (`intctl -H $hw`){
next unless /$hw/;
$cpu = (split)[4];
if (exists $hw_assigned_to{$cpu}) {
push @hw_to_reassign, $hw;
} else {
$hw_assigned_to{$cpu} = $hw;
}
$cpu_assigned_to{$hw} = $cpu; # optional
}
$cpu = 0;
while ($hw = shift @hw_to_reassign) {
$cpu++ while ($hw_assigned_to{$cpu});
$cpu_assigned_to{$hw} = $cpu; # optional
$hw_assigned_to{$cpu} = $hw;
print "$hw cpu $cpu_assigned_to{$hw} re-assigned to $cpu\n";
system ("intctl -M -H $hw -I 1 -c $cpu");
}
}
print "\n";
foreach $cpu (sort keys %hw_assigned_to) {
print "cpu $cpu --> $hw_assigned_to{$cpu}\n";
}


Hein van den Heuvel
Honored Contributor

Re: script to find logic



Forgot to say this would be a PERL script.. if not obvious.

Also, I see I have my loop nesting wrong
The first section is a double nesting of lanscan and intctl building a list of device which have a duplicate cpu.
Then comes a section to deal with those (after $cpu=0).
Finally comes an overview report (after print \n)

Should be:

use strict;
use warnings;
my ($cpu, $hw, @hw_to_reassign, %cpu_assigned_to, %hw_assigned_to);

foreach (`lanscan`) {
next if /Hardware|Path/;
chomp;
$hw = $_;
foreach (`intctl -H $hw`){
next unless /$hw/;
$cpu = (split)[4];
if (exists $hw_assigned_to{$cpu}) {
push @hw_to_reassign, $hw;
} else {
$hw_assigned_to{$cpu} = $hw;
}
$cpu_assigned_to{$hw} = $cpu; # optional
}
}
$cpu = 0;
while ($hw = shift @hw_to_reassign) {
$cpu++ while ($hw_assigned_to{$cpu});
$cpu_assigned_to{$hw} = $cpu; # optional
$hw_assigned_to{$cpu} = $hw;
print "$hw cpu $cpu_assigned_to{$hw} re-assigned to $cpu\n";
system ("intctl -M -H $hw -I 1 -c $cpu");
}

print "\n";
foreach $cpu (sort keys %hw_assigned_to) {
print "cpu $cpu --> $hw_assigned_to{$cpu}\n";
}


IT_2007
Honored Contributor

Re: script to find logic

looking for a shell script otherwise would go to perl.

thanks.

Re: script to find logic

Hi,

Is there a reason why you don't just move the interrupts around once manually and then use:

intctl -s /etc/my_interrupt_cfg

Then every time you reboot you can just call

intctl -r /etc/my_interrupt_cfg

Which will restore the config to how you had it before.

Of course if you have iCAP CPUs or vPars... the number of CPUs will change and this won't work.

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Hein van den Heuvel
Honored Contributor

Re: script to find logic

I much like Duncan's idea.
I guess that a reason why I keep reading and replying to the forums always something new to learn. This time the -r / -s option for intctl

I had an opportunity to test my script on my 2620.
It almost worked. Only serious problem:
chomp;
$hw = $_;
Should be
$hw = (split)[0];

I looked at the intctl output some more, and tehre is no reason to first do the lanscan + individual intctl's. You can call it once adn licp up the ' lan ' lines remembering the hardware addresses and cpu's as you go.

Minor re-hash:

"move_network_interrupts.pl" 39 lines, 932 characters
use strict;
use warnings;
my ($cpu, $hw, @hw_to_reassign, %cpu_assigned_to, %hw_assigned_to);

#
# Loop through hardware looking for lan entries as:
# 0/1/2/1 lan iether N/A 1
#
foreach (`intctl`){
if (/(\S+)\s+lan\s+\S+\s+\S+\s+(\d+)/) {
$hw = $1;
$cpu = $2;
print "... $hw $cpu\n";
if ($hw_assigned_to{$cpu}) {
push @hw_to_reassign, $hw;
} else {
$hw_assigned_to{$cpu} = $hw;
}
$cpu_assigned_to{$hw} = $cpu;
}
}
#
# Re-assign duplica
#
$cpu = 0;
while ($hw = shift @hw_to_reassign) {
$cpu++ while ($hw_assigned_to{$cpu});
print "reassining $hw cpu $cpu_assigned_to{$hw} to $cpu\n";
system ("intctl -M -H $hw -I 1 -c $cpu");
$cpu_assigned_to{$hw} = $cpu;
$hw_assigned_to{$cpu} = $hw;
}
#
# Final report
#
print "\n";
foreach $cpu (sort keys %hw_assigned_to) {
print "cpu $cpu --> $hw_assigned_to{$cpu}\n";
}

Sample run:

>perl move_network_interrupts.pl
... 0/1/2/0 0
... 0/1/2/1 0
reassining 0/1/2/1 cpu 0 to 1
intctl: Moved the interrupt: 1, of card 0/1/2/1, driver iether, from CPU:0 to CPU:1

cpu 0 --> 0/1/2/0
cpu 1 --> 0/1/2/1


Enjoy,
Hein.