linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Arun.Ramadoss@microchip.com
Cc: linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com,
	linux@armlinux.org.uk, kuba@kernel.org, pabeni@redhat.com,
	netdev@vger.kernel.org, davem@davemloft.net,
	hkallweit1@gmail.com
Subject: Re: [RFC Patch net-next 3/3] net: phy: lan87xx: added ethtool SQI support
Date: Thu, 24 Mar 2022 17:06:35 +0100	[thread overview]
Message-ID: <YjyXCzPVl0ZlRUeE@lunn.ch> (raw)
In-Reply-To: <ba1d251a9bd93cdf4c894313637dd9618cd8091c.camel@microchip.com>

On Thu, Mar 24, 2022 at 03:48:57PM +0000, Arun.Ramadoss@microchip.com wrote:
> Hi Andrew,
> 
> Thanks for the review.
> 
> On Mon, 2022-03-21 at 19:36 +0100, Andrew Lunn wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> > 
> > > +#define T1_DCQ_SQI_MSK                       GENMASK(3, 1)
> > > +static int lan87xx_get_sqi(struct phy_device *phydev)
> > > +{
> > > +     u16 sqi_value[LAN87XX_SQI_ENTRY];
> > > +     for (i = 0; i < LAN87XX_SQI_ENTRY; i++) {
> > > +
> > > +             sqi_value[i] = FIELD_GET(T1_DCQ_SQI_MSK, rc);
> > > +
> > > +     /* Sorting SQI values */
> > > +     sort(sqi_value, LAN87XX_SQI_ENTRY, sizeof(u16),
> > > lan87xx_sqi_cmp, NULL);
> > 
> > Sort is quite heavyweight. Your SQI values are in the range 0-7
> > right?
> > So rather than have an array of LAN87XX_SQI_ENTRY entries, why not
> > create a histogram? You then just need to keep 8 uints. There is no
> > need to perform a sort to discard the outliers, simply remove from
> > the
> > outer histogram buckets. And then you can calculate the average.
> > 
> > That should be faster and use less memory.
> > 
> >      Andrew
> 
> I could get the algorithm for replacing array of LAN87XX_SQI_ENTRY(200)
> to array of 8 (sqi values 0 to 7) and increment the array[sqi_value]
> for every reading. And calculate the Average = ( 1 * array[1] + 2 *
> array[2] ... + 7 * array[7])/LAN87XX_SQI_ENTRY. By this way we get the
> average for 200 entries.
> But I couldn't get the algorithm on how to discard the outliers from
> the buckets. our main aim is to average from array[40] to arrary[160]
> value. Can you bit elaborate on how to remove the outer histogram
> buckets.

So your raw results look something like

array[0] = 10
array[1] = 10
array[2] = 25
array[3] = 100
array[4] = 50
array[5] = 1
array[6] = 4
array[7] = 0

To discard the lower outliers, take 40 away from the array[0],
array[1], array[2], etc. To discard the upper outliers, take 40 away
from array[7], array[6], array[5], etc. So you should end up with:

array[0] = 0
array[1] = 0
array[2] = 5
array[3] = 100
array[4] = 15
array[5] = 0
array[6] = 0
array[7] = 0

and then calculate the average: (2*5 + 3*100 + 4*15) / 120 = 3.

    Andrew

      reply	other threads:[~2022-03-24 16:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 15:53 [RFC Patch net-next 0/3] add ethtool SQI support for LAN87xx T1 Phy Arun Ramadoss
2022-03-21 15:53 ` [RFC Patch net-next 1/3] net: phy: lan87xx: added lan87xx_update_link routine Arun Ramadoss
2022-03-21 15:53 ` [RFC Patch net-next 2/3] net: phy: lan937x: added PHY_POLL_CABLE_TEST flag Arun Ramadoss
2022-03-21 15:53 ` [RFC Patch net-next 3/3] net: phy: lan87xx: added ethtool SQI support Arun Ramadoss
2022-03-21 18:36   ` Andrew Lunn
2022-03-24 15:48     ` Arun.Ramadoss
2022-03-24 16:06       ` Andrew Lunn [this message]

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=YjyXCzPVl0ZlRUeE@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Arun.Ramadoss@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).