Re: O(1) count_active_tasks()

Robert Love (rml@tech9.net)
26 May 2002 15:17:52 -0700


On Sat, 2002-05-25 at 20:51, William Lee Irwin III wrote:
> rml, I heard you're interested in this, but regardless, here it is.
> AFAICT it computes a faithful load average. Against latest 2.5.18 bk.
> rml, don't worry about stomping on this if you need the counters
> ticking for something else and you can do the same thing(s).

I like. Very clean.

One question...

> rq = task_rq_lock(p, &flags);
> + if (p->state == TASK_UNINTERRUPTIBLE)
> + uninterruptible = 1;
> p->state = TASK_RUNNING;
> if (!p->array) {
> + if (uninterruptible)
> + rq->nr_uninterruptible--;
> activate_task(p, rq);
> if (p->prio < rq->curr->prio)
> resched_task(rq->curr);

Why only decrement nr_uninterruptible if it is not already on a
runqueue? I suspect because then you assume it is a spurious wakeup and
did not have a corresponding deactivate_task? Same reason we increment
nr_running in activate_task and not here, I suspect... makes sense.

One thought on a quick way to test if the new method is returning
accurate results would be to leave the current count_active_task code
and then add:

if (nr != (nr_running() + nr_uninterruptible()))
printk("Danger Will Robinson!\n");

but you probably already did something similar.

Robert Love

-
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/