[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 03/11] tci: Make direct jump patching thread-saf
From: |
Alex Bennée |
Subject: |
Re: [Qemu-devel] [PATCH 03/11] tci: Make direct jump patching thread-safe |
Date: |
Fri, 22 Apr 2016 13:49:18 +0100 |
User-agent: |
mu4e 0.9.17; emacs 25.0.92.6 |
Sergey Fedorov <address@hidden> writes:
> On 20/04/16 16:14, Alex Bennée wrote:
>> Sergey Fedorov <address@hidden> writes:
>>
>>> On 20/04/16 12:42, Alex Bennée wrote:
>>>> Sergey Fedorov <address@hidden> writes:
>>>>> diff --git a/tcg/tci/tcg-target.inc.c b/tcg/tci/tcg-target.inc.c
>>>>> index 4afe4d7a8d59..7e6180e62898 100644
>>>>> --- a/tcg/tci/tcg-target.inc.c
>>>>> +++ b/tcg/tci/tcg-target.inc.c
>>>>> @@ -556,6 +556,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
>>>>> const TCGArg *args,
>>>>> if (s->tb_jmp_offset) {
>>>>> /* Direct jump method. */
>>>>> assert(args[0] < ARRAY_SIZE(s->tb_jmp_offset));
>>>>> + /* Align for atomic patching and thread safety */
>>>>> + s->code_ptr = (uint8_t *)(((uintptr_t)s->code_ptr + 3) &
>>>>> ~3);
>>>> Seeing this pattern is being used over and over again I wonder if we
>>>> should have some utility helper functions for this? Perhaps we should
>>>> steal the kernels ALIGN macros?
>>> Good point, really. I see such a macro in hw/display/qxl.c and
>>> kvm-all.c. It'd be better a common definition. Any idea of where to
>>> put it?
>> Somewhere inside include/qemu. osdep.h has ROUND_UP/DOWN functions maybe
>> there makes the most sense?
>
> Hmm, ROUND_UP() seems to be exactly what we need here. Though I think
> compiler could be smart enough to give the same code with
> QEMU_ALIGN_UP() as well. But we'd benefit from something like:
>
> /* n-byte align pointer down */
> #define QEMU_ALIGN_PTR_DOWN(p, n) \
> ((typeof(p))QEMU_ALIGN_DOWN((uintptr_t)(p), (n)))
>
> /* n-byte align pointer up */
> #define QEMU_ALIGN_PTR_UP(p, n) \
> ((typeof(p))QEMU_ALIGN_UP((uintptr_t)(p), (n)))
Sounds good.
--
Alex Bennée
[Qemu-devel] [PATCH 06/11] tcg/s390: Make direct jump patching thread-safe, Sergey Fedorov, 2016/04/07
[Qemu-devel] [PATCH 01/11] tci: Fix build regression, Sergey Fedorov, 2016/04/07
[Qemu-devel] [PATCH 05/11] tcg/i386: Make direct jump patching thread-safe, Sergey Fedorov, 2016/04/07