On Wed, Jun 13, 2018 at 11:26:41AM +0100, Dr. David Alan Gilbert (git) wrote:
[...] > @@ -2932,10 +2943,24 @@ static void *migration_thread(void *opaque) > > migration_update_counters(s, current_time); > > + urgent = false; > if (qemu_file_rate_limit(s->to_dst_file)) { > - /* usleep expects microseconds */ > - g_usleep((s->iteration_start_time + BUFFER_DELAY - > - current_time) * 1000); > + /* Wait for a delay to do rate limiting OR > + * something urgent to post the semaphore. > + */ > + int ms = s->iteration_start_time + BUFFER_DELAY - current_time; > + trace_migration_thread_ratelimit_pre(ms); > + if (qemu_sem_timedwait(&s->rate_limit_sem, ms) == 0) { > + /* We were worken by one or more urgent things but > + * the timedwait will have consumed one of them. > + * The service routine for the urgent wake will dec > + * the semaphore itself for each item it consumes, > + * so add this one we just eat back. > + */ > + qemu_sem_post(&s->rate_limit_sem); Is it possible that we just avoid eating that in the next patch? Then we only provide a helper to "trigger an urgent request" but we only consume the point here? -- Peter Xu