On 31/03/2016 16:35, Sergey Fedorov wrote: >> > My plan was to use some kind of double buffering, where only half of >> > code_gen_buffer is in use. At the end of tb_flush you call cpu_exit() >> > on all CPUs, so that CPUs stop executing chained TBs from the old half >> > before they can see one from the new half. >> > >> > If code_gen_buffer is static you have to preallocate two buffers (and >> > two tbs arrays) and waste one of them; while it is theoretically >> > possible to have CPUs still executing from the old half while you finish >> > the new half, it can be more or less ignored. >> > >> > If it is dynamic, the previously used areas can be freed with call_rcu, >> > and you can safely allocate a new code_gen_buffer and tbs array. >> > >> > I haven't thought much about it; it might require keeping a cache of the >> > tbs array per CPU, and possibly changing the code under "if >> > (tcg_ctx.tb_ctx.tb_invalidated_flag)" to simply exit cpu_exec. > Maybe save this idea for latter? :) We'd better use a simpler approach > at first and then move on and optimize. BTW, a few years ago I came > across an interesting paper on code cache eviction granularities [1].
It depends on what is simpler. Emilio and Fred's code was tricky and touched the central CPU execution loop in cpus.c. Paolo