From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22F1DC3DA7F for ; Mon, 12 Aug 2024 21:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D7SLYzQGySu/90iA+kCTpNsQhViKxnnp2PeJDYY1lvw=; b=L59BBQH52cXkSdawh+Rh/S3JkJ QYRTZwY5844Ny486IBYWjHmiMKKn4ZPDAcqUomW+ljLXOsPwE+2YEsDahJbvBAZ6VpOqDVePt0nu9 66aocR1YYXonG22PR8EsbEJLQk07ijM1hq9QiSVa4kqO+U1IBlxQTS3oOD1zoD1cTlugHyAEHojG9 KtpSir6W2dW4vzVJt7DUD1uHuhyTS4J1RVx6tNSNk7ZvzfpxHcYlQ+beEXXtLOSY7VYJbnJDwa3Mh aNLOAB5cVDRBIzE1ipk7dOQMXUIIiMQtom0hz0LuaucqIh43RQSJ1HqLjQvXMlIslwWiXLi3ECcDv aE/3DpZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdcU0-00000001bnr-227N; Mon, 12 Aug 2024 21:21:40 +0000 Received: from out-170.mta0.migadu.com ([2001:41d0:1004:224b::aa]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdcRf-00000001bZ1-3Utz for linux-arm-kernel@lists.infradead.org; Mon, 12 Aug 2024 21:21:04 +0000 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723497551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D7SLYzQGySu/90iA+kCTpNsQhViKxnnp2PeJDYY1lvw=; b=Arn2BC/ClhBP6vXsgPJPBKEt1MRwKhlGJ6v3ilzMSGfKaqKW0mpxHjW58d7xrGqtiETwl/ Ot+28u1T3UQX0+C8HBzurB+hS0PJy4fLu3iquuAUJn6lx73/pwnJwsThHMZ220q9g93rlA 3hvTcFnPwGAIZkQPDWE71jx3AzdFdx4= Date: Mon, 12 Aug 2024 17:19:06 -0400 MIME-Version: 1.0 Subject: Re: [PATCH net-next v2 2/2] net: xilinx: axienet: Add statistics support To: Andrew Lunn Cc: Radhey Shyam Pandey , netdev@vger.kernel.org, Simon Horman , Jakub Kicinski , Russell King , "David S . Miller" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Paolo Abeni , Michal Simek , Eric Dumazet References: <20240812174118.3560730-1-sean.anderson@linux.dev> <20240812174118.3560730-3-sean.anderson@linux.dev> <70d817a8-5ee4-4ce2-883a-9e95f15f2855@lunn.ch> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sean Anderson In-Reply-To: <70d817a8-5ee4-4ce2-883a-9e95f15f2855@lunn.ch> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_141916_525758_03EA74D0 X-CRM114-Status: GOOD ( 21.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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