Ticket #5865: 5865-posix-nonthreaded.patch

File 5865-posix-nonthreaded.patch, 4.2 KB (added by pcapriotti, 2 years ago)
  • new file rts/posix/Clock.h

    From 35f2540805c69edfbfcb7d00351d7a8293a5ff28 Mon Sep 17 00:00:00 2001
    From: Paolo Capriotti <p.capriotti@gmail.com>
    Date: Tue, 20 Mar 2012 11:57:28 +0000
    Subject: [PATCH] Use monotonic clock in Select.c (#5865)
    
    ---
     rts/posix/Clock.h   |   32 ++++++++++++++++++++++++++++++++
     rts/posix/GetTime.c |   21 +++++++++------------
     rts/posix/Itimer.c  |   11 ++---------
     rts/posix/Select.c  |   14 +++++---------
     4 files changed, 48 insertions(+), 30 deletions(-)
     create mode 100644 rts/posix/Clock.h
    
    diff --git a/rts/posix/Clock.h b/rts/posix/Clock.h
    new file mode 100644
    index 0000000..5062023
    - +  
     1/* ----------------------------------------------------------------------------- 
     2 * 
     3 * (c) The GHC Team, 2012 
     4 * 
     5 * Posix monotonic clock 
     6 * 
     7 * ---------------------------------------------------------------------------*/ 
     8 
     9#ifndef POSIX_CLOCK_H 
     10#define POSIX_CLOCK_H 
     11 
     12#ifdef HAVE_UNISTD_H 
     13# include <unistd.h> 
     14#endif 
     15 
     16#ifdef HAVE_TIME_H 
     17# include <time.h> 
     18#endif 
     19 
     20#ifdef HAVE_SYS_TIME_H 
     21# include <sys/time.h> 
     22#endif 
     23 
     24#ifdef HAVE_CLOCK_GETTIME 
     25# ifdef _POSIX_MONOTONIC_CLOCK 
     26#  define CLOCK_ID CLOCK_MONOTONIC 
     27# else 
     28#  define CLOCK_ID CLOCK_REALTIME 
     29# endif 
     30#endif 
     31 
     32#endif /* POSIX_CLOCK_H */ 
  • rts/posix/GetTime.c

    diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
    index 16511ce..4abc82f 100644
    a b  
    1111 
    1212#include "Rts.h" 
    1313#include "GetTime.h" 
    14  
    15 #ifdef HAVE_TIME_H 
    16 # include <time.h> 
    17 #endif 
    18  
    19 #ifdef HAVE_SYS_TIME_H 
    20 # include <sys/time.h> 
    21 #endif 
     14#include "Clock.h" 
    2215 
    2316#if HAVE_SYS_RESOURCE_H 
    2417# include <sys/resource.h> 
    2518#endif 
    2619 
    27 #ifdef HAVE_UNISTD_H 
    28 # include <unistd.h> 
    29 #endif 
    30  
    3120#ifdef HAVE_SYS_TIMES_H 
    3221# include <sys/times.h> 
    3322#endif 
    Time getProcessCPUTime(void) 
    7766 
    7867Time getProcessElapsedTime(void) 
    7968{ 
     69#ifdef HAVE_CLOCK_GETTIME 
     70    struct timespec ts; 
     71 
     72    clock_gettime(CLOCK_ID, &ts); 
     73    return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec); 
     74#else 
    8075    struct timeval tv; 
     76 
    8177    gettimeofday(&tv, (struct timezone *) NULL); 
    8278    return SecondsToTime(tv.tv_sec) + USToTime(tv.tv_usec); 
     79#endif 
    8380} 
    8481 
    8582void getProcessTimes(Time *user, Time *elapsed) 
  • rts/posix/Itimer.c

    diff --git a/rts/posix/Itimer.c b/rts/posix/Itimer.c
    index 13ba345..8c9b1f8 100644
    a b  
    2424#include "Itimer.h" 
    2525#include "Proftimer.h" 
    2626#include "Schedule.h" 
    27 #include "Select.h" 
     27#include "Clock.h" 
    2828 
    2929/* As recommended in the autoconf manual */ 
    3030# ifdef TIME_WITH_SYS_TIME 
    initTicker (Time interval, TickProc handle_tick) 
    123123#if defined(USE_TIMER_CREATE) 
    124124    { 
    125125        struct sigevent ev; 
    126         clockid_t clock; 
    127126 
    128127        // Keep programs like valgrind happy 
    129128        memset(&ev, 0, sizeof(ev)); 
    initTicker (Time interval, TickProc handle_tick) 
    131130        ev.sigev_notify = SIGEV_SIGNAL; 
    132131        ev.sigev_signo  = ITIMER_SIGNAL; 
    133132 
    134 #if defined(CLOCK_MONOTONIC) 
    135         clock = CLOCK_MONOTONIC; 
    136 #else 
    137         clock = CLOCK_REALTIME; 
    138 #endif 
    139  
    140         if (timer_create(clock, &ev, &timer) != 0) { 
     133        if (timer_create(CLOCK_ID, &ev, &timer) != 0) { 
    141134            sysErrorBelch("timer_create"); 
    142135            stg_exit(EXIT_FAILURE); 
    143136        } 
  • rts/posix/Select.c

    diff --git a/rts/posix/Select.c b/rts/posix/Select.c
    index 013b374..cec721d 100644
    a b  
    1717#include "Select.h" 
    1818#include "AwaitEvent.h" 
    1919#include "Stats.h" 
     20#include "GetTime.h" 
    2021 
    2122# ifdef HAVE_SYS_SELECT_H 
    2223#  include <sys/select.h> 
     
    2627#  include <sys/types.h> 
    2728# endif 
    2829 
    29 # ifdef HAVE_SYS_TIME_H 
    30 #  include <sys/time.h> 
    31 # endif 
    32  
    3330#include <errno.h> 
    3431#include <string.h> 
    3532 
    36 #ifdef HAVE_UNISTD_H 
    37 #include <unistd.h> 
    38 #endif 
     33#include "Clock.h" 
    3934 
    4035#if !defined(THREADED_RTS) 
    4136 
     
    5348 */ 
    5449LowResTime getourtimeofday(void) 
    5550{ 
    56   return TimeToUS(stat_getElapsedTime()) / 10000; 
     51  return TimeToUS(getProcessElapsedTime()) / 10000; 
    5752} 
    5853 
    5954/* There's a clever trick here to avoid problems when the time wraps 
    awaitEvent(rtsBool wait) 
    246241           
    247242          /* check for threads that need waking up  
    248243           */ 
     244 
    249245          wakeUpSleepingThreads(getourtimeofday()); 
    250            
     246 
    251247          /* If new runnable threads have arrived, stop waiting for 
    252248           * I/O and run them. 
    253249           */