lbalance: update tools for new time (and jmap!)
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 10 Jun 2014 06:22:25 +0000 (15:52 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 10 Jun 2014 06:22:25 +0000 (15:52 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/lbalance/tools/Makefile
ccan/lbalance/tools/lbalance.c

index fce690c2c3077d42887649ee9cfa9a05054a5196..de7223e4151539fee48bacecf2ee419ef83caa79 100644 (file)
@@ -1,13 +1,18 @@
 #! /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 $@ $<
index 228c947fe7d921de7a7d4663e669a0f771051879..e783adfa124aa1559ef9f4dfe27a98065ef77c34 100644 (file)
@@ -1,21 +1,27 @@
 #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 timeval start = time_now();
+       struct timeabs 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 timeval start = time_now();
+       struct timeabs 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++;