1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
// SPDX-License-Identifier: MIT
/*
* Copyright © 2023 Intel Corporation
*/
#include <drm/drm_managed.h>
#include <regs/xe_gt_regs.h>
#include "xe_device.h"
#include "xe_gt.h"
#include "xe_gt_sysfs.h"
#include "xe_gt_throttle.h"
#include "xe_mmio.h"
#include "xe_platform_types.h"
#include "xe_pm.h"
/**
* DOC: Xe GT Throttle
*
* The GT frequency may be throttled by hardware/firmware for various reasons
* that are provided through attributes under the ``freq0/throttle/`` directory.
* Their availability depend on the platform and some may not be visible if that
* reason is not available.
*
* The ``reasons`` attribute can be used by sysadmin to monitor all possible
* reasons for throttling and report them. It's preferred over monitoring
* ``status`` and then reading the reason from individual attributes since that
* is racy. If there's no throttling happening, "none" is returned.
*
* The following attributes are available on Crescent Island platform:
*
* - ``status``: Overall throttle status (0: no throttling, 1: throttling)
* - ``reasons``: Array of reasons causing throttling separated by space
* - ``reason_pl1``: package PL1
* - ``reason_pl2``: package PL2
* - ``reason_pl4``: package PL4
* - ``reason_prochot``: prochot
* - ``reason_soc_thermal``: SoC thermal
* - ``reason_mem_thermal``: Memory thermal
* - ``reason_vr_thermal``: VR thermal
* - ``reason_iccmax``: ICCMAX
* - ``reason_ratl``: RATL thermal algorithm
* - ``reason_soc_avg_thermal``: SoC average temp
* - ``reason_fastvmode``: VR is hitting FastVMode
* - ``reason_psys_pl1``: PSYS PL1
* - ``reason_psys_pl2``: PSYS PL2
* - ``reason_p0_freq``: P0 frequency
* - ``reason_psys_crit``: PSYS critical
*
* Other platforms support the following reasons:
*
* - ``status``: Overall throttle status (0: no throttling, 1: throttling)
* - ``reasons``: Array of reasons causing throttling separated by space
* - ``reason_pl1``: package PL1
* - ``reason_pl2``: package PL2
* - ``reason_pl4``: package PL4, Iccmax etc.
* - ``reason_thermal``: thermal
* - ``reason_prochot``: prochot
* - ``reason_ratl``: RATL hermal algorithm
* - ``reason_vr_thermalert``: VR THERMALERT
* - ``reason_vr_tdc``: VR TDC
*/
struct throttle_attribute {
struct kobj_attribute attr;
u32 mask;
};
static struct xe_gt *dev_to_gt(struct device *dev)
{
return kobj_to_gt(dev->kobj.parent);
}
static struct xe_gt *throttle_to_gt(struct kobject *kobj)
{
return dev_to_gt(kobj_to_dev(kobj));
}
static struct throttle_attribute *kobj_attribute_to_throttle(struct kobj_attribute *attr)
{
return container_of(attr, struct throttle_attribute, attr);
}
u32 xe_gt_throttle_get_limit_reasons(struct xe_gt *gt)
{
struct xe_device *xe = gt_to_xe(gt);
struct xe_reg reg;
u32 val, mask;
if (xe_gt_is_media_type(gt))
reg = MTL_MEDIA_PERF_LIMIT_REASONS;
else
reg = GT0_PERF_LIMIT_REASONS;
if (xe->info.platform == XE_CRESCENTISLAND)
mask = CRI_PERF_LIMIT_REASONS_MASK;
else
mask = GT0_PERF_LIMIT_REASONS_MASK;
xe_pm_runtime_get(xe);
val = xe_mmio_read32(>->mmio, reg) & mask;
xe_pm_runtime_put(xe);
return val;
}
static bool is_throttled_by(struct xe_gt *gt, u32 mask)
{
return xe_gt_throttle_get_limit_reasons(gt) & mask;
}
static ssize_t reason_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
struct throttle_attribute *ta = kobj_attribute_to_throttle(attr);
struct xe_gt *gt = throttle_to_gt(kobj);
return sysfs_emit(buff, "%u\n", is_throttled_by(gt, ta->mask));
}
static const struct attribute_group *get_platform_throttle_group(struct xe_device *xe);
static ssize_t reasons_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
struct xe_gt *gt = throttle_to_gt(kobj);
struct xe_device *xe = gt_to_xe(gt);
const struct attribute_group *group;
struct attribute **pother;
ssize_t ret = 0;
u32 reasons;
reasons = xe_gt_throttle_get_limit_reasons(gt);
if (!reasons)
goto ret_none;
group = get_platform_throttle_group(xe);
for (pother = group->attrs; *pother; pother++) {
struct kobj_attribute *kattr = container_of(*pother, struct kobj_attribute, attr);
struct throttle_attribute *other_ta = kobj_attribute_to_throttle(kattr);
if (other_ta->mask != U32_MAX && reasons & other_ta->mask)
ret += sysfs_emit_at(buff, ret, "%s ", (*pother)->name);
}
if (drm_WARN_ONCE(&xe->drm, !ret, "Unknown reason: %#x\n", reasons))
goto ret_none;
/* Drop extra space from last iteration above */
ret--;
ret += sysfs_emit_at(buff, ret, "\n");
return ret;
ret_none:
return sysfs_emit(buff, "none\n");
}
#define THROTTLE_ATTR_RO(name, _mask) \
struct throttle_attribute attr_##name = { \
.attr = __ATTR(name, 0444, reason_show, NULL), \
.mask = _mask, \
}
#define THROTTLE_ATTR_RO_FUNC(name, _mask, _show) \
struct throttle_attribute attr_##name = { \
.attr = __ATTR(name, 0444, _show, NULL), \
.mask = _mask, \
}
static THROTTLE_ATTR_RO_FUNC(reasons, 0, reasons_show);
static THROTTLE_ATTR_RO(status, U32_MAX);
static THROTTLE_ATTR_RO(reason_pl1, POWER_LIMIT_1_MASK);
static THROTTLE_ATTR_RO(reason_pl2, POWER_LIMIT_2_MASK);
static THROTTLE_ATTR_RO(reason_pl4, POWER_LIMIT_4_MASK);
static THROTTLE_ATTR_RO(reason_thermal, THERMAL_LIMIT_MASK);
static THROTTLE_ATTR_RO(reason_prochot, PROCHOT_MASK);
static THROTTLE_ATTR_RO(reason_ratl, RATL_MASK);
static THROTTLE_ATTR_RO(reason_vr_thermalert, VR_THERMALERT_MASK);
static THROTTLE_ATTR_RO(reason_vr_tdc, VR_TDC_MASK);
static struct attribute *throttle_attrs[] = {
&attr_reasons.attr.attr,
&attr_status.attr.attr,
&attr_reason_pl1.attr.attr,
&attr_reason_pl2.attr.attr,
&attr_reason_pl4.attr.attr,
&attr_reason_thermal.attr.attr,
&attr_reason_prochot.attr.attr,
&attr_reason_ratl.attr.attr,
&attr_reason_vr_thermalert.attr.attr,
&attr_reason_vr_tdc.attr.attr,
NULL
};
static THROTTLE_ATTR_RO(reason_vr_thermal, VR_THERMAL_MASK);
static THROTTLE_ATTR_RO(reason_soc_thermal, SOC_THERMAL_LIMIT_MASK);
static THROTTLE_ATTR_RO(reason_mem_thermal, MEM_THERMAL_MASK);
static THROTTLE_ATTR_RO(reason_iccmax, ICCMAX_MASK);
static THROTTLE_ATTR_RO(reason_soc_avg_thermal, SOC_AVG_THERMAL_MASK);
static THROTTLE_ATTR_RO(reason_fastvmode, FASTVMODE_MASK);
static THROTTLE_ATTR_RO(reason_psys_pl1, PSYS_PL1_MASK);
static THROTTLE_ATTR_RO(reason_psys_pl2, PSYS_PL2_MASK);
static THROTTLE_ATTR_RO(reason_p0_freq, P0_FREQ_MASK);
static THROTTLE_ATTR_RO(reason_psys_crit, PSYS_CRIT_MASK);
static struct attribute *cri_throttle_attrs[] = {
/* Common */
&attr_reasons.attr.attr,
&attr_status.attr.attr,
&attr_reason_pl1.attr.attr,
&attr_reason_pl2.attr.attr,
&attr_reason_pl4.attr.attr,
&attr_reason_prochot.attr.attr,
&attr_reason_ratl.attr.attr,
/* CRI */
&attr_reason_vr_thermal.attr.attr,
&attr_reason_soc_thermal.attr.attr,
&attr_reason_mem_thermal.attr.attr,
&attr_reason_iccmax.attr.attr,
&attr_reason_soc_avg_thermal.attr.attr,
&attr_reason_fastvmode.attr.attr,
&attr_reason_psys_pl1.attr.attr,
&attr_reason_psys_pl2.attr.attr,
&attr_reason_p0_freq.attr.attr,
&attr_reason_psys_crit.attr.attr,
NULL
};
static const struct attribute_group throttle_group_attrs = {
.name = "throttle",
.attrs = throttle_attrs,
};
static const struct attribute_group cri_throttle_group_attrs = {
.name = "throttle",
.attrs = cri_throttle_attrs,
};
static const struct attribute_group *get_platform_throttle_group(struct xe_device *xe)
{
switch (xe->info.platform) {
case XE_CRESCENTISLAND:
return &cri_throttle_group_attrs;
default:
return &throttle_group_attrs;
}
}
static void gt_throttle_sysfs_fini(void *arg)
{
struct xe_gt *gt = arg;
struct xe_device *xe = gt_to_xe(gt);
const struct attribute_group *group = get_platform_throttle_group(xe);
sysfs_remove_group(gt->freq, group);
}
int xe_gt_throttle_init(struct xe_gt *gt)
{
struct xe_device *xe = gt_to_xe(gt);
const struct attribute_group *group = get_platform_throttle_group(xe);
int err;
err = sysfs_create_group(gt->freq, group);
if (err)
return err;
return devm_add_action_or_reset(xe->drm.dev, gt_throttle_sysfs_fini, gt);
}
|