Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Zhi Wang <zhi.a.wang@intel.com>
To: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org
Subject: [RFC 4/7] drm/i915: Introduce dynamic private PAT management
Date: Wed, 16 Aug 2017 05:31:12 +0800	[thread overview]
Message-ID: <1502832675-6123-5-git-send-email-zhi.a.wang@intel.com> (raw)
In-Reply-To: <1502832675-6123-1-git-send-email-zhi.a.wang@intel.com>

To manage the dynamic private PAT entries, this patch introduces some
basic functionalities for getting and putting an expected private PAT
entry.

When building the private PAT mapping between virtual PPAT indexes and
physical PPAT indexes, GVT-g would check if there is already an usable
private PAT entry.

If it's a perfect match, it would be directly used.

If it's not a perfect match and there is still unused PPAT entry, GVT
will allocate a new PPAT entry index for a guest.

If it's not a perfect match and there is no available unused PPAT entry,
GVT will use the parital matched PPAT entry index.

Each dynamic PPAT entry is associated with a reference count. If no
vGPU is using it, it will be freed.

Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
---
 drivers/gpu/drm/i915/gvt/gtt.c | 100 +++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/gvt/gtt.h |   6 +++
 2 files changed, 106 insertions(+)

diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
index c630015..6e19d7a 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -2254,6 +2254,103 @@ static int setup_spt_oos(struct intel_gvt *gvt)
 	return ret;
 }
 
+static void setup_private_pat(struct intel_gvt *gvt)
+{
+	struct drm_i915_private *dev_priv = gvt->dev_priv;
+	struct intel_gvt_gtt *gtt = &gvt->gtt;
+	struct intel_gvt_gtt_pat_ops *ops = gtt->pat_ops;
+	int i;
+
+	i = find_first_bit(dev_priv->avail_ppat_bitmap, gtt->max_ppat_index);
+	if (i >= gtt->max_ppat_index) {
+		DRM_DEBUG_DRIVER("no private PAT support\n");
+		return;
+	}
+
+	gtt->has_ppat = true;
+
+	/* Save available PPAT bitmap from host */
+	bitmap_copy(gtt->avail_ppat_bitmap, dev_priv->avail_ppat_bitmap,
+			gtt->max_ppat_index);
+
+	/* Read host PPAT configuration */
+	for_each_clear_bit(i, gtt->avail_ppat_bitmap, gtt->max_ppat_index)
+		gtt->ppat_value[i] = ops->get_pat_value(NULL, i, gvt);
+}
+
+static int get_private_pat_index(struct intel_gvt *gvt, u32 value)
+{
+	struct drm_i915_private *dev_priv = gvt->dev_priv;
+	struct intel_gvt_gtt *gtt = &gvt->gtt;
+	struct intel_gvt_gtt_pat_ops *ops = gtt->pat_ops;
+	int i, index, used;
+	unsigned int score, best_score;
+
+	if (WARN_ON(!gtt->has_ppat))
+		return 0;
+
+	score = best_score = 0;
+	used = 0;
+
+	/* First, find a suitable value from available configurations */
+	for_each_clear_bit(i, gtt->avail_ppat_bitmap, gtt->max_ppat_index) {
+		score = ops->match_pat_value(gtt->ppat_value[i], value);
+		/* Perfect match */
+		if (score == ~0) {
+			index = i;
+			goto found;
+		}
+
+		if (score > best_score) {
+			index = i;
+			best_score = score;
+		}
+		used++;
+	}
+
+	if (!best_score && used == gtt->max_ppat_index) {
+		DRM_ERROR("cannot find a suitable PPAT entry\n");
+		return -ENOSPC;
+	}
+
+	/*
+	 * Found a matched entry which is not perfect,
+	 * but we don't have a available free entry
+	 */
+	if (best_score && used == gtt->max_ppat_index)
+		goto found;
+
+	/* Allocate a new one */
+	index = find_first_bit(gtt->avail_ppat_bitmap, gtt->max_ppat_index);
+	clear_bit(index, gtt->avail_ppat_bitmap);
+	gtt->ppat_value[index] = value;
+	ops->set_pat_value(NULL, index, gtt->ppat_value[index], gvt);
+
+found:
+	/* Not need to increase reference for host entries.*/
+	if (test_bit(index, dev_priv->avail_ppat_bitmap))
+		return index;
+
+	atomic_inc(&gtt->ppat_refc[index]);
+	return index;
+}
+
+static void put_private_pat_index(struct intel_gvt *gvt, unsigned int index)
+{
+	struct drm_i915_private *dev_priv = gvt->dev_priv;
+	struct intel_gvt_gtt *gtt = &gvt->gtt;
+
+	if (WARN_ON(!gtt->has_ppat))
+		return;
+
+	/* Nothing to do with host PPAT configuration */
+	if (test_bit(index, dev_priv->avail_ppat_bitmap))
+		return;
+
+	if (atomic_dec_and_test(&gtt->ppat_refc[index]))
+		set_bit(index, gtt->avail_ppat_bitmap);
+}
+
 /**
  * intel_vgpu_find_ppgtt_mm - find a PPGTT mm object
  * @vgpu: a vGPU
@@ -2386,12 +2483,15 @@ int intel_gvt_init_gtt(struct intel_gvt *gvt)
 		gvt->gtt.pte_ops = &gen8_gtt_pte_ops;
 		gvt->gtt.gma_ops = &gen8_gtt_gma_ops;
 		gvt->gtt.pat_ops = &gen8_pat_ops;
+		gvt->gtt.max_ppat_index = 8;
 		gvt->gtt.mm_alloc_page_table = gen8_mm_alloc_page_table;
 		gvt->gtt.mm_free_page_table = gen8_mm_free_page_table;
 	} else {
 		return -ENODEV;
 	}
 
+	setup_private_pat(gvt);
+
 	page = (void *)get_zeroed_page(GFP_KERNEL);
 	if (!page) {
 		gvt_err("fail to allocate scratch ggtt page\n");
diff --git a/drivers/gpu/drm/i915/gvt/gtt.h b/drivers/gpu/drm/i915/gvt/gtt.h
index 02f6bd9..6cd4fc7 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.h
+++ b/drivers/gpu/drm/i915/gvt/gtt.h
@@ -100,6 +100,12 @@ struct intel_gvt_gtt {
 
 	struct page *scratch_ggtt_page;
 	unsigned long scratch_ggtt_mfn;
+
+	DECLARE_BITMAP(avail_ppat_bitmap, MAX_PPAT_INDEX);
+	unsigned int ppat_value[MAX_PPAT_INDEX];
+	atomic_t ppat_refc[MAX_PPAT_INDEX];
+	unsigned int max_ppat_index;
+	bool has_ppat;
 };
 
 enum {
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2017-08-15 21:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 21:31 [RFC 0/7] Introduce dynamic PPAT managment for GVT-g Zhi Wang
2017-08-15 13:51 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-08-15 21:31 ` [RFC 1/7] drm/i915: Introduce a bitmap to indicate available PPAT entries Zhi Wang
2017-08-15 21:31 ` [RFC 2/7] drm/i915/gvt: Introduce GEN8 private PAT ops Zhi Wang
2017-08-16  5:12   ` Zhenyu Wang
2017-08-16 13:46     ` Zhi Wang
2017-08-16  6:52   ` Zhenyu Wang
2017-08-15 21:31 ` [RFC 3/7] drm/i915: Introduce GEN8 {set, get} private PAT index ops Zhi Wang
2017-08-15 21:31 ` Zhi Wang [this message]
2017-08-15 21:31 ` [RFC 5/7] drm/i915/gvt: Introduce functions for retiring all shadow PPGTTs of a vGPU Zhi Wang
2017-08-15 21:31 ` [RFC 6/7] drm/i915/gvt: Introduce virtual private PAT support Zhi Wang
2017-08-16  5:18   ` Zhenyu Wang
2017-08-16 13:48     ` Zhi Wang
2017-08-16  6:13       ` Zhenyu Wang
2017-08-16  6:29         ` Wang, Zhi A
2017-08-15 21:31 ` [RFC 7/7] drm/i915/gvt: Translate virtual PPAT indexes Zhi Wang
2017-08-15 21:33 ` [RFC 0/7] Introduce dynamic PPAT managment for GVT-g Zhi Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502832675-6123-5-git-send-email-zhi.a.wang@intel.com \
    --to=zhi.a.wang@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox