From patchwork Wed Mar 30 01:22:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 8692181 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 7D7689F36E for ; Wed, 30 Mar 2016 01:25:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D79A620351 for ; Wed, 30 Mar 2016 01:25:01 +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 22F42202F8 for ; Wed, 30 Mar 2016 01:25:01 +0000 (UTC) Received: from localhost ([::1]:51327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1al4sW-0002Uq-GT for patchwork-qemu-devel@patchwork.kernel.org; Tue, 29 Mar 2016 21:25:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1al4qm-0007eJ-Vn for qemu-devel@nongnu.org; Tue, 29 Mar 2016 21:23:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1al4ql-0008PO-WE for qemu-devel@nongnu.org; Tue, 29 Mar 2016 21:23:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1al4ql-0008PD-QB for qemu-devel@nongnu.org; Tue, 29 Mar 2016 21:23:11 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 7CE02821C3; Wed, 30 Mar 2016 01:23:11 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-7-94.pek2.redhat.com [10.72.7.94]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2U1Mu24025729; Tue, 29 Mar 2016 21:23:09 -0400 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Wed, 30 Mar 2016 09:22:54 +0800 Message-Id: <1459300975-5987-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1459300975-5987-1-git-send-email-jasowang@redhat.com> References: <1459300975-5987-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , Sameeh Jubran Subject: [Qemu-devel] [PULL V2 6/7] e1000: Fixing interrupts pace. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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: Sameeh Jubran This patch introduces an upper bound for number of interrupts per second. Without this bound an interrupt storm can occur as it has been observed on Windows 10 when disabling the device. According to the SPEC - Intel PCI/PCI-X Family of Gigabit Ethernet Controllers Software Developer's Manual, section 13.4.18 - the Ethernet controller guarantees a maximum observable interrupt rate of 7813 interrupts/sec. If there is no upper bound this could lead to an interrupt storm by e1000 (when mit_delay < 500) causing interrupts to fire at a very high pace. Thus if mit_delay < 500 then the delay should be set to the minimum delay possible which is 500. This can be calculated easily as follows: Interval = 10^9 / (7813 * 256) = 500. Signed-off-by: Sameeh Jubran Signed-off-by: Jason Wang --- hw/net/e1000.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 0387fa0..09b9ab5 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -357,6 +357,14 @@ set_interrupt_cause(E1000State *s, int index, uint32_t val) } mit_update_delay(&mit_delay, s->mac_reg[ITR]); + /* + * According to e1000 SPEC, the Ethernet controller guarantees + * a maximum observable interrupt rate of 7813 interrupts/sec. + * Thus if mit_delay < 500 then the delay should be set to the + * minimum delay possible which is 500. + */ + mit_delay = (mit_delay < 500) ? 500 : mit_delay; + if (mit_delay) { s->mit_timer_on = 1; timer_mod(s->mit_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +