configure: add gettid() test
[fio.git] / t / genzipf.c
index 3f36ece86dbc6933cbc4d0469d9ce49277b47f63..4fc10ae72d8421e3407d0239d0f96c2257529d59 100644 (file)
@@ -3,8 +3,8 @@
  * what an access pattern would look like.
  *
  * For instance, the following would generate a zipf distribution
- * with theta 1.2, using 262144 (1 GB / 4096) values and split the reporting into
- * 20 buckets:
+ * with theta 1.2, using 262144 (1 GiB / 4096) values and split the
+ * reporting into 20 buckets:
  *
  *     ./t/fio-genzipf -t zipf -i 1.2 -g 1 -b 4096 -o 20
  *
@@ -14,7 +14,6 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
-#include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -49,7 +48,7 @@ enum {
 };
 
 static int dist_type = TYPE_ZIPF;
-static unsigned long gb_size = 500;
+static unsigned long gib_size = 500;
 static unsigned long block_size = 4096;
 static unsigned long output_nranges = DEF_NR_OUTPUT;
 static double percentage;
@@ -59,9 +58,14 @@ static int output_type = OUTPUT_NORMAL;
 #define DEF_ZIPF_VAL   1.2
 #define DEF_PARETO_VAL 0.3
 
+static unsigned int hashv(unsigned long long val)
+{
+       return jhash(&val, sizeof(val), 0) & (hash_size - 1);
+}
+
 static struct node *hash_lookup(unsigned long long val)
 {
-       struct flist_head *l = &hash[hash_long(val, hash_bits)];
+       struct flist_head *l = &hash[hashv(val)];
        struct flist_head *entry;
        struct node *n;
 
@@ -74,14 +78,13 @@ static struct node *hash_lookup(unsigned long long val)
        return NULL;
 }
 
-static struct node *hash_insert(struct node *n, unsigned long long val)
+static void hash_insert(struct node *n, unsigned long long val)
 {
-       struct flist_head *l = &hash[hash_long(val, hash_bits)];
+       struct flist_head *l = &hash[hashv(val)];
 
        n->val = val;
        n->hits = 1;
        flist_add_tail(&n->list, l);
-       return n;
 }
 
 static void usage(void)
@@ -127,7 +130,7 @@ static int parse_options(int argc, char *argv[])
                        }
                        break;
                case 'g':
-                       gb_size = strtoul(optarg, NULL, 10);
+                       gib_size = strtoul(optarg, NULL, 10);
                        break;
                case 'i':
                        dist_val = atof(optarg);
@@ -223,7 +226,7 @@ static void output_normal(struct node *nodes, unsigned long nnodes,
 
                if (percentage) {
                        if (total_vals >= blocks) {
-                               double cs = i * block_size / (1024 * 1024);
+                               double cs = (double) i * block_size / (1024.0 * 1024.0);
                                char p = 'M';
 
                                if (cs > 1024.0) {
@@ -287,9 +290,10 @@ int main(int argc, char *argv[])
                return 1;
 
        if (output_type != OUTPUT_CSV)
-               printf("Generating %s distribution with %f input and %lu GB size and %lu block_size.\n", dist_types[dist_type], dist_val, gb_size, block_size);
+               printf("Generating %s distribution with %f input and %lu GiB size and %lu block_size.\n",
+                      dist_types[dist_type], dist_val, gib_size, block_size);
 
-       nranges = gb_size * 1024 * 1024 * 1024ULL;
+       nranges = gib_size * 1024 * 1024 * 1024ULL;
        nranges /= block_size;
 
        if (dist_type == TYPE_ZIPF)
@@ -306,7 +310,7 @@ int main(int argc, char *argv[])
 
        hash_size = 1 << hash_bits;
 
-       hash = malloc(hash_size * sizeof(struct flist_head));
+       hash = calloc(hash_size, sizeof(struct flist_head));
        for (i = 0; i < hash_size; i++)
                INIT_FLIST_HEAD(&hash[i]);
 
@@ -329,7 +333,6 @@ int main(int argc, char *argv[])
                        hash_insert(&nodes[j], offset);
                        j++;
                }
-
        }
 
        qsort(nodes, j, sizeof(struct node), node_cmp);