VirtualBox

Changeset 1862 in kBuild for trunk/src/kmk


Ignore:
Timestamp:
Oct 14, 2008 1:04:03 AM (16 years ago)
Author:
bird
Message:

kmk: some preliminary allocation caching. seems dep, variables, variable sets and files would be good candidates for generic alloc caches.

Location:
trunk/src/kmk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/incdep.c

    r1854 r1862  
    150150  const char *err_msg;
    151151
     152  struct dep *dep_start;            /* start of the current dep block. */
     153  struct dep *dep_end;              /* end of the current dep block. */
     154
    152155  struct incdep_variable_in_set *recorded_variables_in_set_head;
    153156  struct incdep_variable_in_set *recorded_variables_in_set_tail;
     
    233236   For working around multithreaded performance problems found on Darwin,
    234237   Linux (glibc), and possibly other systems. */
    235 static void *incdep_xmalloc (struct incdep *cur, size_t size)
     238static void *
     239incdep_xmalloc (struct incdep *cur, size_t size)
    236240{
    237241  void *ptr;
     
    255259
    256260/* memset(malloc(sz),'\0',sz) wrapper. */
    257 static void *incdep_xcalloc (struct incdep *cur, size_t size)
     261static void *
     262incdep_xcalloc (struct incdep *cur, size_t size)
    258263{
    259264  void *ptr;
     
    275280
    276281/* free wrapper */
    277 static void incdep_xfree (struct incdep *cur, void *ptr)
     282static void
     283incdep_xfree (struct incdep *cur, void *ptr)
    278284{
    279285  /* free() *must* work for the allocation hacks above because
     
    283289}
    284290
     291/* alloc a dep structure. These are allocated in bunches to save time. */
     292struct dep *
     293incdep_alloc_dep (struct incdep *cur)
     294{
     295  if (cur->dep_start != cur->dep_end)
     296    return cur->dep_start++;
     297
     298  cur->dep_start = (struct dep *)incdep_xcalloc (cur, sizeof(struct dep) * 256);
     299  cur->dep_end = cur->dep_start + 256;
     300  return cur->dep_start++;
     301}
    285302
    286303
     
    457474incdep_worker (void)
    458475{
     476#ifdef PARSE_IN_WORKER
     477  struct dep *dep_start = NULL;
     478  struct dep *dep_end = NULL;
     479#endif
     480
    459481  incdep_lock ();
    460482
     
    480502      cur->is_worker = 1;
    481503      incdep_read_file (cur, NILF);
     504
    482505#ifdef PARSE_IN_WORKER
     506      cur->dep_start = dep_start;
     507      cur->dep_end = dep_end;
     508
    483509      eval_include_dep_file (cur, NILF);
    484 #endif
     510
     511      dep_start = cur->dep_start;
     512      cur->dep_start = NULL;
     513      dep_end = cur->dep_end;
     514      cur->dep_end = NULL;
     515#endif
     516
    485517      cur->is_worker = 0;
    486518      incdep_lock ();
     
    13371369
    13381370                  /* add it to the list. */
    1339                   *nextdep = dep = incdep_xcalloc (curdep, sizeof (*dep));
     1371                  *nextdep = dep = incdep_alloc_dep (curdep);
    13401372                  dep->name = incdep_record_strcache (curdep, cur, endp - cur);
    13411373                  dep->includedep = 1;
     
    14411473       cur->err_line_no = 0;
    14421474       cur->err_msg = NULL;
     1475       cur->dep_start = NULL;
     1476       cur->dep_end = NULL;
    14431477       cur->recorded_variables_in_set_head = NULL;
    14441478       cur->recorded_variables_in_set_tail = NULL;
  • trunk/src/kmk/misc.c

    r1859 r1862  
    712712/* Cache free struct dep to save time in free during snap_deps.
    713713   free is esp. slow on darwin for some reason. */
    714 static struct dep *free_deps;
     714static struct dep *free_deps = NULL;
     715static struct dep *free_deps_start = NULL;
     716static struct dep *free_deps_end = NULL;
    715717
    716718static struct dep *
    717719alloc_dep_int (void)
    718720{
    719     struct dep *d = free_deps;
    720     if (d)
    721       free_deps = d->next;
    722     else
    723       d = xmalloc (sizeof (struct dep));
    724     return d;
     721  struct dep *d = free_deps;
     722  if (MY_PREDICT_TRUE(d))
     723    free_deps = d->next;
     724  else if (free_deps_start != free_deps_end)
     725    d = free_deps_start++;
     726  else
     727    {
     728      /* allocate another chunk block. */
     729      free_deps_start = xmalloc (sizeof (struct dep) * 256);
     730      free_deps_end = free_deps_start + 256;
     731      d = free_deps_start++;
     732    }
     733  return d;
    725734}
    726735
  • trunk/src/kmk/read.c

    r1861 r1862  
    30793079
    30803080      /* Add it to the front of the chain.  */
     3081#if !defined(KMK) || !defined(NO_ARCHIVES)
    30813082      new1 = xmalloc (size);
     3083#else
     3084      if (sizeof (struct dep) == size) /* use the cache */
     3085        new1 = (struct nameseq *)alloc_dep ();
     3086      else
     3087        new1 = xmalloc (size);
     3088#endif
    30823089      new1->name = name;
    30833090      new1->next = new;
     
    38893896#endif /* !NO_ARCHIVES */
    38903897                  {
     3898#if !defined(KMK) && !defined(NO_ARCHIVES)
    38913899                    struct nameseq *elt = xmalloc (size);
     3900#else
     3901                    struct nameseq *elt = size == sizeof(struct dep)
     3902                                        ? (void *)alloc_dep() : xmalloc (size);
     3903#endif
    38923904                    memset (elt, '\0', size);
    38933905                    elt->name = strcache_add (gl.gl_pathv[i]);
     
    39003912#endif
    39013913            globfree (&gl);
     3914#if !defined(KMK) && !defined(NO_ARCHIVES)
    39023915            free (old);
     3916#else
     3917            if (size == sizeof(struct dep))
     3918              free_dep ((struct dep *)old);
     3919            else
     3920              free (old);
     3921#endif
    39033922            break;
    39043923          }
  • trunk/src/kmk/remake.c

    r1857 r1862  
    240240
    241241              /* Free the storage.  */
     242#ifndef KMK
    242243              free (g);
     244#else
     245              free_dep (g);
     246#endif
    243247
    244248              g = lastgoal == 0 ? goals : lastgoal->next;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette