From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1y0g-0006Ao-Mi for qemu-devel@nongnu.org; Sun, 15 May 2016 11:31:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1y0a-0007Gh-I2 for qemu-devel@nongnu.org; Sun, 15 May 2016 11:31:13 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:36831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1y0a-0007GB-AN for qemu-devel@nongnu.org; Sun, 15 May 2016 11:31:08 -0400 Received: by mail-lf0-x241.google.com with SMTP id y84so13145229lfc.3 for ; Sun, 15 May 2016 08:31:08 -0700 (PDT) From: Max Filippov Date: Sun, 15 May 2016 18:28:09 +0300 Message-Id: <1463326089-15526-3-git-send-email-jcmvbkbc@gmail.com> In-Reply-To: <1463326089-15526-1-git-send-email-jcmvbkbc@gmail.com> References: <1463326089-15526-1-git-send-email-jcmvbkbc@gmail.com> Subject: [Qemu-devel] [PATCH 2/2] 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: Zhou Jie , Max Filippov From: Zhou Jie open_eth_start_xmit has a huge stack usage of 65536 bytes approx. Moving large arrays to heap to reduce stack usage. Reduce size of a buffer allocated on stack to 0x600 bytes, which is the maximal frame length when HUGEN bit is not set in MODER, only allocate buffer on heap when that is too small. Thus heap is not used in typical use case. Signed-off-by: Zhou Jie Signed-off-by: Max Filippov --- 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 c269992..484d113 100644 --- a/hw/net/opencores_eth.c +++ b/hw/net/opencores_eth.c @@ -482,7 +482,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; @@ -497,6 +498,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 > sizeof(buffer)) { + buf = g_new(uint8_t, tx_len); + } else { + buf = buffer; + } if (len > tx_len) { len = tx_len; } @@ -505,6 +511,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 > sizeof(buffer)) { + g_free(buf); + } if (tx->len_flags & TXD_WR) { s->tx_desc = 0; -- 2.1.4