Re: [PATCH net-next v3 2/2] net: xilinx: axienet: Add statistics support
From: Sean Anderson
Date: Tue Aug 20 2024 - 10:24:09 EST
On 8/16/24 22:42, Jakub Kicinski wrote:
> On Thu, 15 Aug 2024 10:40:31 -0400 Sean Anderson wrote:
>> + u64 hw_stat_base[STAT_COUNT];
>> + u64 hw_last_counter[STAT_COUNT];
>
> I think hw_last_counter has to be u32..
>
>> + seqcount_mutex_t hw_stats_seqcount;
>> + struct mutex stats_lock;
>> + struct delayed_work stats_work;
>> + bool reset_in_progress;
>> +
>> struct work_struct dma_err_task;
>>
>> int tx_irq;
>> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
>> index b2d7c396e2e3..9353a4f0ab1b 100644
>> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
>> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
>> @@ -519,11 +519,55 @@ static void axienet_setoptions(struct net_device *ndev, u32 options)
>> lp->options |= options;
>> }
>>
>> +static u64 axienet_stat(struct axienet_local *lp, enum temac_stat stat)
>> +{
>> + u32 counter;
>> +
>> + if (lp->reset_in_progress)
>> + return lp->hw_stat_base[stat];
>> +
>> + counter = axienet_ior(lp, XAE_STATS_OFFSET + stat * 8);
>> + return lp->hw_stat_base[stat] + (counter - lp->hw_last_counter[stat]);
>
> .. or you need to cast the (counter - lp->...) result to u32.
> Otherwise counter's type is getting bumped to 64 and you're just doing
> 64b math here.
Yes, good catch. I think I changed the type while refactoring and forgot about it.
I think I'll expose the byte counters for the next revision to make it
easier to test rollover. I tried testing the packet counters overnight,
but I'm using a trial license for these devices at the moment and it
expired before the counters rolled over.
--Sean
>> +}
>> +
>> +static void axienet_stats_update(struct axienet_local *lp, bool reset)
>> +{
>> + enum temac_stat stat;
>> +
>> + write_seqcount_begin(&lp->hw_stats_seqcount);
>> + lp->reset_in_progress = reset;
>> + for (stat = 0; stat < STAT_COUNT; stat++) {
>> + u32 counter = axienet_ior(lp, XAE_STATS_OFFSET + stat * 8);
>> +
>> + lp->hw_stat_base[stat] += counter - lp->hw_last_counter[stat];
>> + lp->hw_last_counter[stat] = counter;
>> + }
>> + write_seqcount_end(&lp->hw_stats_seqcount);