Skip to content

Commit f44aa4e

Browse files
Shuo A Liuwenlingz
authored andcommitted
hv: sched_iorr: add init functions of sched_iorr
We set timeslice to 10ms as default, and set tick interval to 1ms. When init sched_iorr scheduler, we init a periodic timer as the tick and init the runqueue to maintain objects in the sched_control. Destroy the timer in deinit. Tracked-On: #4178 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Signed-off-by: Yu Wang <yu1.wang@intel.com> Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent ed40086 commit f44aa4e

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

hypervisor/common/sched_iorr.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <per_cpu.h>
99
#include <schedule.h>
1010

11+
#define CONFIG_SLICE_MS 10UL
1112
struct sched_iorr_data {
1213
/* keep list as the first item */
1314
struct list_head list;
@@ -17,17 +18,48 @@ struct sched_iorr_data {
1718
int64_t left_cycles;
1819
};
1920

20-
int sched_iorr_init(__unused struct sched_control *ctl)
21+
static void sched_tick_handler(__unused void *param)
2122
{
22-
return 0;
2323
}
2424

25-
void sched_iorr_deinit(__unused struct sched_control *ctl)
25+
/*
26+
* @pre ctl->pcpu_id == get_pcpu_id()
27+
*/
28+
int sched_iorr_init(struct sched_control *ctl)
29+
{
30+
struct sched_iorr_control *iorr_ctl = &per_cpu(sched_iorr_ctl, ctl->pcpu_id);
31+
uint64_t tick_period = CYCLES_PER_MS;
32+
int ret = 0;
33+
34+
ASSERT(get_pcpu_id() == ctl->pcpu_id, "Init scheduler on wrong CPU!");
35+
36+
ctl->priv = iorr_ctl;
37+
INIT_LIST_HEAD(&iorr_ctl->runqueue);
38+
39+
/* The tick_timer is periodically */
40+
initialize_timer(&iorr_ctl->tick_timer, sched_tick_handler, ctl,
41+
rdtsc() + tick_period, TICK_MODE_PERIODIC, tick_period);
42+
43+
if (add_timer(&iorr_ctl->tick_timer) < 0) {
44+
pr_err("Failed to add schedule tick timer!");
45+
ret = -1;
46+
}
47+
return ret;
48+
}
49+
50+
void sched_iorr_deinit(struct sched_control *ctl)
2651
{
52+
struct sched_iorr_control *iorr_ctl = (struct sched_iorr_control *)ctl->priv;
53+
del_timer(&iorr_ctl->tick_timer);
2754
}
2855

29-
void sched_iorr_init_data(__unused struct thread_object *obj)
56+
void sched_iorr_init_data(struct thread_object *obj)
3057
{
58+
struct sched_iorr_data *data;
59+
60+
data = (struct sched_iorr_data *)obj->data;
61+
INIT_LIST_HEAD(&data->list);
62+
data->left_cycles = data->slice_cycles = CONFIG_SLICE_MS * CYCLES_PER_MS;
3163
}
3264

3365
static struct thread_object *sched_iorr_pick_next(__unused struct sched_control *ctl)

0 commit comments

Comments
 (0)