Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1663892pxx; Fri, 30 Oct 2020 16:06:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4QmjFjrldtIxd2resAbw4wQn/3xTbNjdboIPCbE8bOmjWv7c2K9ZUN85itY1JfHlbVZOB X-Received: by 2002:a17:906:7f92:: with SMTP id f18mr4750943ejr.189.1604099184161; Fri, 30 Oct 2020 16:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604099184; cv=none; d=google.com; s=arc-20160816; b=ASnkhqcYVEii5ab441Sw5Ni6VU5+2O9gH7DzGZszrPs6GfFkP/SpEFwj8wfVL8fB3L ty8hXpLrHpAsO9D6g4Vru8KU6Oo7/XYBQXGfFDhJSOYvE4HrB4tsdiwxuLqRdzl8q/R4 3D+0FQJj8s312/7TvifDruE7/zMrtd7cpyGyJQ/9A6nv9HXda0huHb7XBelJmHWVZ+F5 CncnvRl2/Z/bbJEKQ3JzKxdTofSAImQUbzsgIY0ARB1CKPk+ocqz7u97vdRzrdqxqi/j vWqhKbdMGih9i8GfETus+lXqqaHVF4yMC0LVTkaMw0nzpf9cbLVcj4eqICJR0W+LdYTv dajQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WZUWoGAH6M0vOc7felvtoYqBxBRmN7X/BhItNhFZdvY=; b=aqCJZLh87P02vqL7nVIev5OxTVwEwF5cv+KYafi1BTGZG9YtBsRG1E/rNntNqxu4QG VFn0VHIUWKvafdHPEVFRFdN6wxldqIsXKlf+qSMkh6If2FSJA/aeFwgweIXgU8tRY2JR fdsEFBD3C04HjiHlYuUVPpUgvnio25PJUZ1YavbNL48PoD5L2CQhS3DDeQEDyTRdWXjr mWy4qjcjDBj+UPdXLKSHFnl3TGSmB6WULKULw54hqcLnu99XLTEx8JMttA4zqLA5y6aP MFSaKGLFEDiby7eTfL7vfAVZkdRagQThn38vBgOauIiLEiTxtYX/EdkamTULWWUhtKzr /aRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="sguMJ/0c"; 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 d14si5758265edu.275.2020.10.30.16.06.02; Fri, 30 Oct 2020 16:06:24 -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=casper.20170209 header.b="sguMJ/0c"; 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 S1726070AbgJ3XCa (ORCPT + 99 others); Fri, 30 Oct 2020 19:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbgJ3XC3 (ORCPT ); Fri, 30 Oct 2020 19:02:29 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23B65C0613D5 for ; Fri, 30 Oct 2020 16:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=WZUWoGAH6M0vOc7felvtoYqBxBRmN7X/BhItNhFZdvY=; b=sguMJ/0cYARAs5QSQab7j5MJ3T IDOhDVRUtFm9/+yJoKf2hcLDDPV2b7mw253Vdt0OZLrIuP8/8mhj7ZA6SD6pYKVRSno9wyo61VN/0 g1Uyy9SJun8TojUoQ5bkr1m+7Eq59pZqdyGjdz5Ed64VdpKW0w3KYs8+/und0cSQJAsBiE4W4cj1z mJ3I9jjR+n0o8bMocetNICMqyXSoOaKmut98Pk32UnD3MAhCC6pYpWVGa5cpNe3wROCcdHOeYzSNw cGatizLkbLFZ2m+n6zFtVvbSPnKWWKNOEyESZkNSGG6Ipmw0faPGLetSakQcFZuJZzF69y9ByIZW/ NRPxiycA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYdPA-0002jI-5x; Fri, 30 Oct 2020 23:01:56 +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 0E5DA300446; Sat, 31 Oct 2020 00:01:53 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E9A8C286B0708; Sat, 31 Oct 2020 00:01:52 +0100 (CET) Date: Sat, 31 Oct 2020 00:01:52 +0100 From: Peter Zijlstra To: Steven Rostedt Cc: Jesper Dangaard Brouer , mingo@kernel.org, tglx@linutronix.de, 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 Subject: Re: [PATCH 4/6] perf: Optimize get_recursion_context() Message-ID: <20201030230152.GT2594@hirez.programming.kicks-ass.net> References: <20201030151345.540479897@infradead.org> <20201030151955.187580298@infradead.org> <20201030181138.215b2b6a@carbon> <20201030162248.58e388f0@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201030162248.58e388f0@oasis.local.home> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 30, 2020 at 04:22:48PM -0400, Steven Rostedt wrote: > As this is something that ftrace recursion also does, perhaps we should > move this into interrupt.h so that anyone that needs a counter can get > it quickly, and not keep re-implementing it. Works for me, however: > /* > * Quickly find what context you are in. > * 0 - normal > * 1 - softirq > * 2 - hard interrupt > * 3 - NMI > */ > static inline int irq_context() > { > unsigned int pc = preempt_count(); > int rctx = 0; unsigned > > if (pc & (NMI_MASK)) > rctx++; > if (pc & (NMI_MASK | HARDIRQ_MASK)) > rctx++; > if (pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)) > rctx++; > > return rctx; > } otherwise you'll get an extra instruction to sign extend it, which is daft (yes, i've been staring at GCC output far too much). Also, gcc-9 does worse (like 1 byte iirc) with: rctx += !!(pc & (NMI_MASK)); rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK)); rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)); but gcc-10 doesn't seem to care.