From: Blue Swirl <blauwirbel@gmail.com>
To: Artyom Tarasenko <atar4qemu@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] fix disabling interrupts in sun4u
Date: Sat, 30 Jul 2011 21:13:00 +0000 [thread overview]
Message-ID: <CAAu8pHt-YadE80Uhd0AF_pvpcL3TofW-zn1hZFWYb+c8OKtsyA@mail.gmail.com> (raw)
In-Reply-To: <CACXAS8Ckcr7hX9NKaP-Ruqjbvb+yz_NmMxERGFstZ+U+5QT0hQ@mail.gmail.com>
On Sat, Jul 30, 2011 at 8:58 PM, Artyom Tarasenko <atar4qemu@gmail.com> wrote:
> On Sat, Jul 30, 2011 at 10:32 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
>> On Sat, Jul 30, 2011 at 11:19 PM, Artyom Tarasenko <atar4qemu@gmail.com> wrote:
>>> On Sat, Jul 30, 2011 at 3:25 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
>>>> On Sat, Jul 30, 2011 at 3:31 PM, Artyom Tarasenko <atar4qemu@gmail.com> wrote:
>>>>> On Sat, Jul 30, 2011 at 11:09 AM, Blue Swirl <blauwirbel@gmail.com> wrote:
>>>>>> On Mon, Jul 25, 2011 at 8:22 PM, Artyom Tarasenko <atar4qemu@gmail.com> wrote:
>>>>>>> clear interrupt request if the interrupt priority < CPU pil
>>>>>>> clear hardware interrupt request if interrupts are disabled
>>>>>>>
>>>>>>> Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
>>>>>>> ---
>>>>>>> hw/sun4u.c | 6 ++++--
>>>>>>> 1 files changed, 4 insertions(+), 2 deletions(-)
>>>>>>>
>>>>>>> diff --git a/hw/sun4u.c b/hw/sun4u.c
>>>>>>> index d7dcaf0..7f95aeb 100644
>>>>>>> --- a/hw/sun4u.c
>>>>>>> +++ b/hw/sun4u.c
>>>>>>> @@ -255,7 +255,7 @@ void cpu_check_irqs(CPUState *env)
>>>>>>> pil |= 1 << 14;
>>>>>>> }
>>>>>>>
>>>>>>> - if (!pil) {
>>>>>>> + if (pil < (2 << env->psrpil)){
>>>>>>
>>>>>> Sorry, I don't understand the patch. Where is this '2' coming from?
>>>>>
>>>>> We shouldn't interrupt at levels <= psrpil. The bit corresponding to
>>>>> psrpil is (1<< psrpil),
>>>>> the next bit is (2 << psrpil).
>>>>
>>>> Now I see. The check below "i > env->psrpil" does something similar
>>>> but it doesn't reset interrupt.
>>>>
>>>> How about pil < (1 << (env->psrpil + 1))? I think that makes the
>>>> purpose clearer.
>>>
>>> But it's also one operation more. Shall I just add a comment?
>>
>> I think the compiler should be able to calculate that 1 << (x + 1) == 2 << x.
>>
> Are you sure?
>
> $ cat test_smart_shift.c
> int main (int argc, char *argv[]) {
> return 1 << (1+argc);
> }
>
> $ sparc64-linux-gnu-gcc-4.4.5 -O2 -S test_smart_shift.c
> cat test_smart_shift.s
> .file "test_smart_shift.c"
> .section ".text"
> .align 4
> .align 32
> .global main
> .type main, #function
> .proc 04
> main:
> mov 1, %g1
> add %o0, 1, %o0
> sll %g1, %o0, %o0
> jmp %o7+8
> sra %o0, 0, %o0
> .size main, .-main
> .ident "GCC: (GNU) 4.4.5"
> .section .note.GNU-stack,"",@progbits
Same happens on amd64. Well, the compiler isn't so smart as I thought.
Then please use the 2 << version with a comment.
>>>>>>
>>>>>>> if (env->interrupt_request & CPU_INTERRUPT_HARD) {
>>>>>>> CPUIRQ_DPRINTF("Reset CPU IRQ (current interrupt %x)\n",
>>>>>>> env->interrupt_index);
>>>>>>> @@ -287,10 +287,12 @@ void cpu_check_irqs(CPUState *env)
>>>>>>> break;
>>>>>>> }
>>>>>>> }
>>>>>>> - } else {
>>>>>>> + } else if (env->interrupt_request & CPU_INTERRUPT_HARD) {
>>>>>>> CPUIRQ_DPRINTF("Interrupts disabled, pil=%08x pil_in=%08x softint=%08x "
>>>>>>> "current interrupt %x\n",
>>>>>>> pil, env->pil_in, env->softint, env->interrupt_index);
>>>>>>> + env->interrupt_index = 0;
>>>>>>> + cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
>>>>>>
>>>>>> Why reset the index? The idea is that the interrupt is left pending a
>>>>>> change to PIL etc.
>>>>>
>>>>> But it is kept in env->pil_in and env->softint . Am I missing some
>>>>> scenario where it's not enough?
>>>>
>>>> cpu-exec.c:378 checks interrupt_index, not pil_in etc.
>>>
>>> The scenario this patch is trying to fix:
>>>
>>> There comes an interrupt N, the PIL is small enough to proceed,
>>> proceeding disables the interrupts.
>>> Then the interrupt handler deasserts N and enables the interrupts. The
>>> interrupt N comes again but is not processed because of old_interrupt
>>> != new_interrupt check.
>>
>> Deasserting the interrupt should clear pil_in which should flow down
>> to interrupt_index. It's a bug if this does not happen.
>
> Ok, I'll drop the second part in v2 then.
>
>
> --
> Regards,
> Artyom Tarasenko
>
> solaris/sparc under qemu blog: http://tyom.blogspot.com/
>
next prev parent reply other threads:[~2011-07-30 21:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-25 17:22 [Qemu-devel] [PATCH] fix disabling interrupts in sun4u Artyom Tarasenko
2011-07-28 10:31 ` tsnsaito
2011-07-28 11:51 ` Artyom Tarasenko
2011-07-28 12:03 ` tsnsaito
2011-07-28 12:10 ` Tsuneo Saito
2011-07-28 12:55 ` Artyom Tarasenko
2011-07-28 12:50 ` Artyom Tarasenko
2011-07-28 13:40 ` tsnsaito
2011-07-28 14:44 ` Artyom Tarasenko
2011-07-29 1:21 ` tsnsaito
2011-07-30 9:28 ` Blue Swirl
2011-07-30 9:09 ` Blue Swirl
2011-07-30 12:31 ` Artyom Tarasenko
2011-07-30 13:25 ` Blue Swirl
2011-07-30 20:19 ` Artyom Tarasenko
2011-07-30 20:32 ` Blue Swirl
2011-07-30 20:58 ` Artyom Tarasenko
2011-07-30 21:13 ` Blue Swirl [this message]
2011-08-28 11:39 ` Blue Swirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAu8pHt-YadE80Uhd0AF_pvpcL3TofW-zn1hZFWYb+c8OKtsyA@mail.gmail.com \
--to=blauwirbel@gmail.com \
--cc=atar4qemu@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).