[Spice-devel] [master PATCH 2/2] server: netstat: send random data not zeros

Alon Levy alevy at redhat.com
Tue Oct 18 11:02:45 PDT 2011


On Tue, Oct 18, 2011 at 07:20:15PM +0200, Uri Lublin wrote:
> WAN accelerators may compress the zeros which results with a
> wrong bandwidth calculation.
> 

ACK with some nitpicks on whitespace.

I was hoping we will throw this stuff away, but I guess it's still
there..

> The buffer is initialized once.
> ---
>  server/main_channel.c |   32 ++++++++++++++++++++++++++++----
>  1 files changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/server/main_channel.c b/server/main_channel.c
> index a4db724..3a94066 100644
> --- a/server/main_channel.c
> +++ b/server/main_channel.c
> @@ -34,6 +34,7 @@
>  #include <fcntl.h>
>  #include <errno.h>
>  #include <ctype.h>
> +#include <stdlib.h>
> 
>  #include "server/red_common.h"
>  #include "server/demarshallers.h"
> @@ -44,7 +45,7 @@
>  #include "red_channel.h"
>  #include "generated_marshallers.h"
> 
> -#define ZERO_BUF_SIZE 4096
> +#define RANDOM_BUF_SIZE 4096
> 
>  // approximate max receive message size for main channel
>  #define RECEIVE_BUF_SIZE \
> @@ -57,7 +58,7 @@
> 
>  #define PING_INTERVAL (1000 * 10)
> 
> -static uint8_t zero_page[ZERO_BUF_SIZE] = {0};
> +static uint8_t random_page[RANDOM_BUF_SIZE];
> 
>  typedef struct RedsOutItem RedsOutItem;
>  struct RedsOutItem {
> @@ -155,6 +156,28 @@ enum NetTestStage {
>      NET_TEST_STAGE_RATE,
>  };
> 
> +
> +static void random_page_init(void)
> +{
> +    static int done = 0; /* do it only once */
> +    int i, n;
> +    uint32_t *p = (uint32_t*)random_page;
> +
> +    if (done)
> +        return;
curlies.

> +    done = 1;
> +
> +    /* assuming devides with no remainder. otherwise some zeros at the end */
> +    n = sizeof(random_page) / sizeof(uint32_t);
> +
> +    srandom(time(NULL));
> +    for (i=0; i<n; i++, p++) {
spaces please.

> +        *p = random();
> +    }
> +
> +}
> +
> +
extra line.

>  int main_channel_is_connected(MainChannel *main_chan)
>  {
>      return red_channel_is_connected(&main_chan->base);
> @@ -370,9 +393,9 @@ static void main_channel_marshall_ping(SpiceMarshaller *m, int size, int ping_id
>      spice_marshall_msg_ping(m, &ping);
> 
>      while (size > 0) {
> -        int now = MIN(ZERO_BUF_SIZE, size);
> +        int now = MIN(RANDOM_BUF_SIZE, size);
>          size -= now;
> -        spice_marshaller_add_ref(m, zero_page, now);
> +        spice_marshaller_add_ref(m, random_page, now);
>      }
>  }
> 
> @@ -982,6 +1005,7 @@ MainChannel* main_channel_init(void)
>      RedChannel *channel;
>      ChannelCbs channel_cbs;
> 
> +    random_page_init();
> 
>      channel_cbs.config_socket = main_channel_config_socket;
>      channel_cbs.on_disconnect = main_channel_client_on_disconnect;
> -- 
> 1.7.6.4
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list