From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omr1.cc.ipv6.vt.edu ([2607:b400:92:8300:0:c6:2117:b0e] helo=omr1.cc.vt.edu) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gPBJE-00046o-5B for kernelnewbies@kernelnewbies.org; Tue, 20 Nov 2018 14:03:40 -0500 Received: from mr2.cc.vt.edu (mr2.cc.vt.edu [IPv6:2607:b400:92:8400:0:90:e077:bf22]) by omr1.cc.vt.edu (8.14.4/8.14.4) with ESMTP id wAKJ3crG011955 for ; Tue, 20 Nov 2018 14:03:38 -0500 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by mr2.cc.vt.edu (8.14.7/8.14.7) with ESMTP id wAKJ3WID011933 for ; Tue, 20 Nov 2018 14:03:38 -0500 Received: by mail-qk1-f197.google.com with SMTP id c7so4314864qkg.16 for ; Tue, 20 Nov 2018 11:03:38 -0800 (PST) From: valdis.kletnieks@vt.edu To: Pintu Agarwal Subject: Re: [ARM64] Printing IRQ stack usage information In-Reply-To: References: <28496.1542300549@turing-police.cc.vt.edu> <49219.1542367988@turing-police.cc.vt.edu> <5997.1542386778@turing-police.cc.vt.edu> <15703.1542393111@turing-police.cc.vt.edu> Mime-Version: 1.0 Date: Tue, 20 Nov 2018 14:03:28 -0500 Message-ID: <38799.1542740608@turing-police.cc.vt.edu> Cc: mark.rutland@arm.com, Jungseok Lee , kernelnewbies@kernelnewbies.org, catalin.marinas@arm.com, Sungjinn Chung , will.deacon@arm.com, open list , Russell King - ARM Linux , Takahiro Akashi , linux-arm-kernel@lists.infradead.org List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============3160311796033896997==" Errors-To: kernelnewbies-bounces@kernelnewbies.org Message-ID: <20181120190328.cK_h5RGh5mT7tfd87fcwBnP2cLr5bicR8LuDnzp9XaU@z> --===============3160311796033896997== Content-Type: multipart/signed; boundary="==_Exmh_1542740607_2819P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit --==_Exmh_1542740607_2819P Content-Type: text/plain; charset=us-ascii 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.. :) --==_Exmh_1542740607_2819P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Comment: Exmh version 2.9.0 11/07/2018 iQEVAwUBW/Raf40DS38y7CIcAQJlIAf/ZwgLssOW1kKbDHlhdiZqMxTkeroALLNs PsLoezZywUY+BnN27zys0F6zRG6t11P29NhoI5sCMSHwRliulMmfFb2AABtlW93e R2Y6YbgbI47wnZw4KUDB09ty14r+DlT7O1ETBqIsmtkeGx1JVBePnRGGiljGIJV4 Jfj8aGNzKPqt4X/nt/by2frSne7H6kkoCOjvcjKzCLFXkGTSuiiYxyq/ldu299nW OR2+9XtfukCMe0jOvVdWagj70C4EkoLlAjjGOFvmX8ogBrtMkklgBkehaYBc99sL JkrRRC8VZzTxzw1CQEh91DMrxtZaY7nSjSNSysMACB6U1fTOfywB7g== =TbrW -----END PGP SIGNATURE----- --==_Exmh_1542740607_2819P-- --===============3160311796033896997== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============3160311796033896997==--