lkml.org 
[lkml]   [2006]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: [Patch 2/7] Add sysctl for schedstats

    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 majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2006-02-27 09:55    [W:4.143 / U:0.392 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site