Skip to content

Commit 1011dcc

Browse files
author
Peter Zijlstra
committed
sched,preempt: Move preempt_dynamic to debug.c
Move the #ifdef SCHED_DEBUG bits to kernel/sched/debug.c in order to collect all the debugfs bits. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Valentin Schneider <valentin.schneider@arm.com> Link: https://lkml.kernel.org/r/20210412102001.353833279@infradead.org
1 parent 8a99b68 commit 1011dcc

3 files changed

Lines changed: 78 additions & 77 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5371,9 +5371,9 @@ enum {
53715371
preempt_dynamic_full,
53725372
};
53735373

5374-
static int preempt_dynamic_mode = preempt_dynamic_full;
5374+
int preempt_dynamic_mode = preempt_dynamic_full;
53755375

5376-
static int sched_dynamic_mode(const char *str)
5376+
int sched_dynamic_mode(const char *str)
53775377
{
53785378
if (!strcmp(str, "none"))
53795379
return preempt_dynamic_none;
@@ -5387,7 +5387,7 @@ static int sched_dynamic_mode(const char *str)
53875387
return -EINVAL;
53885388
}
53895389

5390-
static void sched_dynamic_update(int mode)
5390+
void sched_dynamic_update(int mode)
53915391
{
53925392
/*
53935393
* Avoid {NONE,VOLUNTARY} -> FULL transitions from ever ending up in
@@ -5444,79 +5444,8 @@ static int __init setup_preempt_mode(char *str)
54445444
}
54455445
__setup("preempt=", setup_preempt_mode);
54465446

5447-
#ifdef CONFIG_SCHED_DEBUG
5448-
5449-
static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf,
5450-
size_t cnt, loff_t *ppos)
5451-
{
5452-
char buf[16];
5453-
int mode;
5454-
5455-
if (cnt > 15)
5456-
cnt = 15;
5457-
5458-
if (copy_from_user(&buf, ubuf, cnt))
5459-
return -EFAULT;
5460-
5461-
buf[cnt] = 0;
5462-
mode = sched_dynamic_mode(strstrip(buf));
5463-
if (mode < 0)
5464-
return mode;
5465-
5466-
sched_dynamic_update(mode);
5467-
5468-
*ppos += cnt;
5469-
5470-
return cnt;
5471-
}
5472-
5473-
static int sched_dynamic_show(struct seq_file *m, void *v)
5474-
{
5475-
static const char * preempt_modes[] = {
5476-
"none", "voluntary", "full"
5477-
};
5478-
int i;
5479-
5480-
for (i = 0; i < ARRAY_SIZE(preempt_modes); i++) {
5481-
if (preempt_dynamic_mode == i)
5482-
seq_puts(m, "(");
5483-
seq_puts(m, preempt_modes[i]);
5484-
if (preempt_dynamic_mode == i)
5485-
seq_puts(m, ")");
5486-
5487-
seq_puts(m, " ");
5488-
}
5489-
5490-
seq_puts(m, "\n");
5491-
return 0;
5492-
}
5493-
5494-
static int sched_dynamic_open(struct inode *inode, struct file *filp)
5495-
{
5496-
return single_open(filp, sched_dynamic_show, NULL);
5497-
}
5498-
5499-
static const struct file_operations sched_dynamic_fops = {
5500-
.open = sched_dynamic_open,
5501-
.write = sched_dynamic_write,
5502-
.read = seq_read,
5503-
.llseek = seq_lseek,
5504-
.release = single_release,
5505-
};
5506-
5507-
extern struct dentry *debugfs_sched;
5508-
5509-
static __init int sched_init_debug_dynamic(void)
5510-
{
5511-
debugfs_create_file("sched_preempt", 0644, debugfs_sched, NULL, &sched_dynamic_fops);
5512-
return 0;
5513-
}
5514-
late_initcall(sched_init_debug_dynamic);
5515-
5516-
#endif /* CONFIG_SCHED_DEBUG */
55175447
#endif /* CONFIG_PREEMPT_DYNAMIC */
55185448

5519-
55205449
/*
55215450
* This is the entry point to schedule() from kernel preemption
55225451
* off of irq context.

‎kernel/sched/debug.c‎

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,71 @@ static const struct file_operations sched_scaling_fops = {
213213

214214
#endif /* SMP */
215215

216+
#ifdef CONFIG_PREEMPT_DYNAMIC
217+
218+
static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf,
219+
size_t cnt, loff_t *ppos)
220+
{
221+
char buf[16];
222+
int mode;
223+
224+
if (cnt > 15)
225+
cnt = 15;
226+
227+
if (copy_from_user(&buf, ubuf, cnt))
228+
return -EFAULT;
229+
230+
buf[cnt] = 0;
231+
mode = sched_dynamic_mode(strstrip(buf));
232+
if (mode < 0)
233+
return mode;
234+
235+
sched_dynamic_update(mode);
236+
237+
*ppos += cnt;
238+
239+
return cnt;
240+
}
241+
242+
static int sched_dynamic_show(struct seq_file *m, void *v)
243+
{
244+
static const char * preempt_modes[] = {
245+
"none", "voluntary", "full"
246+
};
247+
int i;
248+
249+
for (i = 0; i < ARRAY_SIZE(preempt_modes); i++) {
250+
if (preempt_dynamic_mode == i)
251+
seq_puts(m, "(");
252+
seq_puts(m, preempt_modes[i]);
253+
if (preempt_dynamic_mode == i)
254+
seq_puts(m, ")");
255+
256+
seq_puts(m, " ");
257+
}
258+
259+
seq_puts(m, "\n");
260+
return 0;
261+
}
262+
263+
static int sched_dynamic_open(struct inode *inode, struct file *filp)
264+
{
265+
return single_open(filp, sched_dynamic_show, NULL);
266+
}
267+
268+
static const struct file_operations sched_dynamic_fops = {
269+
.open = sched_dynamic_open,
270+
.write = sched_dynamic_write,
271+
.read = seq_read,
272+
.llseek = seq_lseek,
273+
.release = single_release,
274+
};
275+
276+
#endif /* CONFIG_PREEMPT_DYNAMIC */
277+
216278
__read_mostly bool sched_debug_enabled;
217279

218-
struct dentry *debugfs_sched;
280+
static struct dentry *debugfs_sched;
219281

220282
static __init int sched_init_debug(void)
221283
{
@@ -225,6 +287,9 @@ static __init int sched_init_debug(void)
225287

226288
debugfs_create_file("features", 0644, debugfs_sched, NULL, &sched_feat_fops);
227289
debugfs_create_bool("debug_enabled", 0644, debugfs_sched, &sched_debug_enabled);
290+
#ifdef CONFIG_PREEMPT_DYNAMIC
291+
debugfs_create_file("preempt", 0644, debugfs_sched, NULL, &sched_dynamic_fops);
292+
#endif
228293

229294
debugfs_create_u32("latency_ns", 0644, debugfs_sched, &sysctl_sched_latency);
230295
debugfs_create_u32("min_granularity_ns", 0644, debugfs_sched, &sysctl_sched_min_granularity);

‎kernel/sched/sched.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,5 +2734,12 @@ static inline bool is_per_cpu_kthread(struct task_struct *p)
27342734
}
27352735
#endif
27362736

2737-
void swake_up_all_locked(struct swait_queue_head *q);
2738-
void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
2737+
extern void swake_up_all_locked(struct swait_queue_head *q);
2738+
extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
2739+
2740+
#ifdef CONFIG_PREEMPT_DYNAMIC
2741+
extern int preempt_dynamic_mode;
2742+
extern int sched_dynamic_mode(const char *str);
2743+
extern void sched_dynamic_update(int mode);
2744+
#endif
2745+

0 commit comments

Comments
 (0)