From patchwork Sun May 15 15:28:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 9096551 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 948AF9F1D3 for ; Sun, 15 May 2016 15:32:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E19CA2028D for ; Sun, 15 May 2016 15:32:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 393CC20279 for ; Sun, 15 May 2016 15:32:03 +0000 (UTC) Received: from localhost ([::1]:40618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1y1S-0007VZ-I6 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 15 May 2016 11:32:02 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XTmT0eZKRF4TN2CLCxKReYI5VW2EACnp6CVuViA0OJg=; b=tkIWHKw0Ob6qoySMvtLK8S5ntsjRqy/de0qNYRbG4t2Xb/Tz9dwMRgPHQvn2pw2VTs rS9heNbd64xRo/xxfQqnshoR9eb7dqB562Urhi0+xFOpxqD/ClhfAvFHs4My2xmYFuWX 0E51B4xe/CuBTpgVDZJGNOIEvZZUXW7ON4+jaREdwqINNnx7fCXPcD9HFY+JRqmg/Ybr uvXJcwX+e2lcJjd8EjLYmAHyBJKhCWlejcdpCrzcx5FZjDr+kGtb+FAVUzL45pSncePR 6gKaFDFZz6Yp84sTwvIs4Y9f7zgyx13ssPaoc8jVAeG76QgnWAqB6/GNIuiVMQCAffoq SvGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XTmT0eZKRF4TN2CLCxKReYI5VW2EACnp6CVuViA0OJg=; b=CIDVpce9bL4fDcTTLJnfHtxI04lfXBw2Lnvr+aQGubv2DdGuOA8ZxFYv7z5LW1hQ1l EAtbClf1FH0qvWTrkViF1izMo6HcJu8mxlNdZRw6mgVABx8xVcc2VmZG6ztHDmuUBmUN aAZBV7vgoyqn/KZThiJAWywMKh8hp8E9xUqC+A6gchwoEOGOXv2R0cOo9joFatcw0MRC zvIGpFz+5dYJWaAoo43s5TOrSzX4qcZ5au6c7bMZOZA/47tMsFNPBVCZWY3Cj375o+Da 82aqocNU4GC2pGOHVMbffNmnmOvNilmx15nUvapylheibDc/AhU7Jc5jsAOQzNh/Bl+R 7xRw== X-Gm-Message-State: AOPr4FWTuDkRW+DjxVfM5lINtTUyJKAYo2iIDu6OsscfB1RtrC1iYfB4c9D5IMFDQCb0IQ== X-Received: by 10.25.39.73 with SMTP id n70mr10377769lfn.91.1463326267554; Sun, 15 May 2016 08:31:07 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id tg1sm4505275lbb.7.2016.05.15.08.31.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 15 May 2016 08:31:06 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Sun, 15 May 2016 18:28:09 +0300 Message-Id: <1463326089-15526-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463326089-15526-1-git-send-email-jcmvbkbc@gmail.com> References: <1463326089-15526-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH 2/2] hw/net/opencores_eth: Allocating Large sized arrays to heap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Zhou Jie Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;