Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
daf9ee7d
Commit
daf9ee7d
authored
Jun 03, 2014
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io failtest timer tools: fallout from time changes.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
c92b4966
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
67 additions
and
54 deletions
+67
-54
ccan/failtest/failtest.c
ccan/failtest/failtest.c
+4
-4
ccan/io/backend.h
ccan/io/backend.h
+1
-1
ccan/io/io.c
ccan/io/io.c
+2
-2
ccan/io/io.h
ccan/io/io.h
+2
-2
ccan/io/poll.c
ccan/io/poll.c
+5
-5
ccan/timer/_info
ccan/timer/_info
+3
-3
ccan/timer/test/run-add.c
ccan/timer/test/run-add.c
+2
-1
ccan/timer/test/run-ff.c
ccan/timer/test/run-ff.c
+10
-4
ccan/timer/test/run.c
ccan/timer/test/run.c
+15
-8
ccan/timer/timer.c
ccan/timer/timer.c
+12
-12
ccan/timer/timer.h
ccan/timer/timer.h
+7
-8
tools/ccanlint/async.c
tools/ccanlint/async.c
+1
-1
tools/tools.c
tools/tools.c
+3
-3
No files found.
ccan/failtest/failtest.c
View file @
daf9ee7d
...
...
@@ -91,7 +91,7 @@ static int control_fd = -1;
/* If we're a child, this is the first call we did ourselves. */
static
struct
failtest_call
*
our_history_start
=
NULL
;
/* For printing runtime with --trace. */
static
struct
time
spec
start
;
static
struct
time
abs
start
;
/* Set when failtest_hook returns FAIL_PROBE */
static
bool
probing
=
false
;
/* Table to track duplicates. */
...
...
@@ -761,13 +761,13 @@ static bool should_fail(struct failtest_call *call)
if
(
child
==
0
)
{
traceindent
++
;
if
(
tracef
)
{
struct
time
spec
diff
;
struct
time
rel
diff
;
const
char
*
p
;
char
*
failpath
;
struct
failtest_call
*
c
;
c
=
tlist_tail
(
&
history
,
list
);
diff
=
time_
sub
(
time_now
(),
start
);
diff
=
time_
between
(
time_now
(),
start
);
failpath
=
failpath_string
();
p
=
strrchr
(
c
->
file
,
'/'
);
if
(
p
)
...
...
@@ -776,7 +776,7 @@ static bool should_fail(struct failtest_call *call)
p
=
c
->
file
;
trace
(
"%u->%u (%u.%02u): %s (%s:%u)
\n
"
,
getppid
(),
getpid
(),
(
int
)
diff
.
t
v_sec
,
(
int
)
diff
.
tv_nsec
/
10000000
,
(
int
)
diff
.
t
s
.
tv_sec
,
(
int
)
diff
.
ts
.
tv_nsec
/
10000000
,
failpath
,
p
,
c
->
line
);
free
(
failpath
);
}
...
...
ccan/io/backend.h
View file @
daf9ee7d
...
...
@@ -92,7 +92,7 @@ bool add_duplex(struct io_conn *c);
void
del_listener
(
struct
io_listener
*
l
);
void
backend_plan_changed
(
struct
io_conn
*
conn
);
void
backend_wait_changed
(
const
void
*
wait
);
void
backend_add_timeout
(
struct
io_conn
*
conn
,
struct
time
spec
ts
);
void
backend_add_timeout
(
struct
io_conn
*
conn
,
struct
time
rel
duration
);
void
backend_del_timeout
(
struct
io_conn
*
conn
);
void
backend_del_conn
(
struct
io_conn
*
conn
);
...
...
ccan/io/io.c
View file @
daf9ee7d
...
...
@@ -198,7 +198,7 @@ struct io_conn *io_duplex_(struct io_conn *old, struct io_plan plan)
return
conn
;
}
bool
io_timeout_
(
struct
io_conn
*
conn
,
struct
time
spec
ts
,
bool
io_timeout_
(
struct
io_conn
*
conn
,
struct
time
rel
t
,
struct
io_plan
(
*
cb
)(
struct
io_conn
*
,
void
*
),
void
*
arg
)
{
assert
(
cb
);
...
...
@@ -212,7 +212,7 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts,
conn
->
timeout
->
next
=
cb
;
conn
->
timeout
->
next_arg
=
arg
;
backend_add_timeout
(
conn
,
t
s
);
backend_add_timeout
(
conn
,
t
);
return
true
;
}
...
...
ccan/io/io.h
View file @
daf9ee7d
...
...
@@ -391,7 +391,7 @@ struct io_plan io_wait_(const void *wait,
/**
* io_timeout - set timeout function if the callback doesn't complete.
* @conn: the current connection.
* @t
s
: how long until the timeout should be called.
* @t: how long until the timeout should be called.
* @cb: callback to call.
* @arg: argument to @cb.
*
...
...
@@ -419,7 +419,7 @@ struct io_plan io_wait_(const void *wait,
(fn), (arg), \
struct io_conn *), \
(arg))
bool
io_timeout_
(
struct
io_conn
*
conn
,
struct
time
spec
ts
,
bool
io_timeout_
(
struct
io_conn
*
conn
,
struct
time
rel
t
,
struct
io_plan
(
*
fn
)(
struct
io_conn
*
,
void
*
),
void
*
arg
);
/**
...
...
ccan/io/poll.c
View file @
daf9ee7d
...
...
@@ -285,12 +285,12 @@ static bool finish_conns(struct io_conn **ready)
return
false
;
}
void
backend_add_timeout
(
struct
io_conn
*
conn
,
struct
time
spec
duration
)
void
backend_add_timeout
(
struct
io_conn
*
conn
,
struct
time
rel
duration
)
{
if
(
!
timeouts
.
base
)
timers_init
(
&
timeouts
,
time_now
());
timer_add
(
&
timeouts
,
&
conn
->
timeout
->
timer
,
time_add
(
time_now
(),
duration
));
time
abs
_add
(
time_now
(),
duration
));
conn
->
timeout
->
conn
=
conn
;
}
...
...
@@ -330,11 +330,11 @@ void *do_io_loop(struct io_conn **ready)
while
(
!
io_loop_return
)
{
int
i
,
r
,
timeout
=
INT_MAX
;
struct
time
spec
now
;
struct
time
abs
now
;
bool
some_timeouts
=
false
;
if
(
timeouts
.
base
)
{
struct
time
spec
first
;
struct
time
abs
first
;
struct
list_head
expired
;
struct
io_timeout
*
t
;
...
...
@@ -353,7 +353,7 @@ void *do_io_loop(struct io_conn **ready)
/* Now figure out how long to wait for the next one. */
if
(
timer_earliest
(
&
timeouts
,
&
first
))
{
uint64_t
f
=
time_to_msec
(
time_
sub
(
first
,
now
));
uint64_t
f
=
time_to_msec
(
time_
between
(
first
,
now
));
if
(
f
<
INT_MAX
)
timeout
=
f
;
}
...
...
ccan/timer/_info
View file @
daf9ee7d
...
...
@@ -37,14 +37,14 @@
* s = malloc(sizeof(*s));
* s->string = argv[1];
* timer_add(&timers, &s->timer,
* time_add(time_now(),
* time_from_msec(atol(argv[2]))));
* time
abs
_add(time_now(),
*
time_from_msec(atol(argv[2]))));
* list_add_tail(&strings, &s->node);
* argv += 2;
* }
*
* while (!list_empty(&strings)) {
* struct time
spec
now = time_now();
* struct time
abs
now = time_now();
* list_for_each(&strings, s, node)
* printf("%s", s->string);
* timers_expire(&timers, now, &expired);
...
...
ccan/timer/test/run-add.c
View file @
daf9ee7d
...
...
@@ -20,11 +20,12 @@ int main(void)
struct
timer
t
;
uint64_t
diff
;
unsigned
int
i
;
struct
timeabs
epoch
=
{
{
0
,
0
}
};
/* This is how many tests you plan to run */
plan_tests
(
2
+
(
18
+
(
MAX_ORD
-
4
)
*
3
)
*
(
18
+
(
MAX_ORD
-
4
)
*
3
));
timers_init
(
&
timers
,
time_from_nsec
(
0
)
);
timers_init
(
&
timers
,
epoch
);
ok1
(
timers_check
(
&
timers
,
NULL
));
for
(
i
=
0
;
i
<
4
;
i
++
)
...
...
ccan/timer/test/run-ff.c
View file @
daf9ee7d
...
...
@@ -3,6 +3,12 @@
#include <ccan/timer/timer.c>
#include <ccan/tap/tap.h>
static
struct
timeabs
timeabs_from_usec
(
unsigned
long
long
usec
)
{
struct
timeabs
epoch
=
{
{
0
,
0
}
};
return
timeabs_add
(
epoch
,
time_from_usec
(
usec
));
}
int
main
(
void
)
{
struct
timers
timers
;
...
...
@@ -12,11 +18,11 @@ int main(void)
/* This is how many tests you plan to run */
plan_tests
(
3
);
timers_init
(
&
timers
,
time_from_usec
(
1364726722653919ULL
));
timer_add
(
&
timers
,
&
t
,
time_from_usec
(
1364726722703919ULL
));
timers_expire
(
&
timers
,
time_from_usec
(
1364726722653920ULL
),
&
expired
);
timers_init
(
&
timers
,
time
abs
_from_usec
(
1364726722653919ULL
));
timer_add
(
&
timers
,
&
t
,
time
abs
_from_usec
(
1364726722703919ULL
));
timers_expire
(
&
timers
,
time
abs
_from_usec
(
1364726722653920ULL
),
&
expired
);
ok1
(
list_empty
(
&
expired
));
timers_expire
(
&
timers
,
time_from_usec
(
1364726725454187ULL
),
&
expired
);
timers_expire
(
&
timers
,
time
abs
_from_usec
(
1364726725454187ULL
),
&
expired
);
ok1
(
!
list_empty
(
&
expired
));
ok1
(
list_top
(
&
expired
,
struct
timer
,
list
)
==
&
t
);
...
...
ccan/timer/test/run.c
View file @
daf9ee7d
...
...
@@ -3,34 +3,41 @@
#include <ccan/timer/timer.c>
#include <ccan/tap/tap.h>
static
struct
timeabs
timeabs_from_nsec
(
unsigned
long
long
nsec
)
{
struct
timeabs
epoch
=
{
{
0
,
0
}
};
return
timeabs_add
(
epoch
,
time_from_nsec
(
nsec
));
}
int
main
(
void
)
{
struct
timers
timers
;
struct
timer
t
[
64
];
struct
list_head
expired
;
struct
time
spec
earliest
;
struct
time
abs
earliest
;
uint64_t
i
;
struct
timeabs
epoch
=
{
{
0
,
0
}
};
/* This is how many tests you plan to run */
plan_tests
(
488
);
timers_init
(
&
timers
,
time_from_nsec
(
0
)
);
timers_init
(
&
timers
,
epoch
);
ok1
(
timers_check
(
&
timers
,
NULL
));
ok1
(
!
timer_earliest
(
&
timers
,
&
earliest
));
timer_add
(
&
timers
,
&
t
[
0
],
time_from_nsec
(
1
));
timer_add
(
&
timers
,
&
t
[
0
],
time
abs
_from_nsec
(
1
));
ok1
(
timers_check
(
&
timers
,
NULL
));
ok1
(
timer_earliest
(
&
timers
,
&
earliest
));
ok1
(
time_eq
(
earliest
,
grains_to_time
(
t
[
0
].
time
)));
ok1
(
time
abs
_eq
(
earliest
,
grains_to_time
(
t
[
0
].
time
)));
timer_del
(
&
timers
,
&
t
[
0
]);
ok1
(
timers_check
(
&
timers
,
NULL
));
ok1
(
!
timer_earliest
(
&
timers
,
&
earliest
));
/* Check timer ordering. */
for
(
i
=
0
;
i
<
32
;
i
++
)
{
timer_add
(
&
timers
,
&
t
[
i
*
2
],
time_from_nsec
(
1ULL
<<
i
));
timer_add
(
&
timers
,
&
t
[
i
*
2
],
time
abs
_from_nsec
(
1ULL
<<
i
));
ok1
(
timers_check
(
&
timers
,
NULL
));
timer_add
(
&
timers
,
&
t
[
i
*
2
+
1
],
time_from_nsec
((
1ULL
<<
i
)
+
1
));
timer_add
(
&
timers
,
&
t
[
i
*
2
+
1
],
time
abs
_from_nsec
((
1ULL
<<
i
)
+
1
));
ok1
(
timers_check
(
&
timers
,
NULL
));
}
...
...
@@ -52,9 +59,9 @@ int main(void)
for
(
i
=
0
;
i
<
32
;
i
++
)
{
uint64_t
exp
=
(
uint64_t
)
TIMER_GRANULARITY
<<
i
;
timer_add
(
&
timers
,
&
t
[
i
*
2
],
time_from_nsec
(
exp
));
timer_add
(
&
timers
,
&
t
[
i
*
2
],
time
abs
_from_nsec
(
exp
));
ok1
(
timers_check
(
&
timers
,
NULL
));
timer_add
(
&
timers
,
&
t
[
i
*
2
+
1
],
time_from_nsec
(
exp
+
1
));
timer_add
(
&
timers
,
&
t
[
i
*
2
+
1
],
time
abs
_from_nsec
(
exp
+
1
));
ok1
(
timers_check
(
&
timers
,
NULL
));
}
...
...
ccan/timer/timer.c
View file @
daf9ee7d
...
...
@@ -12,23 +12,23 @@ struct timer_level {
struct
list_head
list
[
PER_LEVEL
];
};
static
uint64_t
time_to_grains
(
struct
time
spec
ts
)
static
uint64_t
time_to_grains
(
struct
time
abs
t
)
{
return
ts
.
tv_sec
*
((
uint64_t
)
1000000000
/
TIMER_GRANULARITY
)
+
(
ts
.
tv_nsec
/
TIMER_GRANULARITY
);
return
t
.
t
s
.
tv_sec
*
((
uint64_t
)
1000000000
/
TIMER_GRANULARITY
)
+
(
t
.
t
s
.
tv_nsec
/
TIMER_GRANULARITY
);
}
static
struct
time
spec
grains_to_time
(
uint64_t
grains
)
static
struct
time
abs
grains_to_time
(
uint64_t
grains
)
{
struct
time
spec
ts
;
struct
time
abs
t
;
ts
.
tv_sec
=
grains
/
(
1000000000
/
TIMER_GRANULARITY
);
ts
.
tv_nsec
=
(
grains
%
(
1000000000
/
TIMER_GRANULARITY
))
t
.
t
s
.
tv_sec
=
grains
/
(
1000000000
/
TIMER_GRANULARITY
);
t
.
t
s
.
tv_nsec
=
(
grains
%
(
1000000000
/
TIMER_GRANULARITY
))
*
TIMER_GRANULARITY
;
return
t
s
;
return
t
;
}
void
timers_init
(
struct
timers
*
timers
,
struct
time
spec
start
)
void
timers_init
(
struct
timers
*
timers
,
struct
time
abs
start
)
{
unsigned
int
i
;
...
...
@@ -63,7 +63,7 @@ static void timer_add_raw(struct timers *timers, struct timer *t)
list_add_tail
(
l
,
&
t
->
list
);
}
void
timer_add
(
struct
timers
*
timers
,
struct
timer
*
t
,
struct
time
spec
when
)
void
timer_add
(
struct
timers
*
timers
,
struct
timer
*
t
,
struct
time
abs
when
)
{
t
->
time
=
time_to_grains
(
when
);
...
...
@@ -203,7 +203,7 @@ static bool update_first(struct timers *timers)
return
true
;
}
bool
timer_earliest
(
struct
timers
*
timers
,
struct
time
spec
*
first
)
bool
timer_earliest
(
struct
timers
*
timers
,
struct
time
abs
*
first
)
{
if
(
!
update_first
(
timers
))
return
false
;
...
...
@@ -261,7 +261,7 @@ static void timer_fast_forward(struct timers *timers, uint64_t time)
/* Fills list of expired timers. */
void
timers_expire
(
struct
timers
*
timers
,
struct
time
spec
expire
,
struct
time
abs
expire
,
struct
list_head
*
list
)
{
uint64_t
now
=
time_to_grains
(
expire
);
...
...
ccan/timer/timer.h
View file @
daf9ee7d
...
...
@@ -31,7 +31,7 @@ struct timer;
*
* timers_init(&timeouts, time_now());
*/
void
timers_init
(
struct
timers
*
timers
,
struct
time
spec
start
);
void
timers_init
(
struct
timers
*
timers
,
struct
time
abs
start
);
/**
* timers_cleanup - free allocations within timers struct.
...
...
@@ -57,10 +57,9 @@ void timers_cleanup(struct timers *timers);
* struct timer t;
*
* // Timeout in 100ms.
* timer_add(&timeouts, &t, time_add(time_now(), time_from_msec(100)));
* timer_add(&timeouts, &t, time
abs
_add(time_now(), time_from_msec(100)));
*/
void
timer_add
(
struct
timers
*
timers
,
struct
timer
*
timer
,
struct
timespec
when
);
void
timer_add
(
struct
timers
*
timers
,
struct
timer
*
timer
,
struct
timeabs
when
);
/**
* timer_del - remove an unexpired timer.
...
...
@@ -77,17 +76,17 @@ void timer_del(struct timers *timers, struct timer *timer);
/**
* timer_earliest - find out the first time when a timer will expire
* @timers: the struct timers
* @first: the time, only set if there is a timer.
* @first: the
expiry
time, only set if there is a timer.
*
* This returns false, and doesn't alter @first if there are no
* timers. Otherwise, it sets @first to the expiry time of the first
* timer (rounded to TIMER_GRANULARITY nanoseconds), and returns true.
*
* Example:
* struct time
spec next = { (time_t)-1ULL, -1UL
};
* struct time
abs next = { { (time_t)-1ULL, -1UL }
};
* timer_earliest(&timeouts, &next);
*/
bool
timer_earliest
(
struct
timers
*
timers
,
struct
time
spec
*
first
);
bool
timer_earliest
(
struct
timers
*
timers
,
struct
time
abs
*
first
);
/**
* timers_expire - update timers structure and remove expired timers.
...
...
@@ -114,7 +113,7 @@ bool timer_earliest(struct timers *timers, struct timespec *first);
* printf("Timer expired!\n");
*/
void
timers_expire
(
struct
timers
*
timers
,
struct
time
spec
expire
,
struct
time
abs
expire
,
struct
list_head
*
list
);
/**
...
...
tools/ccanlint/async.c
View file @
daf9ee7d
...
...
@@ -68,7 +68,7 @@ static void run_more(void)
signal
(
SIGALRM
,
killme
);
itim
.
it_interval
.
tv_sec
=
itim
.
it_interval
.
tv_usec
=
0
;
itim
.
it_value
=
timespec_to_timeval
(
time_from_msec
(
c
->
time_ms
));
itim
.
it_value
=
timespec_to_timeval
(
time_from_msec
(
c
->
time_ms
)
.
ts
);
setitimer
(
ITIMER_REAL
,
&
itim
,
NULL
);
c
->
status
=
system
(
c
->
command
);
...
...
tools/tools.c
View file @
daf9ee7d
...
...
@@ -39,7 +39,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
int
p
[
2
];
struct
rbuf
in
;
int
status
,
ms
;
struct
time
spec
start
;
struct
time
abs
start
;
*
ok
=
false
;
if
(
pipe
(
p
)
!=
0
)
...
...
@@ -71,7 +71,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
signal
(
SIGALRM
,
killme
);
itim
.
it_interval
.
tv_sec
=
itim
.
it_interval
.
tv_usec
=
0
;
itim
.
it_value
=
timespec_to_timeval
(
time_from_msec
(
*
timeout_ms
));
itim
.
it_value
=
timespec_to_timeval
(
time_from_msec
(
*
timeout_ms
)
.
ts
);
setitimer
(
ITIMER_REAL
,
&
itim
,
NULL
);
status
=
system
(
cmd
);
...
...
@@ -90,7 +90,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
if
(
waitpid
(
pid
,
&
status
,
0
)
!=
pid
)
err
(
1
,
"Failed to wait for child"
);
ms
=
time_to_msec
(
time_
sub
(
time_now
(),
start
));
ms
=
time_to_msec
(
time_
between
(
time_now
(),
start
));
if
(
ms
>
*
timeout_ms
)
*
timeout_ms
=
0
;
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment