[PATCH]drm/i915/gvt: Add CAP support for QoS

Ping Gao ping.a.gao at intel.com
Wed Aug 2 06:39:51 UTC 2017


Cap control the maximum amount of vGPU resource will be able to
consume, valid value is [0, 100]. 0 and 100 means no upper cap.
Similar with weight, cap is another kind of method to limit the
time slice.

This patch introduced a new parameter for cap, and let the time
slice calculated by the weight and cap together.

TODO: need associate it with mdev generic QoS interface after it
upstreamed.

Signed-off-by: Ping Gao <ping.a.gao at intel.com>
---
 drivers/gpu/drm/i915/gvt/gvt.h          |  1 +
 drivers/gpu/drm/i915/gvt/sched_policy.c | 28 +++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index 0f85fff..8bfeda3 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -140,6 +140,7 @@ struct intel_vgpu_display {
 
 struct vgpu_sched_ctl {
 	int weight;
+	int cap;
 };
 
 struct intel_vgpu {
diff --git a/drivers/gpu/drm/i915/gvt/sched_policy.c b/drivers/gpu/drm/i915/gvt/sched_policy.c
index 436377d..815c030 100644
--- a/drivers/gpu/drm/i915/gvt/sched_policy.c
+++ b/drivers/gpu/drm/i915/gvt/sched_policy.c
@@ -93,7 +93,8 @@ static void gvt_balance_timeslice(struct gvt_sched_data *sched_data)
 	 */
 	if (stage == 0) {
 		int total_weight = 0;
-		ktime_t fair_timeslice;
+		ktime_t fair_timeslice = 0;
+		ktime_t max_timeslice = 0;
 
 		list_for_each(pos, &sched_data->lru_runq_head) {
 			vgpu_data = container_of(pos, struct vgpu_sched_data, lru_list);
@@ -102,11 +103,27 @@ static void gvt_balance_timeslice(struct gvt_sched_data *sched_data)
 
 		list_for_each(pos, &sched_data->lru_runq_head) {
 			vgpu_data = container_of(pos, struct vgpu_sched_data, lru_list);
-			fair_timeslice = ms_to_ktime(GVT_TS_BALANCE_PERIOD_MS) *
-						vgpu_data->sched_ctl.weight /
-						total_weight;
 
-			vgpu_data->allocated_ts = fair_timeslice;
+			if (total_weight) {
+				fair_timeslice = ms_to_ktime(GVT_TS_BALANCE_PERIOD_MS) *
+							vgpu_data->sched_ctl.weight /
+							total_weight;
+			}
+			if (!fair_timeslice)
+				fair_timeslice = ms_to_ktime(GVT_TS_BALANCE_PERIOD_MS);
+
+			max_timeslice = ms_to_ktime(GVT_TS_BALANCE_PERIOD_MS) *
+						vgpu_data->sched_ctl.cap / 100;
+			if (!max_timeslice)
+				max_timeslice = ms_to_ktime(GVT_TS_BALANCE_PERIOD_MS);
+
+			/* As weight and cap both are the way to control GPU
+			 * resource by limiting time slice, when they been set
+			 * at the same time, the allocated time slice will choose
+			 * the smaller one.
+			 */
+			vgpu_data->allocated_ts = fair_timeslice < max_timeslice ?
+							fair_timeslice : max_timeslice;
 			vgpu_data->left_ts = vgpu_data->allocated_ts;
 		}
 	} else {
@@ -298,6 +315,7 @@ static int tbs_sched_init_vgpu(struct intel_vgpu *vgpu)
 		return -ENOMEM;
 
 	data->sched_ctl.weight = vgpu->sched_ctl.weight;
+	data->sched_ctl.cap = vgpu->sched_ctl.cap;
 	data->vgpu = vgpu;
 	INIT_LIST_HEAD(&data->lru_list);
 
-- 
2.7.4



More information about the intel-gvt-dev mailing list