Skip to content

Commit 43e33f5

Browse files
htejunPeter Zijlstra
authored andcommitted
sched/core: Reorganize cgroup bandwidth control interface file reads
- Update tg_get_cfs_*() to return u64 values. These are now used as the low level accessors to the fair's bandwidth configuration parameters. Translation to usecs takes place in these functions. - Add tg_bandwidth() which reads all three bandwidth parameters using tg_get_cfs_*(). - Reimplement cgroup interface read functions using tg_bandwidth(). Drop cfs from the function names. This is to prepare for adding bandwidth control support to sched_ext. tg_bandwidth() will be used as the muxing point similar to tg_weight(). No functional changes. Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent de4c80c commit 43e33f5

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

kernel/sched/core.c

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9404,7 +9404,7 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
94049404
return 0;
94059405
}
94069406

9407-
static long tg_get_cfs_period(struct task_group *tg)
9407+
static u64 tg_get_cfs_period(struct task_group *tg)
94089408
{
94099409
u64 cfs_period_us;
94109410

@@ -9414,20 +9414,20 @@ static long tg_get_cfs_period(struct task_group *tg)
94149414
return cfs_period_us;
94159415
}
94169416

9417-
static long tg_get_cfs_quota(struct task_group *tg)
9417+
static u64 tg_get_cfs_quota(struct task_group *tg)
94189418
{
94199419
u64 quota_us;
94209420

94219421
if (tg->cfs_bandwidth.quota == RUNTIME_INF)
9422-
return -1;
9422+
return RUNTIME_INF;
94239423

94249424
quota_us = tg->cfs_bandwidth.quota;
94259425
do_div(quota_us, NSEC_PER_USEC);
94269426

94279427
return quota_us;
94289428
}
94299429

9430-
static long tg_get_cfs_burst(struct task_group *tg)
9430+
static u64 tg_get_cfs_burst(struct task_group *tg)
94319431
{
94329432
u64 burst_us;
94339433

@@ -9614,22 +9614,42 @@ static int cpu_cfs_local_stat_show(struct seq_file *sf, void *v)
96149614
return 0;
96159615
}
96169616

9617-
static u64 cpu_cfs_period_read_u64(struct cgroup_subsys_state *css,
9618-
struct cftype *cft)
9617+
static void tg_bandwidth(struct task_group *tg,
9618+
u64 *period_us_p, u64 *quota_us_p, u64 *burst_us_p)
96199619
{
9620-
return tg_get_cfs_period(css_tg(css));
9620+
if (period_us_p)
9621+
*period_us_p = tg_get_cfs_period(tg);
9622+
if (quota_us_p)
9623+
*quota_us_p = tg_get_cfs_quota(tg);
9624+
if (burst_us_p)
9625+
*burst_us_p = tg_get_cfs_burst(tg);
96219626
}
96229627

9623-
static s64 cpu_cfs_quota_read_s64(struct cgroup_subsys_state *css,
9624-
struct cftype *cft)
9628+
static u64 cpu_period_read_u64(struct cgroup_subsys_state *css,
9629+
struct cftype *cft)
96259630
{
9626-
return tg_get_cfs_quota(css_tg(css));
9631+
u64 period_us;
9632+
9633+
tg_bandwidth(css_tg(css), &period_us, NULL, NULL);
9634+
return period_us;
96279635
}
96289636

9629-
static u64 cpu_cfs_burst_read_u64(struct cgroup_subsys_state *css,
9630-
struct cftype *cft)
9637+
static s64 cpu_quota_read_s64(struct cgroup_subsys_state *css,
9638+
struct cftype *cft)
96319639
{
9632-
return tg_get_cfs_burst(css_tg(css));
9640+
u64 quota_us;
9641+
9642+
tg_bandwidth(css_tg(css), NULL, &quota_us, NULL);
9643+
return quota_us; /* (s64)RUNTIME_INF becomes -1 */
9644+
}
9645+
9646+
static u64 cpu_burst_read_u64(struct cgroup_subsys_state *css,
9647+
struct cftype *cft)
9648+
{
9649+
u64 burst_us;
9650+
9651+
tg_bandwidth(css_tg(css), NULL, NULL, &burst_us);
9652+
return burst_us;
96339653
}
96349654

96359655
static int cpu_cfs_period_write_u64(struct cgroup_subsys_state *css,
@@ -9712,17 +9732,17 @@ static struct cftype cpu_legacy_files[] = {
97129732
#ifdef CONFIG_CFS_BANDWIDTH
97139733
{
97149734
.name = "cfs_period_us",
9715-
.read_u64 = cpu_cfs_period_read_u64,
9735+
.read_u64 = cpu_period_read_u64,
97169736
.write_u64 = cpu_cfs_period_write_u64,
97179737
},
97189738
{
97199739
.name = "cfs_quota_us",
9720-
.read_s64 = cpu_cfs_quota_read_s64,
9740+
.read_s64 = cpu_quota_read_s64,
97219741
.write_s64 = cpu_cfs_quota_write_s64,
97229742
},
97239743
{
97249744
.name = "cfs_burst_us",
9725-
.read_u64 = cpu_cfs_burst_read_u64,
9745+
.read_u64 = cpu_burst_read_u64,
97269746
.write_u64 = cpu_cfs_burst_write_u64,
97279747
},
97289748
{
@@ -9944,8 +9964,10 @@ static int __maybe_unused cpu_period_quota_parse(char *buf,
99449964
static int cpu_max_show(struct seq_file *sf, void *v)
99459965
{
99469966
struct task_group *tg = css_tg(seq_css(sf));
9967+
u64 period_us, quota_us;
99479968

9948-
cpu_period_quota_print(sf, tg_get_cfs_period(tg), tg_get_cfs_quota(tg));
9969+
tg_bandwidth(tg, &period_us, &quota_us, NULL);
9970+
cpu_period_quota_print(sf, period_us, quota_us);
99499971
return 0;
99509972
}
99519973

@@ -9996,7 +10018,7 @@ static struct cftype cpu_files[] = {
999610018
{
999710019
.name = "max.burst",
999810020
.flags = CFTYPE_NOT_ON_ROOT,
9999-
.read_u64 = cpu_cfs_burst_read_u64,
10021+
.read_u64 = cpu_burst_read_u64,
1000010022
.write_u64 = cpu_cfs_burst_write_u64,
1000110023
},
1000210024
#endif /* CONFIG_CFS_BANDWIDTH */

0 commit comments

Comments
 (0)