Skip to content

Commit 45ceffa

Browse files
harp-intelCopilot
andauthored
improve SSTTF script error handling (#503)
* improve SSTTF script error handling Signed-off-by: Harper, Jason M <[email protected]> * fix comment Co-authored-by: Copilot <[email protected]> --------- Signed-off-by: Harper, Jason M <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 4a6eb11 commit 45ceffa

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

internal/report/table_defs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,11 @@ func sstTFHPTableValues(outputs map[string]script.ScriptOutput) []Field {
13551355
continue
13561356
}
13571357
for j, value := range values {
1358+
// confirm value is a number
1359+
if _, err := strconv.Atoi(value); err != nil {
1360+
slog.Warn("unexpected non-numeric value in line", slog.String("line", line), slog.String("value", value))
1361+
return []Field{}
1362+
}
13581363
if j > 1 {
13591364
value = value + "00"
13601365
}
@@ -1393,6 +1398,11 @@ func sstTFLPTableValues(outputs map[string]script.ScriptOutput) []Field {
13931398
continue
13941399
}
13951400
for j, value := range values {
1401+
// confirm value is a number
1402+
if _, err := strconv.Atoi(value); err != nil {
1403+
slog.Warn("unexpected non-numeric value in line", slog.String("line", line), slog.String("value", value))
1404+
return []Field{}
1405+
}
13961406
fields[j].Values = append(fields[j].Values, value+"00")
13971407
}
13981408
}

internal/script/script_defs.go

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,27 @@ done
604604
SSTTFHPScriptName: {
605605
Name: SSTTFHPScriptName,
606606
ScriptTemplate: `# Is SST-TF supported?
607-
supported=$(pcm-tpmi 5 0xF8 -d -b 12:12 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
607+
if ! supported=$(pcm-tpmi 5 0xF8 -d -b 12:12 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
608+
echo "Error: Failed to check if SST-TF is supported" >&2
609+
exit 1
610+
fi
611+
if [[ ! "$supported" =~ ^[0-9]+$ ]]; then
612+
echo "Error: Invalid output from pcm-tpmi when checking support" >&2
613+
exit 1
614+
fi
608615
if [ "$supported" -eq 0 ]; then
609616
echo "SST-TF is not supported"
610617
exit 0
611618
fi
612619
# Is SST-TF enabled?
613-
enabled=$(pcm-tpmi 5 0x78 -d -b 9:9 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
620+
if ! enabled=$(pcm-tpmi 5 0x78 -d -b 9:9 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
621+
echo "Error: Failed to check if SST-TF is enabled" >&2
622+
exit 1
623+
fi
624+
if [[ ! "$enabled" =~ ^[0-9]+$ ]]; then
625+
echo "Error: Invalid output from pcm-tpmi when checking enabled status" >&2
626+
exit 1
627+
fi
614628
if [ "$enabled" -eq 0 ]; then
615629
echo "SST-TF is not enabled"
616630
exit 0
@@ -622,7 +636,14 @@ do
622636
# Get the # of cores in this bucket
623637
bithigh=$((i*8+7))
624638
bitlow=$((i*8))
625-
numcores=$(pcm-tpmi 5 0x100 -d -b $bithigh:$bitlow -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
639+
if ! numcores=$(pcm-tpmi 5 0x100 -d -b $bithigh:$bitlow -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
640+
echo "Error: Failed to get number of cores for bucket $i" >&2
641+
exit 1
642+
fi
643+
if [[ ! "$numcores" =~ ^[0-9]+$ ]]; then
644+
echo "Error: Invalid output from pcm-tpmi when getting number of cores for bucket $i" >&2
645+
exit 1
646+
fi
626647
# if the number of cores is 0, skip this bucket
627648
if [ "$numcores" -eq 0 ]; then
628649
continue
@@ -634,8 +655,15 @@ do
634655
# 5 isa frequencies per bucket (AVX, AVX2, AVX-512, AVX-512 heavy, AMX)
635656
for((j=0; j<5; j++))
636657
do
637-
offset=$((j*8 + 264)) // 264 is 0x108 (SST_TF_INFO_2) AVX
638-
freq=$(pcm-tpmi 5 $offset -d -b $bithigh:$bitlow -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
658+
offset=$((j*8 + 264)) # 264 is 0x108 (SST_TF_INFO_2) AVX
659+
if ! freq=$(pcm-tpmi 5 $offset -d -b $bithigh:$bitlow -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
660+
echo "Error: Failed to get frequency for instruction set $j in bucket $i" >&2
661+
exit 1
662+
fi
663+
if [[ ! "$freq" =~ ^[0-9]+$ ]]; then
664+
echo "Error: Invalid frequency value for instruction set $j in bucket $i" >&2
665+
exit 1
666+
fi
639667
echo -n "$freq"
640668
if [ $j -lt 4 ]; then
641669
echo -n ","
@@ -653,13 +681,29 @@ done
653681
SSTTFLPScriptName: {
654682
Name: SSTTFLPScriptName,
655683
ScriptTemplate: `# Is SST-TF supported?
656-
supported=$(pcm-tpmi 5 0xF8 -d -b 12:12 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
684+
if ! supported=$(pcm-tpmi 5 0xF8 -d -b 12:12 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
685+
echo "Error: Failed to check if SST-TF is supported" >&2
686+
exit 1
687+
fi
688+
if [[ ! "$supported" =~ ^[0-9]+$ ]]; then
689+
echo "Error: Invalid output from pcm-tpmi when checking support" >&2
690+
exit 1
691+
fi
692+
657693
if [ "$supported" -eq 0 ]; then
658694
echo "SST-TF is not supported"
659695
exit 0
660696
fi
661697
# Is SST-TF enabled?
662-
enabled=$(pcm-tpmi 5 0x78 -d -b 9:9 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
698+
if ! enabled=$(pcm-tpmi 5 0x78 -d -b 9:9 -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
699+
echo "Error: Failed to check if SST-TF is enabled" >&2
700+
exit 1
701+
fi
702+
if [[ ! "$enabled" =~ ^[0-9]+$ ]]; then
703+
echo "Error: Invalid output from pcm-tpmi when checking enabled status" >&2
704+
exit 1
705+
fi
706+
663707
if [ "$enabled" -eq 0 ]; then
664708
echo "SST-TF is not enabled"
665709
exit 0
@@ -670,7 +714,14 @@ for((j=0; j<5; j++))
670714
do
671715
bithigh=$((j*8+23))
672716
bitlow=$((j*8+16))
673-
freq=$(pcm-tpmi 5 0xF8 -d -b $bithigh:$bitlow -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}')
717+
if ! freq=$(pcm-tpmi 5 0xF8 -d -b $bithigh:$bitlow -i 0 -e 0 | tail -n 2 | head -n 1 | awk '{print $5}'); then
718+
echo "Error: Failed to get frequency for instruction set $j" >&2
719+
exit 1
720+
fi
721+
if [[ ! "$freq" =~ ^[0-9]+$ ]]; then
722+
echo "Error: Invalid frequency value for instruction set $j" >&2
723+
exit 1
724+
fi
674725
echo -n "$freq"
675726
if [ $j -ne 4 ]; then
676727
echo -n ","

0 commit comments

Comments
 (0)