Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1366715pxx; Fri, 30 Oct 2020 08:24:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBNlMGmHQtsKfFGVtUMl4MQKcRbDJDAQmCH5BaFI7HSysRmS77KfPG0td5c34CcK7DPsgp X-Received: by 2002:aa7:dd49:: with SMTP id o9mr2871658edw.143.1604071474560; Fri, 30 Oct 2020 08:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604071474; cv=none; d=google.com; s=arc-20160816; b=IpikCPNGy4jSNxzwq+8sh9VrqoMwCVGgCz2Tk+1mtjr+/ix2FWRYuAukHxydT/fOGb R0j9FgNzoQGs8XsAYk26kZcKLIQq+gB695DOWwrEH1n32DdiEf/jAoeOSz844XLAgDa2 s/p8mONliUxma83YL2mAJBpEiSWEBoiH9X5QGgztcH0D7AZEbp9DK5PT2GSF4kaJ0Ei8 bgwK7vaWpLnrJ2MhgXqZbhcM6jJO1y9+hrLm7z7o6/hjdRpSvJbgpIS3pL9iFlDxmfug Svy0hS1owGxKiaQC9928RQbYh51l9iQNOEQZ6mjDDvSOIBHaf6PCR+wSO8cGh2EtOTpE rhBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=e7UtJQ0GpwJ2/6Ic+CVEgkpSKe0Ng6nztF3SR5eihrM=; b=nMs9YBJP3brSKgl5hIex5k9ordwvBWs/qEyhHujvGC4fIYQLMw3kiI1ij7sqCMzfZK R8Oob/jS2oe6oQ35W/JPQJ9oqpS42SVlXuWKc6RTKLFQv8JGX52oConmNxP+AR8lUvqz WiydhgKQXjen44oO/PfBIvF5c/bPuSMl4zpf6goDbm+DkNSJC1jgt+FKrIt1zp3SWN13 ZjpTw+chg92Z+gsVt0/wrNJUmiw9C2FjSN5o1ANsYvq4GaWrgdK6VVv+HCiVavtn1sdL 65JfYui0HZfg1XDJZhQ7Obsbzp9LU9X1SXqCeJTGVg+mcwlh0KazRxDj+twAv/4KAB/b OOIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=K64cO9dF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r15si4683423ejy.36.2020.10.30.08.24.10; Fri, 30 Oct 2020 08:24:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=K64cO9dF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727198AbgJ3PVv (ORCPT + 99 others); Fri, 30 Oct 2020 11:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727171AbgJ3PVu (ORCPT ); Fri, 30 Oct 2020 11:21:50 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 232D9C0613CF for ; Fri, 30 Oct 2020 08:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=e7UtJQ0GpwJ2/6Ic+CVEgkpSKe0Ng6nztF3SR5eihrM=; b=K64cO9dFMsNCyudlOf6mol0kuI pweGGpyOEciWklL806vVZohx2dZs/ECWRDKS/qusMk6f5gQVop1uvrucGsiYdFGSmZ+qQzxfS/xcP hdbG45S5REl+z3LfctDIENQ3u19EHm4Uc3Cp3J8PGv/7JpLpACtRINk/zwoqUTg7BoR+ZRMVbyE+h cDl4m/DNOzLbdMUk/mE9U8OIEY3ndVHBwpgxl8xwaMBnvfl4W8iMW4BxlqLjDTmAC6lx2HxVbXqRA vgUZBgY9eeJjkqCLhqWTe4xdJcCkQVyIG53GDqmXzGViy0B5203XSY1xKMVHq2eNlwS63eEWjyUri KEeouBxA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYWDK-0003Lg-JQ; Fri, 30 Oct 2020 15:21:15 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 13DDB307936; Fri, 30 Oct 2020 16:21:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id EFEC82B708596; Fri, 30 Oct 2020 16:21:11 +0100 (CET) Message-ID: <20201030151955.187580298@infradead.org> User-Agent: quilt/0.66 Date: Fri, 30 Oct 2020 16:13:49 +0100 From: Peter Zijlstra To: mingo@kernel.org, tglx@linutronix.de, rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, kan.liang@linux.intel.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, ak@linux.intel.com, eranian@google.com, peterz@infradead.org, Jesper Dangaard Brouer Subject: [PATCH 4/6] perf: Optimize get_recursion_context() References: <20201030151345.540479897@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Look ma, no branches!" Cc: Jesper Dangaard Brouer Cc: Steven Rostedt Signed-off-by: Peter Zijlstra (Intel) --- kernel/events/internal.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) --- a/kernel/events/internal.h +++ b/kernel/events/internal.h @@ -205,16 +205,15 @@ DEFINE_OUTPUT_COPY(__output_copy_user, a static inline int get_recursion_context(int *recursion) { - int rctx; + unsigned int pc = preempt_count(); + unsigned int rctx = 0; - if (unlikely(in_nmi())) - rctx = 3; - else if (in_irq()) - rctx = 2; - else if (in_serving_softirq()) - rctx = 1; - else - rctx = 0; + if (pc & (NMI_MASK)) + rctx++; + if (pc & (NMI_MASK | HARDIRQ_MASK)) + rctx++; + if (pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)) + rctx++; if (recursion[rctx]) return -1;