diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/ChangeLog | 6 | ||||
-rw-r--r-- | runtime/alloc.c | 4 | ||||
-rw-r--r-- | runtime/map.c | 32 | ||||
-rw-r--r-- | runtime/pmap-gen.c | 87 |
4 files changed, 71 insertions, 58 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 1b271846..dff894b4 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,5 +1,9 @@ 2005-11-10 Martin Hunt <hunt@redhat.com> - + * map.c: Doc updates. + * pmap-gen.c: Change a bunch of generated function names to + avoid conflicts with maps with the same key and value types. + +2005-11-10 Martin Hunt <hunt@redhat.com> * map.c (_stp_cmp): Use _stp_div64(). 2005-11-09 Martin Hunt <hunt@redhat.com> diff --git a/runtime/alloc.c b/runtime/alloc.c index 8f34dea3..b647a532 100644 --- a/runtime/alloc.c +++ b/runtime/alloc.c @@ -115,7 +115,7 @@ void *_stp_valloc_cpu(size_t len, int cpu) struct _stp_percpu_data { void *ptrs[NR_CPUS]; - void *blkp; + void *data; }; #ifdef CONFIG_SMP @@ -187,7 +187,7 @@ void _stp_vfree_percpu(const void *ptr) #define _stp_valloc_percpu(type) \ ((type *)(__stp_valloc_percpu(sizeof(type), __alignof__(type)))) -#define _stp_percpu_dptr(ptr) (((struct _stp_percpu_data *)~(unsigned long)(ptr))->blkp) +#define _stp_percpu_dptr(ptr) (((struct _stp_percpu_data *)~(unsigned long)(ptr))->data) /** Frees memory allocated by _stp_alloc or _stp_calloc. * @param ptr pointer to memory to free diff --git a/runtime/map.c b/runtime/map.c index 76f8b87b..f962bfe5 100644 --- a/runtime/map.c +++ b/runtime/map.c @@ -795,7 +795,16 @@ static void _stp_add_agg(struct map_node *aptr, struct map_node *ptr) } } -void _stp_pmap_agg (MAP map) +/** Aggregate per-cpu maps. + * This function aggregates the per-cpu maps into an aggregated + * map. A pointer to that aggregated map is returned. + * + * A write lock must be held on the map during this function. + * + * @param map A pointer to a pmap. + * @returns a pointer to an aggregated map. + */ +MAP _stp_pmap_agg (MAP map) { int i, hash; MAP m, agg; @@ -810,7 +819,6 @@ void _stp_pmap_agg (MAP map) _stp_map_clear (agg); for_each_cpu(i) { - dbug("cpu %d\n", i); m = per_cpu_ptr (map, i); /* walk the hash chains. */ for (hash = 0; hash < HASH_TABLE_SIZE; hash++) { @@ -833,18 +841,20 @@ void _stp_pmap_agg (MAP map) } } } + return agg; } -#define AGG_PMAP(map) (_stp_percpu_dptr(map)) - -void _stp_pmap_printn(MAP map, int n, const char *fmt) -{ - MAP m = _stp_percpu_dptr(map); - _stp_pmap_agg(map); - _stp_map_printn (m, n, fmt); -} -#define _stp_pmap_print(map,fmt) _stp_pmap_printn(map,0,fmt) +/** Get the aggregation map for a pmap. + * This function returns a pointer to the aggregation map. + * It does not do any aggregation. + * @param map A pointer to a pmap. + * @returns a pointer to an aggregated map. + * @sa _stp_pmap_agg() + */ +#define _stp_pmap_get_agg(map) (_stp_percpu_dptr(map)) +#define _stp_pmap_printn(map,n,fmt) _stp_map_printn (_stp_pmap_agg(map), n, fmt) +#define _stp_pmap_print(map,fmt) _stp_map_printn(_stp_pmap_agg(map),0,fmt) static void _new_map_clear_node (struct map_node *m) { diff --git a/runtime/pmap-gen.c b/runtime/pmap-gen.c index cb203a88..0d05fedc 100644 --- a/runtime/pmap-gen.c +++ b/runtime/pmap-gen.c @@ -1,5 +1,5 @@ /* -*- linux-c -*- - * map API generator + * pmap API generator * Copyright (C) 2005 Red Hat Inc. * * This file is part of systemtap, and is free software. You can @@ -8,10 +8,10 @@ * later version. */ -/** @file map-gen.c - * @brief Map function generator +/** @file pmap-gen.c + * @brief Pmap function generator * This file is a template designed to be included as many times as - * needed to generate the necessary map functions. + * needed to generate the necessary pmap functions. */ #define JOIN(x,y) JOINx(x,y) @@ -191,7 +191,7 @@ /* */ -struct KEYSYM(map_node) { +struct KEYSYM(pmap_node) { /* list of other nodes in the map */ struct list_head lnode; /* list of nodes with the same hash value */ @@ -225,10 +225,10 @@ struct KEYSYM(map_node) { }) /* returns 1 on match, 0 otherwise */ -static int KEYSYM(map_key_cmp) (struct map_node *m1, struct map_node *m2) +static int KEYSYM(pmap_key_cmp) (struct map_node *m1, struct map_node *m2) { - struct KEYSYM(map_node) *n1 = (struct KEYSYM(map_node) *)m1; - struct KEYSYM(map_node) *n2 = (struct KEYSYM(map_node) *)m2; + struct KEYSYM(pmap_node) *n1 = (struct KEYSYM(pmap_node) *)m1; + struct KEYSYM(pmap_node) *n2 = (struct KEYSYM(pmap_node) *)m2; if (KEY1_EQ_P(n1->key1, n2->key1) #if KEY_ARITY > 1 && KEY2_EQ_P(n1->key2, n2->key2) @@ -249,11 +249,10 @@ static int KEYSYM(map_key_cmp) (struct map_node *m1, struct map_node *m2) } /* copy keys for m2 -> m1 */ -static void KEYSYM(map_copy_keys) (struct map_node *m1, struct map_node *m2) +static void KEYSYM(pmap_copy_keys) (struct map_node *m1, struct map_node *m2) { - struct KEYSYM(map_node) *dst = (struct KEYSYM(map_node) *)m1; - struct KEYSYM(map_node) *src = (struct KEYSYM(map_node) *)m2; - dbug("copy\n"); + struct KEYSYM(pmap_node) *dst = (struct KEYSYM(pmap_node) *)m1; + struct KEYSYM(pmap_node) *src = (struct KEYSYM(pmap_node) *)m2; #if KEY1_TYPE == STRING str_copy (dst->key1, src->key1); #else @@ -289,10 +288,10 @@ static void KEYSYM(map_copy_keys) (struct map_node *m1, struct map_node *m2) #endif } -static key_data KEYSYM(map_get_key) (struct map_node *mn, int n, int *type) +static key_data KEYSYM(pmap_get_key) (struct map_node *mn, int n, int *type) { key_data ptr; - struct KEYSYM(map_node) *m = (struct KEYSYM(map_node) *)mn; + struct KEYSYM(pmap_node) *m = (struct KEYSYM(pmap_node) *)mn; if (n > KEY_ARITY || n < 1) { if (type) @@ -344,7 +343,7 @@ static key_data KEYSYM(map_get_key) (struct map_node *mn, int n, int *type) } -static unsigned int KEYSYM(keycheck) (ALLKEYSD(key)) +static unsigned int KEYSYM(pkeycheck) (ALLKEYSD(key)) { #if KEY1_TYPE == STRING if (key1 == NULL) @@ -381,7 +380,7 @@ static unsigned int KEYSYM(keycheck) (ALLKEYSD(key)) return 1; } -static unsigned int KEYSYM(hash) (ALLKEYSD(key)) +static unsigned int KEYSYM(phash) (ALLKEYSD(key)) { unsigned int hash = KEY1_HASH(key1); #if KEY_ARITY > 1 @@ -403,20 +402,20 @@ static unsigned int KEYSYM(hash) (ALLKEYSD(key)) #if VALUE_TYPE == INT64 || VALUE_TYPE == STRING MAP KEYSYM(_stp_pmap_new) (unsigned max_entries) { - MAP map = _stp_pmap_new (max_entries, VALUE_TYPE, sizeof(struct KEYSYM(map_node)), 0); + MAP map = _stp_pmap_new (max_entries, VALUE_TYPE, sizeof(struct KEYSYM(pmap_node)), 0); if (map) { int i; MAP m; for_each_cpu(i) { m = per_cpu_ptr (map, i); - m->get_key = KEYSYM(map_get_key); - m->copy = KEYSYM(map_copy_keys); - m->cmp = KEYSYM(map_key_cmp); + m->get_key = KEYSYM(pmap_get_key); + m->copy = KEYSYM(pmap_copy_keys); + m->cmp = KEYSYM(pmap_key_cmp); } m = _stp_percpu_dptr(map); - m->get_key = KEYSYM(map_get_key); - m->copy = KEYSYM(map_copy_keys); - m->cmp = KEYSYM(map_key_cmp); + m->get_key = KEYSYM(pmap_get_key); + m->copy = KEYSYM(pmap_copy_keys); + m->cmp = KEYSYM(pmap_key_cmp); } return map; } @@ -446,14 +445,14 @@ MAP KEYSYM(_stp_pmap_new) (unsigned max_entries, int htype, ...) switch (htype) { case HIST_NONE: - map = _stp_pmap_new (max_entries, STAT, sizeof(struct KEYSYM(map_node)), 0); + map = _stp_pmap_new (max_entries, STAT, sizeof(struct KEYSYM(pmap_node)), 0); break; case HIST_LOG: - map = _stp_pmap_new_hstat_log (max_entries, sizeof(struct KEYSYM(map_node)), + map = _stp_pmap_new_hstat_log (max_entries, sizeof(struct KEYSYM(pmap_node)), buckets); break; case HIST_LINEAR: - map = _stp_pmap_new_hstat_linear (max_entries, sizeof(struct KEYSYM(map_node)), + map = _stp_pmap_new_hstat_linear (max_entries, sizeof(struct KEYSYM(pmap_node)), start, stop, interval); break; default: @@ -466,14 +465,14 @@ MAP KEYSYM(_stp_pmap_new) (unsigned max_entries, int htype, ...) MAP m; for_each_cpu(i) { m = per_cpu_ptr (map, i); - m->get_key = KEYSYM(map_get_key); - m->copy = KEYSYM(map_copy_keys); - m->cmp = KEYSYM(map_key_cmp); + m->get_key = KEYSYM(pmap_get_key); + m->copy = KEYSYM(pmap_copy_keys); + m->cmp = KEYSYM(pmap_key_cmp); } m = _stp_percpu_dptr(map); - m->get_key = KEYSYM(map_get_key); - m->copy = KEYSYM(map_copy_keys); - m->cmp = KEYSYM(map_key_cmp); + m->get_key = KEYSYM(pmap_get_key); + m->copy = KEYSYM(pmap_copy_keys); + m->cmp = KEYSYM(pmap_key_cmp); } return map; } @@ -484,19 +483,19 @@ int KEYSYM(__stp_pmap_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add) unsigned int hv; struct hlist_head *head; struct hlist_node *e; - struct KEYSYM(map_node) *n; + struct KEYSYM(pmap_node) *n; if (map == NULL) return -2; - if (KEYSYM(keycheck) (ALLKEYS(key)) == 0) + if (KEYSYM(pkeycheck) (ALLKEYS(key)) == 0) return -2; - hv = KEYSYM(hash) (ALLKEYS(key)); + hv = KEYSYM(phash) (ALLKEYS(key)); head = &map->hashes[hv]; hlist_for_each(e, head) { - n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head)); + n = (struct KEYSYM(pmap_node) *)((long)e - sizeof(struct list_head)); dbug("map_node =%lx\n", (long)n); if (KEY1_EQ_P(n->key1, key1) #if KEY_ARITY > 1 @@ -526,7 +525,7 @@ int KEYSYM(__stp_pmap_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add) if VAL_IS_ZERO(val,add) return 0; - n = (struct KEYSYM(map_node)*)_new_map_create (map, head); + n = (struct KEYSYM(pmap_node)*)_new_map_create (map, head); if (n == NULL) return -1; KEYCPY(n); @@ -555,7 +554,7 @@ VALTYPE KEYSYM(_stp_pmap_get_cpu) (MAP pmap, ALLKEYSD(key)) unsigned int hv; struct hlist_head *head; struct hlist_node *e; - struct KEYSYM(map_node) *n; + struct KEYSYM(pmap_node) *n; VALTYPE res; MAP map; @@ -564,11 +563,11 @@ VALTYPE KEYSYM(_stp_pmap_get_cpu) (MAP pmap, ALLKEYSD(key)) map = per_cpu_ptr (pmap, get_cpu()); - hv = KEYSYM(hash) (ALLKEYS(key)); + hv = KEYSYM(phash) (ALLKEYS(key)); head = &map->hashes[hv]; hlist_for_each(e, head) { - n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head)); + n = (struct KEYSYM(pmap_node) *)((long)e - sizeof(struct list_head)); dbug("map_node =%lx\n", (long)n); if (KEY1_EQ_P(n->key1, key1) #if KEY_ARITY > 1 @@ -604,20 +603,20 @@ VALTYPE KEYSYM(_stp_pmap_get) (MAP pmap, ALLKEYSD(key)) unsigned int hv; struct hlist_head *head; struct hlist_node *e; - struct KEYSYM(map_node) *n, *anode = NULL; + struct KEYSYM(pmap_node) *n, *anode = NULL; VALTYPE res; MAP map, agg; if (pmap == NULL) return (VALTYPE)0; - hv = KEYSYM(hash) (ALLKEYS(key)); + hv = KEYSYM(phash) (ALLKEYS(key)); /* first look it up in the aggregation map */ agg = _stp_percpu_dptr(pmap); ahead = &agg->hashes[hv]; hlist_for_each(e, ahead) { - n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head)); + n = (struct KEYSYM(pmap_node) *)((long)e - sizeof(struct list_head)); dbug("map_node =%lx\n", (long)n); if (KEY1_EQ_P(n->key1, key1) #if KEY_ARITY > 1 @@ -644,7 +643,7 @@ VALTYPE KEYSYM(_stp_pmap_get) (MAP pmap, ALLKEYSD(key)) map = per_cpu_ptr (pmap, get_cpu()); head = &map->hashes[hv]; hlist_for_each(e, head) { - n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head)); + n = (struct KEYSYM(pmap_node) *)((long)e - sizeof(struct list_head)); dbug("map_node =%lx\n", (long)n); if (KEY1_EQ_P(n->key1, key1) #if KEY_ARITY > 1 |