Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp731965ybi; Fri, 24 May 2019 10:30:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBWAxLakUjJA6SQvjAkGghkTTpnkX1cKRBtED3ikuruowW5LPXhB+Lj33BsuAWGeIhGzmp X-Received: by 2002:a17:902:a505:: with SMTP id s5mr16944812plq.54.1558719050569; Fri, 24 May 2019 10:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719050; cv=none; d=google.com; s=arc-20160816; b=px2WCbG9pxBARoL2cfVXQK7R8ZPaWPqAfgstD1/FrQOxjU2GOFwSxmq1l19TwcYiba 4hrDFSf7bDFurDy9Nv7qO2/aabwyP4DzU4L3kql0+ve84PBwp3Jl3shFlIvIkw1KJsWv cKUF/bn9HzHsdcKBN6aTFxkingXFlHHetEz+iqLI7B0Tor/EU1C+l+4s5yimcJ+MfZgx tClTLo1gq5rvhyjuVbhWnJGJdgCQ/Y8uthyeqerXZePZ7ESz0hTeI5Aph8Ff7Lsy6JOV Je4Ibg6lV65GGRAWeEyGWAV57iZhrj4PQxzBtCw7SBoqgEW5tHo2k9GDS3FHosVBKT8N 46xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=75rhnVHSvjmqLvvdgYENj3nGhRiudMWiA8VdX44GuEA=; b=HjpdvrIn+je81pMpsNBi1zv8BXJoc3SBBHGWb6BTg2u2sXX2BYUR+J3SqVIPIEcWUC Oy7HuYIPr++nalyemPxoIjlLJtRg0pIOj7UvtKKZsXrl2mkLg/7RLaSM4KOMIs+NWmmD Yi8VZ+qhj+wmUSOb14Wrx9FMVqAU23Rj6n1T0CyVhtnCZ9NGNv8uMrC/JYuz+Db0tIMu hizmF2s2523jWY/F6YXw2zm5KXtNzd12Eu3FQlqfBKTe3dzckLxt38eeUgzkFYazZ/fc oiZKnt9YCCIASj6b/e8qFlm8DU8fTf440NlhzgL87RUF77qlX8zplkCaFCbA6/BSMLNb qLLw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si2597823pga.576.2019.05.24.10.30.34; Fri, 24 May 2019 10:30:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731967AbfEXR2t (ORCPT + 99 others); Fri, 24 May 2019 13:28:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44724 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbfEXR2t (ORCPT ); Fri, 24 May 2019 13:28:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 028C3305B16F; Fri, 24 May 2019 17:28:49 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-85.bos.redhat.com [10.18.17.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD5EB5D71B; Fri, 24 May 2019 17:28:47 +0000 (UTC) Subject: Re: [PATCH v2] locking/lock_events: Use this_cpu_add() when necessary To: Will Deacon Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying References: <20190524165346.26373-1-longman@redhat.com> <20190524171939.GA9120@fuggles.cambridge.arm.com> From: Waiman Long Organization: Red Hat Message-ID: Date: Fri, 24 May 2019 13:28:47 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190524171939.GA9120@fuggles.cambridge.arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 24 May 2019 17:28:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/24/19 1:19 PM, Will Deacon wrote: > On Fri, May 24, 2019 at 12:53:46PM -0400, Waiman Long wrote: >> The kernel test robot has reported that the use of __this_cpu_add() >> causes bug messages like: >> >> BUG: using __this_cpu_add() in preemptible [00000000] code: ... >> >> This is only an issue on preempt kernel where preemption can happen in >> the middle of a percpu operation. We are still using __this_cpu_*() for >> !preempt kernel to avoid additional overhead in case CONFIG_PREEMPT_COUNT >> is set. >> >> v2: Simplify the condition to just preempt or !preempt. >> >> Fixes: a8654596f0371 ("locking/rwsem: Enable lock event counting") >> Signed-off-by: Waiman Long >> --- >> kernel/locking/lock_events.h | 23 +++++++++++++++++++++-- >> 1 file changed, 21 insertions(+), 2 deletions(-) >> >> diff --git a/kernel/locking/lock_events.h b/kernel/locking/lock_events.h >> index feb1acc54611..05f34068ec06 100644 >> --- a/kernel/locking/lock_events.h >> +++ b/kernel/locking/lock_events.h >> @@ -30,13 +30,32 @@ enum lock_events { >> */ >> DECLARE_PER_CPU(unsigned long, lockevents[lockevent_num]); >> >> +/* >> + * The purpose of the lock event counting subsystem is to provide a low >> + * overhead way to record the number of specific locking events by using >> + * percpu counters. It is the percpu sum that matters, not specifically >> + * how many of them happens in each cpu. >> + * >> + * In !preempt kernel, we can just use __this_cpu_*() as preemption >> + * won't happen in the middle of the percpu operation. In preempt kernel, >> + * preemption happens in the middle of the percpu operation may produce >> + * incorrect result. >> + */ >> +#ifdef CONFIG_PREEMPT >> +#define lockevent_percpu_inc(x) this_cpu_inc(x) >> +#define lockevent_percpu_add(x, v) this_cpu_add(x, v) >> +#else >> +#define lockevent_percpu_inc(x) __this_cpu_inc(x) >> +#define lockevent_percpu_add(x, v) __this_cpu_add(x, v) > Are you sure this works wrt IRQs? For example, if I take an interrupt when > trying to update the counter, and then the irq handler takes a qspinlock > which in turn tries to update the counter. Would I lose an update in that > scenario? > > Will Good point! But this will be an issue even if we use the non-underscore version as I don't think it will disable interrupt. Also it is only a problem if the percpu operation is more than 1 instruction. It is a single instruction for x86. Other architectures may require more than 1 instruction. In those cases, we may lose count, but it is still better than getting the count from one CPU and put it into another CPU. Cheers, Longman