[systemd-devel] [systemd-commits] Makefile.am src/readahead

Lennart Poettering lennart at poettering.net
Tue Mar 26 10:38:44 PDT 2013


On Tue, 26.03.13 10:33, Auke-Jan Kok (auke at kemper.freedesktop.org) wrote:

Heyhey, wait.

> +        clock_gettime(CLOCK_MONOTONIC, &starttime);

Could you please turn this into an usec_t? We generally use usec_t for
everything, it's much simpler to use. We won't use the floating point
stuff then either. usec_t is actually a uint64_t so you can do normal
calculations with it, without involving floats or antyhing.

usec_t starttime;
starttime = now(CLOCK_MONOTONIC);



> +
>          /* If there's no pack file yet we lower the kernel readahead
>           * so that mincore() is accurate. If there is a pack file
>           * already we assume it is accurate enough so that kernel
> @@ -447,10 +459,21 @@ static int collect(const char *root) {
>                                          free(p);
>                                  else {
>                                          unsigned long ul;
> +                                        struct timespec ts;
> +                                        struct item *entry;
> +
> +                                        entry = new0(struct item, 1);

Needs an OOM check.

>  
>                                          ul = fd_first_block(m->fd);
>  
> -                                        if ((k = hashmap_put(files, p, SECTOR_TO_PTR(ul))) < 0) {
> +                                        clock_gettime(CLOCK_MONOTONIC, &ts);
> +
> +                                        entry->block = ul;
> +                                        entry->path = strdup(p);

Needs an OOM check.


> +                                        entry->bin = round((ts.tv_sec - starttime.tv_sec +
> +                                                     ((ts.tv_nsec -
> starttime.tv_nsec) / 1000000000.0)) / 2.0);

No floats please, unless we have to use them.

> +
> +                                        if ((k = hashmap_put(files, p, entry)) < 0) {
>                                                  log_warning("set_put() failed: %s", strerror(-k));
>                                                  free(p);
>                                          }
> @@ -518,8 +541,7 @@ done:
>  
>                  j = ordered;
>                  HASHMAP_FOREACH_KEY(q, p, files, i) {
> -                        j->path = p;
> -                        j->block = PTR_TO_SECTOR(q);
> +                        memcpy(j, q, sizeof(struct item));
>                          j++;
>                  }

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list