the principle looks OK to me, just a few minor nits:
> #ifdef CONFIG_SCHEDSTATS
> +
> +int schedstats_sysctl = 0; /* schedstats turned off by default */
no need to initialize to 0.
> +static DEFINE_PER_CPU(int, schedstats) = 0;
ditto.
> +
> +static void schedstats_set(int val)
> +{
> + int i;
> + static spinlock_t schedstats_lock = SPIN_LOCK_UNLOCKED;
move spinlock out of the function and use DEFINE_SPINLOCK. (But ... see
below for suggestion to get rid of this lock altogether.)
> + spin_lock(&schedstats_lock);
> + schedstats_sysctl = val;
> + for (i = 0; i < NR_CPUS; i++)
> + per_cpu(schedstats, i) = val;
> + spin_unlock(&schedstats_lock);
> +}
> +
> +static int __init schedstats_setup_enable(char *str)
> +{
> + schedstats_sysctl = 1;
> + schedstats_set(schedstats_sysctl);
> + return 1;
> +}
> +
> +__setup("schedstats", schedstats_setup_enable);
> +
> +int schedstats_sysctl_handler(ctl_table *table, int write, struct file *filp,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> +{
> + int ret, prev = schedstats_sysctl;
> + struct task_struct *g, *t;
> +
> + ret = proc_dointvec(table, write, filp, buffer, lenp, ppos);
> + if ((ret != 0) || (prev == schedstats_sysctl))
> + return ret;
> + if (schedstats_sysctl) {
> + read_lock(&tasklist_lock);
> + do_each_thread(g, t) {
> + memset(&t->sched_info, 0, sizeof(t->sched_info));
> + } while_each_thread(g, t);
> + read_unlock(&tasklist_lock);
> + }
> + schedstats_set(schedstats_sysctl);
why not just introduce a schedstats_lock mutex, and acquire it for both
the 'if (schedstats_sysctl)' line and the schedstats_set() line. That
will make the locking meaningful: two parallel sysctl ops will be atomic
to each other. [right now they wont be and they can clear schedstat data
in parallel -> not a big problem but it makes schedstats_lock rather
meaningless]
> -#define SCHEDSTAT_VERSION 12
> +#define SCHEDSTAT_VERSION 13
>
> static int show_schedstat(struct seq_file *seq, void *v)
> {
> @@ -394,6 +439,10 @@ static int show_schedstat(struct seq_fil
>
> seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION);
> seq_printf(seq, "timestamp %lu\n", jiffies);
> + if (!schedstats_sysctl) {
> + seq_printf(seq, "State Off\n");
> + return 0;
> + }
and show_schedstat() should then also take the schedstats_lock mutex.
Ingo
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]