1

ftrace is used for function tracing of kernel. Now how does it work for interrupts. Can it track kernel functions in interrupt mode. If so can you explain how it works. I am trying to write a function that tracks function calls and it works fine in Supervisor mode but does not work in interrupt mode (goes into loop). I need to make it work in IRQ mode.

karthikpj
  • 33
  • 1
  • 8
  • This is a line from my trace output (x86 system) when I do a function trace on "*_irq_handler": "Xorg-1448 [000] d.h. 830819.774909: ironlake_irq_handler <-__handle _irq_event_percpu". The "h" means it is in hardirq context. Does that answer your second question? And could you please expand on the first? – michaeljt Jan 08 '17 at 16:13

1 Answers1

2

As in Linux kernel ARM exception stack init details, the amount of IRQ stack used by Linux is minimal. ARM has several banked registers including lr and sp for the IRQ modes. In the Linux ARM kernel, these registers are used only briefly to transfer information to the supervisor (8K) stack. This supervisor stack is allocate per kernel process and also contain a task context block with pointers to the memory manager, scheduler and file system information.

So in Linux, the supervisor stack has the stack information for all modes, including FIQ, IRQ, undefined instruction, data and instruction faults. This means only one stack needs to be traced. Special information (pseudo assembler) is included in entry-armv.S, such as UNWIND(.fnend) and ENDPROC(__irq_usr) which annotate the kernel with ELF information to create unwind tables that allow the stack tracing code to understand the layout of data on the stack.

Vector page mapping in ARM Linux has some additional details such as the vector_name assembler macro which does the stack/mode switching. The vector_name assembler macro is the only code that actually executes in IRQ mode. irq_usr and irq_svc execute in supervisor mode, with the supervisor stack.

Community
  • 1
  • 1
artless noise
  • 21,212
  • 6
  • 68
  • 105
  • How does ftrace print the function name from stack.Can you point me to the implementation part of printing function name in ftrace (I mean code). I have checked ftrace.c file in the kernel source but could not understand it. – karthikpj Jan 11 '17 at 14:51
  • The [stacktrace.c](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm/kernel/stacktrace.c?id=refs/tags/v4.10-rc3) does a stack trace with standard offsets as per [ARM lr and fp](http://stackoverflow.com/questions/15752188/arm-link-register-and-frame-pointer/15752671#15752671). [unwind.c](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm/kernel/unwind.c?id=refs/tags/v4.10-rc3) is a more modern version is which the PC and tables are consulted to determine the function. – artless noise Jan 12 '17 at 13:40
  • [ftrace-design](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/trace/ftrace-design.rst) by Mike Frysinger has more details and should be current to your kernel version. – artless noise Jan 03 '22 at 17:16