diff options
| author | Patrick Williams <iawillia@us.ibm.com> | 2012-04-24 14:07:36 -0500 |
|---|---|---|
| committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2012-05-03 13:32:54 -0500 |
| commit | 9a94e04ad4f91d72b43d42fc0a85e271085775e1 (patch) | |
| tree | cbfe3e5911febb11a5d568f6438b89738d77bdca /src | |
| parent | 3be094d3fa4618a90dcb90d1814c73fde9d7d4ac (diff) | |
| download | blackbird-hostboot-9a94e04ad4f91d72b43d42fc0a85e271085775e1.tar.gz blackbird-hostboot-9a94e04ad4f91d72b43d42fc0a85e271085775e1.zip | |
Optimize xmltohb.pl
Change-Id: Ifb00eeed9411d6406aa1e8678d5b4b2e6443afde
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/935
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Tested-by: Jenkins Server
Diffstat (limited to 'src')
| -rwxr-xr-x | src/usr/targeting/common/xmltohb/xmltohb.pl | 254 |
1 files changed, 135 insertions, 119 deletions
diff --git a/src/usr/targeting/common/xmltohb/xmltohb.pl b/src/usr/targeting/common/xmltohb/xmltohb.pl index eb344db53..a75d53e49 100755 --- a/src/usr/targeting/common/xmltohb/xmltohb.pl +++ b/src/usr/targeting/common/xmltohb/xmltohb.pl @@ -1836,9 +1836,12 @@ sub enforceString { ################################################################################ # Get hash ref to supported simple types and their properties ################################################################################ +my $g_simpleTypeProperties_cache = 0; sub simpleTypeProperties { + return $g_simpleTypeProperties_cache if ($g_simpleTypeProperties_cache); + my %typesHoH = (); # Intentionally didn't wrap these to 80 columns to keep them lined up and @@ -1855,7 +1858,9 @@ sub simpleTypeProperties { $typesHoH{"enumeration"} = { supportsArray => 1, canBeHex => 1, complexTypeSupport => 0, typeName => "XMLTOHB_USE_PARENT_ATTR_ID" , bytes => 0, bits => 0 , default => \&defaultEnum , alignment => 1, specialPolicies =>\&null, packfmt => "packEnumeration"}; $typesHoH{"hbmutex"} = { supportsArray => 1, canBeHex => 1, complexTypeSupport => 0, typeName => "mutex_t*" , bytes => 8, bits => 64, default => \&defaultZero , alignment => 8, specialPolicies =>\&enforceHbMutex, packfmt =>\&packQuad}; - return \%typesHoH; + $g_simpleTypeProperties_cache = \%typesHoH; + + return $g_simpleTypeProperties_cache; } ################################################################################ @@ -1982,8 +1987,7 @@ sub maxEnumValue { my $candidateMax = 0; foreach my $enumerator (@{$enumeration->{enumerator}}) { - my $candidateMax = unhexify(enumNameToValue( - $enumeration,$enumerator->{name})); + my $candidateMax = enumNameToValue($enumeration,$enumerator->{name}); if($candidateMax > $max) { $max = $candidateMax; @@ -2037,26 +2041,39 @@ sub enumNameToValue { my $found = 0; my $enumeratorValue; - foreach my $enumerator (@{$enumeration->{enumerator}}) + if (defined $enumeration->{__optimized}) { - my $currentEnumeratorValue; - if(exists $enumerator->{value} ) - { - $nextEnumeratorValue = unhexify($enumerator->{value}) + 1; - $currentEnumeratorValue = unhexify($enumerator->{value}); - } - else - { - $currentEnumeratorValue = $nextEnumeratorValue; - $nextEnumeratorValue += 1; - } - - if($enumerator->{name} eq $enumeratorName) - { - $found = 1; - $enumeratorValue = $currentEnumeratorValue; - last; - } + if (defined $enumeration->{__optimized}->{$enumeratorName}) + { + $found = 1; + $enumeratorValue = $enumeration->{__optimized}->{$enumeratorName}; + } + } + else + { + foreach my $enumerator (@{$enumeration->{enumerator}}) + { + my $currentEnumeratorValue; + if(exists $enumerator->{value} ) + { + $currentEnumeratorValue = unhexify($enumerator->{value}); + $nextEnumeratorValue = $currentEnumeratorValue + 1; + } + else + { + $currentEnumeratorValue = $nextEnumeratorValue; + $nextEnumeratorValue += 1; + } + + $enumeration->{__optimized}->{$enumerator->{name}} + = $currentEnumeratorValue; + + if($enumerator->{name} eq $enumeratorName) + { + $found = 1; + $enumeratorValue = $currentEnumeratorValue; + } + } } if(!$found) @@ -2605,12 +2622,11 @@ sub writeTargetingImage { # for code update. At minimum, ensure that we always process at this level # in the given order my @targetsAoH = (); - my $numTargets = 0; foreach my $targetInstance (@{$attributes->{targetInstance}}) { push(@targetsAoH, $targetInstance); - $numTargets++; } + my $numTargets = @targetsAoH; my $numAttributes = 0; foreach my $targetInstance (@targetsAoH) @@ -2704,128 +2720,128 @@ sub writeTargetingImage { } } + my %attributeDefCache = + map { $_->{id} => $_} @{$attributes->{attribute}}; + for my $attributeId (sort(keys %attrhash)) { - foreach my $attributeDef (@{$attributes->{attribute}}) + my $attributeDef = $attributeDefCache{$attributeId}; + if (not defined $attributeDef) { - my $section; - if( $attributeDef->{id} eq $attributeId ) - { - if( exists $attributeDef->{writeable} - && $attributeDef->{persistency} eq "non-volatile" ) - { - $section = "pnor-rw"; - } - elsif ( !exists $attributeDef->{writeable} - && $attributeDef->{persistency} eq "non-volatile") - { - $section = "pnor-ro"; - } - elsif ($attributeDef->{persistency} eq "volatile" ) - { - $section = "heap-pnor-initialized"; - } - elsif($attributeDef->{persistency} eq "volatile-zeroed") - { - $section = "heap-zero-initialized"; - } - else - { - fatal("Persistency not supported."); - } + fatal("Attribute $attributeId is not found."); + } - if($section eq "pnor-ro") - { - my ($rodata,$alignment) = packAttribute($attributes, - $attributeDef, - $attrhash{$attributeId}->{default}); + my $section; + if( exists $attributeDef->{writeable} + && $attributeDef->{persistency} eq "non-volatile" ) + { + $section = "pnor-rw"; + } + elsif ( !exists $attributeDef->{writeable} + && $attributeDef->{persistency} eq "non-volatile") + { + $section = "pnor-ro"; + } + elsif ($attributeDef->{persistency} eq "volatile" ) + { + $section = "heap-pnor-initialized"; + } + elsif($attributeDef->{persistency} eq "volatile-zeroed") + { + $section = "heap-zero-initialized"; + } + else + { + fatal("Persistency not supported."); + } - # Align the data as necessary - my $pads = ($alignment - ($offset % $alignment)) - % $alignment; - $roAttrBinData .= pack ("@".$pads); - $offset += $pads; + if($section eq "pnor-ro") + { + my ($rodata,$alignment) = packAttribute($attributes, + $attributeDef, + $attrhash{$attributeId}->{default}); - $attributePointerBinData .= packQuad( - $offset + $pnorRoBaseAddress); + # Align the data as necessary + my $pads = ($alignment - ($offset % $alignment)) + % $alignment; + $roAttrBinData .= pack ("@".$pads); + $offset += $pads; - $offset += (length $rodata); + $attributePointerBinData .= packQuad( + $offset + $pnorRoBaseAddress); - $roAttrBinData .= $rodata; - } - elsif($section eq "pnor-rw") - { - my ($rwdata,$alignment) = packAttribute($attributes, - $attributeDef, - $attrhash{$attributeId}->{default}); + $offset += (length $rodata); - #print "Wrote to pnor-rw value ",$attributeDef->{id}, ", - #", $attrhash{$attributeId}->{default}," \n"; + $roAttrBinData .= $rodata; + } + elsif($section eq "pnor-rw") + { + my ($rwdata,$alignment) = packAttribute($attributes, + $attributeDef, + $attrhash{$attributeId}->{default}); - # Align the data as necessary - my $pads = ($alignment - ($rwOffset % $alignment)) - % $alignment; - $rwAttrBinData .= pack ("@".$pads); - $rwOffset += $pads; + #print "Wrote to pnor-rw value ",$attributeDef->{id}, ", + #", $attrhash{$attributeId}->{default}," \n"; - $attributePointerBinData .= packQuad( - $rwOffset + $pnorRwBaseAddress); + # Align the data as necessary + my $pads = ($alignment - ($rwOffset % $alignment)) + % $alignment; + $rwAttrBinData .= pack ("@".$pads); + $rwOffset += $pads; - $rwOffset += (length $rwdata); + $attributePointerBinData .= packQuad( + $rwOffset + $pnorRwBaseAddress); - $rwAttrBinData .= $rwdata; + $rwOffset += (length $rwdata); - } - elsif($section eq "heap-zero-initialized") - { - my ($heapZeroInitData,$alignment) = packAttribute( - $attributes, - $attributeDef,$attrhash{$attributeId}->{default}); + $rwAttrBinData .= $rwdata; - # Align the data as necessary - my $pads = ($alignment - ($heapZeroInitOffset + } + elsif($section eq "heap-zero-initialized") + { + my ($heapZeroInitData,$alignment) = packAttribute( + $attributes, + $attributeDef,$attrhash{$attributeId}->{default}); + + # Align the data as necessary + my $pads = ($alignment - ($heapZeroInitOffset % $alignment)) % $alignment; - $heapZeroInitBinData .= pack ("@".$pads); - $heapZeroInitOffset += $pads; + $heapZeroInitBinData .= pack ("@".$pads); + $heapZeroInitOffset += $pads; - $attributePointerBinData .= packQuad( - $heapZeroInitOffset + $heapZeroInitBaseAddr); + $attributePointerBinData .= packQuad( + $heapZeroInitOffset + $heapZeroInitBaseAddr); - $heapZeroInitOffset += (length $heapZeroInitData); + $heapZeroInitOffset += (length $heapZeroInitData); - $heapZeroInitBinData .= $heapZeroInitData; + $heapZeroInitBinData .= $heapZeroInitData; - } - elsif($section eq "heap-pnor-initialized") - { - my ($heapPnorInitData,$alignment) = packAttribute( - $attributes, - $attributeDef,$attrhash{$attributeId}->{default}); + } + elsif($section eq "heap-pnor-initialized") + { + my ($heapPnorInitData,$alignment) = packAttribute( + $attributes, + $attributeDef,$attrhash{$attributeId}->{default}); - # Align the data as necessary - my $pads = ($alignment - ($heapPnorInitOffset + # Align the data as necessary + my $pads = ($alignment - ($heapPnorInitOffset % $alignment)) % $alignment; - $heapPnorInitBinData .= pack ("@".$pads); - $heapPnorInitOffset += $pads; + $heapPnorInitBinData .= pack ("@".$pads); + $heapPnorInitOffset += $pads; - $attributePointerBinData .= packQuad( - $heapPnorInitOffset + $heapPnorInitBaseAddr); + $attributePointerBinData .= packQuad( + $heapPnorInitOffset + $heapPnorInitBaseAddr); - $heapPnorInitOffset += (length $heapPnorInitData); + $heapPnorInitOffset += (length $heapPnorInitData); - $heapPnorInitBinData .= $heapPnorInitData; - } - else - { - fatal("Could not find a suitable section."); - } - - $attributesWritten++; - - last; - } + $heapPnorInitBinData .= $heapPnorInitData; + } + else + { + fatal("Could not find a suitable section."); } + $attributesWritten++; } # End attribute loop |

