Skip to content

Commit

Permalink
Merge branch 'unitopia-patches' into unitopia
Browse files Browse the repository at this point in the history
  • Loading branch information
amotzkau committed Oct 2, 2023
2 parents bcdbfd1 + 6ed8328 commit 96da9b2
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 49 deletions.
46 changes: 46 additions & 0 deletions src/autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ AC_MY_ARG_ENABLE(trace-code,yes,,[trace the most recently executed bytecode])
AC_MY_ARG_ENABLE(rxcache_table,yes,,[Cache compiled regular expressions])
AC_MY_ARG_ENABLE(synchronous-heart-beat,yes,,[Do all heart beats at once.])

AC_MY_ARG_ENABLE(posix-timers,no,,[Use POSIX timers for the execution timer])
AC_MY_ARG_ENABLE(opcprof,no,,[create VM instruction usage statistics])
AC_MY_ARG_ENABLE(verbose-opcprof,no,,[with opcprof: include instruction names])
AC_MY_ARG_ENABLE(debug,yes,,[enable sanity checks])
Expand Down Expand Up @@ -535,6 +536,7 @@ AC_CDEF_FROM_ENABLE(trace_code)
AC_CDEF_FROM_ENABLE(rxcache_table)
AC_CDEF_FROM_ENABLE(synchronous_heart_beat)

AC_UPDATE_VAR(enable_posix_timers)
AC_CDEF_FROM_ENABLE(opcprof)
AC_CDEF_FROM_ENABLE(verbose_opcprof)
AC_CDEF_FROM_ENABLE(debug)
Expand Down Expand Up @@ -1844,6 +1846,50 @@ if test "x$enable_use_mccp" = "x" || test "x$enable_use_mccp" = "xyes"; then
fi
fi

# --- Check for POSIX timer ---

AC_MY_SEARCH_LIB(RT,posix-timers,lp_cv_has_posix_timers,posix,posix_path,
[
#include <signal.h>
#include <time.h>
int init(void)
{
timer_t timerid;
struct sigevent sev;
struct itimerspec its;
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGPROF;
sev.sigev_value.sival_ptr = &timerid;
if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1)
return 1;
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 500000000;
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
if (timer_settime(timerid, 0, &its, NULL) == -1)
return 2;
timer_delete(timerid);
return 0;
}
],rt,timer_create,enable_posix_timers)

if test "$lp_cv_has_posix_timers" = "yes"; then
AC_DEFINE(USE_POSIX_TIMERS, 1, [Use POSIX timers for the execution timer?])
else
if test "x$enable_posix_timers" = "xyes"; then
echo "POSIX timer not supported - disabling."
AC_NOT_AVAILABLE(posix-timers)
fi

cdef_posix_timers="#undef"
enable_posix_timers="no"
fi

# ---

AC_CACHE_CHECK(if rename handles directories,
Expand Down
3 changes: 3 additions & 0 deletions src/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ void install_signal_handlers()
if (sigaction(SIGUSR2, &sa, NULL) == -1)
perror("Unable to install signal handler for SIGUSR2");
// Profiling signal handler for the detection of long executions.
if (!init_profiling_timer())
debug_message("%s Unable to create a POSIX timer for profiling, "
"falling back to ITIMER_PROF\n", time_stamp());
sa.sa_handler = handle_profiling_signal;
if (sigaction(SIGPROF, &sa, NULL) == -1) {
profiling_timevalue.tv_sec = 0;
Expand Down
66 changes: 64 additions & 2 deletions src/interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@

#include "my-alloca.h"
#include <assert.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
Expand Down Expand Up @@ -757,6 +758,16 @@ struct timeval profiling_timevalue = {0, 0};

static Bool received_prof_signal = MY_FALSE;

#ifdef USE_POSIX_TIMERS
static timer_t prof_timer;
/* POSIX timer id used for the profiling signal.
*/

static bool have_prof_timer = false;
/* Is prof_timer a valid timer?
*/
#endif

p_int used_memory_at_eval_start = 0;
/* used memory (in bytes) at the beginning of the current execution,
* set by mark_start_evaluation() (and v_limited()).
Expand Down Expand Up @@ -840,6 +851,28 @@ assign_eval_cost_inl(void)

void assign_eval_cost(void) { assign_eval_cost_inl(); }

/*-------------------------------------------------------------------------*/

bool
init_profiling_timer ()
/* Initializes the timer used for long execution signals.
*/
{
#ifdef USE_POSIX_TIMERS
struct sigevent sev;

sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGPROF;
sev.sigev_value.sival_ptr = NULL;
sev.sigev_value.sival_int = 0;
if (timer_create(CLOCK_REALTIME, &sev, &prof_timer) == -1)
return false;

have_prof_timer = true;
#endif
return true;
} /* init_profiling_timer() */

/*-------------------------------------------------------------------------*/
void
handle_profiling_signal(int ignored)
Expand All @@ -860,15 +893,34 @@ mark_start_evaluation (void)
{
// .it_interval is always zero (no auto-repeat), .it_value will be set later
static struct itimerval prof_time_val = { {0,0}, {0,0} };
#ifdef USE_POSIX_TIMERS
static struct itimerspec prof_ptime_val = { {0,0}, {0,0} };
#endif

total_evalcost = 0;
eval_number++;

// start the profiling timer if enabled
if (profiling_timevalue.tv_usec || profiling_timevalue.tv_sec)
{
prof_time_val.it_value = profiling_timevalue;
setitimer(ITIMER_PROF, &prof_time_val, NULL);
#ifdef USE_POSIX_TIMERS
if (have_prof_timer)
{
prof_ptime_val.it_value.tv_sec = profiling_timevalue.tv_sec;
prof_ptime_val.it_value.tv_nsec = profiling_timevalue.tv_usec * 1000L;
if (timer_settime(prof_timer, 0, &prof_ptime_val, NULL) == -1)
{
debug_message("%s Could not start execution timer: %s\n"
, time_stamp(), strerror(errno));
have_prof_timer = false;
}
}
if (!have_prof_timer)
#endif
{
prof_time_val.it_value = profiling_timevalue;
setitimer(ITIMER_PROF, &prof_time_val, NULL);
}
}

if (gettimeofday(&eval_begin, NULL))
Expand All @@ -892,10 +944,20 @@ mark_end_evaluation (void)

{
static struct itimerval prof_time_val = { {0,0}, {0,0} };
#ifdef USE_POSIX_TIMERS
static struct itimerspec prof_ptime_val = { {0,0}, {0,0} };
#endif

// disable the profiling timer
if (profiling_timevalue.tv_usec || profiling_timevalue.tv_sec)
{
#ifdef USE_POSIX_TIMERS
if (have_prof_timer)
timer_settime(prof_timer, 0, &prof_ptime_val, NULL);
else
#endif
setitimer(ITIMER_PROF, &prof_time_val, NULL);
}

if (total_evalcost == 0)
return;
Expand Down
1 change: 1 addition & 0 deletions src/interpret.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ extern void check_a_lot_ref_counts(program_t *search_prog);
#endif

// signal handler for profiling (SIGPROF)
extern bool init_profiling_timer();
extern void handle_profiling_signal(int ignored);
extern Bool set_profiling_time_limit(mp_int limit);
extern mp_int get_profiling_time_limit();
Expand Down
13 changes: 10 additions & 3 deletions src/prolang.y
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,13 @@ get_common_array_type (lpctype_t* t1, lpctype_t* t2)
return result;
}

static lpctype_t*
get_common_lpc_type (lpctype_t* t1, lpctype_t* t2)

{
return get_common_type(t1, t2);
}

static lpctype_t*
get_sub_array_type (lpctype_t* t1, lpctype_t* t2)

Expand Down Expand Up @@ -2561,7 +2568,7 @@ binary_op_types_t types_binary_and_assignment[] = {
{ &_lpctype_mapping, &_lpctype_mapping, &_lpctype_mapping, NULL , NULL , NULL },
{ &_lpctype_mapping, &_lpctype_any_array, &_lpctype_mapping, NULL , NULL , NULL },
{ &_lpctype_any_array, &_lpctype_mapping, NULL, &get_first_type , NULL , NULL },
{ &_lpctype_any_array, &_lpctype_any_array, NULL, &get_common_type , NULL , NULL },
{ &_lpctype_any_array, &_lpctype_any_array, NULL, &get_common_lpc_type , NULL , NULL },
{ &_lpctype_int, &_lpctype_int, &_lpctype_int, NULL , NULL , NULL },
{ &_lpctype_string, &_lpctype_string, &_lpctype_string, NULL , NULL , NULL },
{ &_lpctype_bytes, &_lpctype_bytes, &_lpctype_bytes, NULL , NULL , NULL },
Expand Down Expand Up @@ -2611,7 +2618,7 @@ binary_op_types_t types_binary_and[] = {
{ &_lpctype_mapping, &_lpctype_mapping, &_lpctype_mapping, NULL , NULL , NULL },
{ &_lpctype_mapping, &_lpctype_any_array, &_lpctype_mapping, NULL , NULL , NULL },
{ &_lpctype_any_array, &_lpctype_mapping, NULL, &get_first_type , NULL , NULL },
{ &_lpctype_any_array, &_lpctype_any_array, NULL, &get_common_type , NULL , NULL },
{ &_lpctype_any_array, &_lpctype_any_array, NULL, &get_common_lpc_type , NULL , NULL },
{ &_lpctype_int, &_lpctype_int, &_lpctype_int, NULL , NULL , NULL },
{ &_lpctype_string, &_lpctype_string, &_lpctype_string, NULL , NULL , NULL },
{ &_lpctype_bytes, &_lpctype_bytes, &_lpctype_bytes, NULL , NULL , NULL },
Expand All @@ -2623,7 +2630,7 @@ binary_op_types_t types_binary_and[] = {
* Basically there must be a common type, but ints can be compared with floats also.
*/
binary_op_types_t types_equality[] = {
{ &_lpctype_mixed, &_lpctype_mixed, &_lpctype_int, &get_common_type , NULL , NULL },
{ &_lpctype_mixed, &_lpctype_mixed, &_lpctype_int, &get_common_lpc_type , NULL , NULL },
{ &_lpctype_int, &_lpctype_float, &_lpctype_int, NULL , NULL , NULL },
{ &_lpctype_float, &_lpctype_int, &_lpctype_int, NULL , NULL , NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL }
Expand Down
1 change: 1 addition & 0 deletions src/settings/unitopia
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ with_tls_keyfile=no
enable_malloc_trace=yes
enable_malloc_lpc_trace=yes
enable_use_pthreads=no
enable_posix_timers=yes

# --- Wizlist ---
with_wizlist_file=no
Expand Down
Loading

0 comments on commit 96da9b2

Please sign in to comment.