Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8739869pxu; Sun, 27 Dec 2020 18:19:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz62HgLJFUHlYtVnMGGiDsaXHCyJQzej1GF+ylc+hZViRQPxAps1SaFXSnnFhk8y0XmP6X+ X-Received: by 2002:a17:906:8051:: with SMTP id x17mr38568415ejw.430.1609121945971; Sun, 27 Dec 2020 18:19:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609121945; cv=none; d=google.com; s=arc-20160816; b=TM1rEaLMPNImyExvGnIZG7zvPVUrmtJRyieG7C/h+KOXUDV1Gk8bx8iRFhLwRBn7Fw Uzm5gah+qB9zak6t+8yM6ytR0GyI1FDmUqoWDIZDbOWXO2CO4O7g7aHSy1302FXXdS8W 8h7dEaJtwd/rwC7BobSEBZN2oYgN4QPdYIkfmY+vDT4zlll+KD/7as1UC1UFKnIUkt8W 1nlNEHswFcFl3EZzVdM+YtEzmOFIncovnAydAeJR3dyQURkAnHRuax3AfdJt0e8fNxDL dKVQklLpEL/YuriEGnLSAMCzBuTCia967I5zQu3aTKoeUiFzUgOZuui9u2tu9UQ2tJps gixw== 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=WlI+OY+GRKmZsQCkjzvI0NI50LEOjti5pixl9KO7AJo=; b=08AHbI9xOvk/whhIChVjFimjDfNAjuvNV3oWf12Ijr9mcPm9LvG4u++AaZzGjhDYZS e7IXysDleaUkRMgPsPy3wHzWhoA6vgaWQRiWYMDq8P+U12IMnEQe8vXVMcjAL38N649n efliEQ4kyVnQhcn0aj1taU7qjdJvTjsOq/sGIyYr9u4JeE2hkmp71Mn7cz8bgW9UC5/t jq/CHJ0iYNg4aTiMrLKuifeXi469/L9FmVDrdv0f9vSua7T/b3t2pGOcq1xISSStlTBr zwKwQeGzNDFYSmJdrapc6AlZlS9kwehWprBWIyyqI8YRp1foBcYNbdW23/LdxXQtETy5 ncIw== 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 hr22si16665824ejc.411.2020.12.27.18.18.43; Sun, 27 Dec 2020 18:19:05 -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 S1726418AbgL1CQU (ORCPT + 99 others); Sun, 27 Dec 2020 21:16:20 -0500 Received: from foss.arm.com ([217.140.110.172]:40338 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726361AbgL1CQT (ORCPT ); Sun, 27 Dec 2020 21:16:19 -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 EC1AC1FB; Sun, 27 Dec 2020 18:15:33 -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 527AF3F6CF; Sun, 27 Dec 2020 18:15:32 -0800 (PST) Date: Mon, 28 Dec 2020 02:15:29 +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: <20201228021529.2dlioupobocjcqzk@e107158-lin> References: <20201202115732.27827-1-frederic@kernel.org> <20201202115732.27827-5-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201202115732.27827-5-frederic@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Frederic On 12/02/20 12:57, Frederic Weisbecker wrote: > #endif /* _LINUX_KERNEL_VTIME_H */ > diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c > index 02163d4260d7..5f611658eeab 100644 > --- a/kernel/sched/cputime.c > +++ b/kernel/sched/cputime.c > @@ -44,12 +44,13 @@ static void irqtime_account_delta(struct irqtime *irqtime, u64 delta, > } > > /* > - * Called before incrementing preempt_count on {soft,}irq_enter > + * Called after incrementing preempt_count on {soft,}irq_enter > * and before decrementing preempt_count on {soft,}irq_exit. > */ > -void irqtime_account_irq(struct task_struct *curr) > +void irqtime_account_irq(struct task_struct *curr, unsigned int offset) > { > struct irqtime *irqtime = this_cpu_ptr(&cpu_irqtime); > + unsigned int pc; > s64 delta; > int cpu; > > @@ -59,6 +60,7 @@ void irqtime_account_irq(struct task_struct *curr) > cpu = smp_processor_id(); > delta = sched_clock_cpu(cpu) - irqtime->irq_start_time; > irqtime->irq_start_time += delta; > + pc = preempt_count() - offset; > > /* > * We do not account for softirq time from ksoftirqd here. > @@ -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)? 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 :-) > 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? > vtime_account_hardirq(tsk); > - } else if (in_serving_softirq()) { > + } else if (pc & SOFTIRQ_OFFSET) { > vtime_account_softirq(tsk); > } else if (!IS_ENABLED(CONFIG_HAVE_VIRT_CPU_ACCOUNTING_IDLE) && > is_idle_task(tsk)) { Thanks -- Qais Yousef