[PATCH net-next v2 2/2] net: xilinx: axienet: Add statistics support

Sean Anderson sean.anderson at linux.dev
Mon Aug 12 14:19:06 PDT 2024


On 8/12/24 17:18, Andrew Lunn wrote:
> On Mon, Aug 12, 2024 at 04:25:16PM -0400, Sean Anderson wrote:
>> On 8/12/24 16:22, Andrew Lunn wrote:
>> >>  static int __axienet_device_reset(struct axienet_local *lp)
>> >>  {
>> >>  	u32 value;
>> >>  	int ret;
>> >>  
>> >> +	/* Save statistics counters in case they will be reset */
>> >> +	guard(mutex)(&lp->stats_lock);
>> >> +	if (lp->features & XAE_FEATURE_STATS)
>> >> +		axienet_stats_update(lp, true);
>> > 
>> > My understanding of guard() is that the mutex is held until the
>> > function completes. That is much longer than you need. A
>> > scoped_guard() would be better here, and it makes it clear when the
>> > mutex will be released.
>> 
>> We have to hold it until...
>> 
>> >> +
>> >>  	/* Reset Axi DMA. This would reset Axi Ethernet core as well. The reset
>> >>  	 * process of Axi DMA takes a while to complete as all pending
>> >>  	 * commands/transfers will be flushed or completed during this
>> >> @@ -551,6 +595,23 @@ static int __axienet_device_reset(struct axienet_local *lp)
>> >>  		return ret;
>> >>  	}
>> >>  
>> >> +	/* Update statistics counters with new values */
>> >> +	if (lp->features & XAE_FEATURE_STATS) {
>> >> +		enum temac_stat stat;
>> >> +
>> >> +		write_seqcount_begin(&lp->hw_stats_seqcount);
>> >> +		lp->reset_in_progress = false;
>> >> +		for (stat = 0; stat < STAT_COUNT; stat++) {
>> >> +			u32 counter =
>> >> +				axienet_ior(lp, XAE_STATS_OFFSET + stat * 8);
>> >> +
>> >> +			lp->hw_stat_base[stat] +=
>> >> +				lp->hw_last_counter[stat] - counter;
>> >> +			lp->hw_last_counter[stat] = counter;
>> >> +		}
>> >> +		write_seqcount_end(&lp->hw_stats_seqcount);
>> 
>> ...here
>> 
>> Which is effectively the whole function. The main reason why I used guard() was to
>> simplify the error return cases.
> 
> This is why i personally don't like guard. It is not clear you
> intended the mutex to be held so long, and that this code actually
> requires it. An explicit mutex_unlock() here would make your
> intentions clear, or a scoped_guard. I can see guard avoiding some
> error path bugs, but i suspect it will introduce other problems when
> refactoring code and having to make guesses about what actually needs
> the mutex.

OK, I will go back to explicit lock/unlock for v3.

--Sean




More information about the linux-arm-kernel mailing list