[PATCH 1/7] drm/i915: Allocate power domain set wakerefs dynamically

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since the intel_display_power_domain_set struct, currently its current
size close 1kB, can be allocated on the stack, it's better to allocate
the per-domain wakeref pointer array - used for debugging - within the
struct dynamically, so do this.

The memory freeing is guaranteed by the fact that the acquired domain
references tracked by struct can't be leaked either.

Signed-off-by: Imre Deak <imre.deak@xxxxxxxxx>
---
 .../drm/i915/display/intel_display_power.c    | 61 ++++++++++++++++---
 .../drm/i915/display/intel_display_power.h    |  2 +-
 2 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display_power.c b/drivers/gpu/drm/i915/display/intel_display_power.c
index 4c1de91e56ff9..e2da91c2a9638 100644
--- a/drivers/gpu/drm/i915/display/intel_display_power.c
+++ b/drivers/gpu/drm/i915/display/intel_display_power.c
@@ -830,19 +830,58 @@ void intel_display_power_put_unchecked(struct drm_i915_private *dev_priv,
 }
 #endif
 
+#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
+static intel_wakeref_t *
+get_debug_wakerefs(struct drm_i915_private *i915,
+		   struct intel_display_power_domain_set *power_domain_set)
+{
+	if (power_domain_set->wakerefs)
+		return power_domain_set->wakerefs;
+
+	power_domain_set->wakerefs = kcalloc(POWER_DOMAIN_NUM,
+					     sizeof(*power_domain_set->wakerefs),
+					     GFP_KERNEL);
+
+	drm_WARN_ON_ONCE(&i915->drm, !power_domain_set->wakerefs);
+
+	return power_domain_set->wakerefs;
+}
+
+static void
+free_empty_debug_wakerefs(struct intel_display_power_domain_set *power_domain_set)
+{
+	if (power_domain_set->wakerefs &&
+	    bitmap_empty(power_domain_set->mask.bits, POWER_DOMAIN_NUM))
+		kfree(fetch_and_zero(&power_domain_set->wakerefs));
+}
+#else
+static intel_wakeref_t *
+get_debug_wakerefs(struct drm_i915_private *i915,
+		   struct intel_display_power_domain_set *power_domain_set)
+{
+	return NULL;
+}
+
+static void
+free_empty_debug_wakerefs(struct intel_display_power_domain_set *power_domain_set)
+{
+}
+#endif
+
 void
 intel_display_power_get_in_set(struct drm_i915_private *i915,
 			       struct intel_display_power_domain_set *power_domain_set,
 			       enum intel_display_power_domain domain)
 {
 	intel_wakeref_t __maybe_unused wf;
+	intel_wakeref_t *debug_wakerefs = get_debug_wakerefs(i915, power_domain_set);
 
 	drm_WARN_ON(&i915->drm, test_bit(domain, power_domain_set->mask.bits));
 
 	wf = intel_display_power_get(i915, domain);
-#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
-	power_domain_set->wakerefs[domain] = wf;
-#endif
+	if (debug_wakerefs)
+		debug_wakerefs[domain] = wf;
+
 	set_bit(domain, power_domain_set->mask.bits);
 }
 
@@ -852,6 +891,7 @@ intel_display_power_get_in_set_if_enabled(struct drm_i915_private *i915,
 					  enum intel_display_power_domain domain)
 {
 	intel_wakeref_t wf;
+	intel_wakeref_t *debug_wakerefs = get_debug_wakerefs(i915, power_domain_set);
 
 	drm_WARN_ON(&i915->drm, test_bit(domain, power_domain_set->mask.bits));
 
@@ -859,9 +899,9 @@ intel_display_power_get_in_set_if_enabled(struct drm_i915_private *i915,
 	if (!wf)
 		return false;
 
-#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
-	power_domain_set->wakerefs[domain] = wf;
-#endif
+	if (debug_wakerefs)
+		debug_wakerefs[domain] = wf;
+
 	set_bit(domain, power_domain_set->mask.bits);
 
 	return true;
@@ -873,6 +913,7 @@ intel_display_power_put_mask_in_set(struct drm_i915_private *i915,
 				    struct intel_power_domain_mask *mask)
 {
 	enum intel_display_power_domain domain;
+	intel_wakeref_t *debug_wakerefs = get_debug_wakerefs(i915, power_domain_set);
 
 	drm_WARN_ON(&i915->drm,
 		    !bitmap_subset(mask->bits, power_domain_set->mask.bits, POWER_DOMAIN_NUM));
@@ -880,12 +921,14 @@ intel_display_power_put_mask_in_set(struct drm_i915_private *i915,
 	for_each_power_domain(domain, mask) {
 		intel_wakeref_t __maybe_unused wf = -1;
 
-#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
-		wf = fetch_and_zero(&power_domain_set->wakerefs[domain]);
-#endif
+		if (debug_wakerefs)
+			wf = fetch_and_zero(&debug_wakerefs[domain]);
+
 		intel_display_power_put(i915, domain, wf);
 		clear_bit(domain, power_domain_set->mask.bits);
 	}
+
+	free_empty_debug_wakerefs(power_domain_set);
 }
 
 static int
diff --git a/drivers/gpu/drm/i915/display/intel_display_power.h b/drivers/gpu/drm/i915/display/intel_display_power.h
index 7136ea3f233e9..c847aab7b2f88 100644
--- a/drivers/gpu/drm/i915/display/intel_display_power.h
+++ b/drivers/gpu/drm/i915/display/intel_display_power.h
@@ -146,7 +146,7 @@ struct i915_power_domains {
 struct intel_display_power_domain_set {
 	struct intel_power_domain_mask mask;
 #ifdef CONFIG_DRM_I915_DEBUG_RUNTIME_PM
-	intel_wakeref_t wakerefs[POWER_DOMAIN_NUM];
+	intel_wakeref_t *wakerefs;
 #endif
 };
 
-- 
2.37.1




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux