Messages in this thread | | | Date | Mon, 21 Mar 2022 19:36:37 +0100 | From | Andrew Lunn <> | Subject | Re: [RFC Patch net-next 3/3] net: phy: lan87xx: added ethtool SQI support |
| |
> +#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
| |