|
29 | 29 | # Create logger |
30 | 30 | logger = logging.getLogger(__name__) |
31 | 31 | # Memory regular exception |
32 | | -MEMINFO_REG = re.compile(r'(?P<key>.+):\s+(?P<value>.+) (?P<unit>.)B') |
| 32 | +MEMINFO_REG = re.compile(r'(?P<key>[^:]+):\s+(?P<value>.+)\s+(?P<unit>.)B') |
33 | 33 | FSTAB_RE = re.compile(r'^(?P<path>[^ ]+) +(?P<mount>[^ ]+) +(?P<type>[^ ]+) +(?P<options>[^ ]+) +(?P<dump>\d+) +(?P<pass>\d+)$') |
34 | 34 | BUDDYINFO_REG = re.compile(r'Node\s+(?P<numa_node>\d+).*zone\s+(?P<zone>\w+)\s+(?P<nr_free>.*)') |
35 | 35 | SWAP_REG = re.compile(r'(?P<name>[^ ]+)\s+(?P<type>[^ ]+)\s+(?P<size>\d+)\s+(?P<used>\d+)\s+(?P<prio>-?\d+)') |
@@ -127,76 +127,103 @@ def read_emc(root_path): |
127 | 127 | emc = {} |
128 | 128 | # Initialize emc['cur'] to avoid a crash when starting this service |
129 | 129 | emc['cur'] = 1 |
| 130 | + |
130 | 131 | if os.path.isdir(root_path + "/debug/bpmp/debug/clk/emc"): |
131 | 132 | path = root_path + "/debug/bpmp/debug/clk/emc" |
132 | 133 | # Check if access to this file |
133 | 134 | if os.access(path + "/rate", os.R_OK): |
134 | 135 | with open(path + "/rate", 'r') as f: |
135 | | - # Write min |
136 | 136 | emc['cur'] = int(f.read()) // 1000 |
137 | 137 | # Check if access to this file |
138 | 138 | if os.access(path + "/max_rate", os.R_OK): |
139 | 139 | with open(path + "/max_rate", 'r') as f: |
140 | | - # Write min |
141 | 140 | emc['max'] = int(f.read()) // 1000 |
142 | 141 | # Check if access to this file |
143 | 142 | if os.access(path + "/min_rate", os.R_OK): |
144 | 143 | with open(path + "/min_rate", 'r') as f: |
145 | | - # Write min |
146 | 144 | emc['min'] = int(f.read()) // 1000 |
147 | 145 | # Check if access to this file |
148 | 146 | if os.access(path + "/mrq_rate_locked", os.R_OK): |
149 | 147 | with open(path + "/mrq_rate_locked", 'r') as f: |
150 | | - # Write min |
151 | 148 | emc['override'] = int(f.read()) // 1000 |
| 149 | + |
| 150 | + elif os.path.isdir(root_path + "/../class/devfreq/bwmgr"): |
| 151 | + # Jetson Thor exposes EMC/BWMGR through devfreq instead of the |
| 152 | + # older tegra_bwmgr debugfs interface used on earlier platforms. |
| 153 | + path = root_path + "/../class/devfreq/bwmgr" |
| 154 | + # Check if access to this file |
| 155 | + if os.access(path + "/cur_freq", os.R_OK): |
| 156 | + with open(path + "/cur_freq", 'r') as f: |
| 157 | + emc['cur'] = int(f.read()) // 1000 |
| 158 | + # Check if access to this file |
| 159 | + if os.access(path + "/max_freq", os.R_OK): |
| 160 | + with open(path + "/max_freq", 'r') as f: |
| 161 | + emc['max'] = int(f.read()) // 1000 |
| 162 | + # Check if access to this file |
| 163 | + if os.access(path + "/min_freq", os.R_OK): |
| 164 | + with open(path + "/min_freq", 'r') as f: |
| 165 | + emc['min'] = int(f.read()) // 1000 |
| 166 | + # Optional metadata |
| 167 | + if os.access(path + "/governor", os.R_OK): |
| 168 | + with open(path + "/governor", 'r') as f: |
| 169 | + emc['governor'] = f.read().strip() |
| 170 | + |
152 | 171 | elif os.path.isdir(root_path + "/debug/tegra_bwmgr"): |
153 | 172 | path = root_path + "/debug/clk/override.emc" |
154 | 173 | # Check if access to this file |
155 | 174 | if os.access(path + "/clk_rate", os.R_OK): |
156 | 175 | with open(path + "/clk_rate", 'r') as f: |
157 | | - # Write min |
158 | 176 | emc['cur'] = int(f.read()) // 1000 |
159 | 177 | # Check if access to this file |
160 | 178 | if os.access(path + "/clk_state", os.R_OK): |
161 | 179 | with open(path + "/clk_state", 'r') as f: |
162 | | - # Write min |
163 | 180 | emc['override'] = int(f.read()) // 1000 |
164 | 181 | # Decode from tegra_bwmgr |
165 | 182 | path = root_path + "/tegra_bwmgr" |
166 | 183 | # Check if access to this file |
167 | 184 | if os.access(path + "/emc_max_rate", os.R_OK): |
168 | 185 | with open(path + "/emc_max_rate", 'r') as f: |
169 | | - # Write min |
170 | 186 | emc['max'] = int(f.read()) // 1000 |
171 | 187 | # Check if access to this file |
172 | 188 | if os.access(path + "/emc_min_rate", os.R_OK): |
173 | 189 | with open(path + "/emc_min_rate", 'r') as f: |
174 | | - # Write min |
175 | 190 | emc['min'] = int(f.read()) // 1000 |
| 191 | + |
176 | 192 | elif os.path.isdir(root_path + "/clk/emc"): |
177 | 193 | emc = read_engine(root_path + "/clk/emc") |
178 | | - # Fix max frequency |
| 194 | + |
| 195 | + # Apply nvpmodel EMC cap regardless of which EMC source populated emc['max'] |
179 | 196 | emc_cap = 0 |
180 | | - # Check if access to this file |
181 | 197 | if os.access(root_path + "/nvpmodel_emc_cap/emc_iso_cap", os.R_OK): |
182 | 198 | with open(root_path + "/nvpmodel_emc_cap/emc_iso_cap", 'r') as f: |
183 | | - # Write min |
184 | 199 | emc_cap = int(f.read()) // 1000 |
185 | | - # Fix max EMC |
186 | 200 | if 'max' in emc: |
187 | 201 | if emc_cap > 0 and emc_cap < emc['max']: |
188 | 202 | emc['max'] = emc_cap |
| 203 | + |
189 | 204 | # Percentage utilization |
190 | 205 | # https://forums.developer.nvidia.com/t/real-time-emc-bandwidth-with-sysfs/107479/3 |
191 | 206 | if os.access(root_path + "/debug/cactmon/mc_all", os.R_OK): |
192 | 207 | with open(root_path + "/debug/cactmon/mc_all", 'r') as f: |
193 | 208 | utilization = int(f.read()) |
| 209 | + elif os.access(root_path + "/debug/bpmp/debug/actmon/mc_all_avg_activity", os.R_OK): |
| 210 | + with open(root_path + "/debug/bpmp/debug/actmon/mc_all_avg_activity", 'r') as f: |
| 211 | + utilization = int(f.read()) |
194 | 212 | elif os.access(root_path + "/actmon_avg_activity/mc_all", os.R_OK): |
195 | 213 | with open(root_path + "/actmon_avg_activity/mc_all", 'r') as f: |
196 | 214 | utilization = int(f.read()) |
197 | 215 | else: |
198 | | - # if utilization not accesibile return empty EMC data |
| 216 | + # if utilization not accessible return empty EMC data |
| 217 | + return {} |
| 218 | + |
| 219 | + if emc['cur'] <= 0: |
| 220 | + logger.warning( |
| 221 | + "EMC current frequency value is non-positive (emc['cur']=%s). " |
| 222 | + "Dropping EMC data to avoid division by zero.", |
| 223 | + emc['cur'], |
| 224 | + ) |
199 | 225 | return {} |
| 226 | + |
200 | 227 | emc['val'] = utilization // emc['cur'] |
201 | 228 | # Set always online this engine |
202 | 229 | emc['online'] = True |
|
0 commit comments