Skip to contentSkip to conversation

drm/i915: Do not allocate unused PPAT entries

PATCH Superseded Zhi Wang 1 participant 5 messages Sep 21, 2017

Subsystems (2)
lore
Share & tools
lore

Zhi Wang

author
#0 lore raw

PATCH v18 1/2 drm/i915: Do not allocate unused PPAT entries

Only PPAT entries 0/2/3/4 are using. Remove extra PPAT entry allocation during initialization.

v17:

- Refine ppat_index() and move the comments. (Joonas)

v8:

- Move ppat_index() into i915_gem_gtt.c. (Chris)
- Change the name of ppat_bits_to_index to ppat_index.

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 52 ++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +26 -26
index 731ce22..43e0d23 100644
@@ -230,9 +230,11 @@ static gen8_pte_t gen8_pte_encode(dma_addr_t addr,
 
 	switch (level) {
 	case I915_CACHE_NONE:
+		/* Uncached objects, mostly for scanout */
 		pte |= PPAT_UNCACHED;
 		break;
 	case I915_CACHE_WT:
+		/* for scanout with eLLC */
 		pte |= PPAT_DISPLAY_ELLC;
 		break;
 	default:
@@ -249,6 +251,7 @@ static gen8_pde_t gen8_pde_encode(const dma_addr_t addr,
 	gen8_pde_t pde = _PAGE_PRESENT | _PAGE_RW;
 	pde |= addr;
 	if (level != I915_CACHE_NONE)
+		/* for normal objects, no eLLC */
 		pde |= PPAT_CACHED_PDE;
 	else
 		pde |= PPAT_UNCACHED;
@@ -2988,6 +2991,14 @@ static unsigned int chv_private_pat_match(u8 src, u8 dst)
 		INTEL_PPAT_PERFECT_MATCH : 0;
 }
 
+/* PPAT index = 4 * PAT + 2 * PCD + PWT */
+static inline unsigned int ppat_index(unsigned int bits)
+{
+	return (4 * !!(bits & _PAGE_PAT) +
+		2 * !!(bits & _PAGE_PCD) +
+		!!(bits & _PAGE_PWT));
+}
+
 static void cnl_setup_private_ppat(struct intel_ppat *ppat)
 {
 	ppat->max_entries = 8;
@@ -2997,18 +3008,14 @@ static void cnl_setup_private_ppat(struct intel_ppat *ppat)
 
 	/* XXX: spec is unclear if this is still needed for CNL+ */
 	if (!USES_PPGTT(ppat->i915)) {
-		__alloc_ppat_entry(ppat, 0, GEN8_PPAT_UC);
+		__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED_PDE), GEN8_PPAT_UC);
 		return;
 	}
 
-	__alloc_ppat_entry(ppat, 0, GEN8_PPAT_WB | GEN8_PPAT_LLC);
-	__alloc_ppat_entry(ppat, 1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC);
-	__alloc_ppat_entry(ppat, 2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC);
-	__alloc_ppat_entry(ppat, 3, GEN8_PPAT_UC);
-	__alloc_ppat_entry(ppat, 4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0));
-	__alloc_ppat_entry(ppat, 5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1));
-	__alloc_ppat_entry(ppat, 6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2));
-	__alloc_ppat_entry(ppat, 7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3));
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED_PDE), GEN8_PPAT_WB | GEN8_PPAT_LLC);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_DISPLAY_ELLC), GEN8_PPAT_WT | GEN8_PPAT_LLCELLC);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_UNCACHED), GEN8_PPAT_UC);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED), GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0));
 }
 
 /* The GGTT and PPGTT need a private PPAT setup in order to handle cacheability
@@ -3035,18 +3042,14 @@ static void bdw_setup_private_ppat(struct intel_ppat *ppat)
 		 * So we can still hold onto all our assumptions wrt cpu
 		 * clflushing on LLC machines.
 		 */
-		__alloc_ppat_entry(ppat, 0, GEN8_PPAT_UC);
+		__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED_PDE), GEN8_PPAT_UC);
 		return;
 	}
 
-	__alloc_ppat_entry(ppat, 0, GEN8_PPAT_WB | GEN8_PPAT_LLC);      /* for normal objects, no eLLC */
-	__alloc_ppat_entry(ppat, 1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC);  /* for something pointing to ptes? */
-	__alloc_ppat_entry(ppat, 2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC);  /* for scanout with eLLC */
-	__alloc_ppat_entry(ppat, 3, GEN8_PPAT_UC);                      /* Uncached objects, mostly for scanout */
-	__alloc_ppat_entry(ppat, 4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0));
-	__alloc_ppat_entry(ppat, 5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1));
-	__alloc_ppat_entry(ppat, 6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2));
-	__alloc_ppat_entry(ppat, 7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3));
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED_PDE), GEN8_PPAT_WB | GEN8_PPAT_LLC);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_DISPLAY_ELLC), GEN8_PPAT_WT | GEN8_PPAT_LLCELLC);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_UNCACHED), GEN8_PPAT_UC);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED), GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0));
 }
 
 static void chv_setup_private_ppat(struct intel_ppat *ppat)
@@ -3075,14 +3078,11 @@ static void chv_setup_private_ppat(struct intel_ppat *ppat)
 	 * in order to keep the global status page working.
 	 */
 
-	__alloc_ppat_entry(ppat, 0, CHV_PPAT_SNOOP);
-	__alloc_ppat_entry(ppat, 1, 0);
-	__alloc_ppat_entry(ppat, 2, 0);
-	__alloc_ppat_entry(ppat, 3, 0);
-	__alloc_ppat_entry(ppat, 4, CHV_PPAT_SNOOP);
-	__alloc_ppat_entry(ppat, 5, CHV_PPAT_SNOOP);
-	__alloc_ppat_entry(ppat, 6, CHV_PPAT_SNOOP);
-	__alloc_ppat_entry(ppat, 7, CHV_PPAT_SNOOP);
+	/* See gen8_pte_encode() for the mapping from cache-level to PPAT */
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED_PDE), CHV_PPAT_SNOOP);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_DISPLAY_ELLC), 0);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_UNCACHED), 0);
+	__alloc_ppat_entry(ppat, ppat_index(PPAT_CACHED), CHV_PPAT_SNOOP);
 }
 
 static void gen6_gmch_remove(struct i915_address_space *vm)
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

PATCH 1/2 drm/i915/selftests: Refine the i915_ppat_get test case

Refine the i915_ppat_get test case to catch a bug recently intrduced by me. If the PPAT page table is filled first, then there will be PPAT entries which has the same attributes with another one. If we try to get our entry at this time. Tested on my SKL NUC box.

Cc Ben Widawsky <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Joonas Lahtinen <[email protected]>
---
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 28 +++++++++++----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +11 -17
index cd7eeb6..75cb2d6 100644
@@ -1284,7 +1284,7 @@ static int perform_perfect_match_test(struct intel_ppat *ppat)
 {
 	struct drm_i915_private *i915 = ppat->i915;
 	const struct intel_ppat_entry *entry;
-	int ret, i;
+	int i;
 
 	for_each_set_bit(i, ppat->used, ppat->max_entries) {
 		entry = intel_ppat_get(i915, ppat->entries[i].value);
@@ -1296,9 +1296,7 @@ static int perform_perfect_match_test(struct intel_ppat *ppat)
 			intel_ppat_put(entry);
 			return -EINVAL;
 		}
-		ret = put_and_check_entry(entry);
-		if (ret)
-			return ret;
+		intel_ppat_put(entry);
 	}
 	return 0;
 }
@@ -1328,7 +1326,6 @@ static int perform_partial_match_test(struct intel_ppat *ppat)
 	struct drm_i915_private *i915 = ppat->i915;
 	const struct intel_ppat_entry *entry;
 	u8 value;
-	int ret;
 
 	value = generate_new_value(ppat, value_for_partial_test);
 	if (!value) {
@@ -1350,10 +1347,7 @@ static int perform_partial_match_test(struct intel_ppat *ppat)
 		return -EINVAL;
 	}
 
-	ret = put_and_check_entry(entry);
-	if (ret)
-		return ret;
-
+	intel_ppat_put(entry);
 	return 0;
 }
 
@@ -1373,14 +1367,7 @@ static int igt_ppat_get(void *arg)
 	if (ret)
 		return ret;
 
-	/* case 1: perfect match */
-	ret = perform_perfect_match_test(ppat);
-	if (ret) {
-		pr_err("fail on perfect match test\n");
-		return ret;
-	}
-
-	/* case 2: alloc new entries */
+	/* case 1: alloc new entries */
 	entries = NULL;
 	ret = 0;
 
@@ -1407,6 +1394,13 @@ static int igt_ppat_get(void *arg)
 		*p = entry;
 	}
 
+	/* case 2: perfect match */
+	ret = perform_perfect_match_test(ppat);
+	if (ret) {
+		pr_err("fail on perfect match test\n");
+		return ret;
+	}
+
 	/* case 3: negative test 1, suppose PPAT table is full now */
 	ret = perform_negative_test(ppat);
 	if (ret) {
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH 1/2] drm/i915/selftests: Refine the i915_ppat_get test case

Please drop this one.

-----Original Message-----
From: Wang, Zhi A
Sent: Thursday, September 21, 2017 8:27 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; Widawsky, Benjamin <[email protected]>; Vivi, Rodrigo <[email protected]>
Subject: [PATCH 1/2] drm/i915/selftests: Refine the i915_ppat_get test case

Refine the i915_ppat_get test case to catch a bug recently intrduced by me. If the PPAT page table is filled first, then there will be PPAT entries which has the same attributes with another one. If we try to get our entry at this time. Tested on my SKL NUC box.

Cc Ben Widawsky <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Joonas Lahtinen <[email protected]>
---
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 28 +++++++++++----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1 -1
index cd7eeb6..75cb2d6 100644
@@ -1284,7 +1284,7 @@ static int perform_perfect_match_test(struct intel_ppat *ppat)  {
 	struct drm_i915_private *i915 = ppat->i915;
 	const struct intel_ppat_entry *entry;
-	int ret, i;
+	int i;
 
 	for_each_set_bit(i, ppat->used, ppat->max_entries) {
 		entry = intel_ppat_get(i915, ppat->entries[i].value); @@ -1296,9 +1296,7 @@ static int perform_perfect_match_test(struct intel_ppat *ppat)
 			intel_ppat_put(entry);

return -EINVAL;
}
- ret = put_and_check_entry(entry);
- if (ret)
- return ret;
+ intel_ppat_put(entry);
}
return 0;
}
@@ -1328,7 +1326,6 @@ static int perform_partial_match_test(struct intel_ppat *ppat)
struct drm_i915_private *i915 = ppat->i915;
const struct intel_ppat_entry *entry;
u8 value;
- int ret;

value = generate_new_value(ppat, value_for_partial_test);
if (!value) {
@@ -1350,10 +1347,7 @@ static int perform_partial_match_test(struct intel_ppat *ppat)
return -EINVAL;
}

- ret = put_and_check_entry(entry);
- if (ret)
- return ret;
-
+ intel_ppat_put(entry);
return 0;
}

@@ -1373,14 +1367,7 @@ static int igt_ppat_get(void *arg)
if (ret)
return ret;

- /* case 1: perfect match */
- ret = perform_perfect_match_test(ppat);
- if (ret) {
- pr_err("fail on perfect match test\n");
- return ret;
- }
-
- /* case 2: alloc new entries */
+ /* case 1: alloc new entries */
entries = NULL;
ret = 0;

@@ -1407,6 +1394,13 @@ static int igt_ppat_get(void *arg)
*p = entry;
}

+ /* case 2: perfect match */
+ ret = perform_perfect_match_test(ppat);
+ if (ret) {
+ pr_err("fail on perfect match test\n");
+ return ret;
+ }
+
/* case 3: negative test 1, suppose PPAT table is full now */ ret = perform_negative_test(ppat);
if (ret) {
--
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#3 lore raw

PATCH 1/1 drm/i915: Return the correct score in i915_ppat_get()

In reply to Zhi Wang

The cache attribute of the required entry has to be the same with the existing value. After this requirement is met, the futher comparison should be performed. After this fix, the refined test case can pass.

v2:

- Refine the tittle and comments. (Rodrigo)

Fixes 4395890a4855 ("drm/i915: Introduce private PAT management")
Cc Chris Wilson <[email protected]>
Cc Ben Widawsky <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Joonas Lahtinen <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -1
index 5923b51..636ad7d 100644
@@ -2965,7 +2965,7 @@ static unsigned int bdw_private_pat_match(u8 src, u8 dst)
 	};
 
 	/* Cache attribute has to be matched. */
-	if (GEN8_PPAT_GET_CA(src) == GEN8_PPAT_GET_CA(dst))
+	if (GEN8_PPAT_GET_CA(src) != GEN8_PPAT_GET_CA(dst))
 		return 0;
 
 	score |= CA_MATCH;
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author Reviewed-by Joonas Lahtinen on v1 1/1
#4 lore raw

Re: [PATCH] drm/i915: Return the correct score in i915_ppat_get()

Please drop this one.

-----Original Message-----
From: Wang, Zhi A
Sent: Thursday, September 21, 2017 8:27 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; Widawsky, Benjamin <[email protected]>; Vivi, Rodrigo <[email protected]>
Subject: [PATCH] drm/i915: Return the correct score in i915_ppat_get()

The cache attribute of the required entry has to be the same with the existing value. After this requirement is met, the futher comparison should be performed. After this fix, the refined test case can pass.

v2:

- Refine the tittle and comments. (Rodrigo)

Fixes 4395890a4855 ("drm/i915: Introduce private PAT management")
Cc Chris Wilson <[email protected]>
Cc Ben Widawsky <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Joonas Lahtinen <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -1
index 5923b51..636ad7d 100644
@@ -2965,7 +2965,7 @@ static unsigned int bdw_private_pat_match(u8 src, u8 dst)
 	};
 
 	/* Cache attribute has to be matched. */
-	if (GEN8_PPAT_GET_CA(src) == GEN8_PPAT_GET_CA(dst))
+	if (GEN8_PPAT_GET_CA(src) != GEN8_PPAT_GET_CA(dst))
 		return 0;
 
 	score |= CA_MATCH;

--
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx