Patchwork [v1,2/5] slirp: make timeout local

login
register
mail settings
Submitter pingfan liu
Date Aug. 8, 2013, 6:26 a.m.
Message ID <1375943171-1063-3-git-send-email-pingfank@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/265663/
State New
Headers show

Comments

pingfan liu - Aug. 8, 2013, 6:26 a.m.
Each slirp has its own time to caculate timeout.

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 slirp/slirp.c | 22 ++++++++++------------
 slirp/slirp.h |  3 +++
 2 files changed, 13 insertions(+), 12 deletions(-)
Paolo Bonzini - Aug. 9, 2013, 8:06 a.m.
Il 08/08/2013 08:26, Liu Ping Fan ha scritto:
> Each slirp has its own time to caculate timeout.
> 
> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---
>  slirp/slirp.c | 22 ++++++++++------------
>  slirp/slirp.h |  3 +++
>  2 files changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 80b28ea..55654d5 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -40,8 +40,6 @@ static const uint8_t special_ethaddr[ETH_ALEN] = {
>  static const uint8_t zero_ethaddr[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
>  
>  u_int curtime;
> -static u_int time_fasttimo, last_slowtimo;
> -static int do_slowtimo;
>  
>  static QTAILQ_HEAD(slirp_instances, Slirp) slirp_instances =
>      QTAILQ_HEAD_INITIALIZER(slirp_instances);
> @@ -278,14 +276,13 @@ void slirp_pollfds_fill(GArray *pollfds)
>      /*
>       * First, TCP sockets
>       */
> -    do_slowtimo = 0;
>  
>      QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
>          /*
>           * *_slowtimo needs calling if there are IP fragments
>           * in the fragment queue, or there are TCP connections active
>           */
> -        do_slowtimo |= ((slirp->tcb.so_next != &slirp->tcb) ||
> +        slirp->do_slowtimo = ((slirp->tcb.so_next != &slirp->tcb) ||
>                  (&slirp->ipq.ip_link != slirp->ipq.ip_link.next));
>  
>          for (so = slirp->tcb.so_next; so != &slirp->tcb;
> @@ -299,8 +296,9 @@ void slirp_pollfds_fill(GArray *pollfds)
>              /*
>               * See if we need a tcp_fasttimo
>               */
> -            if (time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK) {
> -                time_fasttimo = curtime; /* Flag when we want a fasttimo */
> +            if (slirp->time_fasttimo == 0 &&
> +                so->so_tcpcb->t_flags & TF_DELACK) {
> +                slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */
>              }
>  
>              /*
> @@ -381,7 +379,7 @@ void slirp_pollfds_fill(GArray *pollfds)
>                      udp_detach(so);
>                      continue;
>                  } else {
> -                    do_slowtimo = 1; /* Let socket expire */
> +                    slirp->do_slowtimo = 1; /* Let socket expire */
>                  }
>              }
>  
> @@ -422,7 +420,7 @@ void slirp_pollfds_fill(GArray *pollfds)
>                      icmp_detach(so);
>                      continue;
>                  } else {
> -                    do_slowtimo = 1; /* Let socket expire */
> +                    slirp->do_slowtimo = 1; /* Let socket expire */
>                  }
>              }
>  
> @@ -454,14 +452,14 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
>          /*
>           * See if anything has timed out
>           */
> -        if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
> +        if (slirp->time_fasttimo && ((curtime - slirp->time_fasttimo) >= 2)) {
>              tcp_fasttimo(slirp);
> -            time_fasttimo = 0;
> +            slirp->time_fasttimo = 0;
>          }
> -        if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
> +        if (slirp->do_slowtimo && ((curtime - slirp->last_slowtimo) >= 499)) {
>              ip_slowtimo(slirp);
>              tcp_slowtimo(slirp);
> -            last_slowtimo = curtime;
> +            slirp->last_slowtimo = curtime;
>          }
>  
>          /*
> diff --git a/slirp/slirp.h b/slirp/slirp.h
> index fe0e65d..008360e 100644
> --- a/slirp/slirp.h
> +++ b/slirp/slirp.h
> @@ -203,6 +203,9 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
>  
>  struct Slirp {
>      QTAILQ_ENTRY(Slirp) entry;
> +    u_int time_fasttimo;
> +    u_int last_slowtimo;
> +    int do_slowtimo;
>  
>      /* virtual network configuration */
>      struct in_addr vnetwork_addr;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

In addition, you could modify slirp_update_timeout to run after
slirp_pollfds_fill, and actually look at the timeout fields to set the
right timeout (2 if time_fasttimo is nonzero, 499 if do_slowtimo is true).

Paolo
pingfan liu - Aug. 9, 2013, 8:48 a.m.
On Fri, Aug 9, 2013 at 4:06 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 08/08/2013 08:26, Liu Ping Fan ha scritto:
>> Each slirp has its own time to caculate timeout.
>>
>> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>> ---
>>  slirp/slirp.c | 22 ++++++++++------------
>>  slirp/slirp.h |  3 +++
>>  2 files changed, 13 insertions(+), 12 deletions(-)
>>
>> diff --git a/slirp/slirp.c b/slirp/slirp.c
>> index 80b28ea..55654d5 100644
>> --- a/slirp/slirp.c
>> +++ b/slirp/slirp.c
>> @@ -40,8 +40,6 @@ static const uint8_t special_ethaddr[ETH_ALEN] = {
>>  static const uint8_t zero_ethaddr[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
>>
>>  u_int curtime;
>> -static u_int time_fasttimo, last_slowtimo;
>> -static int do_slowtimo;
>>
>>  static QTAILQ_HEAD(slirp_instances, Slirp) slirp_instances =
>>      QTAILQ_HEAD_INITIALIZER(slirp_instances);
>> @@ -278,14 +276,13 @@ void slirp_pollfds_fill(GArray *pollfds)
>>      /*
>>       * First, TCP sockets
>>       */
>> -    do_slowtimo = 0;
>>
>>      QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
>>          /*
>>           * *_slowtimo needs calling if there are IP fragments
>>           * in the fragment queue, or there are TCP connections active
>>           */
>> -        do_slowtimo |= ((slirp->tcb.so_next != &slirp->tcb) ||
>> +        slirp->do_slowtimo = ((slirp->tcb.so_next != &slirp->tcb) ||
>>                  (&slirp->ipq.ip_link != slirp->ipq.ip_link.next));
>>
>>          for (so = slirp->tcb.so_next; so != &slirp->tcb;
>> @@ -299,8 +296,9 @@ void slirp_pollfds_fill(GArray *pollfds)
>>              /*
>>               * See if we need a tcp_fasttimo
>>               */
>> -            if (time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK) {
>> -                time_fasttimo = curtime; /* Flag when we want a fasttimo */
>> +            if (slirp->time_fasttimo == 0 &&
>> +                so->so_tcpcb->t_flags & TF_DELACK) {
>> +                slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */
>>              }
>>
>>              /*
>> @@ -381,7 +379,7 @@ void slirp_pollfds_fill(GArray *pollfds)
>>                      udp_detach(so);
>>                      continue;
>>                  } else {
>> -                    do_slowtimo = 1; /* Let socket expire */
>> +                    slirp->do_slowtimo = 1; /* Let socket expire */
>>                  }
>>              }
>>
>> @@ -422,7 +420,7 @@ void slirp_pollfds_fill(GArray *pollfds)
>>                      icmp_detach(so);
>>                      continue;
>>                  } else {
>> -                    do_slowtimo = 1; /* Let socket expire */
>> +                    slirp->do_slowtimo = 1; /* Let socket expire */
>>                  }
>>              }
>>
>> @@ -454,14 +452,14 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
>>          /*
>>           * See if anything has timed out
>>           */
>> -        if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
>> +        if (slirp->time_fasttimo && ((curtime - slirp->time_fasttimo) >= 2)) {
>>              tcp_fasttimo(slirp);
>> -            time_fasttimo = 0;
>> +            slirp->time_fasttimo = 0;
>>          }
>> -        if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
>> +        if (slirp->do_slowtimo && ((curtime - slirp->last_slowtimo) >= 499)) {
>>              ip_slowtimo(slirp);
>>              tcp_slowtimo(slirp);
>> -            last_slowtimo = curtime;
>> +            slirp->last_slowtimo = curtime;
>>          }
>>
>>          /*
>> diff --git a/slirp/slirp.h b/slirp/slirp.h
>> index fe0e65d..008360e 100644
>> --- a/slirp/slirp.h
>> +++ b/slirp/slirp.h
>> @@ -203,6 +203,9 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
>>
>>  struct Slirp {
>>      QTAILQ_ENTRY(Slirp) entry;
>> +    u_int time_fasttimo;
>> +    u_int last_slowtimo;
>> +    int do_slowtimo;
>>
>>      /* virtual network configuration */
>>      struct in_addr vnetwork_addr;
>>
>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>
> In addition, you could modify slirp_update_timeout to run after
> slirp_pollfds_fill, and actually look at the timeout fields to set the
> right timeout (2 if time_fasttimo is nonzero, 499 if do_slowtimo is true).
>
After patch 3,4, the timeout will be an param for GSource's prepare.
So I think I will set the right timeout value in patch4?

Thanks,
Pingfan
> Paolo
Paolo Bonzini - Aug. 9, 2013, 9:32 a.m.
Il 09/08/2013 10:48, liu ping fan ha scritto:
> After patch 3,4, the timeout will be an param for GSource's prepare.
> So I think I will set the right timeout value in patch4?

No, please do it before (in fact you can extract this patch and the
timeout change to a seprate series).  Then patch 4 can simply move the
timeout logic to the GSource's prepare function.

Paolo

Patch

diff --git a/slirp/slirp.c b/slirp/slirp.c
index 80b28ea..55654d5 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -40,8 +40,6 @@  static const uint8_t special_ethaddr[ETH_ALEN] = {
 static const uint8_t zero_ethaddr[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
 
 u_int curtime;
-static u_int time_fasttimo, last_slowtimo;
-static int do_slowtimo;
 
 static QTAILQ_HEAD(slirp_instances, Slirp) slirp_instances =
     QTAILQ_HEAD_INITIALIZER(slirp_instances);
@@ -278,14 +276,13 @@  void slirp_pollfds_fill(GArray *pollfds)
     /*
      * First, TCP sockets
      */
-    do_slowtimo = 0;
 
     QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
         /*
          * *_slowtimo needs calling if there are IP fragments
          * in the fragment queue, or there are TCP connections active
          */
-        do_slowtimo |= ((slirp->tcb.so_next != &slirp->tcb) ||
+        slirp->do_slowtimo = ((slirp->tcb.so_next != &slirp->tcb) ||
                 (&slirp->ipq.ip_link != slirp->ipq.ip_link.next));
 
         for (so = slirp->tcb.so_next; so != &slirp->tcb;
@@ -299,8 +296,9 @@  void slirp_pollfds_fill(GArray *pollfds)
             /*
              * See if we need a tcp_fasttimo
              */
-            if (time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK) {
-                time_fasttimo = curtime; /* Flag when we want a fasttimo */
+            if (slirp->time_fasttimo == 0 &&
+                so->so_tcpcb->t_flags & TF_DELACK) {
+                slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */
             }
 
             /*
@@ -381,7 +379,7 @@  void slirp_pollfds_fill(GArray *pollfds)
                     udp_detach(so);
                     continue;
                 } else {
-                    do_slowtimo = 1; /* Let socket expire */
+                    slirp->do_slowtimo = 1; /* Let socket expire */
                 }
             }
 
@@ -422,7 +420,7 @@  void slirp_pollfds_fill(GArray *pollfds)
                     icmp_detach(so);
                     continue;
                 } else {
-                    do_slowtimo = 1; /* Let socket expire */
+                    slirp->do_slowtimo = 1; /* Let socket expire */
                 }
             }
 
@@ -454,14 +452,14 @@  void slirp_pollfds_poll(GArray *pollfds, int select_error)
         /*
          * See if anything has timed out
          */
-        if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
+        if (slirp->time_fasttimo && ((curtime - slirp->time_fasttimo) >= 2)) {
             tcp_fasttimo(slirp);
-            time_fasttimo = 0;
+            slirp->time_fasttimo = 0;
         }
-        if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
+        if (slirp->do_slowtimo && ((curtime - slirp->last_slowtimo) >= 499)) {
             ip_slowtimo(slirp);
             tcp_slowtimo(slirp);
-            last_slowtimo = curtime;
+            slirp->last_slowtimo = curtime;
         }
 
         /*
diff --git a/slirp/slirp.h b/slirp/slirp.h
index fe0e65d..008360e 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -203,6 +203,9 @@  bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
 
 struct Slirp {
     QTAILQ_ENTRY(Slirp) entry;
+    u_int time_fasttimo;
+    u_int last_slowtimo;
+    int do_slowtimo;
 
     /* virtual network configuration */
     struct in_addr vnetwork_addr;