OpenSTA/power/Power.tcl

291 lines
9.5 KiB
Tcl
Raw Normal View History

2018-11-26 18:15:52 +01:00
# OpenSTA, Static Timing Analyzer
# Copyright (c) 2023, Parallax Software, Inc.
2018-11-26 18:15:52 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-11-26 18:15:52 +01:00
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-11-26 18:15:52 +01:00
################################################################
#
# Power commands.
#
################################################################
namespace eval sta {
define_cmd_args "report_power" \
{ [-instances instances]\
[-corner corner]\
2018-11-26 18:15:52 +01:00
[-digits digits]\
[> filename] [>> filename] }
proc_redirect report_power {
global sta_report_default_digits
parse_key_args "report_power" args \
keys {-instances -corner -digits} flags {}
2018-11-26 18:15:52 +01:00
check_argc_eq0 "report_power" $args
2019-04-29 17:39:05 +02:00
if { [info exists keys(-digits)] } {
2018-11-26 18:15:52 +01:00
set digits $keys(-digits)
check_positive_integer "-digits" $digits
} else {
set digits $sta_report_default_digits
}
set corner [parse_corner keys]
if { [info exists keys(-instances)] } {
2019-02-17 00:31:39 +01:00
set insts [get_instances_error "-instances" $keys(-instances)]
2019-02-18 19:56:38 +01:00
report_power_insts $insts $corner $digits
2018-11-26 18:15:52 +01:00
} else {
report_power_design $corner $digits
}
}
proc report_power_design { corner digits } {
set power_result [design_power $corner]
2018-12-11 21:34:03 +01:00
set totals [lrange $power_result 0 3]
set sequential [lrange $power_result 4 7]
set combinational [lrange $power_result 8 11]
set clock [lrange $power_result 12 15]
set macro [lrange $power_result 16 19]
set pad [lrange $power_result 20 end]
2018-12-14 08:53:17 +01:00
lassign $totals design_internal design_switching design_leakage design_total
2019-02-18 19:56:38 +01:00
2019-03-29 22:18:08 +01:00
set field_width [max [expr $digits + 6] 10]
report_power_title5 "Group" "Internal" "Switching" "Leakage" "Total" $field_width
report_power_title5_units " " "Power" "Power" "Power" "Power" "(Watts)" $field_width
2019-03-29 22:18:08 +01:00
report_title_dashes5 $field_width
report_power_row "Sequential" $sequential $design_total $field_width $digits
report_power_row "Combinational" $combinational $design_total $field_width $digits
report_power_row "Clock" $clock $design_total $field_width $digits
2019-03-29 22:18:08 +01:00
report_power_row "Macro" $macro $design_total $field_width $digits
report_power_row "Pad" $pad $design_total $field_width $digits
report_title_dashes5 $field_width
report_power_row "Total" $power_result $design_total $field_width $digits
2020-12-26 01:55:46 +01:00
report_line "[format %-20s {}][power_col_percent $design_internal $design_total $field_width][power_col_percent $design_switching $design_total $field_width][power_col_percent $design_leakage $design_total $field_width]"
2018-11-26 18:15:52 +01:00
}
2019-03-29 22:18:08 +01:00
proc max { x y } {
if { $x >= $y } {
return $x
} else {
return $y
}
}
proc report_power_title5 { title1 title2 title3 title4 title5 field_width } {
2020-12-26 01:55:46 +01:00
report_line "[format %-20s $title1] [format %${field_width}s $title2] [format %${field_width}s $title3] [format %${field_width}s $title4] [format %${field_width}s $title5]"
2019-03-29 22:18:08 +01:00
}
proc report_power_title5_units { title1 title2 title3 title4 title5 units field_width } {
report_line "[format %-20s $title1] [format %${field_width}s $title2] [format %${field_width}s $title3] [format %${field_width}s $title4] [format %${field_width}s $title5] $units"
}
2019-03-29 22:18:08 +01:00
proc report_power_title4 { title1 title2 title3 title4 field_width } {
2020-12-26 01:55:46 +01:00
report_line " [format %${field_width}s $title1] [format %${field_width}s $title2] [format %${field_width}s $title3] [format %${field_width}s $title4]"
2019-03-29 22:18:08 +01:00
}
proc report_power_title4_units { title1 title2 title3 title4 units field_width } {
report_line " [format %${field_width}s $title1] [format %${field_width}s $title2] [format %${field_width}s $title3] [format %${field_width}s $title4] $units"
}
2019-03-29 22:18:08 +01:00
proc report_title_dashes5 { field_width } {
set count [expr 20 + ($field_width + 1) * 4]
report_title_dashes $count
}
proc report_title_dashes4 { field_width } {
set count [expr ($field_width + 1) * 4]
report_title_dashes $count
}
proc report_title_dashes { count } {
2020-12-26 01:55:46 +01:00
set line ""
2019-03-29 22:18:08 +01:00
for {set i 0} {$i < $count} {incr i} {
2020-12-26 01:55:46 +01:00
set line "-$line"
2019-03-29 22:18:08 +01:00
}
2020-12-26 01:55:46 +01:00
report_line $line
2019-03-29 22:18:08 +01:00
}
proc report_power_row { type row_result design_total field_width digits } {
2018-12-11 21:34:03 +01:00
lassign $row_result internal switching leakage total
2020-05-06 17:09:15 +02:00
if { $design_total == 0.0 || [is_nan $design_total] } {
2018-12-11 19:47:04 +01:00
set percent 0.0
} else {
set percent [expr $total / $design_total * 100]
}
2020-12-28 18:04:57 +01:00
report_line "[format %-20s $type][power_col $internal $field_width $digits][power_col $switching $field_width $digits][power_col $leakage $field_width $digits][power_col $total $field_width $digits] [format %5.1f $percent]%"
2018-11-26 18:15:52 +01:00
}
2020-05-06 17:09:15 +02:00
proc is_nan { str } {
return [string match "*NaN" $str]
}
2020-12-26 01:55:46 +01:00
proc power_col { pwr field_width digits } {
2020-05-06 17:09:15 +02:00
if { [is_nan $pwr] } {
2020-12-26 01:55:46 +01:00
format " %${field_width}s" $pwr
2020-05-06 17:09:15 +02:00
} else {
2020-12-26 01:55:46 +01:00
format " %$field_width.${digits}e" $pwr
2020-05-06 17:09:15 +02:00
}
2018-11-26 18:15:52 +01:00
}
2020-12-26 01:55:46 +01:00
proc power_col_percent { col_total total field_width } {
2020-05-06 17:09:15 +02:00
if { $total == 0.0 || [is_nan $total]} {
2018-12-11 19:47:04 +01:00
set percent 0.0
} else {
2018-12-11 21:34:03 +01:00
set percent [expr $col_total / $total * 100]
2018-12-11 19:47:04 +01:00
}
2020-12-26 01:55:46 +01:00
format "%$field_width.1f%%" $percent
2018-11-26 18:15:52 +01:00
}
2019-02-18 19:56:38 +01:00
proc report_power_line { type pwr digits } {
2020-05-06 17:09:15 +02:00
if { [is_nan $pwr] } {
2020-12-26 01:55:46 +01:00
report_line [format "%-16s %s" $type $pwr]
2020-05-06 17:09:15 +02:00
} else {
2020-12-26 01:55:46 +01:00
report_line [format "%-16s %.${digits}e" $type $pwr]
2020-05-06 17:09:15 +02:00
}
2019-02-18 19:56:38 +01:00
}
proc report_power_insts { insts corner digits } {
set inst_pwrs {}
foreach inst $insts {
set power_result [instance_power $inst $corner]
lappend inst_pwrs [list $inst $power_result]
}
set inst_pwrs [lsort -command inst_pwr_cmp $inst_pwrs]
2019-02-19 01:24:41 +01:00
2019-03-29 22:18:08 +01:00
set field_width [max [expr $digits + 6] 10]
report_power_title4 "Internal" "Switching" "Leakage" "Total" $field_width
report_power_title4_units "Power" "Power" "Power" "Power" "(Watts)" $field_width
2019-03-29 22:18:08 +01:00
report_title_dashes4 $field_width
2019-02-19 01:24:41 +01:00
2019-02-18 19:56:38 +01:00
foreach inst_pwr $inst_pwrs {
set inst [lindex $inst_pwr 0]
set power [lindex $inst_pwr 1]
2019-03-29 22:18:08 +01:00
report_power_inst $inst $power $field_width $digits
2019-02-18 19:56:38 +01:00
}
}
proc inst_pwr_cmp { inst_pwr1 inst_pwr2 } {
set pwr1 [lindex $inst_pwr1 1]
set pwr2 [lindex $inst_pwr2 1]
lassign $pwr1 internal1 switching1 leakage1 total1
lassign $pwr2 internal2 switching2 leakage2 total2
if { $total1 < $total2 } {
return 1
} elseif { $total1 == $total2 } {
return 0
} else {
return -1
}
}
2019-03-29 22:18:08 +01:00
proc report_power_inst { inst power_result field_width digits } {
2019-02-19 01:24:41 +01:00
lassign $power_result internal switching leakage total
2020-12-26 01:55:46 +01:00
report_line "[power_col $internal $field_width $digits][power_col $switching $field_width $digits][power_col $leakage $field_width $digits][power_col $total $field_width $digits] [get_full_name $inst]"
2018-11-26 18:15:52 +01:00
}
2019-02-18 19:56:38 +01:00
################################################################
2018-11-26 18:15:52 +01:00
2019-04-29 17:39:05 +02:00
define_cmd_args "set_power_activity" { [-global]\
[-input]\
[-input_ports ports]\
[-pins pins]\
2021-06-14 00:14:07 +02:00
[-activity activity]\
2019-04-29 17:39:05 +02:00
[-duty duty] }
proc set_power_activity { args } {
parse_key_args "set_power_activity" args \
keys {-input_ports -pins -activity -duty} \
flags {-global -input}
2019-04-29 17:39:05 +02:00
check_argc_eq0 "set_power_activity" $args
2019-04-29 17:39:05 +02:00
set activity 0.0
if { [info exists keys(-activity)] } {
set activity $keys(-activity)
check_float "activity" $activity
if { $activity < 0.0 } {
2020-12-16 06:31:08 +01:00
sta_warn 301 "activity should be 0.0 to 1.0 or 2.0"
2019-04-29 17:39:05 +02:00
}
}
set duty 0.5
if { [info exists keys(-duty)] } {
set duty $keys(-duty)
check_float "duty" $duty
if { $duty < 0.0 || $duty > 1.0 } {
2020-12-16 06:31:08 +01:00
sta_warn 302 "duty should be 0.0 to 1.0"
2019-04-29 17:39:05 +02:00
}
}
2018-11-26 18:15:52 +01:00
2019-04-29 17:39:05 +02:00
if { [info exists flags(-global)] } {
set_power_global_activity $activity $duty
}
if { [info exists flags(-input)] } {
set_power_input_activity $activity $duty
}
if { [info exists keys(-input_ports)] } {
set ports [get_ports_error "input_ports" $keys(-input_ports)]
foreach port $ports {
if { [get_property $port "direction"] == "input" } {
if { [sta::is_clock_src [sta::get_port_pin $port]] } {
sta_warn 299 "activity cannot be set on clock ports."
} else {
set_power_input_port_activity $port $activity $duty
}
2019-04-29 17:39:05 +02:00
}
}
}
if { [info exists keys(-pins)] } {
2020-08-05 16:23:38 +02:00
set pins [get_pins $keys(-pins)]
2019-04-29 17:39:05 +02:00
foreach pin $pins {
set_power_pin_activity $pin $activity $duty
2018-11-26 18:15:52 +01:00
}
}
}
################################################################
define_cmd_args "read_power_activities" { [-scope scope] -vcd filename }
proc read_power_activities { args } {
parse_key_args "read_power_activities" args \
keys {-scope} flags {-vcd}
check_argc_eq1 "set_power_activity" $args
set filename [file nativename [lindex $args 0]]
set scope ""
if { [info exists keys(-scope)] } {
set scope $keys(-scope)
}
read_vcd_activities $filename $scope
}
################################################################
2020-05-06 17:09:15 +02:00
proc power_find_nan { } {
set corner [cmd_corner]
foreach inst [network_leaf_instances] {
set power_result [instance_power $inst $corner]
lassign $power_result internal switching leakage total
if { [is_nan $internal] || [is_nan $switching] || [is_nan $leakage] } {
2020-12-26 01:55:46 +01:00
report_line "[get_full_name $inst] $internal $switching $leakage"
2020-05-06 17:09:15 +02:00
break
}
}
}
2018-11-26 18:15:52 +01:00
# sta namespace end.
}