--- ./fs/proc/proc_misc.c.iow1	2006-05-29 22:04:54.000000000 +0400
+++ ./fs/proc/proc_misc.c	2006-05-29 22:05:18.000000000 +0400
@@ -523,7 +523,7 @@ int show_stat(struct seq_file *p, void *
 	else {
 		show_stat_ve(p, env);
 		__nr_running = nr_running_ve(env);
-		__nr_iowait = nr_iowait_ve(env);
+		__nr_iowait = nr_iowait_ve();
 	}
 #endif
 
--- ./include/linux/sched.h.iow1	2006-05-29 22:04:54.000000000 +0400
+++ ./include/linux/sched.h	2006-05-29 22:05:18.000000000 +0400
@@ -112,7 +112,7 @@ extern unsigned long nr_iowait(void);
 #ifdef CONFIG_VE
 struct ve_struct;
 extern unsigned long nr_running_ve(struct ve_struct *);
-extern unsigned long nr_iowait_ve(struct ve_struct *);
+extern unsigned long nr_iowait_ve(void);
 extern unsigned long nr_uninterruptible_ve(struct ve_struct *);
 #endif
 
--- ./include/linux/ve.h.iow1	2006-05-29 22:04:54.000000000 +0400
+++ ./include/linux/ve.h	2006-05-29 22:05:18.000000000 +0400
@@ -106,7 +106,6 @@ struct ve_cpu_stats {
 	seqcount_t	stat_lock;
 	int		nr_running;
 	int		nr_unint;
-	int		nr_iowait;
 	u64		user;
 	u64		nice;
 	u64		system;
--- ./kernel/sched.c.iow1	2006-05-29 22:05:07.000000000 +0400
+++ ./kernel/sched.c	2006-05-29 22:06:33.000000000 +0400
@@ -427,7 +427,7 @@ static inline void set_task_vcpu(struct 
 }
 
 
-#ifdef CONFIG_VE
+#if defined(CONFIG_VE) && defined(CONFIG_SCHED_VCPU)
 #define cycles_after(a, b)	((long long)(b) - (long long)(a) < 0)
 
 cycles_t ve_sched_get_idle_time(struct ve_struct *ve, int cpu)
@@ -450,18 +450,20 @@ cycles_t ve_sched_get_idle_time(struct v
 	return ret;
 }
 
-cycles_t ve_sched_get_iowait_time(struct ve_struct *ve, int cpu)
+cycles_t ve_sched_get_iowait_time(struct ve_struct *ve, int vcpu)
 {
 	struct ve_cpu_stats *ve_stat;
 	unsigned v;
 	cycles_t strt, ret, cycles;
 
-	ve_stat = VE_CPU_STATS(ve, cpu);
+	ve_stat = VE_CPU_STATS(ve, vcpu);
 	do {
+		struct runqueue *rq;
+		rq = vcpu_rq(vsched_vcpu(this_vsched(), vcpu));
 		v = read_seqcount_begin(&ve_stat->stat_lock);
 		ret = ve_stat->iowait_time;
 		strt = ve_stat->strt_idle_time;
-		if (strt && nr_iowait_ve(ve) > 0) {
+		if (strt && atomic_read(&rq->nr_iowait) > 0) {
 			cycles = get_cycles();
 			if (cycles_after(cycles, strt))
 				ret += cycles - strt;
@@ -471,16 +473,16 @@ cycles_t ve_sched_get_iowait_time(struct
 }
 
 static inline void vcpu_save_ve_idle(struct ve_struct *ve,
-		unsigned int vcpu, cycles_t cycles)
+		vcpu_t vcpu, cycles_t cycles)
 {
 	struct ve_cpu_stats *ve_stat;
 
-	ve_stat = VE_CPU_STATS(ve, vcpu);
+	ve_stat = VE_CPU_STATS(ve, vcpu->id);
 
 	write_seqcount_begin(&ve_stat->stat_lock);
 	if (ve_stat->strt_idle_time) {
 		if (cycles_after(cycles, ve_stat->strt_idle_time)) {
-			if (nr_iowait_ve(ve) == 0)
+			if (atomic_read(&vcpu_rq(vcpu)->nr_iowait) == 0)
 				ve_stat->idle_time += cycles -
 					ve_stat->strt_idle_time;
 			else
@@ -825,11 +827,9 @@ EXPORT_SYMBOL(nr_dead);
 
 #define nr_iowait_inc(cpu, vcpu, ve) do {			\
 		glob_tasks_nrs[cpu].nr_iowait++;		\
-		ve_nr_iowait_inc(ve, vcpu);			\
 	} while (0)
 #define nr_iowait_dec(cpu, vcpu, ve) do {			\
 		glob_tasks_nrs[cpu].nr_iowait--;		\
-		ve_nr_iowait_dec(ve, vcpu);			\
 	} while (0)
 
 #define nr_stopped_inc(cpu, vcpu, ve) do {			\
@@ -983,7 +983,7 @@ static inline void __activate_task(task_
 	enqueue_task(p, rq->active);
 	rq->nr_running++;
 	if (rq->nr_running == 1) {
-		vcpu_save_ve_idle(ve, vcpu, cycles);
+		vcpu_save_ve_idle(ve, task_vcpu(p), cycles);
 		vcpu_attach(rq);
 	}
 }
@@ -1918,14 +1918,21 @@ unsigned long nr_uninterruptible_ve(stru
 	return (unsigned long)(sum < 0 ? 0 : sum);
 }
 
-unsigned long nr_iowait_ve(struct ve_struct *ve)
+unsigned long nr_iowait_ve(void)
 {
 	int i;
 	long sum;
+	struct vcpu_scheduler *vsched;
 
 	sum = 0;
-	for (i = 0; i < NR_CPUS; i++)
-		sum += VE_CPU_STATS(ve, i)->nr_iowait;
+#ifdef CONFIG_SCHED_VCPU
+	vsched = this_vsched();
+	for_each_cpu_mask(i, vsched_vcpu_online_map(vsched)) {
+		struct runqueue *rq;
+		rq = vcpu_rq(vsched_vcpu(vsched, i));
+		sum += atomic_read(&rq->nr_iowait);
+	}
+#endif
 	return (unsigned long)(sum < 0 ? 0 : sum);
 }
 #endif
@@ -2221,7 +2228,7 @@ void pull_task(runqueue_t *src_rq, prio_
 	set_task_vcpu(p, this_cpu);
 	this_rq->nr_running++;
 	if (this_rq->nr_running == 1) {
-		vcpu_save_ve_idle(ve, this_cpu->id, cycles);
+		vcpu_save_ve_idle(ve, this_cpu, cycles);
 		vcpu_attach(this_rq);
 	}
 	enqueue_task(p, this_array);
@@ -2975,7 +2982,7 @@ void scheduler_tick(int user_ticks, int 
 		sys_ticks = 0;
 	}
 	if (p == pcpu(cpu)->idle) {
-		if (atomic_read(&rq->nr_iowait) > 0)
+		if (glob_tasks_nrs[cpu].nr_iowait > 0)
 			cpustat->iowait += sys_ticks;
 		else
 			cpustat->idle += sys_ticks;
