[1/2] drm/i915/gvt: Use real time to do timer check

Submitted by Zhipeng Gong on March 30, 2018, 4:54 a.m.

Details

Message ID 1522385651-27267-2-git-send-email-zhipeng.gong@intel.com
State New
Headers show
Series "drm/i915/gvt: fix some scheduler issues" ( rev: 1 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Zhipeng Gong March 30, 2018, 4:54 a.m.
intel_gvt_schedule check timer through a counter and is supposed
to wake up to increase the counter every ms.
In a system with heavy workload, gvt_service_thread can not get
a chance to run right after wake up and will be delayed several
milliseconds. As a result, one hundred counter interval means
several hundred milliseconds in real time.

This patch use real time instead of counter to do timer check.

Signed-off-by: Zhipeng Gong <zhipeng.gong@intel.com>
---
 drivers/gpu/drm/i915/gvt/sched_policy.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/sched_policy.c b/drivers/gpu/drm/i915/gvt/sched_policy.c
index 75b7bc7..f0ac281 100644
--- a/drivers/gpu/drm/i915/gvt/sched_policy.c
+++ b/drivers/gpu/drm/i915/gvt/sched_policy.c
@@ -226,14 +226,19 @@  static void tbs_sched_func(struct gvt_sched_data *sched_data)
 void intel_gvt_schedule(struct intel_gvt *gvt)
 {
 	struct gvt_sched_data *sched_data = gvt->scheduler.sched_data;
-	static uint64_t timer_check;
+	static ktime_t check_time;
 
 	mutex_lock(&gvt->lock);
 
 	if (test_and_clear_bit(INTEL_GVT_REQUEST_SCHED,
 				(void *)&gvt->service_request)) {
-		if (!(timer_check++ % GVT_TS_BALANCE_PERIOD_MS))
+		ktime_t cur_time = ktime_get();
+
+		if (ktime_sub(cur_time, check_time) >=
+				GVT_TS_BALANCE_PERIOD_MS * NSEC_PER_MSEC) {
+			check_time = cur_time;
 			gvt_balance_timeslice(sched_data);
+		}
 	}
 	clear_bit(INTEL_GVT_REQUEST_EVENT_SCHED, (void *)&gvt->service_request);
 

Comments

On 2018.03.30 12:54:10 +0800, Zhipeng Gong wrote:
> intel_gvt_schedule check timer through a counter and is supposed
> to wake up to increase the counter every ms.
> In a system with heavy workload, gvt_service_thread can not get
> a chance to run right after wake up and will be delayed several
> milliseconds. As a result, one hundred counter interval means
> several hundred milliseconds in real time.
> 
> This patch use real time instead of counter to do timer check.
> 
> Signed-off-by: Zhipeng Gong <zhipeng.gong@intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/sched_policy.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/sched_policy.c b/drivers/gpu/drm/i915/gvt/sched_policy.c
> index 75b7bc7..f0ac281 100644
> --- a/drivers/gpu/drm/i915/gvt/sched_policy.c
> +++ b/drivers/gpu/drm/i915/gvt/sched_policy.c
> @@ -226,14 +226,19 @@ static void tbs_sched_func(struct gvt_sched_data *sched_data)
>  void intel_gvt_schedule(struct intel_gvt *gvt)
>  {
>  	struct gvt_sched_data *sched_data = gvt->scheduler.sched_data;
> -	static uint64_t timer_check;
> +	static ktime_t check_time;
>  
>  	mutex_lock(&gvt->lock);
>  
>  	if (test_and_clear_bit(INTEL_GVT_REQUEST_SCHED,
>  				(void *)&gvt->service_request)) {
> -		if (!(timer_check++ % GVT_TS_BALANCE_PERIOD_MS))
> +		ktime_t cur_time = ktime_get();
> +
> +		if (ktime_sub(cur_time, check_time) >=
> +				GVT_TS_BALANCE_PERIOD_MS * NSEC_PER_MSEC) {
> +			check_time = cur_time;
>  			gvt_balance_timeslice(sched_data);
> +		}
>  	}
>  	clear_bit(INTEL_GVT_REQUEST_EVENT_SCHED, (void *)&gvt->service_request);
>  

Could we refactor this to not use static variable, but update a expire target in
sched_data, then check it against ktime_get()?