[RFC PATCH] drm/i915/gvt: Try cma allocation first for oos page setup

Feng Tang feng.tang at intel.com
Mon Jan 28 02:46:20 UTC 2019


When doing boottime profiling, we found the oos page setup takes about
25~30 ms, while using cma allocation takes less than 10 ms. And if the
preallocated_oos_pages increases in future, it will save more.

This commit will try to allocate the memory from CMA first, and fall
back to the original kzalloc if CMA is not available.

Signed-off-by: Feng Tang <feng.tang at intel.com>
---
 drivers/gpu/drm/i915/gvt/gtt.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
index c7103dd..e8d6f10 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -2496,18 +2496,34 @@ static void clean_spt_oos(struct intel_gvt *gvt)
 static int setup_spt_oos(struct intel_gvt *gvt)
 {
 	struct intel_gvt_gtt *gtt = &gvt->gtt;
-	struct intel_vgpu_oos_page *oos_page;
+	struct intel_vgpu_oos_page *oos_page, *oos_page_base;
+	struct page *cma_page;
+	int npages;
 	int i;
 	int ret;
 
 	INIT_LIST_HEAD(&gtt->oos_page_free_list_head);
 	INIT_LIST_HEAD(&gtt->oos_page_use_list_head);
 
+	/* Try cma allocation first to save setup time */
+	npages = preallocated_oos_pages * sizeof(*oos_page);
+	npages = DIV_ROUND_UP(npages, PAGE_SIZE);
+
+	cma_page = dma_alloc_from_contiguous(NULL, npages, 1, TRUE);
+	if (cma_page) {
+		oos_page_base = page_address(cma_page);
+		memset(oos_page_base, 0, npages << PAGE_SHIFT);
+	}
+
 	for (i = 0; i < preallocated_oos_pages; i++) {
-		oos_page = kzalloc(sizeof(*oos_page), GFP_KERNEL);
-		if (!oos_page) {
-			ret = -ENOMEM;
-			goto fail;
+		if (cma_page) {
+			oos_page = oos_page_base + i;
+		} else {
+			oos_page = kzalloc(sizeof(*oos_page), GFP_KERNEL);
+			if (!oos_page) {
+				ret = -ENOMEM;
+				goto fail;
+			}
 		}
 
 		INIT_LIST_HEAD(&oos_page->list);
-- 
2.7.4



More information about the intel-gvt-dev mailing list