00001
00002
00003
00004
00005
00006 #include <linux/types.h>
00007
00008
00009 typedef struct {
00010 int64_t count;
00011 int64_t sum;
00012 int64_t min, max;
00013 int64_t histogram[BUCKETS];
00014 } stat;
00015
00016
00017 union key_data {
00018 long val;
00019 char *str;
00020 };
00021
00022
00023 enum keytype { NONE, LONG, STR } __attribute__ ((packed));
00024
00025 enum valtype { INT64, STAT, STRING, END };
00026
00027
00028
00029 struct map_node {
00030
00031 struct list_head lnode;
00032
00033 struct hlist_node hnode;
00034 union key_data key1;
00035 union key_data key2;
00036 enum keytype key1type;
00037 enum keytype key2type;
00038 };
00039
00040
00041 struct map_node_int64 {
00042 struct map_node n;
00043 int64_t val;
00044 };
00045
00046
00047 struct map_node_str {
00048 struct map_node n;
00049 char *str;
00050 };
00051
00052
00053 struct map_node_stat {
00054 struct map_node n;
00055 stat stats;
00056 };
00057
00058
00059
00060
00061 struct map_root {
00062
00063 enum valtype type;
00064
00065
00066 int maxnum;
00067
00068
00069 int num;
00070
00071
00072 int no_wrap;
00073
00074
00075 struct list_head head;
00076
00077
00078
00079 struct list_head pool;
00080
00081
00082 struct map_node *key;
00083
00084
00085
00086
00087 u_int8_t create;
00088 enum keytype c_key1type;
00089 enum keytype c_key2type;
00090 struct hlist_head *c_keyhead;
00091 union key_data c_key1;
00092 union key_data c_key2;
00093
00094
00095 struct hlist_head hashes[HASH_TABLE_SIZE];
00096
00097
00098 void *membuf;
00099 };
00100
00101
00102 typedef struct map_root *MAP;
00103
00104
00105 #define key1str(ptr) (ptr->n.key1.str)
00106
00107 #define key2str(ptr) (ptr->n.key2.str)
00108
00109 #define key1int(ptr) (ptr->n.key1.val)
00110
00111 #define key2int(ptr) (ptr->n.key2.val)
00112
00113
00114
00115
00116
00117 #define _stp_map_key2(map, key1, key2) \
00118 ({ \
00119 if (__builtin_types_compatible_p (typeof (key1), char[])) \
00120 if (__builtin_types_compatible_p (typeof (key2), char[])) \
00121 _stp_map_key_str_str (map, (char *)(key1), (char *)(key2)); \
00122 else \
00123 _stp_map_key_str_long (map, (char *)(key1), (long)(key2)); \
00124 else \
00125 if (__builtin_types_compatible_p (typeof (key2), char[])) \
00126 _stp_map_key_long_str (map, (long)(key1), (char *)(key2)); \
00127 else \
00128 _stp_map_key_long_long (map, (long)(key1), (long)(key2)); \
00129 })
00130
00131
00132
00133
00134
00135 #define _stp_map_key(map, key) \
00136 ({ \
00137 if (__builtin_types_compatible_p (typeof (key), char[])) \
00138 _stp_map_key_str (map, (char *)(key)); \
00139 else \
00140 _stp_map_key_long (map, (long)(key)); \
00141 })
00142
00143
00144
00145
00146
00147 #define _stp_map_set(map, val) \
00148 ({ \
00149 if (__builtin_types_compatible_p (typeof (val), char[])) \
00150 _stp_map_set_str (map, (char *)(val)); \
00151 else \
00152 _stp_map_set_int64 (map, (int64_t)(val)); \
00153 })
00154
00155
00156
00157
00158
00159 #define _stp_list_add(map, val) \
00160 ({ \
00161 if (__builtin_types_compatible_p (typeof (val), char[])) \
00162 _stp_list_add_str (map, (char *)(val)); \
00163 else \
00164 _stp_list_add_int64 (map, (int64_t)(val)); \
00165 })
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 #define foreach(map, ptr) \
00177 for (ptr = (typeof(ptr))_stp_map_start(map); ptr; \
00178 ptr = (typeof(ptr))_stp_map_iter (map, (struct map_node *)ptr))
00179