All of lore.kernel.org
 help / color / mirror / Atom feed
From: Blue Swirl <blauwirbel@gmail.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Lucas Meneghel Rodrigues <lmr@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Jan Kiszka <jan.kiszka@web.de>, Avi Kivity <avi@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] pc: Clean up PIC-to-APIC IRQ path
Date: Sun, 4 Sep 2011 09:27:46 +0000	[thread overview]
Message-ID: <CAAu8pHubmNs1bKsQcK-dc=xvW-ZRV-vfpYiyf87DhKoRUEx3mQ@mail.gmail.com> (raw)
In-Reply-To: <4E629F21.6060300@codemonkey.ws>

On Sat, Sep 3, 2011 at 9:41 PM, Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 09/03/2011 04:10 PM, Blue Swirl wrote:
>>
>> On Sat, Sep 3, 2011 at 8:07 PM, Anthony Liguori<anthony@codemonkey.ws>
>>  wrote:
>>>
>>> On 09/01/2011 12:58 AM, Avi Kivity wrote:
>>>>
>>>> On 08/31/2011 07:59 PM, Blue Swirl wrote:
>>>>>
>>>>>>
>>>>>> That makes it impossible to migrate level-triggered irq lines. Or at
>>>>>
>>>>> least,
>>>>>>
>>>>>> the receiver has to remember the state, instead of (or in addition
>>>>>
>>>>> to) the
>>>>>>
>>>>>> sender.
>>>>>
>>>>> Both ends probably need to remember the state. That should work
>>>>> without any multiphase restores and transient suppressors.
>>>>
>>>> State should always correspond to real hardware state - a flip flop or
>>>> capacitor. Input is not state, it is input.
>>>>
>>>>> It might be also possible to introduce stateful signal lines which
>>>>> save and restore their state, then the receiving end could check what
>>>>> is the current level. However, if you consider that the devices may be
>>>>> restored in random order, if the IRQ line device happens to be
>>>>> restored later, the receiver would still get wrong information. Adding
>>>>> priorities could solve this, but I think stateless IRQs are the only
>>>>> sane way.
>>>>
>>>> I agree that irqs should be stateless, since they don't have any memory
>>>> associated.
>>>
>>> In Real Life, you can tie a single bit multiple registers together with
>>> boolean logic to form an output pin.  This is essentially computed state.
>>>  If we wanted to model a stateless pin, we would need to do something
>>> like:
>>>
>>> struct Serial {
>>>   uint8_t thr;
>>>   uint8_t lsr;
>>> };
>>>
>>> static bool serial_get_irq(Serial *s) {
>>>   return (s->thr&  THRE) | (s->lsr&  LSRE);
>>> }
>>>
>>> static void serial_write(Serial *s, uint64_t addr, uint8_t value)
>>> {
>>>   switch (addr) {
>>>   case THR:
>>>      bool old_irq = serial_get_irq(s);
>>>      s->thr = value;
>>>      if (!old_irq&&  serial_get_irq(s)) {
>>>          notify_edge_change(s);
>>>      }
>>>   ...
>>> }
>>>
>>> static void serial_init(Serial *s)
>>> {
>>>    register_pin(s, serial_get_irq);
>>> }
>>>
>>> Obviously, this is pretty sucky.  This is what we do today but we don't
>>> have
>>> a way to query irq value which is wrong.  You could fix that by adding
>>> the
>>> get function but that's not terribly fun.  A better way:
>>>
>>> struct Serial {
>>>    Pin irq;
>>>    uint8_t thr;
>>>    uint8_t lsr;
>>> };
>>>
>>> static void serial_update_irq(Serial *s)
>>> {
>>>   pin_set_level(&s->irq, (s->thr&  THRE) | (s->lsr&  LSRE));
>>> }
>>>
>>> static void serial_write(Serial *s) {
>>>   switch (addr) {
>>>   case THR:
>>>      s->thr = value;
>>>      serial_update_irq(s);
>>>   ...
>>> }
>>>
>>> This results in much nicer code.  The edge handling can be done in
>>> generic
>>> code which will make things more robust overall.
>>
>> I'm sorry but I don't see a huge difference, could you elaborate?
>
> The main difference is whether the Pin is capable of determine if there was
> a level change on its own.  It can only do this is if knows the current
> level which implies that its holding state.
>
>>
>> Maybe if the internal state of Pin is magically shared between the
>> endpoint devices (like typedef bool *Pin) and the devices somehow
>> still save Pin state as part of their own despite the duplication,
>
> I'm somewhat confused by what you mean here.

Pretty similar to what you propose below except the magical sharing.

> If you have two devices that have a connection, one has an output pin and
> one has an input pin.  This would look like this:
>
> struct Serial {
>   Pin irq; // output pin
> };
>
> struct PIIX3 {
>   Pin *in[16]; // input pins
> };
>
> As part of connecting devices, you'd basically do:
>
> PIIX3 piix3;
> Serial serial;
>
> piix3.in[4] = &serial.irq;
>
> serial.irq setting it pin level doesn't do anything to piix3.  piix3 has to
> explicitly read the pin state for its behavior to influence anything.
>
> Here's the flow with taking migration into account:
>
> 1) PIIX3 maintains some type of state, performs action (A) whenever in[3]
> changes its state based on an edge change notifier.
>
> 2) During migration, PIIX3 has its state saved as does Serial.  Pin is part
> of Serial so it also has its state saved.
>
> 3) During restore, PIIX3 has its state restored, as does Serial, and Pin.
>  Action (A) is not invoked because notifiers are not fired when a device is
> not realized.  Restore happens before a device is realized.
>
> So the scenario you're concerned about doesn't happen and it doesn't require
> anything funky.

OK, this should work.

>> this could work. Restoring Pins first and then devices is a sort of
>> priority scheme.
>
> There is no priority.  But devices have an explicit realize event and in
> general, shouldn't react to other devices until realize happens.  You need
> this behavior to support construction properly.
>
> Regards,
>
> Anthony Liguori
>

  reply	other threads:[~2011-09-04  9:28 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-27 14:16 [Qemu-devel] [PATCH] pc: Clean up PIC-to-APIC IRQ path Jan Kiszka
2011-08-28  7:10 ` Blue Swirl
2011-08-28  9:08   ` Jan Kiszka
2011-08-29 19:25 ` Anthony Liguori
2011-08-29 21:06   ` Jan Kiszka
2011-08-29 21:13     ` Avi Kivity
2011-08-29 21:18       ` Jan Kiszka
2011-08-30 19:19       ` Blue Swirl
2011-08-30 19:28         ` Jan Kiszka
2011-08-30 19:43           ` Blue Swirl
2011-08-31  8:25           ` Peter Maydell
2011-08-31 10:53             ` Jan Kiszka
2011-08-31 17:41               ` Blue Swirl
2011-08-31 18:17                 ` Jan Kiszka
2011-08-31 19:44                   ` Blue Swirl
2011-09-04 10:33                     ` Blue Swirl
2011-09-04 12:25                     ` Gleb Natapov
2011-09-03 19:54               ` Anthony Liguori
2011-09-04 12:13                 ` Jan Kiszka
2011-09-04 13:32                   ` Anthony Liguori
2011-09-04 13:36                     ` Jan Kiszka
2011-09-04 13:41                       ` Anthony Liguori
2011-09-04 13:49                         ` Jan Kiszka
2011-09-04 13:57                           ` Anthony Liguori
2011-09-04 14:37                             ` Anthony Liguori
2011-09-04 15:20                               ` Blue Swirl
2011-09-04 15:31                                 ` Anthony Liguori
2011-09-04 15:44                                   ` Blue Swirl
2011-09-05 10:44                             ` Edgar E. Iglesias
2011-09-04 14:12                         ` Avi Kivity
2011-09-04 14:43                           ` Anthony Liguori
2011-09-04 15:03                             ` Avi Kivity
2011-09-04 15:19                               ` Anthony Liguori
2011-09-04 15:34                                 ` Avi Kivity
2011-09-04 15:27                             ` Blue Swirl
2011-09-04 12:17               ` Avi Kivity
2011-09-04 12:37                 ` Jan Kiszka
2011-09-04 12:43                   ` Avi Kivity
2011-09-04 13:38                   ` Anthony Liguori
2011-09-04 13:42                     ` Jan Kiszka
2011-09-04 13:55                       ` Anthony Liguori
2011-09-04 13:35                 ` Anthony Liguori
2011-08-31  8:28         ` Avi Kivity
2011-08-31 16:59           ` Blue Swirl
2011-08-31 18:04             ` Edgar E. Iglesias
2011-08-31 18:28               ` Jan Kiszka
2011-09-01  5:58             ` Avi Kivity
2011-09-03 20:07               ` Anthony Liguori
2011-09-03 21:10                 ` Blue Swirl
2011-09-03 21:41                   ` Anthony Liguori
2011-09-04  9:27                     ` Blue Swirl [this message]
2011-09-03 19:53             ` Anthony Liguori
2011-09-03 21:01               ` Blue Swirl
2011-09-04 14:49                 ` Anthony Liguori
2011-09-05  8:38               ` Edgar E. Iglesias
2011-09-05  8:51                 ` Avi Kivity
2011-09-05  9:02                   ` Peter Maydell
2011-09-05  9:14                     ` Avi Kivity
2011-09-05  9:22                   ` Edgar E. Iglesias
2011-09-05  9:28                     ` Avi Kivity
2011-09-05 10:47                       ` Edgar E. Iglesias
2011-09-05 19:36                 ` Blue Swirl
2011-09-06  7:46                   ` Avi Kivity
2011-09-01  9:08 ` [Qemu-devel] [PATCH v2] pc: Fix and clean " Jan Kiszka
2011-09-03  8:58   ` Blue Swirl
2011-09-03 11:17     ` Jan Kiszka
2011-09-03 11:37       ` Blue Swirl
2011-09-03 18:14         ` Jan Kiszka

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='CAAu8pHubmNs1bKsQcK-dc=xvW-ZRV-vfpYiyf87DhKoRUEx3mQ@mail.gmail.com' \
    --to=blauwirbel@gmail.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=kraxel@redhat.com \
    --cc=lmr@redhat.com \
    --cc=mtosatti@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.