Changeset 1864 for trunk/src/kmk


Ignore:
Timestamp:
Oct 15, 2008, 3:00:57 AM (17 years ago)
Author:
bird
Message:

kmk: use alloc caches for variables, variable sets and varaible set lists.

Location:
trunk/src/kmk
Files:
7 edited

Legend:

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

    r1858 r1864  
    246246}
    247247
     248#ifdef CONFIG_WITH_ALLOC_CACHES
     249void
     250hash_free_items_cached (struct hash_table *ht, struct alloccache *cache)
     251{
     252  void **vec = ht->ht_vec;
     253  void **end = &vec[ht->ht_size];
     254  for (; vec < end; vec++)
     255    {
     256      void *item = *vec;
     257      if (!HASH_VACANT (item))
     258        alloccache_free (cache, item);
     259      *vec = 0;
     260    }
     261  ht->ht_fill = 0;
     262  ht->ht_empty_slots = ht->ht_size;
     263}
     264#endif /* CONFIG_WITH_ALLOC_CACHES */
     265
    248266void
    249267hash_delete_items (struct hash_table *ht)
     
    275293}
    276294
     295#ifdef CONFIG_WITH_ALLOC_CACHES
     296void
     297hash_free_cached (struct hash_table *ht, int free_items, struct alloccache *cache)
     298{
     299  if (free_items)
     300    hash_free_items_cached (ht, cache);
     301  else
     302    {
     303      ht->ht_fill = 0;
     304      ht->ht_empty_slots = ht->ht_size;
     305    }
     306  free (ht->ht_vec);
     307  ht->ht_vec = 0;
     308  ht->ht_capacity = 0;
     309}
     310#endif /* CONFIG_WITH_ALLOC_CACHES */
     311
    277312void
    278313hash_map (struct hash_table *ht, hash_map_func_t map)
  • trunk/src/kmk/hash.h

    r1858 r1864  
    7575void hash_free_items __P((struct hash_table *ht));
    7676void hash_free __P((struct hash_table *ht, int free_items));
     77#ifdef CONFIG_WITH_ALLOC_CACHES
     78void hash_free_items_cached __P((struct hash_table *ht, struct alloccache *cache));
     79void hash_free_cached __P((struct hash_table *ht, int free_items, struct alloccache *cache));
     80#endif
    7781void hash_map __P((struct hash_table *ht, hash_map_func_t map));
    7882void hash_map_arg __P((struct hash_table *ht, hash_map_arg_func_t map, void *arg));
  • trunk/src/kmk/implicit.c

    r1863 r1864  
    265265#ifdef CONFIG_WITH_ALLOC_CACHES
    266266  if (!idep_cache.size)
    267     alloccache_init (&idep_cache, sizeof(struct idep), "dep", NULL, NULL);
     267    alloccache_init (&idep_cache, sizeof (struct idep), "idep", NULL, NULL);
    268268#endif
    269269
  • trunk/src/kmk/main.c

    r1863 r1864  
    648648struct alloccache nameseq_cache;
    649649struct alloccache variable_cache;
     650struct alloccache variable_set_cache;
     651struct alloccache variable_set_list_cache;
    650652
    651653static void
    652654initialize_global_alloc_caches (void)
    653655{
    654   alloccache_init (&dep_cache,      sizeof (struct dep),      "dep",      NULL, NULL);
    655   alloccache_init (&nameseq_cache,  sizeof (struct nameseq),  "nameseq",  NULL, NULL);
    656   alloccache_init (&variable_cache, sizeof (struct variable), "variable", NULL, NULL);
     656  alloccache_init (&dep_cache,               sizeof (struct dep),               "dep",               NULL, NULL);
     657  alloccache_init (&nameseq_cache,           sizeof (struct nameseq),           "nameseq",           NULL, NULL);
     658  alloccache_init (&variable_cache,          sizeof (struct variable),          "variable",          NULL, NULL);
     659  alloccache_init (&variable_set_cache,      sizeof (struct variable_set),      "variable_set",      NULL, NULL);
     660  alloccache_init (&variable_set_list_cache, sizeof (struct variable_set_list), "variable_set_list", NULL, NULL);
    657661}
    658662#endif
     
    29332937  if (!remote_description || *remote_description == '\0')
    29342938    printf (_("\nThis program is built for %s/%s/%s [" __DATE__ " " __TIME__ "]\n"),
    2935             KBUILD_HOST, KBUILD_HOST_ARCH, KBUILD_HOST_CPU, remote_description);
     2939            KBUILD_HOST, KBUILD_HOST_ARCH, KBUILD_HOST_CPU);
    29362940  else
    29372941    printf (_("\nThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"),
  • trunk/src/kmk/make.h

    r1863 r1864  
    575575extern struct alloccache nameseq_cache;
    576576extern struct alloccache variable_cache;
     577extern struct alloccache variable_set_cache;
     578extern struct alloccache variable_set_list_cache;
    577579
    578580#endif /* CONFIG_WITH_ALLOC_CACHES */
  • trunk/src/kmk/misc.c

    r1863 r1864  
    12861286alloccache_print (struct alloccache *cache)
    12871287{
    1288   printf (_("\n# Alloc Cache: %s item size: %u  alloc: %d  total: %u\n"),
     1288  printf (_("\n# Alloc Cache: %s\n"
     1289              "#  Items: size = %-3u  in-use = %-6d  total = %-6u\n"),
    12891290          cache->name, cache->size, (int)cache->alloc_count, cache->total_count);
    12901291}
     
    12951296{
    12961297  struct alloccache *cur;
     1298  puts ("");
    12971299  for (cur = alloccache_head; cur; cur = cur->next)
    12981300    alloccache_print (cur);
  • trunk/src/kmk/variable.c

    r1863 r1864  
    707707  /* Create a new variable definition and add it to the hash table.  */
    708708
     709#ifndef CONFIG_WITH_ALLOC_CACHES
    709710  v = xmalloc (sizeof (struct variable));
     711#else
     712  v = alloccache_alloc (&variable_cache);
     713#endif
    710714  v->name = savestring (name, length);
    711715  v->length = length;
     
    10161020  if (l == 0)
    10171021    {
     1022#ifndef CONFIG_WITH_ALLOC_CACHES
    10181023      l = (struct variable_set_list *)
    10191024        xmalloc (sizeof (struct variable_set_list));
    10201025      l->set = xmalloc (sizeof (struct variable_set));
     1026#else
     1027      l = (struct variable_set_list *)
     1028        alloccache_alloc (&variable_set_list_cache);
     1029      l->set = (struct variable_set *)
     1030        alloccache_alloc (&variable_set_cache);
     1031#endif
    10211032      hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS,
    10221033                 variable_hash_1, variable_hash_2, variable_hash_cmp);
     
    11211132  register struct variable_set *set;
    11221133
     1134#ifndef CONFIG_WITH_ALLOC_CACHES
    11231135  set = xmalloc (sizeof (struct variable_set));
     1136#else
     1137  set = (struct variable_set *) alloccache_alloc (&variable_set_cache);
     1138#endif
    11241139  hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
    11251140             variable_hash_1, variable_hash_2, variable_hash_cmp);
    11261141
     1142#ifndef CONFIG_WITH_ALLOC_CACHES
    11271143  setlist = (struct variable_set_list *)
    11281144    xmalloc (sizeof (struct variable_set_list));
     1145#else
     1146  setlist = (struct variable_set_list *)
     1147    alloccache_alloc (&variable_set_list_cache);
     1148#endif
    11291149  setlist->set = set;
    11301150  setlist->next = current_variable_set_list;
     
    11451165{
    11461166  hash_map (&list->set->table, free_variable_name_and_value);
     1167#ifndef CONFIG_WITH_ALLOC_CACHES
    11471168  hash_free (&list->set->table, 1);
    11481169  free (list->set);
    11491170  free (list);
     1171#else
     1172  hash_free_cached (&list->set->table, 1, &variable_cache);
     1173  alloccache_free (&variable_set_cache, list->set);
     1174  alloccache_free (&variable_set_list_cache, list);
     1175#endif
    11501176}
    11511177
     
    12031229
    12041230  /* Free the one we no longer need.  */
     1231#ifndef CONFIG_WITH_ALLOC_CACHES
    12051232  free (setlist);
    12061233  hash_map (&set->table, free_variable_name_and_value);
    12071234  hash_free (&set->table, 1);
    12081235  free (set);
     1236#else
     1237  alloccache_free (&variable_set_list_cache, setlist);
     1238  hash_map (&set->table, free_variable_name_and_value);
     1239  hash_free_cached (&set->table, 1, &variable_cache);
     1240  alloccache_free (&variable_set_cache, set);
     1241#endif
    12091242}
    12101243
Note: See TracChangeset for help on using the changeset viewer.