diff options
Diffstat (limited to 'include/os/linux/debug_pmu.c')
| -rw-r--r-- | include/os/linux/debug_pmu.c | 484 |
1 files changed, 484 insertions, 0 deletions
diff --git a/include/os/linux/debug_pmu.c b/include/os/linux/debug_pmu.c new file mode 100644 index 0000000..f3e36d0 --- /dev/null +++ b/include/os/linux/debug_pmu.c | |||
| @@ -0,0 +1,484 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2017-2019 NVIDIA Corporation. All rights reserved. | ||
| 3 | * | ||
| 4 | * This software is licensed under the terms of the GNU General Public | ||
| 5 | * License version 2, as published by the Free Software Foundation, and | ||
| 6 | * may be copied, distributed, and modified under those terms. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <nvgpu/enabled.h> | ||
| 16 | #include "debug_pmu.h" | ||
| 17 | #include "os_linux.h" | ||
| 18 | |||
| 19 | #include <linux/debugfs.h> | ||
| 20 | #include <linux/seq_file.h> | ||
| 21 | #include <linux/uaccess.h> | ||
| 22 | |||
| 23 | static int lpwr_debug_show(struct seq_file *s, void *data) | ||
| 24 | { | ||
| 25 | struct gk20a *g = s->private; | ||
| 26 | |||
| 27 | if (g->ops.pmu.pmu_pg_engines_feature_list && | ||
| 28 | g->ops.pmu.pmu_pg_engines_feature_list(g, | ||
| 29 | PMU_PG_ELPG_ENGINE_ID_GRAPHICS) != | ||
| 30 | NVGPU_PMU_GR_FEATURE_MASK_POWER_GATING) { | ||
| 31 | seq_printf(s, "PSTATE: %u\n" | ||
| 32 | "RPPG Enabled: %u\n" | ||
| 33 | "RPPG ref count: %u\n" | ||
| 34 | "RPPG state: %u\n" | ||
| 35 | "MSCG Enabled: %u\n" | ||
| 36 | "MSCG pstate state: %u\n" | ||
| 37 | "MSCG transition state: %u\n", | ||
| 38 | g->ops.clk_arb.get_current_pstate(g), | ||
| 39 | g->elpg_enabled, g->pmu.elpg_refcnt, | ||
| 40 | g->pmu.elpg_stat, g->mscg_enabled, | ||
| 41 | g->pmu.mscg_stat, g->pmu.mscg_transition_state); | ||
| 42 | |||
| 43 | } else | ||
| 44 | seq_printf(s, "ELPG Enabled: %u\n" | ||
| 45 | "ELPG ref count: %u\n" | ||
| 46 | "ELPG state: %u\n", | ||
| 47 | g->elpg_enabled, g->pmu.elpg_refcnt, | ||
| 48 | g->pmu.elpg_stat); | ||
| 49 | |||
| 50 | return 0; | ||
| 51 | |||
| 52 | } | ||
| 53 | |||
| 54 | static int lpwr_debug_open(struct inode *inode, struct file *file) | ||
| 55 | { | ||
| 56 | return single_open(file, lpwr_debug_show, inode->i_private); | ||
| 57 | } | ||
| 58 | |||
| 59 | static const struct file_operations lpwr_debug_fops = { | ||
| 60 | .open = lpwr_debug_open, | ||
| 61 | .read = seq_read, | ||
| 62 | .llseek = seq_lseek, | ||
| 63 | .release = single_release, | ||
| 64 | }; | ||
| 65 | |||
| 66 | static int mscg_stat_show(struct seq_file *s, void *data) | ||
| 67 | { | ||
| 68 | struct gk20a *g = s->private; | ||
| 69 | u64 total_ingating, total_ungating, residency, divisor, dividend; | ||
| 70 | struct pmu_pg_stats_data pg_stat_data = { 0 }; | ||
| 71 | int err; | ||
| 72 | |||
| 73 | /* Don't unnecessarily power on the device */ | ||
| 74 | if (g->power_on) { | ||
| 75 | err = gk20a_busy(g); | ||
| 76 | if (err) | ||
| 77 | return err; | ||
| 78 | |||
| 79 | nvgpu_pmu_get_pg_stats(g, | ||
| 80 | PMU_PG_ELPG_ENGINE_ID_MS, &pg_stat_data); | ||
| 81 | gk20a_idle(g); | ||
| 82 | } | ||
| 83 | total_ingating = g->pg_ingating_time_us + | ||
| 84 | (u64)pg_stat_data.ingating_time; | ||
| 85 | total_ungating = g->pg_ungating_time_us + | ||
| 86 | (u64)pg_stat_data.ungating_time; | ||
| 87 | |||
| 88 | divisor = total_ingating + total_ungating; | ||
| 89 | |||
| 90 | /* We compute the residency on a scale of 1000 */ | ||
| 91 | dividend = total_ingating * 1000; | ||
| 92 | |||
| 93 | if (divisor) | ||
| 94 | residency = div64_u64(dividend, divisor); | ||
| 95 | else | ||
| 96 | residency = 0; | ||
| 97 | |||
| 98 | seq_printf(s, | ||
| 99 | "Time in MSCG: %llu us\n" | ||
| 100 | "Time out of MSCG: %llu us\n" | ||
| 101 | "MSCG residency ratio: %llu\n" | ||
| 102 | "MSCG Entry Count: %u\n" | ||
| 103 | "MSCG Avg Entry latency %u\n" | ||
| 104 | "MSCG Avg Exit latency %u\n", | ||
| 105 | total_ingating, total_ungating, | ||
| 106 | residency, pg_stat_data.gating_cnt, | ||
| 107 | pg_stat_data.avg_entry_latency_us, | ||
| 108 | pg_stat_data.avg_exit_latency_us); | ||
| 109 | return 0; | ||
| 110 | |||
| 111 | } | ||
| 112 | |||
| 113 | static int mscg_stat_open(struct inode *inode, struct file *file) | ||
| 114 | { | ||
| 115 | return single_open(file, mscg_stat_show, inode->i_private); | ||
| 116 | } | ||
| 117 | |||
| 118 | static const struct file_operations mscg_stat_fops = { | ||
| 119 | .open = mscg_stat_open, | ||
| 120 | .read = seq_read, | ||
| 121 | .llseek = seq_lseek, | ||
| 122 | .release = single_release, | ||
| 123 | }; | ||
| 124 | |||
| 125 | static int mscg_transitions_show(struct seq_file *s, void *data) | ||
| 126 | { | ||
| 127 | struct gk20a *g = s->private; | ||
| 128 | struct pmu_pg_stats_data pg_stat_data = { 0 }; | ||
| 129 | u32 total_gating_cnt; | ||
| 130 | int err; | ||
| 131 | |||
| 132 | if (g->power_on) { | ||
| 133 | err = gk20a_busy(g); | ||
| 134 | if (err) | ||
| 135 | return err; | ||
| 136 | |||
| 137 | nvgpu_pmu_get_pg_stats(g, | ||
| 138 | PMU_PG_ELPG_ENGINE_ID_MS, &pg_stat_data); | ||
| 139 | gk20a_idle(g); | ||
| 140 | } | ||
| 141 | total_gating_cnt = g->pg_gating_cnt + pg_stat_data.gating_cnt; | ||
| 142 | |||
| 143 | seq_printf(s, "%u\n", total_gating_cnt); | ||
| 144 | return 0; | ||
| 145 | |||
| 146 | } | ||
| 147 | |||
| 148 | static int mscg_transitions_open(struct inode *inode, struct file *file) | ||
| 149 | { | ||
| 150 | return single_open(file, mscg_transitions_show, inode->i_private); | ||
| 151 | } | ||
| 152 | |||
| 153 | static const struct file_operations mscg_transitions_fops = { | ||
| 154 | .open = mscg_transitions_open, | ||
| 155 | .read = seq_read, | ||
| 156 | .llseek = seq_lseek, | ||
| 157 | .release = single_release, | ||
| 158 | }; | ||
| 159 | |||
| 160 | static int elpg_stat_show(struct seq_file *s, void *data) | ||
| 161 | { | ||
| 162 | struct gk20a *g = s->private; | ||
| 163 | struct pmu_pg_stats_data pg_stat_data = { 0 }; | ||
| 164 | u64 total_ingating, total_ungating, residency, divisor, dividend; | ||
| 165 | int err; | ||
| 166 | |||
| 167 | /* Don't unnecessarily power on the device */ | ||
| 168 | if (g->power_on) { | ||
| 169 | err = gk20a_busy(g); | ||
| 170 | if (err) | ||
| 171 | return err; | ||
| 172 | |||
| 173 | nvgpu_pmu_get_pg_stats(g, | ||
| 174 | PMU_PG_ELPG_ENGINE_ID_GRAPHICS, &pg_stat_data); | ||
| 175 | gk20a_idle(g); | ||
| 176 | } | ||
| 177 | total_ingating = g->pg_ingating_time_us + | ||
| 178 | (u64)pg_stat_data.ingating_time; | ||
| 179 | total_ungating = g->pg_ungating_time_us + | ||
| 180 | (u64)pg_stat_data.ungating_time; | ||
| 181 | divisor = total_ingating + total_ungating; | ||
| 182 | |||
| 183 | /* We compute the residency on a scale of 1000 */ | ||
| 184 | dividend = total_ingating * 1000; | ||
| 185 | |||
| 186 | if (divisor) | ||
| 187 | residency = div64_u64(dividend, divisor); | ||
| 188 | else | ||
| 189 | residency = 0; | ||
| 190 | |||
| 191 | seq_printf(s, | ||
| 192 | "Time in ELPG: %llu us\n" | ||
| 193 | "Time out of ELPG: %llu us\n" | ||
| 194 | "ELPG residency ratio: %llu\n" | ||
| 195 | "ELPG Entry Count: %u\n" | ||
| 196 | "ELPG Avg Entry latency %u us\n" | ||
| 197 | "ELPG Avg Exit latency %u us\n", | ||
| 198 | total_ingating, total_ungating, | ||
| 199 | residency, pg_stat_data.gating_cnt, | ||
| 200 | pg_stat_data.avg_entry_latency_us, | ||
| 201 | pg_stat_data.avg_exit_latency_us); | ||
| 202 | return 0; | ||
| 203 | |||
| 204 | } | ||
| 205 | |||
| 206 | static int elpg_stat_open(struct inode *inode, struct file *file) | ||
| 207 | { | ||
| 208 | return single_open(file, elpg_stat_show, inode->i_private); | ||
| 209 | } | ||
| 210 | |||
| 211 | static const struct file_operations elpg_stat_fops = { | ||
| 212 | .open = elpg_stat_open, | ||
| 213 | .read = seq_read, | ||
| 214 | .llseek = seq_lseek, | ||
| 215 | .release = single_release, | ||
| 216 | }; | ||
| 217 | |||
| 218 | static int elpg_transitions_show(struct seq_file *s, void *data) | ||
| 219 | { | ||
| 220 | struct gk20a *g = s->private; | ||
| 221 | struct pmu_pg_stats_data pg_stat_data = { 0 }; | ||
