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
63f77059
Commit
63f77059
authored
May 20, 2015
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
timer: brute force corruption fix.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
59846988
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6222 additions
and
60 deletions
+6222
-60
ccan/timer/test/run-corrupt2.c
ccan/timer/test/run-corrupt2.c
+6184
-0
ccan/timer/test/run.c
ccan/timer/test/run.c
+1
-0
ccan/timer/timer.c
ccan/timer/timer.c
+37
-60
No files found.
ccan/timer/test/run-corrupt2.c
0 → 100644
View file @
63f77059
This diff is collapsed.
Click to expand it.
ccan/timer/test/run.c
View file @
63f77059
#define CCAN_TIMER_DEBUG
#include <ccan/timer/timer.h>
/* Include the C files directly. */
#include <ccan/timer/timer.c>
...
...
ccan/timer/timer.c
View file @
63f77059
...
...
@@ -148,73 +148,50 @@ static const struct timer *find_first(const struct list_head *list,
return
prev
;
}
static
const
struct
timer
*
get_first
(
const
struct
timers
*
timers
)
/* FIXME: Suboptimal */
static
const
struct
timer
*
brute_force_first
(
const
struct
timers
*
timers
)
{
unsigned
int
level
,
i
,
off
;
bool
need_next
;
uint64_t
base
;
unsigned
int
l
,
i
;
const
struct
timer
*
found
=
NULL
;
struct
list_head
*
h
;
if
(
timers
->
first
<
timers
->
base
)
{
base
=
timers
->
base
;
level
=
0
;
}
else
{
/* May not be accurate, due to timer_del / expiry. */
level
=
level_of
(
timers
,
timers
->
first
);
base
=
timers
->
first
>>
(
TIMER_LEVEL_BITS
*
level
);
}
next:
if
(
!
timers
->
level
[
level
])
return
find_first
(
&
timers
->
far
,
-
1U
,
NULL
);
need_next
=
false
;
off
=
base
%
PER_LEVEL
;
for
(
i
=
0
;
i
<
PER_LEVEL
;
i
++
)
{
h
=
&
timers
->
level
[
level
]
->
list
[(
i
+
off
)
%
PER_LEVEL
];
if
(
!
list_empty
(
h
))
break
;
/* We haven't cascaded yet, so if we wrap, we'll need to
* check next level, too. */
if
(
i
+
off
==
PER_LEVEL
)
need_next
=
true
;
}
if
(
i
==
PER_LEVEL
)
{
level
++
;
base
>>=
TIMER_LEVEL_BITS
;
if
(
off
!=
0
)
/* We need *next* bucket: we've started reusing the
* one above */
base
++
;
goto
next
;
for
(
l
=
0
;
l
<
ARRAY_SIZE
(
timers
->
level
)
&&
timers
->
level
[
l
];
l
++
)
{
for
(
i
=
0
;
i
<
PER_LEVEL
;
i
++
)
found
=
find_first
(
&
timers
->
level
[
l
]
->
list
[
i
],
l
,
found
);
}
/* Level 0 is exact, so they're all the same. */
found
=
find_first
(
h
,
level
,
NULL
);
while
(
need_next
)
{
need_next
=
false
;
if
(
!
timers
->
level
[
level
+
1
])
{
found
=
find_first
(
&
timers
->
far
,
-
1U
,
found
);
}
else
{
/* Current upper bucket has emptied into this
* bucket; we want *next* one. */
base
>>=
TIMER_LEVEL_BITS
;
base
++
;
off
=
base
%
PER_LEVEL
;
if
(
off
==
0
)
{
need_next
=
true
;
}
else
{
h
=
&
timers
->
level
[
level
+
1
]
->
list
[
off
];
found
=
find_first
(
h
,
level
+
1
,
found
);
}
found
=
find_first
(
&
timers
->
far
,
-
1U
,
found
);
return
found
;
}
static
const
struct
timer
*
get_first
(
const
struct
timers
*
timers
)
{
uint64_t
time
;
/* Where can we start from? */
if
(
timers
->
first
<
timers
->
base
)
time
=
timers
->
base
;
else
time
=
timers
->
first
;
/* We can have just far timers, for example. */
if
(
timers
->
level
[
0
])
{
/* First search rest of lower buckets; we've already spilled
* so if we find one there we don't need to search further. */
unsigned
int
i
,
off
=
time
%
PER_LEVEL
;
for
(
i
=
off
;
i
<
PER_LEVEL
;
i
++
)
{
struct
list_head
*
h
=
&
timers
->
level
[
0
]
->
list
[
i
];
if
(
!
list_empty
(
h
))
return
find_first
(
h
,
0
,
NULL
);
}
}
return
found
;
/* From here on, we're searching non-normalized parts of the
* data structure, which is much subtler.
*
* So we brute force. */
return
brute_force_first
(
timers
);
}
static
bool
update_first
(
struct
timers
*
timers
)
...
...
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