-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drm/i915/gt: Use the RPM config register to determine clk frequencies
For many configuration details within RC6 and RPS we are programming intervals for the internal clocks. From gen11, these clocks are configuration via the RPM_CONFIG and so for convenience, we would like to convert to/from more natural units (ns). Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Andi Shyti <andi.shyti@intel.com> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com> Reviewed-by: Andi Shyti <andi.shyti@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200424162805.25920-2-chris@chris-wilson.co.uk
- Loading branch information
Chris Wilson
committed
Apr 24, 2020
1 parent
555a322
commit 9c87855
Showing
11 changed files
with
229 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
* Copyright © 2020 Intel Corporation | ||
*/ | ||
|
||
#include "i915_drv.h" | ||
#include "intel_gt.h" | ||
#include "intel_gt_clock_utils.h" | ||
|
||
#define MHZ_19_2 19200000 /* 19.2MHz, 52.083ns */ | ||
#define MHZ_24 24000000 /* 24MHz, 83.333ns */ | ||
#define MHZ_25 25000000 /* 25MHz, 80ns */ | ||
|
||
static u32 read_clock_frequency(const struct intel_gt *gt) | ||
{ | ||
if (INTEL_GEN(gt->i915) >= 11) { | ||
u32 config; | ||
|
||
config = intel_uncore_read(gt->uncore, RPM_CONFIG0); | ||
config &= GEN11_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_MASK; | ||
config >>= GEN11_RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_SHIFT; | ||
|
||
switch (config) { | ||
case 0: return MHZ_24; | ||
case 1: | ||
case 2: return MHZ_19_2; | ||
default: | ||
case 3: return MHZ_25; | ||
} | ||
} else if (INTEL_GEN(gt->i915) >= 9) { | ||
if (IS_GEN9_LP(gt->i915)) | ||
return MHZ_19_2; | ||
else | ||
return MHZ_24; | ||
} else { | ||
return MHZ_25; | ||
} | ||
} | ||
|
||
void intel_gt_init_clock_frequency(struct intel_gt *gt) | ||
{ | ||
/* | ||
* Note that on gen11+, the clock frequency may be reconfigured. | ||
* We do not, and we assume nobody else does. | ||
*/ | ||
gt->clock_frequency = read_clock_frequency(gt); | ||
GT_TRACE(gt, | ||
"Using clock frequency: %dkHz\n", | ||
gt->clock_frequency / 1000); | ||
} | ||
|
||
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM) | ||
void intel_gt_check_clock_frequency(const struct intel_gt *gt) | ||
{ | ||
if (gt->clock_frequency != read_clock_frequency(gt)) { | ||
dev_err(gt->i915->drm.dev, | ||
"GT clock frequency changed, was %uHz, now %uHz!\n", | ||
gt->clock_frequency, | ||
read_clock_frequency(gt)); | ||
} | ||
} | ||
#endif | ||
|
||
static u64 div_u64_roundup(u64 nom, u32 den) | ||
{ | ||
return div_u64(nom + den - 1, den); | ||
} | ||
|
||
u32 intel_gt_clock_interval_to_ns(const struct intel_gt *gt, u32 count) | ||
{ | ||
return div_u64_roundup(mul_u32_u32(count, 1000 * 1000 * 1000), | ||
gt->clock_frequency); | ||
} | ||
|
||
u32 intel_gt_pm_interval_to_ns(const struct intel_gt *gt, u32 count) | ||
{ | ||
return intel_gt_clock_interval_to_ns(gt, 16 * count); | ||
} | ||
|
||
u32 intel_gt_ns_to_clock_interval(const struct intel_gt *gt, u32 ns) | ||
{ | ||
return div_u64_roundup(mul_u32_u32(gt->clock_frequency, ns), | ||
1000 * 1000 * 1000); | ||
} | ||
|
||
u32 intel_gt_ns_to_pm_interval(const struct intel_gt *gt, u32 ns) | ||
{ | ||
u32 val; | ||
|
||
/* | ||
* Make these a multiple of magic 25 to avoid SNB (eg. Dell XPS | ||
* 8300) freezing up around GPU hangs. Looks as if even | ||
* scheduling/timer interrupts start misbehaving if the RPS | ||
* EI/thresholds are "bad", leading to a very sluggish or even | ||
* frozen machine. | ||
*/ | ||
val = DIV_ROUND_UP(intel_gt_ns_to_clock_interval(gt, ns), 16); | ||
if (IS_GEN(gt->i915, 6)) | ||
val = roundup(val, 25); | ||
|
||
return val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
/* | ||
* Copyright © 2020 Intel Corporation | ||
*/ | ||
|
||
#ifndef __INTEL_GT_CLOCK_UTILS_H__ | ||
#define __INTEL_GT_CLOCK_UTILS_H__ | ||
|
||
#include <linux/types.h> | ||
|
||
struct intel_gt; | ||
|
||
void intel_gt_init_clock_frequency(struct intel_gt *gt); | ||
|
||
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM) | ||
void intel_gt_check_clock_frequency(const struct intel_gt *gt); | ||
#else | ||
static inline void intel_gt_check_clock_frequency(const struct intel_gt *gt) {} | ||
#endif | ||
|
||
u32 intel_gt_clock_interval_to_ns(const struct intel_gt *gt, u32 count); | ||
u32 intel_gt_pm_interval_to_ns(const struct intel_gt *gt, u32 count); | ||
|
||
u32 intel_gt_ns_to_clock_interval(const struct intel_gt *gt, u32 ns); | ||
u32 intel_gt_ns_to_pm_interval(const struct intel_gt *gt, u32 ns); | ||
|
||
#endif /* __INTEL_GT_CLOCK_UTILS_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.