Skip to content

Commit 76d1213

Browse files
Joel FernandesPeter Zijlstra
authored andcommitted
sched/debug: Add support to change sched_ext server params
When a sched_ext server is loaded, tasks in the fair class are automatically moved to the sched_ext class. Add support to modify the ext server parameters similar to how the fair server parameters are modified. Re-use common code between ext and fair servers as needed. Co-developed-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Juri Lelli <juri.lelli@redhat.com> Tested-by: Christian Loehle <christian.loehle@arm.com> Link: https://patch.msgid.link/20260126100050.3854740-6-arighi@nvidia.com
1 parent cd959a3 commit 76d1213

1 file changed

Lines changed: 133 additions & 24 deletions

File tree

kernel/sched/debug.c

Lines changed: 133 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,16 @@ enum dl_param {
330330
DL_PERIOD,
331331
};
332332

333-
static unsigned long fair_server_period_max = (1UL << 22) * NSEC_PER_USEC; /* ~4 seconds */
334-
static unsigned long fair_server_period_min = (100) * NSEC_PER_USEC; /* 100 us */
333+
static unsigned long dl_server_period_max = (1UL << 22) * NSEC_PER_USEC; /* ~4 seconds */
334+
static unsigned long dl_server_period_min = (100) * NSEC_PER_USEC; /* 100 us */
335335

336-
static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubuf,
337-
size_t cnt, loff_t *ppos, enum dl_param param)
336+
static ssize_t sched_server_write_common(struct file *filp, const char __user *ubuf,
337+
size_t cnt, loff_t *ppos, enum dl_param param,
338+
void *server)
338339
{
339340
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
340341
struct rq *rq = cpu_rq(cpu);
342+
struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;
341343
u64 runtime, period;
342344
int retval = 0;
343345
size_t err;
@@ -350,8 +352,8 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubu
350352
scoped_guard (rq_lock_irqsave, rq) {
351353
bool is_active;
352354

353-
runtime = rq->fair_server.dl_runtime;
354-
period = rq->fair_server.dl_period;
355+
runtime = dl_se->dl_runtime;
356+
period = dl_se->dl_period;
355357

356358
switch (param) {
357359
case DL_RUNTIME:
@@ -367,25 +369,25 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubu
367369
}
368370

369371
if (runtime > period ||
370-
period > fair_server_period_max ||
371-
period < fair_server_period_min) {
372+
period > dl_server_period_max ||
373+
period < dl_server_period_min) {
372374
return -EINVAL;
373375
}
374376

375-
is_active = dl_server_active(&rq->fair_server);
377+
is_active = dl_server_active(dl_se);
376378
if (is_active) {
377379
update_rq_clock(rq);
378-
dl_server_stop(&rq->fair_server);
380+
dl_server_stop(dl_se);
379381
}
380382

381-
retval = dl_server_apply_params(&rq->fair_server, runtime, period, 0);
383+
retval = dl_server_apply_params(dl_se, runtime, period, 0);
382384

383385
if (!runtime)
384-
printk_deferred("Fair server disabled in CPU %d, system may crash due to starvation.\n",
385-
cpu_of(rq));
386+
printk_deferred("%s server disabled in CPU %d, system may crash due to starvation.\n",
387+
server == &rq->fair_server ? "Fair" : "Ext", cpu_of(rq));
386388

387389
if (is_active && runtime)
388-
dl_server_start(&rq->fair_server);
390+
dl_server_start(dl_se);
389391

390392
if (retval < 0)
391393
return retval;
@@ -395,36 +397,42 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubu
395397
return cnt;
396398
}
397399

398-
static size_t sched_fair_server_show(struct seq_file *m, void *v, enum dl_param param)
400+
static size_t sched_server_show_common(struct seq_file *m, void *v, enum dl_param param,
401+
void *server)
399402
{
400-
unsigned long cpu = (unsigned long) m->private;
401-
struct rq *rq = cpu_rq(cpu);
403+
struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;
402404
u64 value;
403405

404406
switch (param) {
405407
case DL_RUNTIME:
406-
value = rq->fair_server.dl_runtime;
408+
value = dl_se->dl_runtime;
407409
break;
408410
case DL_PERIOD:
409-
value = rq->fair_server.dl_period;
411+
value = dl_se->dl_period;
410412
break;
411413
}
412414

413415
seq_printf(m, "%llu\n", value);
414416
return 0;
415-
416417
}
417418

418419
static ssize_t
419420
sched_fair_server_runtime_write(struct file *filp, const char __user *ubuf,
420421
size_t cnt, loff_t *ppos)
421422
{
422-
return sched_fair_server_write(filp, ubuf, cnt, ppos, DL_RUNTIME);
423+
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
424+
struct rq *rq = cpu_rq(cpu);
425+
426+
return sched_server_write_common(filp, ubuf, cnt, ppos, DL_RUNTIME,
427+
&rq->fair_server);
423428
}
424429

425430
static int sched_fair_server_runtime_show(struct seq_file *m, void *v)
426431
{
427-
return sched_fair_server_show(m, v, DL_RUNTIME);
432+
unsigned long cpu = (unsigned long) m->private;
433+
struct rq *rq = cpu_rq(cpu);
434+
435+
return sched_server_show_common(m, v, DL_RUNTIME, &rq->fair_server);
428436
}
429437

430438
static int sched_fair_server_runtime_open(struct inode *inode, struct file *filp)
@@ -440,16 +448,57 @@ static const struct file_operations fair_server_runtime_fops = {
440448
.release = single_release,
441449
};
442450

451+
#ifdef CONFIG_SCHED_CLASS_EXT
452+
static ssize_t
453+
sched_ext_server_runtime_write(struct file *filp, const char __user *ubuf,
454+
size_t cnt, loff_t *ppos)
455+
{
456+
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
457+
struct rq *rq = cpu_rq(cpu);
458+
459+
return sched_server_write_common(filp, ubuf, cnt, ppos, DL_RUNTIME,
460+
&rq->ext_server);
461+
}
462+
463+
static int sched_ext_server_runtime_show(struct seq_file *m, void *v)
464+
{
465+
unsigned long cpu = (unsigned long) m->private;
466+
struct rq *rq = cpu_rq(cpu);
467+
468+
return sched_server_show_common(m, v, DL_RUNTIME, &rq->ext_server);
469+
}
470+
471+
static int sched_ext_server_runtime_open(struct inode *inode, struct file *filp)
472+
{
473+
return single_open(filp, sched_ext_server_runtime_show, inode->i_private);
474+
}
475+
476+
static const struct file_operations ext_server_runtime_fops = {
477+
.open = sched_ext_server_runtime_open,
478+
.write = sched_ext_server_runtime_write,
479+
.read = seq_read,
480+
.llseek = seq_lseek,
481+
.release = single_release,
482+
};
483+
#endif /* CONFIG_SCHED_CLASS_EXT */
484+
443485
static ssize_t
444486
sched_fair_server_period_write(struct file *filp, const char __user *ubuf,
445487
size_t cnt, loff_t *ppos)
446488
{
447-
return sched_fair_server_write(filp, ubuf, cnt, ppos, DL_PERIOD);
489+
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
490+
struct rq *rq = cpu_rq(cpu);
491+
492+
return sched_server_write_common(filp, ubuf, cnt, ppos, DL_PERIOD,
493+
&rq->fair_server);
448494
}
449495

450496
static int sched_fair_server_period_show(struct seq_file *m, void *v)
451497
{
452-
return sched_fair_server_show(m, v, DL_PERIOD);
498+
unsigned long cpu = (unsigned long) m->private;
499+
struct rq *rq = cpu_rq(cpu);
500+
501+
return sched_server_show_common(m, v, DL_PERIOD, &rq->fair_server);
453502
}
454503

455504
static int sched_fair_server_period_open(struct inode *inode, struct file *filp)
@@ -465,6 +514,40 @@ static const struct file_operations fair_server_period_fops = {
465514
.release = single_release,
466515
};
467516

517+
#ifdef CONFIG_SCHED_CLASS_EXT
518+
static ssize_t
519+
sched_ext_server_period_write(struct file *filp, const char __user *ubuf,
520+
size_t cnt, loff_t *ppos)
521+
{
522+
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
523+
struct rq *rq = cpu_rq(cpu);
524+
525+
return sched_server_write_common(filp, ubuf, cnt, ppos, DL_PERIOD,
526+
&rq->ext_server);
527+
}
528+
529+
static int sched_ext_server_period_show(struct seq_file *m, void *v)
530+
{
531+
unsigned long cpu = (unsigned long) m->private;
532+
struct rq *rq = cpu_rq(cpu);
533+
534+
return sched_server_show_common(m, v, DL_PERIOD, &rq->ext_server);
535+
}
536+
537+
static int sched_ext_server_period_open(struct inode *inode, struct file *filp)
538+
{
539+
return single_open(filp, sched_ext_server_period_show, inode->i_private);
540+
}
541+
542+
static const struct file_operations ext_server_period_fops = {
543+
.open = sched_ext_server_period_open,
544+
.write = sched_ext_server_period_write,
545+
.read = seq_read,
546+
.llseek = seq_lseek,
547+
.release = single_release,
548+
};
549+
#endif /* CONFIG_SCHED_CLASS_EXT */
550+
468551
static struct dentry *debugfs_sched;
469552

470553
static void debugfs_fair_server_init(void)
@@ -488,6 +571,29 @@ static void debugfs_fair_server_init(void)
488571
}
489572
}
490573

574+
#ifdef CONFIG_SCHED_CLASS_EXT
575+
static void debugfs_ext_server_init(void)
576+
{
577+
struct dentry *d_ext;
578+
unsigned long cpu;
579+
580+
d_ext = debugfs_create_dir("ext_server", debugfs_sched);
581+
if (!d_ext)
582+
return;
583+
584+
for_each_possible_cpu(cpu) {
585+
struct dentry *d_cpu;
586+
char buf[32];
587+
588+
snprintf(buf, sizeof(buf), "cpu%lu", cpu);
589+
d_cpu = debugfs_create_dir(buf, d_ext);
590+
591+
debugfs_create_file("runtime", 0644, d_cpu, (void *) cpu, &ext_server_runtime_fops);
592+
debugfs_create_file("period", 0644, d_cpu, (void *) cpu, &ext_server_period_fops);
593+
}
594+
}
595+
#endif /* CONFIG_SCHED_CLASS_EXT */
596+
491597
static __init int sched_init_debug(void)
492598
{
493599
struct dentry __maybe_unused *numa;
@@ -526,6 +632,9 @@ static __init int sched_init_debug(void)
526632
debugfs_create_file("debug", 0444, debugfs_sched, NULL, &sched_debug_fops);
527633

528634
debugfs_fair_server_init();
635+
#ifdef CONFIG_SCHED_CLASS_EXT
636+
debugfs_ext_server_init();
637+
#endif
529638

530639
return 0;
531640
}

0 commit comments

Comments
 (0)