Skip to content

Commit

Permalink
Use virtual instead of profile time for vmprofile
Browse files Browse the repository at this point in the history
Avoids infinite looping due to system call restarts
triggered by SIGPROF handling.

Virtual time doesn't account for time spent in the
kernel handling system calls but Snabb tries to avoid
spending time in system calls.

(cherry picked from commit c4681a6)
  • Loading branch information
takikawa authored and lukego committed Aug 1, 2018
1 parent 9abd48a commit 6b72001
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lj_vmprofile.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ static void start_timer(int interval)
struct sigaction sa;
tm.it_value.tv_sec = tm.it_interval.tv_sec = interval / 1000;
tm.it_value.tv_usec = tm.it_interval.tv_usec = (interval % 1000) * 1000;
setitimer(ITIMER_PROF, &tm, NULL);
setitimer(ITIMER_VIRTUAL, &tm, NULL);
sa.sa_flags = SA_SIGINFO | SA_RESTART;
sa.sa_sigaction = vmprofile_signal;
sigemptyset(&sa.sa_mask);
sigaction(SIGPROF, &sa, &state.oldsa);
sigaction(SIGVTALRM, &sa, &state.oldsa);
}

static void stop_timer()
{
struct itimerval tm;
tm.it_value.tv_sec = tm.it_interval.tv_sec = 0;
tm.it_value.tv_usec = tm.it_interval.tv_usec = 0;
setitimer(ITIMER_PROF, &tm, NULL);
sigaction(SIGPROF, NULL, &state.oldsa);
setitimer(ITIMER_VIRTUAL, &tm, NULL);
sigaction(SIGVTALRM, NULL, &state.oldsa);
}

/* -- State that the application can manage via FFI ----------------------- */
Expand Down

0 comments on commit 6b72001

Please sign in to comment.