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

Zhao, Yakui yakui.zhao at intel.com
Mon Jan 28 03:28:28 UTC 2019



>-----Original Message-----
>From: intel-gvt-dev [mailto:intel-gvt-dev-bounces at lists.freedesktop.org] On
>Behalf Of Feng Tang
>Sent: Monday, January 28, 2019 10:46 AM
>To: intel-gvt-dev at lists.freedesktop.org; Zhenyu Wang
><zhenyuw at linux.intel.com>; Wang, Zhi A <zhi.a.wang at intel.com>; Xiao
>Zheng <xiao.zheng at intel.com>; He, Min <min.he at intel.com>; Bing Niu
><bing.niu at intel.com>
>Cc: Tang, Feng <feng.tang at intel.com>
>Subject: [RFC PATCH] drm/i915/gvt: Try cma allocation first for oos page setup
>
>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);
>+	}
>+

Currently it will try to call kzalloc for 8192 times.
So can we firstly use the kcalloc to allocate the memory for all the *oos_page and
then initialize the oos_page list?

For the CMA: we need to reserve some regions for CMA. This is not recommended.

> 	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
>
>_______________________________________________
>intel-gvt-dev mailing list
>intel-gvt-dev at lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev


More information about the intel-gvt-dev mailing list