virt: steal_governor: store only the sampling delay
PATCH 1/1 virt: steal_governor: store only the sampling delay
The governor stores the sampling interval in both milliseconds and jiffies, although delayed work only needs the latter.
Convert interval_ms to jiffies in the module parameter setter and store it directly in sg_ctx.delay. Initialize the default delay to HZ and remove the redundant interval_ms member and initialization conversion.
Keep the read-only interval_ms parameter by converting the delay back to milliseconds in its getter. Use the same conversion for the startup message. Both now report the effective interval after jiffy rounding.
--- drivers/virt/steal_governor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/virt/steal_governor.c +11 -7
@@ -39,14 +39,13 @@ struct steal_governor {ktime_t time;u64 steal;unsigned long delay; -unsigned int interval_ms;unsigned int high_threshold;unsigned int low_threshold;struct delayed_work work; };static struct steal_governor sg_ctx = { - .interval_ms =1000 ,/* 1 second */ + .delay =HZ ,/* 1 second */ .high_threshold =500 ,/* 5% */ .low_threshold =200 ,/* 2% */ };
@@ -74,15 +73,21 @@ static int param_set_interval_ms(const char *val, const struct kernel_param *kp)return -EINVAL ; } -return param_set_uint (val, kp); + *(unsigned long *)kp->arg =msecs_to_jiffies (interval); +return 0 ; +} + +static int param_get_interval_ms (char *buffer,const struct kernel_param *kp) +{ +return sprintf (buffer,"%u\n" ,jiffies_to_msecs (*(unsigned long *)kp->arg)); }static const struct kernel_param_ops interval_ms_ops = { .set = param_set_interval_ms, - .get = param_get_uint, + .get = param_get_interval_ms, }; -module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.interval_ms,0444 ); +module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.delay,0444 );MODULE_PARM_DESC (interval_ms,"Sampling frequency in milliseconds. default: 1000" );
@@ -270,13 +275,12 @@ static int __init steal_governor_init(void)return -EINVAL ; } - sg_ctx.delay =msecs_to_jiffies (sg_ctx.interval_ms);INIT_DELAYED_WORK (&sg_ctx.work, steal_governor_loop); sg_ctx.steal =get_system_steal_time (); sg_ctx.time =ktime_get ();schedule_delayed_work (&sg_ctx.work, sg_ctx.delay);pr_info ("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n" , - sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); +jiffies_to_msecs (sg_ctx.delay), sg_ctx.high_threshold, sg_ctx.low_threshold);return 0 ; }
Signature · 1 line
2.53.0
Quoted 66 lines · Yury Norov
The governor stores the sampling interval in both milliseconds and jiffies, although delayed work only needs the latter.
Convert
interval_msto jiffies in the module parameter setter and store it directly in sg_ctx.delay. Initialize the default delay to HZ and remove the redundantinterval_msmember and initialization conversion.Keep the read-only
interval_msparameter by converting the delay back to milliseconds in its getter. Use the same conversion for the startup message. Both now report the effective interval after jiffy rounding.Signed-off-by Yury Norov <[email protected]>--- drivers/virt/steal_governor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)drivers/virt/steal_governor.c +10
-6@@ -39,14 +39,13 @@ struct steal_governor {ktime_t time;u64 steal;unsigned long delay; -unsigned int interval_ms;unsigned int high_threshold;unsigned int low_threshold;struct delayed_work work; };static struct steal_governor sg_ctx = { - .interval_ms =1000 ,/* 1 second */ + .delay =HZ ,/* 1 second */ .high_threshold =500 ,/* 5% */ .low_threshold =200 ,/* 2% */ };@@ -74,15 +73,21 @@ static int param_set_interval_ms(const char *val, const struct kernel_param *kp)return -EINVAL ; } -return param_set_uint (val, kp); + *(unsigned long *)kp->arg =msecs_to_jiffies (interval); +return 0 ; +} + +static int param_get_interval_ms (char *buffer,const struct kernel_param *kp) +{ +return sprintf (buffer,"%u\n" ,jiffies_to_msecs (*(unsigned long *)kp->arg)); }static const struct kernel_param_ops interval_ms_ops = { .set = param_set_interval_ms, - .get = param_get_uint, + .get = param_get_interval_ms, }; -module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.interval_ms,0444 ); +module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.delay,0444 );MODULE_PARM_DESC (interval_ms,"Sampling frequency in milliseconds. default: 1000" );@@ -270,13 +275,12 @@ static int __init steal_governor_init(void)return -EINVAL ; } - sg_ctx.delay =msecs_to_jiffies (sg_ctx.interval_ms);
drivers/virt/steal_governor.c static int __init steal_governor_init(void) · line 286
Quoted 10 lines
drivers/virt/steal_governor.c +1
-1INIT_DELAYED_WORK (&sg_ctx.work, steal_governor_loop); sg_ctx.steal =get_system_steal_time (); sg_ctx.time =ktime_get ();schedule_delayed_work (&sg_ctx.work, sg_ctx.delay);pr_info ("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n" , - sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); +jiffies_to_msecs (sg_ctx.delay), sg_ctx.high_threshold, sg_ctx.low_threshold);return 0 ; }
Looks good to me. One less variable.
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: b76b4c776503bdb4b7844fce3cc1ea9ef46b9c37 Gitweb: https://git.kernel.org/tip/b76b4c776503bdb4b7844fce3cc1ea9ef46b9c37 Author: Yury Norov <[email protected]> AuthorDate: Mon, 26 Oct 2026 13:12:51 -04:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 09 Nov 2026 09:39:58 +01:00
virt: steal_governor: store only the sampling delay
The governor stores the sampling interval in both milliseconds and jiffies, although delayed work only needs the latter.
Convert interval_ms to jiffies in the module parameter setter and store it directly in sg_ctx.delay. Initialize the default delay to HZ and remove the redundant interval_ms member and initialization conversion.
Keep the read-only interval_ms parameter by converting the delay back to milliseconds in its getter. Use the same conversion for the startup message. Both now report the effective interval after jiffy rounding.
--- drivers/virt/steal_governor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/virt/steal_governor.c +11 -7
@@ -39,14 +39,13 @@ struct steal_governor {ktime_t time;u64 steal;unsigned long delay; -unsigned int interval_ms;unsigned int high_threshold;unsigned int low_threshold;struct delayed_work work; };static struct steal_governor sg_ctx = { - .interval_ms =1000 ,/* 1 second */ + .delay =HZ ,/* 1 second */ .high_threshold =500 ,/* 5% */ .low_threshold =200 ,/* 2% */ };
@@ -74,15 +73,21 @@ static int param_set_interval_ms(const char *val, const struct kernel_param *kp)return -EINVAL ; } -return param_set_uint (val, kp); + *(unsigned long *)kp->arg =msecs_to_jiffies (interval); +return 0 ; +} + +static int param_get_interval_ms (char *buffer,const struct kernel_param *kp) +{ +return sprintf (buffer,"%u\n" ,jiffies_to_msecs (*(unsigned long *)kp->arg)); }static const struct kernel_param_ops interval_ms_ops = { .set = param_set_interval_ms, - .get = param_get_uint, + .get = param_get_interval_ms, }; -module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.interval_ms,0444 ); +module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.delay,0444 );MODULE_PARM_DESC (interval_ms,"Sampling frequency in milliseconds. default: 1000" );
@@ -270,13 +275,12 @@ static int __init steal_governor_init(void)return -EINVAL ; } - sg_ctx.delay =msecs_to_jiffies (sg_ctx.interval_ms);INIT_DELAYED_WORK (&sg_ctx.work, steal_governor_loop); sg_ctx.steal =get_system_steal_time (); sg_ctx.time =ktime_get ();schedule_delayed_work (&sg_ctx.work, sg_ctx.delay);pr_info ("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n" , - sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); +jiffies_to_msecs (sg_ctx.delay), sg_ctx.high_threshold, sg_ctx.low_threshold);return 0 ; }
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 64352f46f121a0103eec2e0aeaadad411825e0d3 Gitweb: https://git.kernel.org/tip/64352f46f121a0103eec2e0aeaadad411825e0d3 Author: Yury Norov <[email protected]> AuthorDate: Mon, 26 Oct 2026 13:12:51 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 09 Nov 2026 10:24:01 +01:00
virt: steal_governor: store only the sampling delay
The governor stores the sampling interval in both milliseconds and jiffies, although delayed work only needs the latter.
Convert interval_ms to jiffies in the module parameter setter and store it directly in sg_ctx.delay. Initialize the default delay to HZ and remove the redundant interval_ms member and initialization conversion.
Keep the read-only interval_ms parameter by converting the delay back to milliseconds in its getter. Use the same conversion for the startup message. Both now report the effective interval after jiffy rounding.
--- drivers/virt/steal_governor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/virt/steal_governor.c +11 -7
@@ -39,14 +39,13 @@ struct steal_governor {ktime_t time;u64 steal;unsigned long delay; -unsigned int interval_ms;unsigned int high_threshold;unsigned int low_threshold;struct delayed_work work; };static struct steal_governor sg_ctx = { - .interval_ms =1000 ,/* 1 second */ + .delay =HZ ,/* 1 second */ .high_threshold =500 ,/* 5% */ .low_threshold =200 ,/* 2% */ };
@@ -74,15 +73,21 @@ static int param_set_interval_ms(const char *val, const struct kernel_param *kp)return -EINVAL ; } -return param_set_uint (val, kp); + *(unsigned long *)kp->arg =msecs_to_jiffies (interval); +return 0 ; +} + +static int param_get_interval_ms (char *buffer,const struct kernel_param *kp) +{ +return sprintf (buffer,"%u\n" ,jiffies_to_msecs (*(unsigned long *)kp->arg)); }static const struct kernel_param_ops interval_ms_ops = { .set = param_set_interval_ms, - .get = param_get_uint, + .get = param_get_interval_ms, }; -module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.interval_ms,0444 ); +module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.delay,0444 );MODULE_PARM_DESC (interval_ms,"Sampling frequency in milliseconds. default: 1000" );
@@ -270,13 +275,12 @@ static int __init steal_governor_init(void)return -EINVAL ; } - sg_ctx.delay =msecs_to_jiffies (sg_ctx.interval_ms);INIT_DELAYED_WORK (&sg_ctx.work, steal_governor_loop); sg_ctx.steal =get_system_steal_time (); sg_ctx.time =ktime_get ();schedule_delayed_work (&sg_ctx.work, sg_ctx.delay);pr_info ("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n" , - sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); +jiffies_to_msecs (sg_ctx.delay), sg_ctx.high_threshold, sg_ctx.low_threshold);return 0 ; }
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 70fed49a29f0cf3806182f70dfbf450e5d5cbd4e Gitweb: https://git.kernel.org/tip/70fed49a29f0cf3806182f70dfbf450e5d5cbd4e Author: Yury Norov <[email protected]> AuthorDate: Mon, 26 Oct 2026 13:12:51 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 09 Nov 2026 10:58:00 +01:00
virt: steal_governor: store only the sampling delay
The governor stores the sampling interval in both milliseconds and jiffies, although delayed work only needs the latter.
Convert interval_ms to jiffies in the module parameter setter and store it directly in sg_ctx.delay. Initialize the default delay to HZ and remove the redundant interval_ms member and initialization conversion.
Keep the read-only interval_ms parameter by converting the delay back to milliseconds in its getter. Use the same conversion for the startup message. Both now report the effective interval after jiffy rounding.
--- drivers/virt/steal_governor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/virt/steal_governor.c +11 -7
@@ -39,14 +39,13 @@ struct steal_governor {ktime_t time;u64 steal;unsigned long delay; -unsigned int interval_ms;unsigned int high_threshold;unsigned int low_threshold;struct delayed_work work; };static struct steal_governor sg_ctx = { - .interval_ms =1000 ,/* 1 second */ + .delay =HZ ,/* 1 second */ .high_threshold =500 ,/* 5% */ .low_threshold =200 ,/* 2% */ };
@@ -74,15 +73,21 @@ static int param_set_interval_ms(const char *val, const struct kernel_param *kp)return -EINVAL ; } -return param_set_uint (val, kp); + *(unsigned long *)kp->arg =msecs_to_jiffies (interval); +return 0 ; +} + +static int param_get_interval_ms (char *buffer,const struct kernel_param *kp) +{ +return sprintf (buffer,"%u\n" ,jiffies_to_msecs (*(unsigned long *)kp->arg)); }static const struct kernel_param_ops interval_ms_ops = { .set = param_set_interval_ms, - .get = param_get_uint, + .get = param_get_interval_ms, }; -module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.interval_ms,0444 ); +module_param_cb (interval_ms, &interval_ms_ops, &sg_ctx.delay,0444 );MODULE_PARM_DESC (interval_ms,"Sampling frequency in milliseconds. default: 1000" );
@@ -270,13 +275,12 @@ static int __init steal_governor_init(void)return -EINVAL ; } - sg_ctx.delay =msecs_to_jiffies (sg_ctx.interval_ms);INIT_DELAYED_WORK (&sg_ctx.work, steal_governor_loop); sg_ctx.steal =get_system_steal_time (); sg_ctx.time =ktime_get ();schedule_delayed_work (&sg_ctx.work, sg_ctx.delay);pr_info ("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n" , - sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); +jiffies_to_msecs (sg_ctx.delay), sg_ctx.high_threshold, sg_ctx.low_threshold);return 0 ; }