Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add robust signal captures to QUDA #1449

Open
weinbe2 opened this issue Mar 25, 2024 · 4 comments
Open

Add robust signal captures to QUDA #1449

weinbe2 opened this issue Mar 25, 2024 · 4 comments
Assignees
Labels

Comments

@weinbe2
Copy link
Contributor

weinbe2 commented Mar 25, 2024

Per a suggestion from @paboyle , we should add support for proper signal capturing in QUDA. (BSD references are welcome :) )

@Scidac5usqcd
Copy link

https://github.com/paboyle/Grid/blob/develop/Grid/util/Init.cc

Has some of the sort of gunk you need for trapping SIGFPE, enabling FPE exceptions, SEGV, SIGBUS backtrace printed and on x86 a register dump.

It compiles everywhere (MacOS and Linux at least)
From what I saw of PeTSC, they've done a bit more with the sigaction, and perhaps use a little library.

https://petsc.org/release/src/sys/error/signal.c.html

void * Grid_backtrace_buffer[_NBACKTRACE];

void Grid_sa_signal_handler(int sig,siginfo_t *si,void * ptr)
{
  fprintf(stderr,"Caught signal %d\n",si->si_signo);
  fprintf(stderr,"  mem address %llx\n",(unsigned long long)si->si_addr);
  fprintf(stderr,"         code %d\n",si->si_code);
  // Linux/Posix
#ifdef __linux__
  // And x86 64bit
#ifdef __x86_64__
  ucontext_t * uc= (ucontext_t *)ptr;
  struct sigcontext *sc = (struct sigcontext *)&uc->uc_mcontext;
  fprintf(stderr,"  instruction %llx\n",(unsigned long long)sc->rip);
#define REG(A)  printf("  %s %lx\n",#A,sc-> A);
  REG(rdi);
  REG(rsi);
  REG(rbp);
  REG(rbx);
  REG(rdx);
  REG(rax);
  REG(rcx);
  REG(rsp);
  REG(rip);


  REG(r8);
  REG(r9);
  REG(r10);
  REG(r11);
  REG(r12);
  REG(r13);
  REG(r14);
  REG(r15);
#endif
#endif
  fflush(stderr);
  BACKTRACEFP(stderr);
  fprintf(stderr,"Called backtrace\n");
  fflush(stdout);
  fflush(stderr);
  exit(0);
  return;
};

void Grid_exit_handler(void)
{
  BACKTRACEFP(stdout);
  fflush(stdout);
}
void Grid_debug_handler_init(void)
{
  struct sigaction sa;
  sigemptyset (&sa.sa_mask);
  sa.sa_sigaction= Grid_sa_signal_handler;
  sa.sa_flags    = SA_SIGINFO;
  sigaction(SIGSEGV,&sa,NULL);
  sigaction(SIGTRAP,&sa,NULL);
  sigaction(SIGBUS,&sa,NULL);
  sigaction(SIGUSR2,&sa,NULL);

  feenableexcept( FE_INVALID|FE_OVERFLOW|FE_DIVBYZERO);

  sigaction(SIGFPE,&sa,NULL);
  sigaction(SIGKILL,&sa,NULL);
  sigaction(SIGILL,&sa,NULL);

  atexit(Grid_exit_handler);
}
'''

@Scidac5usqcd
Copy link

Oops signed in on wrong account.... @paboyle

@weinbe2
Copy link
Contributor Author

weinbe2 commented Mar 25, 2024

Thanks @paboyle, I appreciate the references!

@mathiaswagner
Copy link
Member

We already support https://github.com/bombela/backward-cpp,

option(QUDA_BACKWARDS "Enable stacktrace generation using backwards-cpp")

Also @paboyle please don't suggest any Grid samples as this is GPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants