diff mbox

[1/2] return available ioeventfds count in kvm_has_many_ioeventfds()

Message ID 20120313104232.8741.89133.stgit@dhcp-8-167.nay.redhat.com
State New
Headers show

Commit Message

Amos Kong March 13, 2012, 10:42 a.m. UTC
Older kernels have a 6 device limit on the KVM io bus.
This patch makes kvm_has_many_ioeventfds() return available
ioeventfd count. ioeventfd will be disabled if there is
no 7 available ioeventfds.

Signed-off-by: Amos Kong <akong@redhat.com>
---
 hw/virtio-pci.c |    2 +-
 kvm-all.c       |    9 +++------
 2 files changed, 4 insertions(+), 7 deletions(-)

Comments

Jan Kiszka March 13, 2012, 11:50 a.m. UTC | #1
Please tag uq/master patches with "PATCH uq/master".

On 2012-03-13 11:42, Amos Kong wrote:
> Older kernels have a 6 device limit on the KVM io bus.
> This patch makes kvm_has_many_ioeventfds() return available
> ioeventfd count. ioeventfd will be disabled if there is
> no 7 available ioeventfds.
> 
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
>  hw/virtio-pci.c |    2 +-
>  kvm-all.c       |    9 +++------
>  2 files changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index a0fb7c1..d63f303 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -678,7 +678,7 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>      pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
>                       &proxy->bar);
>  
> -    if (!kvm_has_many_ioeventfds()) {
> +    if (kvm_has_many_ioeventfds() != 7) {
>          proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
>      }
>  
> diff --git a/kvm-all.c b/kvm-all.c
> index 3c6b4f0..d12694b 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -78,7 +78,6 @@ struct KVMState
>      int pit_in_kernel;
>      int pit_state2;
>      int xsave, xcrs;
> -    int many_ioeventfds;
>      int irqchip_inject_ioctl;
>  #ifdef KVM_CAP_IRQ_ROUTING
>      struct kvm_irq_routing *irq_routes;
> @@ -510,8 +509,8 @@ static int kvm_check_many_ioeventfds(void)
>          }
>      }
>  
> -    /* Decide whether many devices are supported or not */
> -    ret = i == ARRAY_SIZE(ioeventfds);
> +    /* If i equals to 7, many devices are supported */
> +    ret = i;
>  
>      while (i-- > 0) {
>          kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
> @@ -1078,8 +1077,6 @@ int kvm_init(void)
>      kvm_state = s;
>      memory_listener_register(&kvm_memory_listener, NULL);
>  
> -    s->many_ioeventfds = kvm_check_many_ioeventfds();
> -
>      cpu_interrupt_handler = kvm_handle_interrupt;
>  
>      return 0;
> @@ -1407,7 +1404,7 @@ int kvm_has_many_ioeventfds(void)
>      if (!kvm_enabled()) {
>          return 0;
>      }
> -    return kvm_state->many_ioeventfds;
> +    return kvm_check_many_ioeventfds();

And why are you dropping the caching of the kvm_check_many_ioeventfds()
return value? Is kvm_has_many_ioeventfds not used outside init scopes?

Jan
Amos Kong March 13, 2012, noon UTC | #2
On 13/03/12 19:50, Jan Kiszka wrote:
> Please tag uq/master patches with "PATCH uq/master".
>
> On 2012-03-13 11:42, Amos Kong wrote:
>> Older kernels have a 6 device limit on the KVM io bus.
>> This patch makes kvm_has_many_ioeventfds() return available
>> ioeventfd count. ioeventfd will be disabled if there is
>> no 7 available ioeventfds.
>>
>> Signed-off-by: Amos Kong<akong@redhat.com>
>> ---
>>   hw/virtio-pci.c |    2 +-
>>   kvm-all.c       |    9 +++------
>>   2 files changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
>> index a0fb7c1..d63f303 100644
>> --- a/hw/virtio-pci.c
>> +++ b/hw/virtio-pci.c
>> @@ -678,7 +678,7 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>>       pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
>>                        &proxy->bar);
>>
>> -    if (!kvm_has_many_ioeventfds()) {
>> +    if (kvm_has_many_ioeventfds() != 7) {
>>           proxy->flags&= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
>>       }
>>
>> diff --git a/kvm-all.c b/kvm-all.c
>> index 3c6b4f0..d12694b 100644
>> --- a/kvm-all.c
>> +++ b/kvm-all.c
>> @@ -78,7 +78,6 @@ struct KVMState
>>       int pit_in_kernel;
>>       int pit_state2;
>>       int xsave, xcrs;
>> -    int many_ioeventfds;
>>       int irqchip_inject_ioctl;
>>   #ifdef KVM_CAP_IRQ_ROUTING
>>       struct kvm_irq_routing *irq_routes;
>> @@ -510,8 +509,8 @@ static int kvm_check_many_ioeventfds(void)
>>           }
>>       }
>>
>> -    /* Decide whether many devices are supported or not */
>> -    ret = i == ARRAY_SIZE(ioeventfds);
>> +    /* If i equals to 7, many devices are supported */
>> +    ret = i;
>>
>>       while (i-->  0) {
>>           kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
>> @@ -1078,8 +1077,6 @@ int kvm_init(void)
>>       kvm_state = s;
>>       memory_listener_register(&kvm_memory_listener, NULL);
>>
>> -    s->many_ioeventfds = kvm_check_many_ioeventfds();
>> -
>>       cpu_interrupt_handler = kvm_handle_interrupt;
>>
>>       return 0;
>> @@ -1407,7 +1404,7 @@ int kvm_has_many_ioeventfds(void)
>>       if (!kvm_enabled()) {
>>           return 0;
>>       }
>> -    return kvm_state->many_ioeventfds;
>> +    return kvm_check_many_ioeventfds();
>
> And why are you dropping the caching of the kvm_check_many_ioeventfds()
> return value? Is kvm_has_many_ioeventfds not used outside init scopes?

Hi Jan,

In the past, kvm_state->many_ioeventfds is only updated once at the 
beginning,
I want to use kvm_check_many_ioeventfds() to check if available 
ioeventfd exists
before starting ioeventfd each time.
Jan Kiszka March 13, 2012, 12:24 p.m. UTC | #3
On 2012-03-13 13:00, Amos Kong wrote:
> On 13/03/12 19:50, Jan Kiszka wrote:
>> Please tag uq/master patches with "PATCH uq/master".
>>
>> On 2012-03-13 11:42, Amos Kong wrote:
>>> Older kernels have a 6 device limit on the KVM io bus.
>>> This patch makes kvm_has_many_ioeventfds() return available
>>> ioeventfd count. ioeventfd will be disabled if there is
>>> no 7 available ioeventfds.
>>>
>>> Signed-off-by: Amos Kong<akong@redhat.com>
>>> ---
>>>   hw/virtio-pci.c |    2 +-
>>>   kvm-all.c       |    9 +++------
>>>   2 files changed, 4 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
>>> index a0fb7c1..d63f303 100644
>>> --- a/hw/virtio-pci.c
>>> +++ b/hw/virtio-pci.c
>>> @@ -678,7 +678,7 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>>>       pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
>>>                        &proxy->bar);
>>>
>>> -    if (!kvm_has_many_ioeventfds()) {
>>> +    if (kvm_has_many_ioeventfds() != 7) {
>>>           proxy->flags&= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
>>>       }
>>>
>>> diff --git a/kvm-all.c b/kvm-all.c
>>> index 3c6b4f0..d12694b 100644
>>> --- a/kvm-all.c
>>> +++ b/kvm-all.c
>>> @@ -78,7 +78,6 @@ struct KVMState
>>>       int pit_in_kernel;
>>>       int pit_state2;
>>>       int xsave, xcrs;
>>> -    int many_ioeventfds;
>>>       int irqchip_inject_ioctl;
>>>   #ifdef KVM_CAP_IRQ_ROUTING
>>>       struct kvm_irq_routing *irq_routes;
>>> @@ -510,8 +509,8 @@ static int kvm_check_many_ioeventfds(void)
>>>           }
>>>       }
>>>
>>> -    /* Decide whether many devices are supported or not */
>>> -    ret = i == ARRAY_SIZE(ioeventfds);
>>> +    /* If i equals to 7, many devices are supported */
>>> +    ret = i;
>>>
>>>       while (i-->  0) {
>>>           kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
>>> @@ -1078,8 +1077,6 @@ int kvm_init(void)
>>>       kvm_state = s;
>>>       memory_listener_register(&kvm_memory_listener, NULL);
>>>
>>> -    s->many_ioeventfds = kvm_check_many_ioeventfds();
>>> -
>>>       cpu_interrupt_handler = kvm_handle_interrupt;
>>>
>>>       return 0;
>>> @@ -1407,7 +1404,7 @@ int kvm_has_many_ioeventfds(void)
>>>       if (!kvm_enabled()) {
>>>           return 0;
>>>       }
>>> -    return kvm_state->many_ioeventfds;
>>> +    return kvm_check_many_ioeventfds();
>>
>> And why are you dropping the caching of the kvm_check_many_ioeventfds()
>> return value? Is kvm_has_many_ioeventfds not used outside init scopes?
> 
> Hi Jan,
> 
> In the past, kvm_state->many_ioeventfds is only updated once at the 
> beginning,

And the additional use case of patch 2 is not hot path either, right?

> I want to use kvm_check_many_ioeventfds() to check if available 
> ioeventfd exists
> before starting ioeventfd each time.

OK, but than kvm_has_many_ioeventfds is not the right name for this
function anymore. Call it "kvm_get_available_ioventfds" or so, but not
in a away that implies a boolean return value.

Jan
Amos Kong March 13, 2012, 1:05 p.m. UTC | #4
----- Original Message -----
> On 2012-03-13 13:00, Amos Kong wrote:
> > On 13/03/12 19:50, Jan Kiszka wrote:
> >> Please tag uq/master patches with "PATCH uq/master".
> >>
> >> On 2012-03-13 11:42, Amos Kong wrote:
> >>> Older kernels have a 6 device limit on the KVM io bus.
> >>> This patch makes kvm_has_many_ioeventfds() return available
> >>> ioeventfd count. ioeventfd will be disabled if there is
> >>> no 7 available ioeventfds.
> >>>
> >>> Signed-off-by: Amos Kong<akong@redhat.com>
> >>> ---
> >>>   hw/virtio-pci.c |    2 +-
> >>>   kvm-all.c       |    9 +++------
> >>>   2 files changed, 4 insertions(+), 7 deletions(-)
> >>>
> >>> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> >>> index a0fb7c1..d63f303 100644
> >>> --- a/hw/virtio-pci.c
> >>> +++ b/hw/virtio-pci.c
> >>> @@ -678,7 +678,7 @@ void virtio_init_pci(VirtIOPCIProxy *proxy,
> >>> VirtIODevice *vdev)
> >>>       pci_register_bar(&proxy->pci_dev, 0,
> >>>       PCI_BASE_ADDRESS_SPACE_IO,
> >>>                        &proxy->bar);
> >>>
> >>> -    if (!kvm_has_many_ioeventfds()) {
> >>> +    if (kvm_has_many_ioeventfds() != 7) {
> >>>           proxy->flags&= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
> >>>       }
> >>>
> >>> diff --git a/kvm-all.c b/kvm-all.c
> >>> index 3c6b4f0..d12694b 100644
> >>> --- a/kvm-all.c
> >>> +++ b/kvm-all.c
> >>> @@ -78,7 +78,6 @@ struct KVMState
> >>>       int pit_in_kernel;
> >>>       int pit_state2;
> >>>       int xsave, xcrs;
> >>> -    int many_ioeventfds;
> >>>       int irqchip_inject_ioctl;
> >>>   #ifdef KVM_CAP_IRQ_ROUTING
> >>>       struct kvm_irq_routing *irq_routes;
> >>> @@ -510,8 +509,8 @@ static int kvm_check_many_ioeventfds(void)
> >>>           }
> >>>       }
> >>>
> >>> -    /* Decide whether many devices are supported or not */
> >>> -    ret = i == ARRAY_SIZE(ioeventfds);
> >>> +    /* If i equals to 7, many devices are supported */
> >>> +    ret = i;
> >>>
> >>>       while (i-->  0) {
> >>>           kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
> >>> @@ -1078,8 +1077,6 @@ int kvm_init(void)
> >>>       kvm_state = s;
> >>>       memory_listener_register(&kvm_memory_listener, NULL);
> >>>
> >>> -    s->many_ioeventfds = kvm_check_many_ioeventfds();
> >>> -
> >>>       cpu_interrupt_handler = kvm_handle_interrupt;
> >>>
> >>>       return 0;
> >>> @@ -1407,7 +1404,7 @@ int kvm_has_many_ioeventfds(void)
> >>>       if (!kvm_enabled()) {
> >>>           return 0;
> >>>       }
> >>> -    return kvm_state->many_ioeventfds;
> >>> +    return kvm_check_many_ioeventfds();
> >>
> >> And why are you dropping the caching of the
> >> kvm_check_many_ioeventfds()
> >> return value? Is kvm_has_many_ioeventfds not used outside init
> >> scopes?
> > 
> > Hi Jan,
> > 
> > In the past, kvm_state->many_ioeventfds is only updated once at the
> > beginning,
> 
> And the additional use case of patch 2 is not hot path either, right?

Hi Jan,

It's not hot, it's called during init virtio-pci devices.
 
> > I want to use kvm_check_many_ioeventfds() to check if available
> > ioeventfd exists
> > before starting ioeventfd each time.
> 
> OK, but than kvm_has_many_ioeventfds is not the right name for this
> function anymore. Call it "kvm_get_available_ioventfds" or so, but
> not
> in a away that implies a boolean return value.

Yeah, will fix it in v2.

Amos.
diff mbox

Patch

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index a0fb7c1..d63f303 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -678,7 +678,7 @@  void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
     pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
                      &proxy->bar);
 
-    if (!kvm_has_many_ioeventfds()) {
+    if (kvm_has_many_ioeventfds() != 7) {
         proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
     }
 
diff --git a/kvm-all.c b/kvm-all.c
index 3c6b4f0..d12694b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -78,7 +78,6 @@  struct KVMState
     int pit_in_kernel;
     int pit_state2;
     int xsave, xcrs;
-    int many_ioeventfds;
     int irqchip_inject_ioctl;
 #ifdef KVM_CAP_IRQ_ROUTING
     struct kvm_irq_routing *irq_routes;
@@ -510,8 +509,8 @@  static int kvm_check_many_ioeventfds(void)
         }
     }
 
-    /* Decide whether many devices are supported or not */
-    ret = i == ARRAY_SIZE(ioeventfds);
+    /* If i equals to 7, many devices are supported */
+    ret = i;
 
     while (i-- > 0) {
         kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
@@ -1078,8 +1077,6 @@  int kvm_init(void)
     kvm_state = s;
     memory_listener_register(&kvm_memory_listener, NULL);
 
-    s->many_ioeventfds = kvm_check_many_ioeventfds();
-
     cpu_interrupt_handler = kvm_handle_interrupt;
 
     return 0;
@@ -1407,7 +1404,7 @@  int kvm_has_many_ioeventfds(void)
     if (!kvm_enabled()) {
         return 0;
     }
-    return kvm_state->many_ioeventfds;
+    return kvm_check_many_ioeventfds();
 }
 
 int kvm_has_gsi_routing(void)