Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2738812pxb; Mon, 31 Jan 2022 03:17:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxunL117BKLna0TpaFRjlVDPrm6shDfrq8Fp+HdLZW1uo5mufiBrhpK/0qO/OZFqJ3mqAHv X-Received: by 2002:a05:6402:2754:: with SMTP id z20mr20111552edd.235.1643627873854; Mon, 31 Jan 2022 03:17:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643627873; cv=none; d=google.com; s=arc-20160816; b=Dcfe0Bydny3Le5O9v4CDV5XKecVZCWgTOnSGmg3vmKMY2+r9i24P0KUFZwP/EnGYnR GPrzHjW5Fucdqdd91LMN548fLZgoOOuITc8nRHOctwxEI30XTbZRKa3kT1eWQk7AFbkV RKXGDjWWT+r86xQ/M6JOLfg/3Z5TuacOqeVkves66RFyBWLCsmidUmENxXwNOerS2uVW JGcEopBucoIPhC2O5RbRO+vXa7K6ToszXQbYaiRHCXFg44qSftAjSsax0VezfaDvvACK 9amOmBndB7GIA2wTAW5H36U9/A2CQQ0s8juR0O0b/GnrYO1NSuxtLCYNyWkZJ7ruy555 qhAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/TiQff5wo3sO+pFFw8tQM78i8yOOCdG1QUdQMAaCrlI=; b=dM4aH0gNaEo/qhDgtF7QzQUaD0WtiD8M5+HpLIkOUtqTlibKpxcuMyE0NPpbEdXAwr fYzQlteveZ6yQSVwdD4N/k5asdPqH0QkJjdHLnoEsogN2KttRwp4JzkOG688VQz7xI/u ZO4qpFoOFDaQ4Yye6GMg2TZauLUt+9N0TP6zm7q8BeEhnP8MIrD/K04Oo9QTi+hv4A0I BaVLJ+7aE4UtzLSM30F+Klo8eSYZfifDfbUX1ZGFELLLIBHyjMbEvWmAHULUbW0DXh2Y VCxPFKjq8K8tnHWz2RcSqoIZnZC+kwq9pWgp1CbNmqDv16uWHQturbJ2E1YYljVpedzG lHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=Do2Gi2DK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si7339195edy.568.2022.01.31.03.17.29; Mon, 31 Jan 2022 03:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=Do2Gi2DK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239255AbiA1Q06 (ORCPT + 99 others); Fri, 28 Jan 2022 11:26:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiA1Q05 (ORCPT ); Fri, 28 Jan 2022 11:26:57 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF0CAC061714 for ; Fri, 28 Jan 2022 08:26:56 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id a25so9746479lji.9 for ; Fri, 28 Jan 2022 08:26:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=/TiQff5wo3sO+pFFw8tQM78i8yOOCdG1QUdQMAaCrlI=; b=Do2Gi2DKC15Aw4E1xojPxTgGkV5ex3ur2btG97aL4HsoKMU75Fm7UiNPtsxMQ+1j24 kmfziPNoo5ML2ZvB/9CMGQ+I7JL9d7LP/2zVGq6nqyb465w8dPPbcXpM3E5UHlLqtqOn e1exTLIzNhkszp9vq9EJZ7cg+9FuI+APNSk3TBpLfbXs4bn0x3dtvZLeBIBHh22V1z8C vg/O4SO26LWluC2kyAj6Z0cgVeKmhCedEyXfOeHvh0vmM6REEdpgxkGWDqXp3hkJ1lGI Q5q3N3GQBg3MphXbz/BmC4podMB5XoYSe3WljznxqNz89hKmaYqHBaRLq8dyQQoGSM6t uGFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=/TiQff5wo3sO+pFFw8tQM78i8yOOCdG1QUdQMAaCrlI=; b=nrRGPJ7xVvbA4G4w9d9y1c51eG+hMiv+TNOs1GjwHwvtkIwuBfKQAo/5rYO8dETR3L rIeNOoJW0vMMxKOaegemt/qqYyW4zdb1b1fC/shXmuI3l1UUI83qaOV6m0XjNXpQ4gBg qbr+BXPZ7ZMYwPAqFKJzymotUlXD1lAbZOMuq3LbbGUtK1FdZVGTBcmT92sYm2wRxtt4 HoAA6najpcVMBjgZTEs2SvZC5sc9TvV7A/IpjnTLvVpeiVGPyxv0OtyYGELqeopmjmQa aRR1v2xLBU4njDOHVnP2G5tI1YlImcX6Pl10bhmbHXP+QY2DejgvTrZ+Yf1zx4SqzhUV zJ2w== X-Gm-Message-State: AOAM531+ym33bQUjCisTWLrYnq0iiSb+lfve9pQhfdmB0VMRREgl03OR Zn7CfoihTtSl6RxVB+8h/FXe7A== X-Received: by 2002:a05:651c:1509:: with SMTP id e9mr889498ljf.155.1643387214989; Fri, 28 Jan 2022 08:26:54 -0800 (PST) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id v17sm1954968ljh.5.2022.01.28.08.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 08:26:54 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, andrew@lunn.ch, David.Laight@ACULAB.COM, Vivien Didelot , Florian Fainelli , Vladimir Oltean , linux-kernel@vger.kernel.org Subject: [PATCH v3 net-next 1/2] net: dsa: mv88e6xxx: Improve performance of busy bit polling Date: Fri, 28 Jan 2022 17:26:49 +0100 Message-Id: <20220128162650.2510062-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220128162650.2510062-1-tobias@waldekranz.com> References: <20220128162650.2510062-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid a long delay when a busy bit is still set and has to be polled again. Measurements on a system with 2 Opals (6097F) and one Agate (6352) show that even with this much tighter loop, we have about a 50% chance of the bit being cleared on the first poll, all other accesses see the bit being cleared on the second poll. On a standard MDIO bus running MDC at 2.5MHz, a single access with 32 bits of preamble plus 32 bits of data takes 64*(1/2.5MHz) = 25.6us. This means that mv88e6xxx_smi_direct_wait took 26us + CPU overhead in the fast scenario, but 26us + 1500us + 26us + CPU overhead in the slow case - bringing the average close to 1ms. With this change in place, the slow case is closer to 2*26us + CPU overhead, with the average well below 100us - a 10x improvement. This translates to real-world winnings. On a 3-chip 20-port system, the modprobe time drops by 88%: Before: root@coronet:~# time modprobe mv88e6xxx real 0m 15.99s user 0m 0.00s sys 0m 1.52s After: root@coronet:~# time modprobe mv88e6xxx real 0m 2.21s user 0m 0.00s sys 0m 1.54s Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 13 ++++++++++--- drivers/net/dsa/mv88e6xxx/smi.c | 11 +++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 58ca684d73f7..1023e4549359 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -86,12 +86,16 @@ int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val) int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask, u16 val) { + const unsigned long timeout = jiffies + msecs_to_jiffies(50); u16 data; int err; int i; - /* There's no bus specific operation to wait for a mask */ - for (i = 0; i < 16; i++) { + /* There's no bus specific operation to wait for a mask. Even + * if the initial poll takes longer than 50ms, always do at + * least one more attempt. + */ + for (i = 0; time_before(jiffies, timeout) || (i < 2); i++) { err = mv88e6xxx_read(chip, addr, reg, &data); if (err) return err; @@ -99,7 +103,10 @@ int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg, if ((data & mask) == val) return 0; - usleep_range(1000, 2000); + if (i < 2) + cpu_relax(); + else + usleep_range(1000, 2000); } dev_err(chip->dev, "Timeout while waiting for switch\n"); diff --git a/drivers/net/dsa/mv88e6xxx/smi.c b/drivers/net/dsa/mv88e6xxx/smi.c index 282fe08db050..728ef3f54ec5 100644 --- a/drivers/net/dsa/mv88e6xxx/smi.c +++ b/drivers/net/dsa/mv88e6xxx/smi.c @@ -55,11 +55,15 @@ static int mv88e6xxx_smi_direct_write(struct mv88e6xxx_chip *chip, static int mv88e6xxx_smi_direct_wait(struct mv88e6xxx_chip *chip, int dev, int reg, int bit, int val) { + const unsigned long timeout = jiffies + msecs_to_jiffies(50); u16 data; int err; int i; - for (i = 0; i < 16; i++) { + /* Even if the initial poll takes longer than 50ms, always do + * at least one more attempt. + */ + for (i = 0; time_before(jiffies, timeout) || (i < 2); i++) { err = mv88e6xxx_smi_direct_read(chip, dev, reg, &data); if (err) return err; @@ -67,7 +71,10 @@ static int mv88e6xxx_smi_direct_wait(struct mv88e6xxx_chip *chip, if (!!(data & BIT(bit)) == !!val) return 0; - usleep_range(1000, 2000); + if (i < 2) + cpu_relax(); + else + usleep_range(1000, 2000); } return -ETIMEDOUT; -- 2.25.1