From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

lazy stack: new tracepoint for stack pre-faults

This last patch of the series adds new tracepoint - mmu_vm_stack_fault -
which when enabled allows one to see how particular app triggers
the stack page faults. The tracepoint captures the stack fault address,
the thread id and number of the page (0 being the 1st page).

Please note this does not capture the 1st page of the stack (page_no 0) as this 
one
pre-faulted by the parent thread that creates a new one.

./scripts/run.py -e /tests/tst-pipe.so --trace=mmu_vm_stack_fault 
--trace-backtrace -H
./scripts/trace.py extract && ./scripts/trace.py list -bl

0xffff8000016b7040 >init            0         0.002215401 mmu_vm_stack_fault   
thread=32, addr=0x00002000000ff9d0, page_no=1
  mmu::vm_fault(unsigned long, exception_frame*)
  page_fault
  ex_pf
  std_malloc(unsigned long, unsigned long)
  malloc
  operator new(unsigned long)
  do_main_thread(void*)
  std::_Function_handler<void (), pthread_private::pthread::pthread(void* 
(*)(void*), void*, sigset_t, pthread_private::thread_attr 
const*)::{lambda()#1}>::_M_invoke(std::_Any_data const&) __invoke_impl<void, 
pthread_private::pthread::pthread(void* (*)(void*), void*, sigset_t, const 
pthread_private::thread_attr*)::<lambda()>&>__invoke_r<void, 
pthread_private::pthread::pthread(void* (*)(void*), void*, sigset_t, const 
pthread_private::thread_attr*)::<lambda()>&> _M_invoke
  sched::thread::main()
  thread_main_c

...

0xffff8000016b7040 >init            0         0.084799151 mmu_vm_stack_fault   
thread=32, addr=0x00002000000f8440, page_no=8
  mmu::vm_fault(unsigned long, exception_frame*)
  page_fault
  ex_pf
  memory::page_pool::l1::alloc_page()
  untracked_alloc_page
  memory::alloc_page()
  std_malloc(unsigned long, unsigned long)
  malloc
  operator new(unsigned long)
  lookup
  sys_lstat

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>

---
diff --git a/core/mmu.cc b/core/mmu.cc
--- a/core/mmu.cc
+++ b/core/mmu.cc
@@ -1413,6 +1413,9 @@ bool access_fault(vma& vma, unsigned int error_code)
 TRACEPOINT(trace_mmu_vm_fault, "addr=%p, error_code=%x", uintptr_t, unsigned 
int);
 TRACEPOINT(trace_mmu_vm_fault_sigsegv, "addr=%p, error_code=%x, %s", 
uintptr_t, unsigned int, const char*);
 TRACEPOINT(trace_mmu_vm_fault_ret, "addr=%p, error_code=%x", uintptr_t, 
unsigned int);
+#if CONF_lazy_stack
+TRACEPOINT(trace_mmu_vm_stack_fault, "thread=%d, addr=%p, page_no=%d", 
unsigned int, uintptr_t, unsigned int);
+#endif
 
 static void vm_sigsegv(uintptr_t addr, exception_frame* ef)
 {
@@ -1438,6 +1441,14 @@ void vm_fault(uintptr_t addr, exception_frame* ef)
         trace_mmu_vm_fault_sigsegv(addr, ef->get_error(), "fast");
         return;
     }
+#if CONF_lazy_stack
+    auto stack = sched::thread::current()->get_stack_info();
+    void *v_addr = reinterpret_cast<void*>(addr);
+    if (v_addr >= stack.begin && v_addr < stack.begin + stack.size) {
+        trace_mmu_vm_stack_fault(sched::thread::current()->id(), addr,
+            ((u64)(stack.begin + stack.size - addr)) / 4096);
+    }
+#endif
     addr = align_down(addr, mmu::page_size);
     WITH_LOCK(vma_list_mutex.for_read()) {
         auto vma = find_intersecting_vma(addr);

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000cdb7c005eb296ba3%40google.com.

Reply via email to