From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avF4K-0001Ww-51 for qemu-devel@nongnu.org; Tue, 26 Apr 2016 22:19:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avF4F-0006i7-De for qemu-devel@nongnu.org; Tue, 26 Apr 2016 22:19:11 -0400 Received: from [59.151.112.132] (port=54708 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avF4E-0006i1-Qn for qemu-devel@nongnu.org; Tue, 26 Apr 2016 22:19:07 -0400 References: <1461722868-11624-1-git-send-email-zhoujie2011@cn.fujitsu.com> From: Zhou Jie Message-ID: <57202190.9070106@cn.fujitsu.com> Date: Wed, 27 Apr 2016 10:18:56 +0800 MIME-Version: 1.0 In-Reply-To: <1461722868-11624-1-git-send-email-zhoujie2011@cn.fujitsu.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v2] hw/net/opencores_eth: Allocating Large sized arrays to heap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: jcmvbkbc@gmail.com Hi Max, When I committed another patch which named as "hw/net/virtio-net: Allocating Large sized arrays to heap" . Christian Borntraeger said that 16k is usually perfectly fine for a userspace stack and doing allocations in a hot path might actually hurt performance. Although the size is 65536 bytes here, I think open_eth_start_xmit is in a hot path. So, it is OK, if you think that this patch should not be applied. Sincerely, Zhou Jie On 2016/4/27 10:07, 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 > --- > 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]; > 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; > -- ------------------------------------------------ 周潔 Dept 1 No. 6 Wenzhu Road, Nanjing, 210012, China TEL:+86+25-86630566-8557 FUJITSU INTERNAL:7998-8557 E-Mail:zhoujie2011@cn.fujitsu.com ------------------------------------------------