[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YjyXCzPVl0ZlRUeE@lunn.ch>
Date: Thu, 24 Mar 2022 17:06:35 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Arun.Ramadoss@...rochip.com
Cc: linux-kernel@...r.kernel.org, UNGLinuxDriver@...rochip.com,
linux@...linux.org.uk, kuba@...nel.org, pabeni@...hat.com,
netdev@...r.kernel.org, davem@...emloft.net, hkallweit1@...il.com
Subject: Re: [RFC Patch net-next 3/3] net: phy: lan87xx: added ethtool SQI
support
On Thu, Mar 24, 2022 at 03:48:57PM +0000, Arun.Ramadoss@...rochip.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
Powered by blists - more mailing lists