Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp553871ybl; Fri, 30 Aug 2019 03:52:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxR6J9IXA2h6gnHqOhvc8/XAOPaUMsto4adCg0O9Ku+m3xNE//d9w8DDYS8CGME8tLoECF6 X-Received: by 2002:a17:90a:e28a:: with SMTP id d10mr15192670pjz.107.1567162332298; Fri, 30 Aug 2019 03:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567162332; cv=none; d=google.com; s=arc-20160816; b=gLyrqwecBECsG6weRFUdX7PsI4TV9RbKJufc37r+bMux2pXkL9vZg6J6HvouU5Mk2F wFiIwChJpT87xIJl35iObmLF9Jeub5MMcRDGIVv62bj5qizetc2we4k8CAkT7Q2ro3Df CuB8/u6I1/Ed4RHIVDHhXiI//WB3ZOm11iy/bu1NDlSTc4qcGobuRh/R9GrCE+4j/FMU RYGbHLI2FLg1wgEVu+1+y8FWvLp4iFTd15CRvxJC8HW3HAmMt2At0q9daLErQ9TYIaYE 02RInaOYDeTMF9pLGHrGQxcSL+hWzldlXC86xzhu5RXxSQVuQzrq4vHAHUXXbTnX8/m6 rOpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xhHEQ5g98RcYZnrkT1HyTjArZGcmSmqC2rkBEZO9ZKA=; b=Q7HzuQAohoKE/YjgnCAyeWh8c+euHeEyIJ6OKW3PrIMOBLt2ivSTqCQISqPiml4Mmv xZbBxp+Vq80jB3lEbxzLXqhJPemnXiabajB/6+71ZidXCDO/8KTawJilrycfgtCPpDzp 5zek9RXWj9VXtBw00XE2XbULtvSaifv/kdHQICpJiXf7W4OyKL5g9gckWoXvP8amvZzC vtlawk/Juvqj5Lz3xXYFZYrY57CknPI4mJOpW9lREopxCcpDOUEqPazohKVxsnzAsT83 f2eECWw4bT9zp1NgRT5BaPSC/DMfWJtWNnclyX14ktIPmOEJubeslWh1h+pR9yTJiYVV kJig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d24si4285767plr.187.2019.08.30.03.51.56; Fri, 30 Aug 2019 03:52:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728148AbfH3Kt2 (ORCPT + 99 others); Fri, 30 Aug 2019 06:49:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:45210 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726902AbfH3Kt2 (ORCPT ); Fri, 30 Aug 2019 06:49:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 484C5AC1C; Fri, 30 Aug 2019 10:49:27 +0000 (UTC) Date: Fri, 30 Aug 2019 12:49:25 +0200 From: Joerg Roedel To: Eric Dumazet , Robin Murphy Cc: linux-kernel , iommu@lists.linux-foundation.org, Eric Dumazet , Jinyu Qi Subject: Re: [PATCH] iommu/iova: avoid false sharing on fq_timer_on Message-ID: <20190830104925.GI17192@suse.de> References: <20190828131338.89832-1-edumazet@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828131338.89832-1-edumazet@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Looks good to me, but adding Robin for his opinion. On Wed, Aug 28, 2019 at 06:13:38AM -0700, Eric Dumazet wrote: > In commit 14bd9a607f90 ("iommu/iova: Separate atomic variables > to improve performance") Jinyu Qi identified that the atomic_cmpxchg() > in queue_iova() was causing a performance loss and moved critical fields > so that the false sharing would not impact them. > > However, avoiding the false sharing in the first place seems easy. > We should attempt the atomic_cmpxchg() no more than 100 times > per second. Adding an atomic_read() will keep the cache > line mostly shared. > > This false sharing came with commit 9a005a800ae8 > ("iommu/iova: Add flush timer"). > > Signed-off-by: Eric Dumazet > Cc: Jinyu Qi > Cc: Joerg Roedel > --- > drivers/iommu/iova.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index 3e1a8a6755723a927a7942a7429ab7e6c19a0027..41c605b0058f9615c2dbdd83f1de2404a9b1d255 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -577,7 +577,9 @@ void queue_iova(struct iova_domain *iovad, > > spin_unlock_irqrestore(&fq->lock, flags); > > - if (atomic_cmpxchg(&iovad->fq_timer_on, 0, 1) == 0) > + /* Avoid false sharing as much as possible. */ > + if (!atomic_read(&iovad->fq_timer_on) && > + !atomic_cmpxchg(&iovad->fq_timer_on, 0, 1)) > mod_timer(&iovad->fq_timer, > jiffies + msecs_to_jiffies(IOVA_FQ_TIMEOUT)); > } > -- > 2.23.0.187.g17f5b7556c-goog