On 02/08/2016 21:22, Emilio G. Cota wrote: > An alternative is to have a separate lock for safe work, and check for > safe work once there are no other locks held; a good place to do this is > at the beginning of cpu_loop_exec. This scales better, and I'd argue > it's simpler. In fact, I posted a patch that does this about a year > ago (!): > https://lists.nongnu.org/archive/html/qemu-devel/2015-08/msg02576.html
I like the idea. > Paolo didn't like condvars, but now I see them coming up again. I guess > he still won't like the synchronize_rcu() call in there, and I don't like > it either, but I don't think that's an essential part of that patch. The problem with CPUs coming up late is indeed present in this patch, I'll review your patch on the flight. :) synchronize_rcu() is actually relatively cheap with URCU, so I guess that's fine. An alternative to that could be a pthread_barrier_t, but it can be added later. Another way to fix the issue with a variable number of waiters could be to wrap safe work with rcu_read_lock and rcu_read_unlock, and put a synchronize_rcu() at the beginning of the CPU thread function. But it can be done later too. Your patch from a year ago, right now, seems to be the best to me. I'd like to make it use regular work items instead of the special cpu->tcg_work_func, but that's pretty much it. Paolo