qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] hw/net/opencores_eth: Allocating Large sized


From: Wei, Jiangang
Subject: Re: [Qemu-devel] [PATCH v2] hw/net/opencores_eth: Allocating Large sized arrays to heap
Date: Wed, 27 Apr 2016 03:27:47 +0000

On Wed, 2016-04-27 at 10:07 +0800, Zhou Jie wrote:
> open_eth_start_xmit has a huge stack usage of 65536 bytes approx.
> Moving large arrays to heap to reduce stack usage.
> 
> Signed-off-by: Zhou Jie <address@hidden>
> ---
>  hw/net/opencores_eth.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c
> index c6094fb..fa0a4e7 100644
> --- a/hw/net/opencores_eth.c
> +++ b/hw/net/opencores_eth.c
> @@ -483,7 +483,8 @@ static NetClientInfo net_open_eth_info = {
>  
>  static void open_eth_start_xmit(OpenEthState *s, desc *tx)
>  {
> -    uint8_t buf[65536];
> +    uint8_t *buf = NULL;
> +    uint8_t buffer[0x600];
Hi,

I'm curious about 0x600.
How do you determine this size?
IMO, Max's suggestion looks more reasonable.
(1536 bytes, maximal frame length when HUGEN bit is not set in MODER)

Regards,
wei
>      unsigned len = GET_FIELD(tx->len_flags, TXD_LEN);
>      unsigned tx_len = len;
>  
> @@ -498,6 +499,11 @@ static void open_eth_start_xmit(OpenEthState *s, desc 
> *tx)
>  
>      trace_open_eth_start_xmit(tx->buf_ptr, len, tx_len);
>  
> +    if (tx_len > 0x600) {
> +        buf = g_new(uint8_t, tx_len);
> +    } else {
> +        buf = buffer;
> +    }
>      if (len > tx_len) {
>          len = tx_len;
>      }
> @@ -506,6 +512,9 @@ static void open_eth_start_xmit(OpenEthState *s, desc *tx)
>          memset(buf + len, 0, tx_len - len);
>      }
>      qemu_send_packet(qemu_get_queue(s->nic), buf, tx_len);
> +    if (tx_len > 0x600) {
> +        g_free(buf);
> +    }
>  
>      if (tx->len_flags & TXD_WR) {
>          s->tx_desc = 0;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]