Commit 2b794d69 authored by Paul Eggert's avatar Paul Eggert

Port timers to OpenBSD, plus check for timer failures.

OpenBSD problem reported by Han Boetes.
* profiler.c (setup_cpu_timer): Check for failure of timer_settime
and/or setitimer.
(Fprofiler_cpu_stop): Don't assume HAVE_SETITIMER.
* syssignal.h (HAVE_ITIMERSPEC): New macro.  This is for platforms
like OpenBSD, which has timer_settime but does not declare it.
OpenBSD does not define SIGEV_SIGNAL, so use that when deciding
whether to use itimerspec-related primitives.  All uses of
HAVE_TIMER_SETTIME replaced with HAVE_ITIMERSPEC.
parent a1a9f411
2012-10-04 Paul Eggert <eggert@cs.ucla.edu>
Port timers to OpenBSD, plus check for timer failures.
OpenBSD problem reported by Han Boetes.
* profiler.c (setup_cpu_timer): Check for failure of timer_settime
and/or setitimer.
(Fprofiler_cpu_stop): Don't assume HAVE_SETITIMER.
* syssignal.h (HAVE_ITIMERSPEC): New macro. This is for platforms
like OpenBSD, which has timer_settime but does not declare it.
OpenBSD does not define SIGEV_SIGNAL, so use that when deciding
whether to use itimerspec-related primitives. All uses of
HAVE_TIMER_SETTIME replaced with HAVE_ITIMERSPEC.
2012-09-30 Paul Eggert <eggert@cs.ucla.edu> 2012-09-30 Paul Eggert <eggert@cs.ucla.edu>
Merge from gnulib, incorporating: Merge from gnulib, incorporating:
......
...@@ -42,7 +42,7 @@ static struct atimer *atimers; ...@@ -42,7 +42,7 @@ static struct atimer *atimers;
/* The alarm timer and whether it was properly initialized, if /* The alarm timer and whether it was properly initialized, if
POSIX timers are available. */ POSIX timers are available. */
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
static timer_t alarm_timer; static timer_t alarm_timer;
static bool alarm_timer_ok; static bool alarm_timer_ok;
#endif #endif
...@@ -296,7 +296,7 @@ set_alarm (void) ...@@ -296,7 +296,7 @@ set_alarm (void)
#endif #endif
EMACS_TIME now, interval; EMACS_TIME now, interval;
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
if (alarm_timer_ok) if (alarm_timer_ok)
{ {
struct itimerspec ispec; struct itimerspec ispec;
...@@ -416,7 +416,7 @@ void ...@@ -416,7 +416,7 @@ void
init_atimer (void) init_atimer (void)
{ {
struct sigaction action; struct sigaction action;
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
struct sigevent sigev; struct sigevent sigev;
sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = SIGALRM; sigev.sigev_signo = SIGALRM;
......
...@@ -204,7 +204,7 @@ record_backtrace (log_t *log, EMACS_INT count) ...@@ -204,7 +204,7 @@ record_backtrace (log_t *log, EMACS_INT count)
/* The profiler timer and whether it was properly initialized, if /* The profiler timer and whether it was properly initialized, if
POSIX timers are available. */ POSIX timers are available. */
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
static timer_t profiler_timer; static timer_t profiler_timer;
static bool profiler_timer_ok; static bool profiler_timer_ok;
#endif #endif
...@@ -240,7 +240,7 @@ handle_profiler_signal (int signal) ...@@ -240,7 +240,7 @@ handle_profiler_signal (int signal)
{ {
Lisp_Object oquit; Lisp_Object oquit;
EMACS_INT count = 1; EMACS_INT count = 1;
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
if (profiler_timer_ok) if (profiler_timer_ok)
{ {
int overruns = timer_getoverrun (profiler_timer); int overruns = timer_getoverrun (profiler_timer);
...@@ -288,7 +288,7 @@ setup_cpu_timer (Lisp_Object sampling_interval) ...@@ -288,7 +288,7 @@ setup_cpu_timer (Lisp_Object sampling_interval)
emacs_sigaction_init (&action, deliver_profiler_signal); emacs_sigaction_init (&action, deliver_profiler_signal);
sigaction (SIGPROF, &action, 0); sigaction (SIGPROF, &action, 0);
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
if (! profiler_timer_ok) if (! profiler_timer_ok)
{ {
/* System clocks to try, in decreasing order of desirability. */ /* System clocks to try, in decreasing order of desirability. */
...@@ -322,14 +322,18 @@ setup_cpu_timer (Lisp_Object sampling_interval) ...@@ -322,14 +322,18 @@ setup_cpu_timer (Lisp_Object sampling_interval)
{ {
struct itimerspec ispec; struct itimerspec ispec;
ispec.it_value = ispec.it_interval = interval; ispec.it_value = ispec.it_interval = interval;
timer_settime (profiler_timer, 0, &ispec, 0); if (timer_settime (profiler_timer, 0, &ispec, 0) == 0)
return TIMER_SETTIME_RUNNING; return TIMER_SETTIME_RUNNING;
} }
#endif #endif
#ifdef HAVE_SETITIMER
timer.it_value = timer.it_interval = make_timeval (interval); timer.it_value = timer.it_interval = make_timeval (interval);
setitimer (ITIMER_PROF, &timer, 0); if (setitimer (ITIMER_PROF, &timer, 0) == 0)
return SETITIMER_RUNNING; return SETITIMER_RUNNING;
#endif
return NOT_RUNNING;
} }
DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start, DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start,
...@@ -367,7 +371,7 @@ Return non-nil if the profiler was running. */) ...@@ -367,7 +371,7 @@ Return non-nil if the profiler was running. */)
case NOT_RUNNING: case NOT_RUNNING:
return Qnil; return Qnil;
#ifdef HAVE_TIMER_SETTIME #ifdef HAVE_ITIMERSPEC
case TIMER_SETTIME_RUNNING: case TIMER_SETTIME_RUNNING:
{ {
struct itimerspec disable; struct itimerspec disable;
...@@ -377,6 +381,7 @@ Return non-nil if the profiler was running. */) ...@@ -377,6 +381,7 @@ Return non-nil if the profiler was running. */)
break; break;
#endif #endif
#ifdef HAVE_SETITIMER
case SETITIMER_RUNNING: case SETITIMER_RUNNING:
{ {
struct itimerval disable; struct itimerval disable;
...@@ -384,6 +389,7 @@ Return non-nil if the profiler was running. */) ...@@ -384,6 +389,7 @@ Return non-nil if the profiler was running. */)
setitimer (ITIMER_PROF, &disable, 0); setitimer (ITIMER_PROF, &disable, 0);
} }
break; break;
#endif
} }
signal (SIGPROF, SIG_IGN); signal (SIGPROF, SIG_IGN);
......
...@@ -29,8 +29,12 @@ extern void init_signals (bool); ...@@ -29,8 +29,12 @@ extern void init_signals (bool);
#define FORWARD_SIGNAL_TO_MAIN_THREAD #define FORWARD_SIGNAL_TO_MAIN_THREAD
#endif #endif
#if (defined SIGPROF && (defined HAVE_TIMER_SETTIME || defined HAVE_SETITIMER) \ #if defined HAVE_TIMER_SETTIME && defined SIGEV_SIGNAL
&& !defined PROFILING) # define HAVE_ITIMERSPEC
#endif
#if (defined SIGPROF && !defined PROFILING \
&& (defined HAVE_SETITIMER || defined HAVE_ITIMERSPEC))
# define PROFILER_CPU_SUPPORT # define PROFILER_CPU_SUPPORT
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment