Commit 32356920 authored by Ping Gao's avatar Ping Gao Committed by Zhenyu Wang

drm/i915/gvt: factor out the scheduler

Factor out the scheduler to a more clear structure, the basic
logic is to find out next vGPU first and then schedule it.
vGPUs were ordered in a LRU list, scheduler scan from the LRU
list head and choose the first vGPU who has pending workload.
Signed-off-by: default avatarPing Gao <ping.a.gao@intel.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
parent f6504cce
...@@ -48,7 +48,7 @@ static bool vgpu_has_pending_workload(struct intel_vgpu *vgpu) ...@@ -48,7 +48,7 @@ static bool vgpu_has_pending_workload(struct intel_vgpu *vgpu)
} }
struct vgpu_sched_data { struct vgpu_sched_data {
struct list_head list; struct list_head lru_list;
struct intel_vgpu *vgpu; struct intel_vgpu *vgpu;
ktime_t sched_in_time; ktime_t sched_in_time;
...@@ -64,7 +64,7 @@ struct gvt_sched_data { ...@@ -64,7 +64,7 @@ struct gvt_sched_data {
struct intel_gvt *gvt; struct intel_gvt *gvt;
struct hrtimer timer; struct hrtimer timer;
unsigned long period; unsigned long period;
struct list_head runq_head; struct list_head lru_runq_head;
}; };
static void try_to_schedule_next_vgpu(struct intel_gvt *gvt) static void try_to_schedule_next_vgpu(struct intel_gvt *gvt)
...@@ -118,36 +118,17 @@ static void try_to_schedule_next_vgpu(struct intel_gvt *gvt) ...@@ -118,36 +118,17 @@ static void try_to_schedule_next_vgpu(struct intel_gvt *gvt)
wake_up(&scheduler->waitq[i]); wake_up(&scheduler->waitq[i]);
} }
/* in nanosecond */ static struct intel_vgpu *find_busy_vgpu(struct gvt_sched_data *sched_data)
#define GVT_DEFAULT_TIME_SLICE 1000000
static void tbs_sched_func(struct gvt_sched_data *sched_data)
{ {
struct vgpu_sched_data *vgpu_data; struct vgpu_sched_data *vgpu_data;
struct intel_gvt *gvt = sched_data->gvt;
struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
struct intel_vgpu *vgpu = NULL; struct intel_vgpu *vgpu = NULL;
struct list_head *pos, *head; struct list_head *head = &sched_data->lru_runq_head;
struct list_head *pos;
/* no vgpu or has already had a target */
if (list_empty(&sched_data->runq_head) || scheduler->next_vgpu)
goto out;
if (scheduler->current_vgpu) {
vgpu_data = scheduler->current_vgpu->sched_data;
head = &vgpu_data->list;
} else {
head = &sched_data->runq_head;
}
/* search a vgpu with pending workload */ /* search a vgpu with pending workload */
list_for_each(pos, head) { list_for_each(pos, head) {
if (pos == &sched_data->runq_head)
continue;
vgpu_data = container_of(pos, struct vgpu_sched_data, list); vgpu_data = container_of(pos, struct vgpu_sched_data, lru_list);
if (!vgpu_has_pending_workload(vgpu_data->vgpu)) if (!vgpu_has_pending_workload(vgpu_data->vgpu))
continue; continue;
...@@ -155,8 +136,33 @@ static void tbs_sched_func(struct gvt_sched_data *sched_data) ...@@ -155,8 +136,33 @@ static void tbs_sched_func(struct gvt_sched_data *sched_data)
break; break;
} }
return vgpu;
}
/* in nanosecond */
#define GVT_DEFAULT_TIME_SLICE 1000000
static void tbs_sched_func(struct gvt_sched_data *sched_data)
{
struct intel_gvt *gvt = sched_data->gvt;
struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
struct vgpu_sched_data *vgpu_data;
struct intel_vgpu *vgpu = NULL;
/* no active vgpu or has already had a target */
if (list_empty(&sched_data->lru_runq_head) || scheduler->next_vgpu)
goto out;
vgpu = find_busy_vgpu(sched_data);
if (vgpu) { if (vgpu) {
scheduler->next_vgpu = vgpu; scheduler->next_vgpu = vgpu;
/* Move the last used vGPU to the tail of lru_list */
vgpu_data = vgpu->sched_data;
list_del_init(&vgpu_data->lru_list);
list_add_tail(&vgpu_data->lru_list,
&sched_data->lru_runq_head);
gvt_dbg_sched("pick next vgpu %d\n", vgpu->id); gvt_dbg_sched("pick next vgpu %d\n", vgpu->id);
} }
out: out:
...@@ -200,7 +206,7 @@ static int tbs_sched_init(struct intel_gvt *gvt) ...@@ -200,7 +206,7 @@ static int tbs_sched_init(struct intel_gvt *gvt)
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&data->runq_head); INIT_LIST_HEAD(&data->lru_runq_head);
hrtimer_init(&data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); hrtimer_init(&data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
data->timer.function = tbs_timer_fn; data->timer.function = tbs_timer_fn;
data->period = GVT_DEFAULT_TIME_SLICE; data->period = GVT_DEFAULT_TIME_SLICE;
...@@ -232,7 +238,7 @@ static int tbs_sched_init_vgpu(struct intel_vgpu *vgpu) ...@@ -232,7 +238,7 @@ static int tbs_sched_init_vgpu(struct intel_vgpu *vgpu)
return -ENOMEM; return -ENOMEM;
data->vgpu = vgpu; data->vgpu = vgpu;
INIT_LIST_HEAD(&data->list); INIT_LIST_HEAD(&data->lru_list);
vgpu->sched_data = data; vgpu->sched_data = data;
...@@ -250,10 +256,10 @@ static void tbs_sched_start_schedule(struct intel_vgpu *vgpu) ...@@ -250,10 +256,10 @@ static void tbs_sched_start_schedule(struct intel_vgpu *vgpu)
struct gvt_sched_data *sched_data = vgpu->gvt->scheduler.sched_data; struct gvt_sched_data *sched_data = vgpu->gvt->scheduler.sched_data;
struct vgpu_sched_data *vgpu_data = vgpu->sched_data; struct vgpu_sched_data *vgpu_data = vgpu->sched_data;
if (!list_empty(&vgpu_data->list)) if (!list_empty(&vgpu_data->lru_list))
return; return;
list_add_tail(&vgpu_data->list, &sched_data->runq_head); list_add_tail(&vgpu_data->lru_list, &sched_data->lru_runq_head);
if (!hrtimer_active(&sched_data->timer)) if (!hrtimer_active(&sched_data->timer))
hrtimer_start(&sched_data->timer, ktime_add_ns(ktime_get(), hrtimer_start(&sched_data->timer, ktime_add_ns(ktime_get(),
...@@ -264,7 +270,7 @@ static void tbs_sched_stop_schedule(struct intel_vgpu *vgpu) ...@@ -264,7 +270,7 @@ static void tbs_sched_stop_schedule(struct intel_vgpu *vgpu)
{ {
struct vgpu_sched_data *vgpu_data = vgpu->sched_data; struct vgpu_sched_data *vgpu_data = vgpu->sched_data;
list_del_init(&vgpu_data->list); list_del_init(&vgpu_data->lru_list);
} }
static struct intel_gvt_sched_policy_ops tbs_schedule_ops = { static struct intel_gvt_sched_policy_ops tbs_schedule_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment