Re: [Qemu-devel] [PATCH 05/10] tcg: Prepare TB invalidation for lockless TB lookup

2016-07-21 Thread Sergey Fedorov
On 21/07/16 14:25, Paolo Bonzini wrote: > > - Original Message - >> From: "Sergey Fedorov" >> To: "Paolo Bonzini" >> Cc: qemu-devel@nongnu.org, "sergey fedorov" , >> "alex bennee" >> Sent: Thursday, July 21,

Re: [Qemu-devel] [PATCH 05/10] tcg: Prepare TB invalidation for lockless TB lookup

2016-07-21 Thread Sergey Fedorov
On 20/07/16 01:27, Paolo Bonzini wrote: > > - Original Message - >> From: "Sergey Fedorov" >> To: "Paolo Bonzini" , qemu-devel@nongnu.org >> Cc: "sergey fedorov" , "alex bennee" >> >> Sent: Tuesday, July 19, 20

Re: [Qemu-devel] [PATCH 05/10] tcg: Prepare TB invalidation for lockless TB lookup

2016-07-19 Thread Sergey Fedorov
27; but before calling > tb_add_jump() since TB lookup is to be performed out of 'tb_lock' in > future. Note that we don't have to check 'last_tb'; an already invalidated > TB will not be executed anyway and it is thus safe to patch it. > > Suggested-by: Serge

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
On 18/07/16 20:58, Paolo Bonzini wrote: > > On 18/07/2016 19:31, Sergey Fedorov wrote: >> On 18/07/16 20:28, Paolo Bonzini wrote: >>> On 18/07/2016 19:25, Sergey Fedorov wrote: >>>>>> @@ -753,14 +753,14 @@ static inline void >>>&

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
On 18/07/16 20:28, Paolo Bonzini wrote: > > On 18/07/2016 19:25, Sergey Fedorov wrote: >>>> @@ -753,14 +753,14 @@ static inline void >>>> cpu_get_invalid_tb_cpu_state(target_ulong *pc, >>>>

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
On 18/07/16 20:00, Paolo Bonzini wrote: > > On 18/07/2016 18:57, Sergey Fedorov wrote: >> On 18/07/16 19:53, Paolo Bonzini wrote: >>> On 18/07/2016 18:52, Sergey Fedorov wrote: >>>> So how are we going to use them? >>> Instead of atomic_read/atomic_set

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
On 18/07/16 20:22, Paolo Bonzini wrote: > > On 18/07/2016 19:17, Sergey Fedorov wrote: >> On 18/07/16 20:11, Paolo Bonzini wrote: >>> On 18/07/2016 19:07, Sergey Fedorov wrote: >>>> On 18/07/16 20:00, Paolo Bonzini wrote: >>>>> On 18/07/2016 18:57

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
On 18/07/16 20:11, Paolo Bonzini wrote: > > On 18/07/2016 19:07, Sergey Fedorov wrote: >> On 18/07/16 20:00, Paolo Bonzini wrote: >>> On 18/07/2016 18:57, Sergey Fedorov wrote: >>>> On 18/07/16 19:53, Paolo Bonzini wrote: >>>>> On 18/07/2016 18:52,

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
On 18/07/16 19:53, Paolo Bonzini wrote: > > On 18/07/2016 18:52, Sergey Fedorov wrote: >> So how are we going to use them? > Instead of atomic_read/atomic_set when marking invalid TBs. But shouldn't they be atomic to avoid reading torn writes? Thanks, Sergey > > dif

Re: [Qemu-devel] [PATCH] atomics: add volatile_read/volatile_set

2016-07-18 Thread Sergey Fedorov
So how are we going to use them? Thanks, Sergey On 18/07/16 17:17, Paolo Bonzini wrote: > Signed-off-by: Paolo Bonzini > --- > docs/atomics.txt | 19 --- > include/qemu/atomic.h | 17 + > 2 files changed, 33 insertions(+), 3 deletions(-) > > diff --git a/doc

Re: [Qemu-devel] [PATCH 4/5] cpu-exec: Move TB execution stuff out of cpu_exec()

2016-07-15 Thread Sergey Fedorov
On 15/07/16 09:45, Stefan Weil wrote: > Hi, > > Am 11.05.2016 um 12:21 schrieb Sergey Fedorov: > [...] >> int cpu_exec(CPUState *cpu) >> @@ -516,8 +576,6 @@ int cpu_exec(CPUState *cpu) >> CPUArchState *env = &x86_cpu->env; >> #endif >>

[Qemu-devel] [PATCH] cpu-exec: Move down some declarations in cpu_exec()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov This will fix a compiler warning with -Wclobbered: http://lists.nongnu.org/archive/html/qemu-devel/2016-07/msg03347.html Reported-by: Stefan Weil Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- cpu-exec.c | 7 +++ 1 file changed, 3 insertions(+), 4

[Qemu-devel] [PATCH v4 04/12] cpus: Wrap mutex used to protect CPU work

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov This will be useful to enable CPU work on user mode emulation. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index 04687c85bcd4

[Qemu-devel] [PATCH v4 12/12] tcg: Make tb_flush() thread safe

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Use async_safe_run_on_cpu() to make tb_flush() thread safe. It can happen that multiple threads schedule a safe work to flush the translation buffer. To keep statistics and debugging output sane, always check if the translation buffer has already been flushed. Signed-off

[Qemu-devel] [PATCH v4 07/12] linux-user: Rework exclusive operation mechanism

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov A single variable 'pending_cpus' was used for both counting currently running CPUs and for signalling the pending exclusive operation request. To prepare for supporting operations which requires a quiescent state, like translation buffer flush, it is useful

[Qemu-devel] [PATCH v4 09/12] linux-user: Support CPU work queue

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Make CPU work core functions common between system and user-mode emulation. User-mode does not have BQL, so process_queued_cpu_work() is protected by 'exclusive_lock'. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- Cha

[Qemu-devel] [PATCH v4 06/12] linux-user: Use QemuMutex and QemuCond

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Convert pthread_mutex_t and pthread_cond_t to QemuMutex and QemuCond. This will allow to make some locks and conditional variables common between user and system mode emulation. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée

[Qemu-devel] [PATCH v4 03/12] cpus: Move common code out of {async_, }run_on_cpu()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Move the code common between run_on_cpu() and async_run_on_cpu() into a new function queue_work_on_cpu(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 42 ++ 1 file changed, 18

[Qemu-devel] [PATCH v4 08/12] linux-user: Add qemu_cpu_is_self() and qemu_cpu_kick()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- linux-user/main.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 5ff0b20bad89..a8790ac63f68 100644 --- a/linux-user

[Qemu-devel] [PATCH v4 10/12] bsd-user: Support CPU work queue

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov It is a minimalistic support because bsd-linux claims to be _not_ threadsafe. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- bsd-user/main.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index

[Qemu-devel] [PATCH v4 00/12] cpu-exec: Safe work in quiescent state

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Hi, This is a v4 for the series [1]. There's only a small change to keep tb_flush() statistic and debugging output sane. I also picked up "Reviewed-by" tags. This series is available at a public git repository: https://github.com/sergefdrv/qemu.git s

[Qemu-devel] [PATCH v4 05/12] cpus: Rename flush_queued_work()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov To avoid possible confusion, rename flush_queued_work() to process_queued_cpu_work(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c

[Qemu-devel] [PATCH v4 02/12] cpus: pass CPUState to run_on_cpu helpers

2016-07-15 Thread Sergey Fedorov
lable. Signed-off-by: Alex Bennée [Sergey Fedorov: - eliminate more CPUState in user data; - remove unnecessary user data passing; - fix target-s390x/kvm.c and target-s390x/misc_helper.c] Signed-off-by: Sergey Fedorov Acked-by: David Gibson (ppc parts) Reviewed-by: Christian Borntraeger

[Qemu-devel] [PATCH v4 11/12] cpu-exec-common: Introduce async_safe_run_on_cpu()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov This patch is based on the ideas found in work of KONRAD Frederic [1], Alex Bennée [2], and Alvise Rigo [3]. This mechanism allows to perform an operation safely in a quiescent state. Quiescent state means: (1) no vCPU is running and (2) BQL in system-mode or

[Qemu-devel] [PATCH v4 01/12] atomic: introduce atomic_dec_fetch.

2016-07-15 Thread Sergey Fedorov
From: Alex Bennée Useful for counting down. Signed-off-by: Alex Bennée Signed-off-by: Sergey Fedorov --- include/qemu/atomic.h | 4 1 file changed, 4 insertions(+) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 7e13fca351d1..560b1af703a8 100644 --- a/include/qemu

[Qemu-devel] [PATCH v4 10/12] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpu-exec.c | 17 - 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index bbaed5bb1978..073d783398f3 100644 --- a/cpu-exec.c

[Qemu-devel] [PATCH v4 08/12] tcg: set up tb->page_addr before insertion

2016-07-15 Thread Sergey Fedorov
From: Alex Bennée This ensures that if we find the TB on the slow path that tb->page_addr is correctly set before being tested. Signed-off-by: Alex Bennée Reviewed-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- translate-all.c | 8 1 file changed, 4 insertions(+), 4 deleti

[Qemu-devel] [PATCH v4 11/12] tcg: Merge tb_find_slow() and tb_find_fast()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov These functions are not too big and can be merged together. This makes locking scheme more clear and easier to follow. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpu-exec.c | 72

[Qemu-devel] [PATCH v4 04/12] tcg: Prepare safe access to tb_flushed out of tb_lock

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Ensure atomicity and ordering of CPU's 'tb_flushed' access for future translation block lookup out of 'tb_lock'. This field can only be touched from another thread by tb_flush() in user mode emulation. So the only access to be sequential atomic

[Qemu-devel] [PATCH v4 06/12] tcg: Introduce tb_mark_invalid() and tb_is_invalid()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov These functions will be used to make translation block invalidation safe with concurrent lockless lookup in the global hash table. Most targets don't use 'cs_base'; so marking TB as invalid is as simple as assigning -1 to 'cs_base'. SPARC targe

[Qemu-devel] [PATCH v4 12/12] tcg: rename tb_find_physical()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov In fact, this function does not exactly perform a lookup by physical address as it is descibed for comment on get_page_addr_code(). Thus it may be a bit confusing to have "physical" in it's name. So rename it to tb_htable_lookup() to better reflect its actua

[Qemu-devel] [PATCH v4 05/12] target-i386: Remove redundant HF_SOFTMMU_MASK

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov 'HF_SOFTMMU_MASK' is only set when 'CONFIG_SOFTMMU' is defined. So there's no need in this flag: test 'CONFIG_SOFTMMU' instead. Suggested-by: Paolo Bonzini Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by:

[Qemu-devel] [PATCH v4 09/12] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-15 Thread Sergey Fedorov
l the MTTCG work is completed. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- v2 (hot path) - Add r-b tags v1 (hot path, split from base-patches series) - revert name tweaking - drop test jmp_list_next outside lock - me

[Qemu-devel] [PATCH v4 01/12] util/qht: Document memory ordering assumptions

2016-07-15 Thread Sergey Fedorov
Bonzini [Sergey Fedorov: commit title and message provided; comment on qht_remove() elided] Signed-off-by: Sergey Fedorov --- Changes in v4: - Modified version of Paolo's patch is used --- include/qemu/qht.h | 5 + util/qht.c | 7 ++- 2 files changed, 11 insertions(+), 1 del

[Qemu-devel] [PATCH v4 07/12] tcg: Prepare TB invalidation for lockless TB lookup

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov When invalidating a translation block, set an invalid CPU state into the TranslationBlock structure first. As soon as the TB is marked with an invalid CPU state, there is no need to remove it from CPU's 'tb_jmp_cache'. However it will be necessary to rech

[Qemu-devel] [PATCH v4 02/12] tcg: Pass last_tb by value to tb_find_fast()

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov This is a small clean up. tb_find_fast() is a final consumer of this variable so no need to pass it by reference. 'last_tb' is always updated by subsequent cpu_loop_exec_tb() in cpu_exec(). This change also simplifies calling cpu_exec_nocache() in cpu_handle

[Qemu-devel] [PATCH v4 00/12] Reduce lock contention on TCG hot-path

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Hi, This is a respin of this series [1]. Here I used a modified version of Paolo's patch to docuement memory ordering assumptions for certain QHT operations. The last patch is a suggestion for renaming tb_find_physicall(). This series can be fetch from the publi

[Qemu-devel] [PATCH v4 03/12] tcg: Prepare safe tb_jmp_cache lookup out of tb_lock

2016-07-15 Thread Sergey Fedorov
From: Sergey Fedorov Ensure atomicity of CPU's 'tb_jmp_cache' access for future translation block lookup out of 'tb_lock'. Note that this patch does *not* make CPU's TLB invalidation safe if it is done from some other thread while the CPU is in its execution loop.

Re: [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions

2016-07-15 Thread Sergey Fedorov
On 15/07/16 15:51, Paolo Bonzini wrote: > > On 15/07/2016 14:37, Sergey Fedorov wrote: >> I understand why an implied wmb can be expected after the entry is >> removed: so that the caller can trash the contents of the object >> removed. However that would require double

Re: [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions

2016-07-15 Thread Sergey Fedorov
On 13/07/16 14:13, Paolo Bonzini wrote: > diff --git a/include/qemu/qht.h b/include/qemu/qht.h > index 70bfc68..f4f1d55 100644 > --- a/include/qemu/qht.h > +++ b/include/qemu/qht.h > @@ -69,6 +69,9 @@ void qht_destroy(struct qht *ht); > * Attempting to insert a NULL @p is a bug. > * Inserting t

Re: [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions

2016-07-14 Thread Sergey Fedorov
On 14/07/16 16:56, Paolo Bonzini wrote: > > On 13/07/2016 19:50, Sergey Fedorov wrote: >> On 13/07/16 10:36, Paolo Bonzini wrote: >>> On 13/07/2016 01:19, Emilio G. Cota wrote: >>>> I wouldn't put those comments in the source--seqlock callers should >>&

Re: [Qemu-devel] [PATCH v3 10/11] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-14 Thread Sergey Fedorov
On 14/07/16 16:01, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> Signed-off-by: Sergey Fedorov >> Signed-off-by: Sergey Fedorov > Reviewed-by: Alex Bennée > > Much better than my cack-hander attempt to clean this up ;-)

Re: [Qemu-devel] [PATCH v3 06/11] tcg: Introduce tb_mark_invalid() and tb_is_invalid()

2016-07-14 Thread Sergey Fedorov
On 14/07/16 15:53, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> These functions will be used to make translation block invalidation safe >> with concurrent lockless lookup in the global hash table. >> >> Most targets don&#x

Re: [Qemu-devel] [PATCH v3 04/11] tcg: Prepare safe access to tb_flushed out of tb_lock

2016-07-14 Thread Sergey Fedorov
On 14/07/16 15:45, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> Ensure atomicity of CPU's 'tb_flushed' access for future translation >> block lookup out of 'tb_lock'. >> >> This field can only be

Re: [Qemu-devel] [PATCH v3 07/11] tcg: Prepare TB invalidation for lockless TB lookup

2016-07-14 Thread Sergey Fedorov
On 14/07/16 15:59, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> When invalidating a translation block, set an invalid CPU state into the >> TranslationBlock structure first. All subsequent changes are ordered >> after it wit

Re: [Qemu-devel] [PATCH v3 00/11] Reduce lock contention on TCG hot-path

2016-07-14 Thread Sergey Fedorov
On 14/07/16 12:55, Alex Bennée wrote: > Sergey Fedorov writes: > >> On 13/07/16 10:39, Paolo Bonzini wrote: >>> Have you measured performance with the series? In any case, it's nice >>> to see MTTCG finally taking shape! >> No, I didn't measure

Re: [Qemu-devel] [PATCH v3 06/11] tcg: Introduce tb_mark_invalid() and tb_is_invalid()

2016-07-14 Thread Sergey Fedorov
On 14/07/16 13:25, Alex Bennée wrote: > Sergey Fedorov writes: > >> > From: Sergey Fedorov >> > >> > These functions will be used to make translation block invalidation safe >> > with concurrent lockless lookup in the global hash table. >> > &

Re: [Qemu-devel] [RFC v2 11/11] tcg: Make tb_flush() thread safe

2016-07-14 Thread Sergey Fedorov
On 14/07/16 11:41, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> Use async_safe_run_on_cpu() to make tb_flush() thread safe. >> >> Signed-off-by: Sergey Fedorov >> Signed-off-by: Sergey Fedorov >> --- >> >&

[Qemu-devel] [PATCH v3 12/12] tcg: Make tb_flush() thread safe

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov Use async_safe_run_on_cpu() to make tb_flush() thread safe. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- Changes in v3: - 'tb_flushed' removed Changes in v2: - stale comment about unsafe tb_flush() removed --- cpu-exec.c

[Qemu-devel] [PATCH v3 08/12] linux-user: Add qemu_cpu_is_self() and qemu_cpu_kick()

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- linux-user/main.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 5ff0b20bad89..a8790ac63f68 100644 --- a/linux-user/main.c +++ b/linux-user/main.c

[Qemu-devel] [PATCH v3 09/12] linux-user: Support CPU work queue

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov Make CPU work core functions common between system and user-mode emulation. User-mode does not have BQL, so process_queued_cpu_work() is protected by 'exclusive_lock'. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- Changes in v2: - '

[Qemu-devel] [PATCH v3 03/12] cpus: Move common code out of {async_, }run_on_cpu()

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov Move the code common between run_on_cpu() and async_run_on_cpu() into a new function queue_work_on_cpu(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 42 ++ 1 file changed, 18

[Qemu-devel] [PATCH v3 06/12] linux-user: Use QemuMutex and QemuCond

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov Convert pthread_mutex_t and pthread_cond_t to QemuMutex and QemuCond. This will allow to make some locks and conditional variables common between user and system mode emulation. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée

[Qemu-devel] [PATCH v3 05/12] cpus: Rename flush_queued_work()

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov To avoid possible confusion, rename flush_queued_work() to process_queued_cpu_work(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c

[Qemu-devel] [PATCH v3 07/12] linux-user: Rework exclusive operation mechanism

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov A single variable 'pending_cpus' was used for both counting currently running CPUs and for signalling the pending exclusive operation request. To prepare for supporting operations which requires a quiescent state, like translation buffer flush, it is useful

[Qemu-devel] [PATCH v3 11/12] cpu-exec-common: Introduce async_safe_run_on_cpu()

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov This patch is based on the ideas found in work of KONRAD Frederic [1], Alex Bennée [2], and Alvise Rigo [3]. This mechanism allows to perform an operation safely in a quiescent state. Quiescent state means: (1) no vCPU is running and (2) BQL in system-mode or

[Qemu-devel] [PATCH v3 04/12] cpus: Wrap mutex used to protect CPU work

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov This will be useful to enable CPU work on user mode emulation. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index 04687c85bcd4

[Qemu-devel] [PATCH v3 00/12] cpu-exec: Safe work in quiescent state

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov Hi, This is a v3 for the RFC series [1]. This is not RFC anymore because bsd-user is supported now. However I wasn't able to even compile-test bsd-user so some help on this would be really appreciated. This series is available at a public git repository:

[Qemu-devel] [PATCH v3 02/12] cpus: pass CPUState to run_on_cpu helpers

2016-07-13 Thread Sergey Fedorov
lable. Signed-off-by: Alex Bennée [Sergey Fedorov: - eliminate more CPUState in user data; - remove unnecessary user data passing; - fix target-s390x/kvm.c and target-s390x/misc_helper.c] Signed-off-by: Sergey Fedorov Acked-by: David Gibson (ppc parts) Reviewed-by: Christian Borntraeger

[Qemu-devel] [PATCH v3 10/12] bsd-user: Support CPU work queue

2016-07-13 Thread Sergey Fedorov
From: Sergey Fedorov It is a minimalistic support because bsd-linux claims to be _not_ threadsafe. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- bsd-user/main.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index

[Qemu-devel] [PATCH v3 01/12] atomic: introduce atomic_dec_fetch.

2016-07-13 Thread Sergey Fedorov
From: Alex Bennée Useful for counting down. Signed-off-by: Alex Bennée Signed-off-by: Sergey Fedorov --- include/qemu/atomic.h | 4 1 file changed, 4 insertions(+) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 7a590969b59f..8ac9ca7f457a 100644 --- a/include/qemu

Re: [Qemu-devel] [PATCH v3 00/11] Reduce lock contention on TCG hot-path

2016-07-13 Thread Sergey Fedorov
On 13/07/16 10:39, Paolo Bonzini wrote: > If anything, for historical reasons one might rename tb_find_physical to > tb_find_slow and leave the tb_find_fast name, but I think the patch is > good as is. I think tb_find_htable() or tb_find_global_htable() could also be good options if we're going to

Re: [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions

2016-07-13 Thread Sergey Fedorov
On 13/07/16 14:13, Paolo Bonzini wrote: > > On 12/07/2016 22:13, Sergey Fedorov wrote: >> diff --git a/include/qemu/qht.h b/include/qemu/qht.h >> index 70bfc68b8d67..5f633e5d8100 100644 >> --- a/include/qemu/qht.h >> +++ b/include/qemu/qht.h >> @@ -69,6 +69,

Re: [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions

2016-07-13 Thread Sergey Fedorov
On 13/07/16 10:36, Paolo Bonzini wrote: > > On 13/07/2016 01:19, Emilio G. Cota wrote: >> I wouldn't put those comments in the source--seqlock callers should >> know what they're doing, and what barriers seqlocks imply. > In general I'd agree with you, however in this case the "begin" calls > are w

Re: [Qemu-devel] [PATCH v3 00/11] Reduce lock contention on TCG hot-path

2016-07-13 Thread Sergey Fedorov
On 13/07/16 10:39, Paolo Bonzini wrote: > On 12/07/2016 22:13, Sergey Fedorov wrote: >> From: Sergey Fedorov >> >> Hi, >> >> This is my respin of Alex's v2 series [1]. >> >> The first 8 patches are preparation for the patch 9, the subjec

[Qemu-devel] [PATCH v3 11/11] tcg: Merge tb_find_slow() and tb_find_fast()

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov These functions are not too big and can be merged together. This makes locking scheme more clear and easier to follow. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- cpu-exec.c | 72 ++ 1 file

[Qemu-devel] [PATCH v3 07/11] tcg: Prepare TB invalidation for lockless TB lookup

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov When invalidating a translation block, set an invalid CPU state into the TranslationBlock structure first. All subsequent changes are ordered after it with smp_wmb(). This pairs with implied smp_rmb() of qht_lookup() in tb_find_physical(). As soon as the TB is marked with

[Qemu-devel] [PATCH v3 10/11] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- cpu-exec.c | 15 +++ 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 4eabd534aba0..22c672fe03fd 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -281,7

[Qemu-devel] [PATCH v3 09/11] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-12 Thread Sergey Fedorov
l the MTTCG work is completed. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- v2 (hot path) - Add r-b tags v1 (hot path, split from base-patches series) - revert name tweaking - drop test jmp_list_next outside

[Qemu-devel] [PATCH v3 08/11] tcg: set up tb->page_addr before insertion

2016-07-12 Thread Sergey Fedorov
From: Alex Bennée This ensures that if we find the TB on the slow path that tb->page_addr is correctly set before being tested. Signed-off-by: Alex Bennée Reviewed-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- translate-all.c | 8 1 file changed, 4 insertions(+), 4 deleti

[Qemu-devel] [PATCH v3 06/11] tcg: Introduce tb_mark_invalid() and tb_is_invalid()

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov These functions will be used to make translation block invalidation safe with concurrent lockless lookup in the global hash table. Most targets don't use 'cs_base'; so marking TB as invalid is as simple as assigning -1 to 'cs_base'. SPARC targe

[Qemu-devel] [PATCH v3 05/11] target-i386: Remove redundant HF_SOFTMMU_MASK

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov 'HF_SOFTMMU_MASK' is only set when 'CONFIG_SOFTMMU' is defined. So there's no need in this flag: test 'CONFIG_SOFTMMU' instead. Suggested-by: Paolo Bonzini Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- target-i38

[Qemu-devel] [PATCH v3 04/11] tcg: Prepare safe access to tb_flushed out of tb_lock

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov Ensure atomicity of CPU's 'tb_flushed' access for future translation block lookup out of 'tb_lock'. This field can only be touched from another thread by tb_flush() in user mode emulation. So the only access to be atomic is: * a single write in tb

[Qemu-devel] [PATCH v3 02/11] cpu-exec: Pass last_tb by value to tb_find_fast()

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov This is a small clean up. tb_find_fast() is a final consumer of this variable so no need to pass it by reference. 'last_tb' is always updated by subsequent cpu_loop_exec_tb() in cpu_exec(). This change also simplifies calling cpu_exec_nocache() in cpu_handle

[Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov It is naturally expected that some memory ordering should be provided around qht_insert(), qht_remove(), and qht_lookup(). Document these assumptions in the header file and put some comments in the source to denote how that memory ordering requirements are fulfilled. Signed

[Qemu-devel] [PATCH v3 03/11] tcg: Prepare safe tb_jmp_cache lookup out of tb_lock

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov Ensure atomicity of CPU's 'tb_jmp_cache' access for future translation block lookup out of 'tb_lock'. Note that this patch does *not* make CPU's TLB invalidation safe if it is done from some other thread while the CPU is in its execution loop.

[Qemu-devel] [PATCH v3 00/11] Reduce lock contention on TCG hot-path

2016-07-12 Thread Sergey Fedorov
From: Sergey Fedorov Hi, This is my respin of Alex's v2 series [1]. The first 8 patches are preparation for the patch 9, the subject matter of this series, which enables lockless translation block lookup. The main change here is that Paolo's suggestion is implemented: TBs are m

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-11 Thread Sergey Fedorov
On 11/07/16 17:03, Paolo Bonzini wrote: > > On 11/07/2016 15:06, Sergey Fedorov wrote: >> On 08/07/16 23:52, Paolo Bonzini wrote: >>> On 08/07/2016 22:24, Sergey Fedorov wrote: >>>> I remember, I've just found that we discussed it in this thr

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-11 Thread Sergey Fedorov
On 08/07/16 23:52, Paolo Bonzini wrote: > > On 08/07/2016 22:24, Sergey Fedorov wrote: >> I remember, I've just found that we discussed it in this thread: >> >> http://thread.gmane.org/gmane.comp.emulators.qemu/401723/focus=406852 >> >> I was thinking of ju

Re: [Qemu-devel] [RFC v2 02/11] cpus: pass CPUState to run_on_cpu helpers

2016-07-11 Thread Sergey Fedorov
On 11/07/16 15:36, Christian Borntraeger wrote: > On 07/06/2016 11:14 PM, Sergey Fedorov wrote: >> From: Alex Bennée >> >> CPUState is a fairly common pointer to pass to these helpers. This means >> if you need other arguments for the async_run_on_cpu case you end up &g

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-08 Thread Sergey Fedorov
On 08/07/16 23:18, Paolo Bonzini wrote: > > On 08/07/2016 21:55, Sergey Fedorov wrote: >> On 08/07/16 17:07, Paolo Bonzini wrote: >>> On 08/07/2016 14:32, Sergey Fedorov wrote: >>>>>>>> I think we can do even better. One option is using a separate

Re: [Qemu-devel] [PATCH v2 3/6] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-08 Thread Sergey Fedorov
On 05/07/16 19:18, Alex Bennée wrote: > Lock contention in the hot path of moving between existing patched > TranslationBlocks is the main drag in multithreaded performance. This > patch pushes the tb_lock() usage down to the two places that really need > it: > > - code generation (tb_gen_code) >

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-08 Thread Sergey Fedorov
On 08/07/16 17:07, Paolo Bonzini wrote: > > On 08/07/2016 14:32, Sergey Fedorov wrote: >>>>>> I think we can do even better. One option is using a separate tiny lock >>>>>> to protect direct jump set/reset instead of tb_lock. >>>> If you hav

Re: [Qemu-devel] [PATCH v2 3/6] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-08 Thread Sergey Fedorov
On 08/07/16 21:03, Alex Bennée wrote: > Sergey Fedorov writes: > >> On 07/07/16 17:18, Sergey Fedorov wrote: >>> On 05/07/16 19:18, Alex Bennée wrote: >>>> Lock contention in the hot path of moving between existing patched >>>> TranslationBlocks is the

Re: [Qemu-devel] [PATCH v2 3/6] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-08 Thread Sergey Fedorov
On 07/07/16 17:18, Sergey Fedorov wrote: > On 05/07/16 19:18, Alex Bennée wrote: >> Lock contention in the hot path of moving between existing patched >> TranslationBlocks is the main drag in multithreaded performance. This >> patch pushes the tb_lock() usage down to the t

Re: [Qemu-devel] [PATCH v2 3/6] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-08 Thread Sergey Fedorov
On 07/07/16 17:18, Sergey Fedorov wrote: > On 05/07/16 19:18, Alex Bennée wrote: >> Lock contention in the hot path of moving between existing patched >> TranslationBlocks is the main drag in multithreaded performance. This >> patch pushes the tb_lock() usage down to the t

Re: [Qemu-devel] [PATCH v2 1/6] tcg: Ensure safe tb_jmp_cache lookup out of 'tb_lock'

2016-07-08 Thread Sergey Fedorov
On 05/07/16 19:18, Alex Bennée wrote: > From: Sergey Fedorov > > First, ensure atomicity of CPU's 'tb_jmp_cache' access by: > * using atomic_read() to look up a TB when not holding 'tb_lock'; > * using atomic_write() to remove a TB from each CPU's lo

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-08 Thread Sergey Fedorov
On 08/07/16 14:02, Paolo Bonzini wrote: >> On 08/07/16 11:40, Paolo Bonzini wrote: >>> Even better: add a "bool *tb_locked" argument to tb_find_slow, and >>> don't move the mmap_lock release. Then tb_find_fast knows directly >>> whether tb_lock is taken, and you don't need any of tb_lock_reset >>>

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-08 Thread Sergey Fedorov
On 08/07/16 11:40, Paolo Bonzini wrote: > Even better: add a "bool *tb_locked" argument to tb_find_slow, and > don't move the mmap_lock release. Then tb_find_fast knows directly > whether tb_lock is taken, and you don't need any of tb_lock_reset > or mmap_lock_reset. I think we can do even better

Re: [Qemu-devel] [PATCH v2 2/6] tcg: set up tb->page_addr before insertion

2016-07-08 Thread Sergey Fedorov
On 07/07/16 17:08, Sergey Fedorov wrote: > On 05/07/16 19:18, Alex Bennée wrote: >> This ensures that if we find the TB on the slow path that tb->page_addr >> is correctly set before being tested. >> >> Signed-off-by: Alex Bennée > Reveiwed-by: Sergey Fedorov Ho

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-07 Thread Sergey Fedorov
On 07/07/16 22:46, Sergey Fedorov wrote: > On 07/07/16 22:36, Alex Bennée wrote: >> Sergey Fedorov writes: >> >>> From: Sergey Fedorov >>> >>> Signed-off-by: Sergey Fedorov >>> Signed-off-by: Sergey Fedorov >>> --- >>> cp

Re: [Qemu-devel] [RFC v2 11/11] tcg: Make tb_flush() thread safe

2016-07-07 Thread Sergey Fedorov
On 07/07/16 00:15, Sergey Fedorov wrote: > From: Sergey Fedorov > > Use async_safe_run_on_cpu() to make tb_flush() thread safe. I've just realized that this allows to remove CPUState::tb_flushed as well. Regards, Sergey

Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-07 Thread Sergey Fedorov
On 07/07/16 22:36, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> Signed-off-by: Sergey Fedorov >> Signed-off-by: Sergey Fedorov >> --- >> cpu-exec.c | 15 +-- >> 1 file changed, 9 insertions(+), 6

[Qemu-devel] [PATCH 1/3] tcg: Introduce mmap_lock_reset()

2016-07-07 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- bsd-user/mmap.c | 7 +++ include/exec/exec-all.h | 2 ++ linux-user/mmap.c | 7 +++ 3 files changed, 16 insertions(+) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 610f91b28584

Re: [Qemu-devel] [PATCH v2 6/6] tcg: cpu-exec: roll-up tb_find_fast/slow

2016-07-07 Thread Sergey Fedorov
From: Sergey Fedorov Here is my attempt ;-) Kind regards, Sergey Sergey Fedorov (3): tcg: Introduce mmap_lock_reset() tcg: Introduce tb_lock_locked() tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump() bsd-user/mmap.c | 7 +++ cpu-exec.c | 15

[Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump()

2016-07-07 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- cpu-exec.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index dd0bd5007701..54c935039592 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -295,7

[Qemu-devel] [PATCH 2/3] tcg: Introduce tb_lock_locked()

2016-07-07 Thread Sergey Fedorov
From: Sergey Fedorov Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- tcg/tcg.h | 1 + translate-all.c | 9 + 2 files changed, 10 insertions(+) diff --git a/tcg/tcg.h b/tcg/tcg.h index 66d7fc01c53c..ca9329d99f90 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -648,6

Re: [Qemu-devel] [PATCH v2 3/6] tcg: cpu-exec: remove tb_lock from the hot-path

2016-07-07 Thread Sergey Fedorov
removed the #ifdef CONFIG_USER_ONLY stuff as the > locks become NOPs anyway until the MTTCG work is completed. > > Signed-off-by: Alex Bennée > Reviewed-by: Richard Henderson Reviewed-by: Sergey Fedorov > > --- > v3 (base-patches) > - fix merge conflicts with Sergey&

Re: [Qemu-devel] [PATCH v2 2/6] tcg: set up tb->page_addr before insertion

2016-07-07 Thread Sergey Fedorov
On 05/07/16 19:18, Alex Bennée wrote: > This ensures that if we find the TB on the slow path that tb->page_addr > is correctly set before being tested. > > Signed-off-by: Alex Bennée Reveiwed-by: Sergey Fedorov > --- > translate-all.c | 8 > 1 file cha

Re: [Qemu-devel] [PATCH v2 1/6] tcg: Ensure safe tb_jmp_cache lookup out of 'tb_lock'

2016-07-07 Thread Sergey Fedorov
I was not sure if the language I used in the source code comments is 100% correct. So it would be fine if someone could check if it is easy to understand ;) Thanks, Sergey On 05/07/16 19:18, Alex Bennée wrote: > From: Sergey Fedorov > > First, ensure atomicity of CPU's 'tb_j

  1   2   3   4   5   6   7   8   9   >