Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9825409pxu; Tue, 29 Dec 2020 06:15:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzl6AIyoFnp/Ha9I1wEB5CB3dZ7vWwM66jKRAG0Ao05FhiEWKFI6IbcMsOXKWsoIwv0irHJ X-Received: by 2002:a05:6402:19b0:: with SMTP id o16mr46416003edz.270.1609251316345; Tue, 29 Dec 2020 06:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609251316; cv=none; d=google.com; s=arc-20160816; b=YF9X0vAPCh65EBBO3yfIK9eu3m3X6CgLsvAJm+zO16z6LFqfVv7s9Z2iP1NjAIESE2 8EDNvziheNeGCHxz3rOyhR++L+x8lGbvN1D8h4r6iUYJA0L9eXgZWXrKla7X3tVb/xGC mD9OCGRO2xlfZ9Ar6aXoAXoIrFuOhZCAyFuJPGs//8p87E3SaBJhUMCHPZoJCqFiOYJ5 M9sJRFXeZkfkryygbkrQRPBfcPU3wJjsaTOWcR5VSaisSmy1dVR9hIcJNM868aTQ6ngS 6EirjIe4hgZOJq1uFRutSeOncS76bmDUbf4sYfXRgMhpn8ENWi8EvcReYHb1HacM4+RV FYxg== 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; bh=sVcpFbPXw7bR8gfgq3X78/B8P1Pc7OvpEJwjpTcPPJQ=; b=Uqm1nbviC3UuyJ1Ic/Kjk+JJ/6b4VMfbbo0kzS8qhJRLgnb4tUDx9k3zBhcufRcfm8 zf5pToXBjKqys2Ew2o6aHPQUeilBbgD1PYT6BPSN7zYidO1Bm5kVr6ajcLOzsqLEo+r/ 5BXp/atLl4gQjt3DGRkSDEXZnA+FdZqK0gNA5u7nZiWbNKjrRAlcECoVteZ85dEMHh5Y dnazPLQ88rDYtLBafaNLL7GeY5F1PJVSyAOrdjMP8wQNsUpDLMx8r8C4tpvmOB2rtF1k Ni0XRS1YP0WtJalMFO5jG1CXMWNW734F6mZV9l1NnucWVuozVL3UXnN2dsg8rk0rNOjh ob/A== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h22si19432329ejd.179.2020.12.29.06.14.45; Tue, 29 Dec 2020 06:15:16 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726281AbgL2ONV (ORCPT + 99 others); Tue, 29 Dec 2020 09:13:21 -0500 Received: from foss.arm.com ([217.140.110.172]:38678 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbgL2ONV (ORCPT ); Tue, 29 Dec 2020 09:13:21 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 61E841FB; Tue, 29 Dec 2020 06:12:35 -0800 (PST) Received: from e107158-lin (e107158-lin.cambridge.arm.com [10.1.194.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CF38A3F719; Tue, 29 Dec 2020 06:12:33 -0800 (PST) Date: Tue, 29 Dec 2020 14:12:31 +0000 From: Qais Yousef To: Frederic Weisbecker Cc: Thomas Gleixner , Peter Zijlstra , LKML , Tony Luck , Vasily Gorbik , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Christian Borntraeger , Fenghua Yu , Heiko Carstens Subject: Re: [PATCH 4/5] irqtime: Move irqtime entry accounting after irq offset incrementation Message-ID: <20201229141231.c2ppmjucxxbz5j5h@e107158-lin> References: <20201202115732.27827-1-frederic@kernel.org> <20201202115732.27827-5-frederic@kernel.org> <20201228021529.2dlioupobocjcqzk@e107158-lin> <20201229134146.GA21613@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201229134146.GA21613@lothringen> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/29/20 14:41, Frederic Weisbecker wrote: > On Mon, Dec 28, 2020 at 02:15:29AM +0000, Qais Yousef wrote: > > Hi Frederic > > > > On 12/02/20 12:57, Frederic Weisbecker wrote: > > > @@ -66,9 +68,9 @@ void irqtime_account_irq(struct task_struct *curr) > > > * in that case, so as not to confuse scheduler with a special task > > > * that do not consume any time, but still wants to run. > > > */ > > > - if (hardirq_count()) > > > + if (pc & HARDIRQ_MASK) > > > irqtime_account_delta(irqtime, delta, CPUTIME_IRQ); > > > - else if (in_serving_softirq() && curr != this_cpu_ksoftirqd()) > > > + else if ((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd()) > > > > Noob question. Why for SOFTIRQs we do sofirq_count() & *SOFTIRQ_OFFSET*? It > > seems we're in-softirq only if the count is odd numbered. > > > > /me tries to dig more > > > > Hmm could it be because the softirq count is actually 1 bit and the rest is > > for SOFTIRQ_DISABLE_OFFSET (BH disabled)? > > Exactly! > > > > > IOW, 1 bit is for we're in softirq context, and the remaining 7 bits are to > > count BH disable nesting, right? > > > > I guess this would make sense; we don't nest softirqs processing AFAIK. But > > I could be misreading the code too :-) > > You got it right! > > This is commented in softirq.c somewhere: > > /* > * preempt_count and SOFTIRQ_OFFSET usage: > * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving > * softirq processing. > * - preempt_count is changed by SOFTIRQ_DISABLE_OFFSET (= 2 * SOFTIRQ_OFFSET) > * on local_bh_disable or local_bh_enable. > * This lets us distinguish between whether we are currently processing > * softirq and whether we just have bh disabled. > */ > > But we should elaborate on the fact that, indeed, softirq processing can't nest, > while softirq disablement can. I should try to send a patch and comment more > thoroughly on the subtleties of preempt mask in preempt.h. Thanks for the info! > > > > > > irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ); > > > } > > > > > > @@ -417,11 +419,13 @@ void vtime_task_switch(struct task_struct *prev) > > > } > > > # endif > > > > > > -void vtime_account_irq(struct task_struct *tsk) > > > +void vtime_account_irq(struct task_struct *tsk, unsigned int offset) > > > { > > > - if (hardirq_count()) { > > > + unsigned int pc = preempt_count() - offset; > > > + > > > + if (pc & HARDIRQ_OFFSET) { > > > > Shouldn't this be HARDIRQ_MASK like above? > > In the rare cases of nested hardirqs happening with broken drivers, Only the outer hardirq > does matter. All the time spent in the inner hardirqs is included in the outer > one. Ah I see. The original code was doing hardirq_count(), which apparently wasn't right either. Shouldn't it be pc == HARDIRQ_OFFSET then? All odd nest counts will trigger this otherwise, and IIUC we want this to trigger once on first entry only. Thanks -- Qais Yousef