linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: valdis.kletnieks@vt.edu
To: Pintu Agarwal <pintu.ping@gmail.com>
Cc: open list <linux-kernel@vger.kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	Russell King - ARM Linux <linux@armlinux.org.uk>,
	kernelnewbies@kernelnewbies.org,
	Jungseok Lee <jungseoklee85@gmail.com>,
	catalin.marinas@arm.com, will.deacon@arm.com,
	Takahiro Akashi <takahiro.akashi@linaro.org>,
	mark.rutland@arm.com, Sungjinn Chung <barami97@gmail.com>
Subject: Re: [ARM64] Printing IRQ stack usage information
Date: Tue, 20 Nov 2018 14:03:28 -0500	[thread overview]
Message-ID: <38799.1542740608@turing-police.cc.vt.edu> (raw)
In-Reply-To: <CAOuPNLgGuomqaQVtj=1O8tYV_Bq8cqf5HqCxJ-LSGeQOVffnzw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1656 bytes --]

On Tue, 20 Nov 2018 18:21:33 +0530, Pintu Agarwal said:

> + sp = current_stack_pointer;
> + if (on_irq_stack(sp, cpu)) {
> +         stack_start = (unsigned long)per_cpu(irq_stack, cpu);
> +         last_usage = per_cpu(irq_stack_usage, cpu);
> +         curr_usage = sp - stack_start;
> +         pr_info("cpu:%d : sp: %lu, stack_start: %lu, usage: %lu\n", cpu, sp, stack_start, (sp - stack_start));
> +         if (curr_usage > last_usage)
> +                 per_cpu(irq_stack_usage, cpu) = curr_usage;
> + }

This code only works if called from the function that uses the deepest
amount of stack, because curr_usage depends on the current stack
pointer.  If some other routine went 2,934 bytes further into the stack
and then returned, you'll never know.

What you want instead is a way to see what the deepest point reached during
the current call, and compare that to the previous low.

How to detect the used stack? Go look at how the code currently
detects how deep the kernel stacks reached. (Hint 1: look at check_stack_usage()
in kernel/exit.c and stack_not_used().  Hint 2: what other support code
is implied by the implementation of stack_not used()?

> Which is the best place to invoke this ?
> I have the following option:
> 1. kernel/softirq.c => __do_softirq()
> 2. arch/arm64/kernel/smp.c => handle_IPI()
> 3. kernel/softirq.c => irq_exit()
> 4. ???

Pondering the above, what other implementations might work? Hint: if
you have a similar irq_stack_not_used() function, do you need any
additional code in *any* of those 4 places?

(And yes, I could just splat out the needed code - but you'd learn nowhere
near as much that way.. :)




[-- Attachment #2: Type: application/pgp-signature, Size: 486 bytes --]

      reply	other threads:[~2018-11-20 19:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-15 13:22 [ARM64] Printing IRQ stack usage information Pintu Agarwal
2018-11-15 16:49 ` valdis.kletnieks
2018-11-16  6:14   ` Pintu Agarwal
2018-11-16 11:33     ` valdis.kletnieks
2018-11-16 14:40       ` Pintu Agarwal
2018-11-16 16:46         ` valdis.kletnieks
2018-11-16 17:43           ` Pintu Agarwal
2018-11-16 18:31             ` valdis.kletnieks
2018-11-17 13:06               ` Pintu Agarwal
2018-11-20 12:51                 ` Pintu Agarwal
2018-11-20 19:03                   ` valdis.kletnieks [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38799.1542740608@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=barami97@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=jungseoklee85@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=pintu.ping@gmail.com \
    --cc=takahiro.akashi@linaro.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).