From: valdis.kletnieks@vt.edu (valdis.kletnieks at vt.edu) To: kernelnewbies@lists.kernelnewbies.org Subject: [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> 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.. :) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 486 bytes Desc: not available URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20181120/9494a71f/attachment.sig>
WARNING: multiple messages have this Message-ID (diff)
From: valdis.kletnieks@vt.edu To: Pintu Agarwal <pintu.ping@gmail.com> Cc: mark.rutland@arm.com, Jungseok Lee <jungseoklee85@gmail.com>, kernelnewbies@kernelnewbies.org, catalin.marinas@arm.com, Sungjinn Chung <barami97@gmail.com>, will.deacon@arm.com, open list <linux-kernel@vger.kernel.org>, Russell King - ARM Linux <linux@armlinux.org.uk>, Takahiro Akashi <takahiro.akashi@linaro.org>, linux-arm-kernel@lists.infradead.org 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) Message-ID: <20181120190328.cK_h5RGh5mT7tfd87fcwBnP2cLr5bicR8LuDnzp9XaU@z> (raw) In-Reply-To: <CAOuPNLgGuomqaQVtj=1O8tYV_Bq8cqf5HqCxJ-LSGeQOVffnzw@mail.gmail.com> [-- Attachment #1.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 #1.2: Type: application/pgp-signature, Size: 486 bytes --] [-- Attachment #2: Type: text/plain, Size: 170 bytes --] _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2018-11-20 19:03 UTC|newest] Thread overview: 22+ 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 13:22 ` Pintu Agarwal 2018-11-15 16:49 ` valdis.kletnieks at vt.edu 2018-11-15 16:49 ` valdis.kletnieks 2018-11-16 6:14 ` Pintu Agarwal 2018-11-16 6:14 ` Pintu Agarwal 2018-11-16 11:33 ` valdis.kletnieks at vt.edu 2018-11-16 11:33 ` valdis.kletnieks 2018-11-16 14:40 ` Pintu Agarwal 2018-11-16 14:40 ` Pintu Agarwal 2018-11-16 16:46 ` valdis.kletnieks at vt.edu 2018-11-16 16:46 ` valdis.kletnieks 2018-11-16 17:43 ` Pintu Agarwal 2018-11-16 17:43 ` Pintu Agarwal 2018-11-16 18:31 ` valdis.kletnieks at vt.edu 2018-11-16 18:31 ` valdis.kletnieks 2018-11-17 13:06 ` Pintu Agarwal 2018-11-17 13:06 ` Pintu Agarwal 2018-11-20 12:51 ` Pintu Agarwal 2018-11-20 12:51 ` Pintu Agarwal 2018-11-20 19:03 ` valdis.kletnieks at vt.edu [this message] 2018-11-20 19:03 ` valdis.kletnieks
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=kernelnewbies@lists.kernelnewbies.org \ /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: linkBe 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).