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
483c7c96
Commit
483c7c96
authored
Jun 10, 2014
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lbalance: update tools for new time (and jmap!)
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
d9b63547
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
20 deletions
+31
-20
ccan/lbalance/tools/Makefile
ccan/lbalance/tools/Makefile
+12
-7
ccan/lbalance/tools/lbalance.c
ccan/lbalance/tools/lbalance.c
+19
-13
No files found.
ccan/lbalance/tools/Makefile
View file @
483c7c96
#! /usr/bin/make
MODULES
=
../../jmap.o ../../time.o
CCANDIR
=
../../..
CFLAGS
=
-I
../../..
-g
#-O2
LDFLAGS
=
-lJudy
CCAN_OBJS
:=
ccan-jmap.o ccan-time.o
lbalance
:
lbalance.c $(MODULES)
CFLAGS
=
-I
$(CCANDIR)
-Wall
-g
#-O2
LDLIBS
=
-lJudy
$(MODULES)
:
make
-C
../../..
$(
patsubst
../../%.o, ccan/%.o,
$@
)
EXCLUDE
=
lbalance
:
lbalance.c $(CCAN_OBJS)
clean
:
rm
-f
lbalance
$(MODULES)
rm
-f
lbalance
$(CCAN_OBJS)
ccan-jmap.o
:
$(CCANDIR)/ccan/jmap/jmap.c
$(CC)
$(CFLAGS)
-c
-o
$@
$<
ccan-time.o
:
$(CCANDIR)/ccan/time/time.c
$(CC)
$(CFLAGS)
-c
-o
$@
$<
ccan/lbalance/tools/lbalance.c
View file @
483c7c96
#include <ccan/lbalance/lbalance.h>
#include <ccan/lbalance/lbalance.c>
#include <ccan/time/time.h>
#include <ccan/jmap/jmap
_type
.h>
#include <ccan/jmap/jmap.h>
#include <stdio.h>
#include <err.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
/* Defines struct jmap_task. */
JMAP_DEFINE_UINTIDX_TYPE
(
struct
lbalance_task
,
task
);
struct
jmap_task
{
JMAP_MEMBERS
(
unsigned
int
,
struct
lbalance_task
*
);
};
/* Figure out how many loops we need to run for about 1 second. */
static
unsigned
long
burn_count
;
static
void
calibrate_burn_cpu
(
void
)
{
struct
time
val
start
=
time_now
();
struct
time
abs
start
=
time_now
();
while
(
time_less
(
time_now
(),
time_add
(
start
,
time_from_msec
(
1000
))))
while
(
time_before
(
time_now
(),
timeabs_add
(
start
,
time_from_msec
(
1000
))))
burn_count
++
;
printf
(
"Burn count = %lu
\n
"
,
burn_count
);
}
...
...
@@ -23,12 +29,12 @@ static void calibrate_burn_cpu(void)
static
void
burn_cpu
(
void
)
{
unsigned
int
i
,
after
=
0
;
struct
time
val
start
=
time_now
();
struct
time
abs
start
=
time_now
();
/* We do a loop similar to the calibrate_burn_cpu loop. */
for
(
i
=
0
;
i
<
burn_count
;
i
++
)
{
after
+=
time_
less
(
time_now
(),
time
_add
(
start
,
time_from_msec
(
1000
)));
after
+=
time_
before
(
time_now
(),
timeabs
_add
(
start
,
time_from_msec
(
1000
)));
}
/* We use the result so the compiler can't discard it. */
exit
(
after
);
...
...
@@ -51,9 +57,9 @@ static pid_t spawn(char *args[])
int
main
(
int
argc
,
char
*
argv
[])
{
unsigned
int
i
,
num
,
fixed_target
=
0
,
num_done
=
0
,
num_running
=
0
;
unsigned
int
num
,
fixed_target
=
0
,
num_done
=
0
,
num_running
=
0
;
struct
lbalance
*
lb
;
struct
jmap_task
*
tasks
=
jmap_
task_new
(
);
struct
jmap_task
*
tasks
=
jmap_
new
(
struct
jmap_task
);
if
(
argc
<
2
)
{
fprintf
(
stderr
,
...
...
@@ -80,7 +86,7 @@ int main(int argc, char *argv[])
calibrate_burn_cpu
();
while
(
num_done
<
num
)
{
unsigned
int
j
,
target
=
fixed_target
;
unsigned
int
target
=
fixed_target
;
struct
lbalance_task
*
task
;
struct
rusage
ru
;
pid_t
pid
;
...
...
@@ -96,14 +102,14 @@ int main(int argc, char *argv[])
task
=
lbalance_task_new
(
lb
);
else
task
=
(
void
*
)
1
;
jmap_
task_
add
(
tasks
,
pid
,
task
);
jmap_add
(
tasks
,
pid
,
task
);
num_running
++
;
printf
(
"+"
);
fflush
(
stdout
);
}
/* Now wait for something to die! */
pid
=
wait3
(
NULL
,
0
,
&
ru
);
task
=
jmap_
task_
get
(
tasks
,
pid
);
task
=
jmap_get
(
tasks
,
pid
);
if
(
lb
)
lbalance_task_free
(
task
,
&
ru
);
num_done
++
;
...
...
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