123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- #ifndef __TRACING_MAP_H
- #define __TRACING_MAP_H
- #define TRACING_MAP_BITS_DEFAULT 11
- #define TRACING_MAP_BITS_MAX 17
- #define TRACING_MAP_BITS_MIN 7
- #define TRACING_MAP_KEYS_MAX 2
- #define TRACING_MAP_VALS_MAX 3
- #define TRACING_MAP_FIELDS_MAX (TRACING_MAP_KEYS_MAX + \
- TRACING_MAP_VALS_MAX)
- #define TRACING_MAP_SORT_KEYS_MAX 2
- typedef int (*tracing_map_cmp_fn_t) (void *val_a, void *val_b);
- struct tracing_map_field {
- tracing_map_cmp_fn_t cmp_fn;
- union {
- atomic64_t sum;
- unsigned int offset;
- };
- };
- struct tracing_map_elt {
- struct tracing_map *map;
- struct tracing_map_field *fields;
- void *key;
- void *private_data;
- };
- struct tracing_map_entry {
- u32 key;
- struct tracing_map_elt *val;
- };
- struct tracing_map_sort_key {
- unsigned int field_idx;
- bool descending;
- };
- struct tracing_map_sort_entry {
- void *key;
- struct tracing_map_elt *elt;
- bool elt_copied;
- bool dup;
- };
- struct tracing_map_array {
- unsigned int entries_per_page;
- unsigned int entry_size_shift;
- unsigned int entry_shift;
- unsigned int entry_mask;
- unsigned int n_pages;
- void **pages;
- };
- #define TRACING_MAP_ARRAY_ELT(array, idx) \
- (array->pages[idx >> array->entry_shift] + \
- ((idx & array->entry_mask) << array->entry_size_shift))
- #define TRACING_MAP_ENTRY(array, idx) \
- ((struct tracing_map_entry *)TRACING_MAP_ARRAY_ELT(array, idx))
- #define TRACING_MAP_ELT(array, idx) \
- ((struct tracing_map_elt **)TRACING_MAP_ARRAY_ELT(array, idx))
- struct tracing_map {
- unsigned int key_size;
- unsigned int map_bits;
- unsigned int map_size;
- unsigned int max_elts;
- atomic_t next_elt;
- struct tracing_map_array *elts;
- struct tracing_map_array *map;
- const struct tracing_map_ops *ops;
- void *private_data;
- struct tracing_map_field fields[TRACING_MAP_FIELDS_MAX];
- unsigned int n_fields;
- int key_idx[TRACING_MAP_KEYS_MAX];
- unsigned int n_keys;
- struct tracing_map_sort_key sort_key;
- atomic64_t hits;
- atomic64_t drops;
- };
- struct tracing_map_ops {
- int (*elt_alloc)(struct tracing_map_elt *elt);
- void (*elt_copy)(struct tracing_map_elt *to,
- struct tracing_map_elt *from);
- void (*elt_free)(struct tracing_map_elt *elt);
- void (*elt_clear)(struct tracing_map_elt *elt);
- void (*elt_init)(struct tracing_map_elt *elt);
- };
- extern struct tracing_map *
- tracing_map_create(unsigned int map_bits,
- unsigned int key_size,
- const struct tracing_map_ops *ops,
- void *private_data);
- extern int tracing_map_init(struct tracing_map *map);
- extern int tracing_map_add_sum_field(struct tracing_map *map);
- extern int tracing_map_add_key_field(struct tracing_map *map,
- unsigned int offset,
- tracing_map_cmp_fn_t cmp_fn);
- extern void tracing_map_destroy(struct tracing_map *map);
- extern void tracing_map_clear(struct tracing_map *map);
- extern struct tracing_map_elt *
- tracing_map_insert(struct tracing_map *map, void *key);
- extern struct tracing_map_elt *
- tracing_map_lookup(struct tracing_map *map, void *key);
- extern tracing_map_cmp_fn_t tracing_map_cmp_num(int field_size,
- int field_is_signed);
- extern int tracing_map_cmp_string(void *val_a, void *val_b);
- extern int tracing_map_cmp_none(void *val_a, void *val_b);
- extern void tracing_map_update_sum(struct tracing_map_elt *elt,
- unsigned int i, u64 n);
- extern u64 tracing_map_read_sum(struct tracing_map_elt *elt, unsigned int i);
- extern void tracing_map_set_field_descr(struct tracing_map *map,
- unsigned int i,
- unsigned int key_offset,
- tracing_map_cmp_fn_t cmp_fn);
- extern int
- tracing_map_sort_entries(struct tracing_map *map,
- struct tracing_map_sort_key *sort_keys,
- unsigned int n_sort_keys,
- struct tracing_map_sort_entry ***sort_entries);
- extern void
- tracing_map_destroy_sort_entries(struct tracing_map_sort_entry **entries,
- unsigned int n_entries);
- #endif
|