Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2504727imb; Mon, 4 Mar 2019 06:54:08 -0800 (PST) X-Google-Smtp-Source: APXvYqx/nJrONjlhgwjFMEyfLvADIKDK2OSXysYb990/e/ClCJ/OO28Yfsq8f8HugG/f8X1AfxZn X-Received: by 2002:a63:591f:: with SMTP id n31mr18551613pgb.304.1551711248561; Mon, 04 Mar 2019 06:54:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551711248; cv=none; d=google.com; s=arc-20160816; b=x8l5YuPdp0vL+UFSmPE5e99p+6ueCNFqOiL4V5lhNd6ttpkC28R7MZzIQAyHfDjtEa RDkdnkd0+CxIq3VpLFUt51/9KkN0PDpyBgoyK2da+0NwxEm442aHbRcil83kC3bd8R1W dC+mV9Gchsbr1koE76D1MQEt4uXULFCMWDqqX8giqyQEX3rxbilnYnL8Ar/I6d/NjbFG kF/a1khi7px1aoVDenKC5kV0aLzBfaoKKAISfedjmgaJ0ieGrdpJd94LV9yG1db5cvlg rMlgx3hBQFrehe5s49Yfqr0u4jBzEPQhcyLkF/VcOAAlqL6j6l9Zleu7bgzI1HmM+bYg PZTw== 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=/ECryCV2Iyrp4OZgp5OGfU+IgaUP49c/YZWItjYoI9A=; b=KIY0HjJxUAi0x8fD5+6lMsSSqB5s/ls63WP5k/BEZY5+gpBpHbolQpWS5JphHjYpbL j2Vfz7YL2gCRC1nA7c6u7zx4Xarz9mB0kNhuAgq+DfCHVmOsBfTvp4eow9hvs1z1v98r hSll+78Q5Kn1veUmAHxavcZ0Gd/rBjeUQxZnukipnro39kt4hGtZfB7Z2UkdZtc8vH46 ku/OqFn09hRI57SdcTbfUa1CvU5dJNcu1/WAm9A6WeWEVzS2s4xVSbJ09sENJGjWq2F5 uWrTyxMFPfgDmIZoi0NNEDywaAKQ6/jD+sCbpoVds8GL5VAM4+bv5qJa6czJQmKFBAot IbCQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y192si5795536pfb.127.2019.03.04.06.53.53; Mon, 04 Mar 2019 06:54:08 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726430AbfCDOwV (ORCPT + 99 others); Mon, 4 Mar 2019 09:52:21 -0500 Received: from mga02.intel.com ([134.134.136.20]:24010 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbfCDOwV (ORCPT ); Mon, 4 Mar 2019 09:52:21 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Mar 2019 06:52:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,440,1544515200"; d="scan'208";a="304250447" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga005.jf.intel.com with ESMTP; 04 Mar 2019 06:52:20 -0800 Date: Mon, 4 Mar 2019 06:45:26 -0800 From: Fenghua Yu To: Peter Zijlstra Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Paolo Bonzini , Dave Hansen , Ashok Raj , Ravi V Shankar , Xiaoyao Li , linux-kernel , x86 , kvm@vger.kernel.org Subject: Re: [PATCH v4 02/17] drivers/net/b44: Align pwol_mask to unsigned long for better performance Message-ID: <20190304144526.GB230561@romley-ivt3.sc.intel.com> References: <1551494711-213533-1-git-send-email-fenghua.yu@intel.com> <1551494711-213533-3-git-send-email-fenghua.yu@intel.com> <20190304100022.GA32477@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190304100022.GA32477@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 04, 2019 at 11:00:22AM +0100, Peter Zijlstra wrote: > On Fri, Mar 01, 2019 at 06:44:56PM -0800, Fenghua Yu wrote: > > A bit in pwol_mask is set in b44_magic_pattern automatically by set_bit. > > set_bit sets the bit in a single unsigned long location. Since pwol_mask > > may not be aligned to unsigned long, the location may cross two cache > > lines and accessing the location degradates performance. On x86, accessing > > two cache lines in locked instruction in set_bit is called split lock and > > can cause overall performance degradation. > > > > To avoid to impact performance by accessing two cache lines in set_bit, > > align pwol_mask to unsigned long. > > > > Signed-off-by: Fenghua Yu > > --- > > drivers/net/ethernet/broadcom/b44.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c > > index 97ab0dd25552..bc544b6b9c3a 100644 > > --- a/drivers/net/ethernet/broadcom/b44.c > > +++ b/drivers/net/ethernet/broadcom/b44.c > > @@ -1547,7 +1547,8 @@ static void b44_setup_pseudo_magicp(struct b44 *bp) > > u32 val; > > int plen0, plen1, plen2; > > u8 *pwol_pattern; > > - u8 pwol_mask[B44_PMASK_SIZE]; > > + /* Align to unsigned long for better performance in set_bit() */ > > + u8 pwol_mask[B44_PMASK_SIZE] __aligned(sizeof(unsigned long)); > > > > pwol_pattern = kzalloc(B44_PATTERN_SIZE, GFP_KERNEL); > > if (!pwol_pattern) > > That is truly horrid code. But afaict pwol_mask is local and never > exposed to concurrency, so _why_ does it need atomic bitset in the first > place? > > Would not the below be a _much_ better solution? > > > diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c > index 97ab0dd25552..0b4226b406b1 100644 > --- a/drivers/net/ethernet/broadcom/b44.c > +++ b/drivers/net/ethernet/broadcom/b44.c > @@ -1520,7 +1520,7 @@ static int b44_magic_pattern(u8 *macaddr, u8 *ppattern, u8 *pmask, int offset) > > memset(ppattern + offset, 0xff, magicsync); > for (j = 0; j < magicsync; j++) > - set_bit(len++, (unsigned long *) pmask); > + __set_bit(len++, (unsigned long *) pmask); > > for (j = 0; j < B44_MAX_PATTERNS; j++) { > if ((B44_PATTERN_SIZE - len) >= ETH_ALEN) > @@ -1532,7 +1532,7 @@ static int b44_magic_pattern(u8 *macaddr, u8 *ppattern, u8 *pmask, int offset) > for (k = 0; k< ethaddr_bytes; k++) { > ppattern[offset + magicsync + > (j * ETH_ALEN) + k] = macaddr[k]; > - set_bit(len++, (unsigned long *) pmask); > + __set_bit(len++, (unsigned long *) pmask); > } > } > return len - 1; Sure. I will change the patch to your code. And add Signed-off-by: Peter Zijlstra to this patch? Thanks. -Fenghua