On 08/16, Frederic Weisbecker wrote: > > On Fri, Aug 16, 2013 at 06:02:01PM +0200, Oleg Nesterov wrote: > > > + do { > > > + seq = read_seqcount_begin(&ts->sleeptime_seq); > > > + if (ts->idle_active && nr_iowait_cpu(cpu) > 0) { > > > + ktime_t delta = ktime_sub(now, ts->idle_entrytime); > > > + iowait = ktime_add(ts->iowait_sleeptime, delta); > > > + } else { > > > + iowait = ts->iowait_sleeptime; > > > + } > > > + } while (read_seqcount_retry(&ts->sleeptime_seq, seq)); > > > > Unless I missread this patch, this is still racy a bit. > > > > Suppose it is called on CPU_0 and cpu == 1. Suppose that > > ts->idle_active == T and nr_iowait_cpu(cpu) == 1. > > > > So we return iowait_sleeptime + delta. > > > > Suppose that we call get_cpu_iowait_time_us() again. By this time > > the task which incremented ->nr_iowait can be woken up on another > > CPU, and it can do atomic_dec(rq->nr_iowait). So the next time > > we return iowait_sleeptime, and this is not monotonic again. > > Hmm, by the time it decrements nr_iowait, it returned from schedule() and > so idle had flushed the pending iowait sleeptime.
Suppose a task does io_schedule() on CPU_0, and increments the counter. This CPU becomes idle and nr_iowait_cpu(0) == 1. Then this task is woken up, but try_to_wake_up() selects another CPU != 0. It returns from schedule() and decrements the same counter, it doesn't do raw_rq/etc again. nr_iowait_cpu(0) becomes 0. In fact the task can even migrate to another CPU right after raw_rq(). > May be you have some scenario in mind that I'm missing? Or me... Oleg. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/