/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- timer_create
- timer_delete
- timer_settime
- timer_gettime
- timer_getoverrun
- clock_getcpuclockid
- pthread_getcpuclockid
- clock_getres
- clock_gettime
- clock_settime
- clock_nanosleep
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 #include "timerwrappers.h"
23 #include "timerlist.h"
24
25 using namespace dmtcp;
26
27 extern "C" int timer_create(clockid_t clockid, struct sigevent *sevp,
28 timer_t *timerid)
29 {
30 struct sigevent sevOut;
31 timer_t realId;
32 timer_t virtId;
33 int ret;
34 DMTCP_PLUGIN_DISABLE_CKPT();
35 clockid_t realClockId = VIRTUAL_TO_REAL_CLOCK_ID(clockid);
36 if (sevp != NULL && sevp->sigev_notify == SIGEV_THREAD) {
37 ret = timer_create_sigev_thread(realClockId, sevp, &realId, &sevOut);
38 sevp = &sevOut;
39 } else {
40 ret = _real_timer_create(realClockId, sevp, &realId);
41 }
42 if (ret != -1 && timerid != NULL) {
43 virtId = TimerList::instance().on_timer_create(realId, clockid, sevp);
44 JTRACE ("Creating new timer") (clockid) (realClockId) (realId) (virtId);
45 *timerid = virtId;
46 }
47 DMTCP_PLUGIN_ENABLE_CKPT();
48 return ret;
49 }
50
51
52 extern "C" int timer_delete(timer_t timerid)
53 {
54 DMTCP_PLUGIN_DISABLE_CKPT();
55 timer_t realId = VIRTUAL_TO_REAL_TIMER_ID(timerid);
56 int ret = _real_timer_delete(realId);
57 if (ret != -1) {
58 TimerList::instance().on_timer_delete(timerid);
59 JTRACE ("Deleted timer") (timerid);
60 }
61 DMTCP_PLUGIN_ENABLE_CKPT();
62 return ret;
63 }
64
65 extern "C" int timer_settime(timer_t timerid, int flags,
66 const struct itimerspec *new_value,
67 struct itimerspec * old_value)
68 {
69 DMTCP_PLUGIN_DISABLE_CKPT();
70 timer_t realId = VIRTUAL_TO_REAL_TIMER_ID(timerid);
71 int ret = _real_timer_settime(realId, flags, new_value, old_value);
72 if (ret != -1) {
73 TimerList::instance().on_timer_settime(timerid, flags, new_value);
74 }
75 DMTCP_PLUGIN_ENABLE_CKPT();
76 return ret;
77 }
78
79 extern "C" int timer_gettime(timer_t timerid, struct itimerspec *curr_value)
80 {
81 DMTCP_PLUGIN_DISABLE_CKPT();
82 timer_t realId = VIRTUAL_TO_REAL_TIMER_ID(timerid);
83 int ret = _real_timer_gettime(realId, curr_value);
84 DMTCP_PLUGIN_ENABLE_CKPT();
85 return ret;
86 }
87
88 extern "C" int timer_getoverrun(timer_t timerid)
89 {
90 DMTCP_PLUGIN_DISABLE_CKPT();
91 timer_t realId = VIRTUAL_TO_REAL_TIMER_ID(timerid);
92 int ret = _real_timer_getoverrun(realId);
93 // If there was some overrun at checkpoint time, add it to the current value
94 ret += TimerList::instance().getoverrun(timerid);
95 DMTCP_PLUGIN_ENABLE_CKPT();
96 return ret;
97 }
98
99 extern "C" int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
100 {
101 clockid_t realId;
102 DMTCP_PLUGIN_DISABLE_CKPT();
103 int ret = _real_clock_getcpuclockid(pid, &realId);
104 if (ret == 0) {
105 *clock_id = TimerList::instance().on_clock_getcpuclockid(pid, realId);
106 }
107 DMTCP_PLUGIN_ENABLE_CKPT();
108 return ret;
109 }
110
111 extern "C" int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id)
112 {
113 DMTCP_PLUGIN_DISABLE_CKPT();
114 clockid_t realId;
115 int ret = _real_pthread_getcpuclockid(thread, &realId);
116 if (ret == 0) {
117 *clock_id = TimerList::instance().on_pthread_getcpuclockid(thread, realId);
118 }
119 DMTCP_PLUGIN_ENABLE_CKPT();
120 return ret;
121 }
122
123 extern "C" int clock_getres(clockid_t clk_id, struct timespec *res)
124 {
125 DMTCP_PLUGIN_DISABLE_CKPT();
126 clockid_t realId = VIRTUAL_TO_REAL_CLOCK_ID(clk_id);
127 int ret = _real_clock_getres(realId, res);
128 DMTCP_PLUGIN_ENABLE_CKPT();
129 return ret;
130 }
131
132 extern "C" int clock_gettime(clockid_t clk_id, struct timespec *tp)
133 {
134 DMTCP_PLUGIN_DISABLE_CKPT();
135 clockid_t realId = VIRTUAL_TO_REAL_CLOCK_ID(clk_id);
136 int ret = _real_clock_gettime(realId, tp);
137 DMTCP_PLUGIN_ENABLE_CKPT();
138 return ret;
139 }
140
141 extern "C" int clock_settime(clockid_t clk_id, const struct timespec *tp)
142 {
143 DMTCP_PLUGIN_DISABLE_CKPT();
144 clockid_t realId = VIRTUAL_TO_REAL_CLOCK_ID(clk_id);
145 int ret = _real_clock_settime(realId, tp);
146 DMTCP_PLUGIN_ENABLE_CKPT();
147 return ret;
148 }
149
150 // FIXME: The following wrapper disable ckpt for the entire duration of
151 // clock_nanosleep. This is dangerous and can lead to a situation where
152 // checkpointing never happens. Disabling the wrapper for now.
153 #ifdef ENABLE_CLOCK_NANOSLEEP
154 extern "C" int clock_nanosleep(clockid_t clock_id, int flags,
155 const struct timespec *request,
156 struct timespec *remain)
157 {
158 DMTCP_PLUGIN_DISABLE_CKPT();
159 clockid_t realId = VIRTUAL_TO_REAL_CLOCK_ID(clock_id);
160 int ret = _real_clock_nanosleep(realId, flags, request, remain);
161 DMTCP_PLUGIN_ENABLE_CKPT();
162 return ret;
163 }
164 #endif