Skip to content

Commit 8c3b1ba

Browse files
committed
drm/i915/gt: Track the overall awake/busy time
Since we wake the GT up before executing a request, and go to sleep as soon as it is retired, the GT wake time not only represents how long the device is powered up, but also provides a summary, albeit an overestimate, of the device runtime (i.e. the rc0 time to compare against rc6 time). v2: s/busy/awake/ v3: software-gt-awake-time and I915_PMU_SOFTWARE_GT_AWAKE_TIME Signed-off-by: Chris Wilson <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Cc: Matthew Brost <[email protected]> Reported-by: kernel test robot <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e3ed90b commit 8c3b1ba

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

drivers/gpu/drm/i915/gt/debugfs_gt_pm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "i915_drv.h"
1212
#include "intel_gt.h"
1313
#include "intel_gt_clock_utils.h"
14+
#include "intel_gt_pm.h"
1415
#include "intel_llc.h"
1516
#include "intel_rc6.h"
1617
#include "intel_rps.h"
@@ -558,7 +559,9 @@ static int rps_boost_show(struct seq_file *m, void *data)
558559

559560
seq_printf(m, "RPS enabled? %s\n", yesno(intel_rps_is_enabled(rps)));
560561
seq_printf(m, "RPS active? %s\n", yesno(intel_rps_is_active(rps)));
561-
seq_printf(m, "GPU busy? %s\n", yesno(gt->awake));
562+
seq_printf(m, "GPU busy? %s, %llums\n",
563+
yesno(gt->awake),
564+
ktime_to_ms(intel_gt_get_awake_time(gt)));
562565
seq_printf(m, "Boosts outstanding? %d\n",
563566
atomic_read(&rps->num_waiters));
564567
seq_printf(m, "Interactive? %d\n", READ_ONCE(rps->power.interactive));

drivers/gpu/drm/i915/gt/intel_gt_pm.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ static void user_forcewake(struct intel_gt *gt, bool suspend)
3939
intel_gt_pm_put(gt);
4040
}
4141

42+
static void runtime_begin(struct intel_gt *gt)
43+
{
44+
local_irq_disable();
45+
write_seqcount_begin(&gt->stats.lock);
46+
gt->stats.start = ktime_get();
47+
gt->stats.active = true;
48+
write_seqcount_end(&gt->stats.lock);
49+
local_irq_enable();
50+
}
51+
52+
static void runtime_end(struct intel_gt *gt)
53+
{
54+
local_irq_disable();
55+
write_seqcount_begin(&gt->stats.lock);
56+
gt->stats.active = false;
57+
gt->stats.total =
58+
ktime_add(gt->stats.total,
59+
ktime_sub(ktime_get(), gt->stats.start));
60+
write_seqcount_end(&gt->stats.lock);
61+
local_irq_enable();
62+
}
63+
4264
static int __gt_unpark(struct intel_wakeref *wf)
4365
{
4466
struct intel_gt *gt = container_of(wf, typeof(*gt), wakeref);
@@ -67,6 +89,7 @@ static int __gt_unpark(struct intel_wakeref *wf)
6789
i915_pmu_gt_unparked(i915);
6890

6991
intel_gt_unpark_requests(gt);
92+
runtime_begin(gt);
7093

7194
return 0;
7295
}
@@ -79,6 +102,7 @@ static int __gt_park(struct intel_wakeref *wf)
79102

80103
GT_TRACE(gt, "\n");
81104

105+
runtime_end(gt);
82106
intel_gt_park_requests(gt);
83107

84108
i915_vma_parked(gt);
@@ -106,6 +130,7 @@ static const struct intel_wakeref_ops wf_ops = {
106130
void intel_gt_pm_init_early(struct intel_gt *gt)
107131
{
108132
intel_wakeref_init(&gt->wakeref, gt->uncore->rpm, &wf_ops);
133+
seqcount_mutex_init(&gt->stats.lock, &gt->wakeref.mutex);
109134
}
110135

111136
void intel_gt_pm_init(struct intel_gt *gt)
@@ -339,6 +364,30 @@ int intel_gt_runtime_resume(struct intel_gt *gt)
339364
return intel_uc_runtime_resume(&gt->uc);
340365
}
341366

367+
static ktime_t __intel_gt_get_awake_time(const struct intel_gt *gt)
368+
{
369+
ktime_t total = gt->stats.total;
370+
371+
if (gt->stats.active)
372+
total = ktime_add(total,
373+
ktime_sub(ktime_get(), gt->stats.start));
374+
375+
return total;
376+
}
377+
378+
ktime_t intel_gt_get_awake_time(const struct intel_gt *gt)
379+
{
380+
unsigned int seq;
381+
ktime_t total;
382+
383+
do {
384+
seq = read_seqcount_begin(&gt->stats.lock);
385+
total = __intel_gt_get_awake_time(gt);
386+
} while (read_seqcount_retry(&gt->stats.lock, seq));
387+
388+
return total;
389+
}
390+
342391
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
343392
#include "selftest_gt_pm.c"
344393
#endif

drivers/gpu/drm/i915/gt/intel_gt_pm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ int intel_gt_resume(struct intel_gt *gt);
5858
void intel_gt_runtime_suspend(struct intel_gt *gt);
5959
int intel_gt_runtime_resume(struct intel_gt *gt);
6060

61+
ktime_t intel_gt_get_awake_time(const struct intel_gt *gt);
62+
6163
static inline bool is_mock_gt(const struct intel_gt *gt)
6264
{
6365
return I915_SELFTEST_ONLY(gt->awake == -ENODEV);

drivers/gpu/drm/i915/gt/intel_gt_types.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,30 @@ struct intel_gt {
8787

8888
u32 pm_guc_events;
8989

90+
struct {
91+
bool active;
92+
93+
/**
94+
* @lock: Lock protecting the below fields.
95+
*/
96+
seqcount_mutex_t lock;
97+
98+
/**
99+
* @total: Total time this engine was busy.
100+
*
101+
* Accumulated time not counting the most recent block in cases
102+
* where engine is currently busy (active > 0).
103+
*/
104+
ktime_t total;
105+
106+
/**
107+
* @start: Timestamp of the last idle to active transition.
108+
*
109+
* Idle is defined as active == 0, active is active > 0.
110+
*/
111+
ktime_t start;
112+
} stats;
113+
90114
struct intel_engine_cs *engine[I915_NUM_ENGINES];
91115
struct intel_engine_cs *engine_class[MAX_ENGINE_CLASS + 1]
92116
[MAX_ENGINE_INSTANCE + 1];

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,9 +1314,10 @@ static int i915_engine_info(struct seq_file *m, void *unused)
13141314

13151315
wakeref = intel_runtime_pm_get(&i915->runtime_pm);
13161316

1317-
seq_printf(m, "GT awake? %s [%d]\n",
1317+
seq_printf(m, "GT awake? %s [%d], %llums\n",
13181318
yesno(i915->gt.awake),
1319-
atomic_read(&i915->gt.wakeref.count));
1319+
atomic_read(&i915->gt.wakeref.count),
1320+
ktime_to_ms(intel_gt_get_awake_time(&i915->gt)));
13201321
seq_printf(m, "CS timestamp frequency: %u Hz\n",
13211322
RUNTIME_INFO(i915)->cs_timestamp_frequency_hz);
13221323

drivers/gpu/drm/i915/i915_pmu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ config_status(struct drm_i915_private *i915, u64 config)
509509
if (!HAS_RC6(i915))
510510
return -ENODEV;
511511
break;
512+
case I915_PMU_SOFTWARE_GT_AWAKE_TIME:
513+
break;
512514
default:
513515
return -ENOENT;
514516
}
@@ -616,6 +618,9 @@ static u64 __i915_pmu_event_read(struct perf_event *event)
616618
case I915_PMU_RC6_RESIDENCY:
617619
val = get_rc6(&i915->gt);
618620
break;
621+
case I915_PMU_SOFTWARE_GT_AWAKE_TIME:
622+
val = ktime_to_ns(intel_gt_get_awake_time(&i915->gt));
623+
break;
619624
}
620625
}
621626

@@ -916,6 +921,7 @@ create_event_attributes(struct i915_pmu *pmu)
916921
__event(I915_PMU_REQUESTED_FREQUENCY, "requested-frequency", "M"),
917922
__event(I915_PMU_INTERRUPTS, "interrupts", NULL),
918923
__event(I915_PMU_RC6_RESIDENCY, "rc6-residency", "ns"),
924+
__event(I915_PMU_SOFTWARE_GT_AWAKE_TIME, "software-gt-awake-time", "ns"),
919925
};
920926
static const struct {
921927
enum drm_i915_pmu_engine_sample sample;

include/uapi/drm/i915_drm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ enum drm_i915_pmu_engine_sample {
177177
#define I915_PMU_REQUESTED_FREQUENCY __I915_PMU_OTHER(1)
178178
#define I915_PMU_INTERRUPTS __I915_PMU_OTHER(2)
179179
#define I915_PMU_RC6_RESIDENCY __I915_PMU_OTHER(3)
180+
#define I915_PMU_SOFTWARE_GT_AWAKE_TIME __I915_PMU_OTHER(4)
180181

181182
#define I915_PMU_LAST /* Deprecated - do not use */ I915_PMU_RC6_RESIDENCY
182183

0 commit comments

Comments
 (0)