root/plugin/timer/timerlist.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2006-2010 by Jason Ansel, Kapil Arya, and Gene Cooperman *
   3  *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu              *
   4  *                                                                          *
   5  *   This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src).  *
   6  *                                                                          *
   7  *  DMTCP:dmtcp/src is free software: you can redistribute it and/or        *
   8  *  modify it under the terms of the GNU Lesser General Public License as   *
   9  *  published by the Free Software Foundation, either version 3 of the      *
  10  *  License, or (at your option) any later version.                         *
  11  *                                                                          *
  12  *  DMTCP:dmtcp/src is distributed in the hope that it will be useful,      *
  13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
  15  *  GNU Lesser General Public License for more details.                     *
  16  *                                                                          *
  17  *  You should have received a copy of the GNU Lesser General Public        *
  18  *  License along with DMTCP:dmtcp/src.  If not, see                        *
  19  *  <http://www.gnu.org/licenses/>.                                         *
  20  ****************************************************************************/
  21 
  22 #pragma once
  23 #ifndef TIMER_LIST_H
  24 #define TIMER_LIST_H
  25 
  26 #include <time.h>
  27 #include <signal.h>
  28 #include "dmtcpalloc.h"
  29 #include "virtualidtable.h"
  30 #include "jassert.h"
  31 #include "jconvert.h"
  32 
  33 #define REAL_TO_VIRTUAL_TIMER_ID(id) \
  34   TimerList::instance().realToVirtualTimerId(id)
  35 #define VIRTUAL_TO_REAL_TIMER_ID(id) \
  36   TimerList::instance().virtualToRealTimerId(id)
  37 
  38 /*
  39 #define REAL_TO_VIRTUAL_CLOCK_ID(id) \
  40   TimerList::instance().realToVirtualClockId(id)
  41 */
  42 
  43 #define VIRTUAL_TO_REAL_CLOCK_ID(id) \
  44   TimerList::instance().virtualToRealClockId(id)
  45 
  46 namespace dmtcp {
  47   typedef struct TimerInfo {
  48     clockid_t clockid;
  49     struct sigevent sevp;
  50     bool sevp_null;
  51     int flags;
  52     struct itimerspec initial_timerspec;
  53     struct itimerspec curr_timerspec;
  54     int overrun;
  55   } TimerInfo;
  56 
  57 
  58   class TimerList {
  59     public:
  60 #ifdef JALIB_ALLOCATOR
  61       static void* operator new(size_t nbytes, void* p) { return p; }
  62       static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
  63       static void  operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
  64 #endif
  65 
  66       TimerList()
  67         : _timerVirtIdTable("Timer", (timer_t) NULL, 999999)
  68         , _clockVirtIdTable("Clock", (clockid_t) (unsigned) getpid()) {} //(clockid_t) (unsigned long) getpid()) { }
  69 
  70       static TimerList& instance();
  71 
  72       void resetOnFork();
  73       void preCheckpoint();
  74       void postRestart();
  75 
  76       timer_t  virtualToRealTimerId(timer_t virtId) {
  77         return _timerVirtIdTable.virtualToReal(virtId);
  78       }
  79       timer_t  realToVirtualTimerId(timer_t realId) {
  80         return _timerVirtIdTable.realToVirtual(realId);
  81       }
  82       clockid_t  virtualToRealClockId(clockid_t virtId) {
  83         return _clockVirtIdTable.virtualToReal(virtId);
  84       }
  85 //      timer_t  realToVirtualClockId(timer_t realId) {
  86 //        if (_clockVirtIdTable.realIdExists(realId)) {
  87 //          return _clockVirtIdTable.realToVirtual(realId);
  88 //        } else {
  89 //          return -1;
  90 //        }
  91 //      }
  92 
  93       int getoverrun(timer_t id);
  94       timer_t on_timer_create(timer_t realId, clockid_t clockid,
  95                            struct sigevent *sevp);
  96       void on_timer_delete(timer_t timerid);
  97       void on_timer_settime(timer_t timerid, int flags,
  98                             const struct itimerspec *new_value);
  99       clockid_t on_clock_getcpuclockid(pid_t pid, clockid_t clock_id);
 100       clockid_t on_pthread_getcpuclockid(pthread_t thread, clockid_t clock_id);
 101 
 102     private:
 103       void removeStaleClockIds();
 104 
 105       map<timer_t, TimerInfo> _timerInfo;
 106       map<timer_t, TimerInfo>::iterator _iter;
 107       map<clockid_t, pid_t> _clockPidList;
 108       map<clockid_t, pthread_t> _clockPthreadList;
 109 
 110       VirtualIdTable<timer_t> _timerVirtIdTable;
 111       VirtualIdTable<clockid_t> _clockVirtIdTable;
 112   };
 113 }
 114 #endif

/* [<][>][^][v][top][bottom][index][help] */