LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Kai-Heng Feng <kai.heng.feng@canonical.com>
Cc: nic_swsd <nic_swsd@realtek.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	"open list:8169 10/100/1000 GIGABIT ETHERNET DRIVER" 
	<netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] r8169: Implement dynamic ASPM mechanism
Date: Sat, 14 Aug 2021 13:31:15 +0200	[thread overview]
Message-ID: <0c08f92a-2e06-8917-3726-4b67bd875dbc@gmail.com> (raw)
In-Reply-To: <CAAd53p7qVcnwLL-73J4J_QvEfca2Y=Mjr=G-7LaBPMX2FzRCFw@mail.gmail.com>

On 13.08.2021 11:54, Kai-Heng Feng wrote:
> On Fri, Aug 13, 2021 at 2:49 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>>
>> On 12.08.2021 17:53, Kai-Heng Feng wrote:
>>> r8169 NICs on some platforms have abysmal speed when ASPM is enabled.
>>> Same issue can be observed with older vendor drivers.
>>>
>>> The issue is however solved by the latest vendor driver. There's a new
>>> mechanism, which disables r8169's internal ASPM when the NIC traffic has
>>> more than 10 packets, and vice versa.
>>>
>>> Realtek confirmed that all their PCIe LAN NICs, r8106, r8168 and r8125
>>
>> As we have Realtek in this mail thread:
> 
> Is it still in active use? I always think it's just a dummy address...
At least mails to this address are not bounced, and this address still is
in MAINTAINERS. But right, I've never any reaction on mails to this
address. So it may make sense to remove it from MAINTAINERS.
Not sure what the process would be to do this.

> 
>> Typically hw issues affect 1-3 chip versions only. The ASPM problems seem
>> to have been existing for at least 15 years now, in every chip version.
>> It seems that even the new RTL8125 chip generation still has broken ASPM.
> 
> Is there a bug report for that?
> 
No. This was referring to your statement that also r8125 vendor driver
includes this "dynamic ASPM" workaround. They wouldn't have done this
if RTL8125 had proper ASPM support, or?

>> Why was this never fixed? ASPM not considered to be relevant? HW design
>> too broken?
> 
> IIUC, ASPM is extremely relevant to pass EU/US power consumption
> regulation. So I really don't know why the situation under Linux is so
> dire.
> 
It's not something related to Linux, ASPM support in the Realtek chips
is simply broken. This needs to be fixed in HW.
The behavior we see may indicate that certain buffers in the chips are
too small to buffer traffic for full period of ASPM exit latency.

> Kai-Heng
> 
>>
>>> use dynamic ASPM under Windows. So implement the same mechanism here to
>>> resolve the issue.
>>>
>>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>>> ---
>>> v2:
>>>  - Use delayed_work instead of timer_list to avoid interrupt context
>>>  - Use mutex to serialize packet counter read/write
>>>  - Wording change
>>>
>>>  drivers/net/ethernet/realtek/r8169_main.c | 45 +++++++++++++++++++++++
>>>  1 file changed, 45 insertions(+)
>>>
>>> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
>>> index c7af5bc3b8af..7ab2e841dc69 100644
>>> --- a/drivers/net/ethernet/realtek/r8169_main.c
>>> +++ b/drivers/net/ethernet/realtek/r8169_main.c
>>> @@ -624,6 +624,11 @@ struct rtl8169_private {
>>>
>>>       unsigned supports_gmii:1;
>>>       unsigned aspm_manageable:1;
>>> +     unsigned aspm_enabled:1;
>>> +     struct delayed_work aspm_toggle;
>>> +     struct mutex aspm_mutex;
>>> +     u32 aspm_packet_count;
>>> +
>>>       dma_addr_t counters_phys_addr;
>>>       struct rtl8169_counters *counters;
>>>       struct rtl8169_tc_offsets tc_offset;
>>> @@ -2671,6 +2676,8 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
>>>               RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
>>>       }
>>>
>>> +     tp->aspm_enabled = enable;
>>> +
>>>       udelay(10);
>>>  }
>>>
>>> @@ -4408,6 +4415,9 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,
>>>
>>>       dirty_tx = tp->dirty_tx;
>>>
>>> +     mutex_lock(&tp->aspm_mutex);
>>> +     tp->aspm_packet_count += tp->cur_tx - dirty_tx;
>>> +     mutex_unlock(&tp->aspm_mutex);
>>>       while (READ_ONCE(tp->cur_tx) != dirty_tx) {
>>>               unsigned int entry = dirty_tx % NUM_TX_DESC;
>>>               u32 status;
>>> @@ -4552,6 +4562,10 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, int budget
>>>               rtl8169_mark_to_asic(desc);
>>>       }
>>>
>>> +     mutex_lock(&tp->aspm_mutex);
>>> +     tp->aspm_packet_count += count;
>>> +     mutex_unlock(&tp->aspm_mutex);
>>> +
>>>       return count;
>>>  }
>>>
>>> @@ -4659,8 +4673,33 @@ static int r8169_phy_connect(struct rtl8169_private *tp)
>>>       return 0;
>>>  }
>>>
>>> +#define ASPM_PACKET_THRESHOLD 10
>>> +#define ASPM_TOGGLE_INTERVAL 1000
>>> +
>>> +static void rtl8169_aspm_toggle(struct work_struct *work)
>>> +{
>>> +     struct rtl8169_private *tp = container_of(work, struct rtl8169_private,
>>> +                                               aspm_toggle.work);
>>> +     bool enable;
>>> +
>>> +     mutex_lock(&tp->aspm_mutex);
>>> +     enable = tp->aspm_packet_count <= ASPM_PACKET_THRESHOLD;
>>> +     tp->aspm_packet_count = 0;
>>> +     mutex_unlock(&tp->aspm_mutex);
>>> +
>>> +     if (tp->aspm_enabled != enable) {
>>> +             rtl_unlock_config_regs(tp);
>>> +             rtl_hw_aspm_clkreq_enable(tp, enable);
>>> +             rtl_lock_config_regs(tp);
>>> +     }
>>> +
>>> +     schedule_delayed_work(&tp->aspm_toggle, ASPM_TOGGLE_INTERVAL);
>>> +}
>>> +
>>>  static void rtl8169_down(struct rtl8169_private *tp)
>>>  {
>>> +     cancel_delayed_work_sync(&tp->aspm_toggle);
>>> +
>>>       /* Clear all task flags */
>>>       bitmap_zero(tp->wk.flags, RTL_FLAG_MAX);
>>>
>>> @@ -4687,6 +4726,8 @@ static void rtl8169_up(struct rtl8169_private *tp)
>>>       rtl_reset_work(tp);
>>>
>>>       phy_start(tp->phydev);
>>> +
>>> +     schedule_delayed_work(&tp->aspm_toggle, ASPM_TOGGLE_INTERVAL);
>>>  }
>>>
>>>  static int rtl8169_close(struct net_device *dev)
>>> @@ -5347,6 +5388,10 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>>>
>>>       INIT_WORK(&tp->wk.work, rtl_task);
>>>
>>> +     INIT_DELAYED_WORK(&tp->aspm_toggle, rtl8169_aspm_toggle);
>>> +
>>> +     mutex_init(&tp->aspm_mutex);
>>> +
>>>       rtl_init_mac_address(tp);
>>>
>>>       dev->ethtool_ops = &rtl8169_ethtool_ops;
>>>
>>


  reply	other threads:[~2021-08-14 11:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 15:53 Kai-Heng Feng
2021-08-12 15:53 ` [PATCH v2 2/2] r8169: Enable ASPM for selected NICs Kai-Heng Feng
2021-08-12 19:38   ` Heiner Kallweit
2021-08-13 10:11     ` Kai-Heng Feng
2021-08-14 11:23       ` Heiner Kallweit
2021-08-12 19:34 ` [PATCH v2 1/2] r8169: Implement dynamic ASPM mechanism Heiner Kallweit
2021-08-13  9:46   ` Kai-Heng Feng
2021-08-14 11:33     ` Heiner Kallweit
2021-08-13  6:46 ` [r8169] 5b4904cded: BUG:sleeping_function_called_from_invalid_context_at_kernel/locking/mutex.c kernel test robot
2021-08-13  6:48 ` [PATCH v2 1/2] r8169: Implement dynamic ASPM mechanism Heiner Kallweit
2021-08-13  9:54   ` Kai-Heng Feng
2021-08-14 11:31     ` Heiner Kallweit [this message]
2021-08-19  3:11       ` Kai-Heng Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c08f92a-2e06-8917-3726-4b67bd875dbc@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kai.heng.feng@canonical.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --subject='Re: [PATCH v2 1/2] r8169: Implement dynamic ASPM mechanism' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).