11 /* Multi-threaded test for calls to RegisterPair */
13 /* This configuration will test mostly inserting of new elements since
14 the number of repeats is 1. It should also do a lot of rehashing */
16 /* This test case may fail depending on the system configuration.
17 Check the value of /proc/sys/vm/max_map_count and fix by doing
18 Ex: sudo sh -c "echo 131060 > /proc/sys/vm/max_map_count" */
21 #define ELEMENTS_PER_MAP 100
26 #define KEY_TYPE_FIXED_SIZE 8
27 void *key_buffer
= malloc (17);
28 typedef char * name_string
;
29 name_string fake_names
[NUM_MAPS
];
31 /* This variable has to be put in rel.ro */
32 void * volatile maps
[NUM_MAPS
] VTV_PROTECTED_VAR
;
37 void * fake_vts
[NUM_MAPS
* ELEMENTS_PER_MAP
];
39 volatile int current_map
= -1;
40 volatile int threads_completed_it
= 0;
47 for (i
= 0; i
< NUM_MAPS
; ++i
)
49 fake_names
[i
] = (char *) malloc (9 * sizeof (char));
50 snprintf (fake_names
[i
], 9, "name%d", i
);
55 vtv_string_hash(const char *in
)
65 void * do_register_pairs(void *)
67 for (int k
= 0; k
< NUM_REPEATS
; k
++)
70 for (int i
= 0; i
< NUM_MAPS
; i
++)
72 uint32_t *value_ptr
= (uint32_t *) key_buffer
;
73 uint32_t len1
= strlen (fake_names
[i
]);
74 uint32_t hash_value
= vtv_string_hash (fake_names
[i
]);
75 void *temp_array
[ELEMENTS_PER_MAP
];
77 while (current_map
< (k
*NUM_MAPS
+ i
))
80 __VLTChangePermission(__VLTP_READ_WRITE
);
84 *value_ptr
= hash_value
;
86 memcpy ((char *) key_buffer
+ KEY_TYPE_FIXED_SIZE
, fake_names
[i
],
91 __VLTRegisterPairDebug ((void **) &maps
[i
], (char *) key_buffer
, 128,
92 &fake_vts
[curr_fake_vt
], "", "");
94 __VLTRegisterPair ((void **) &maps
[i
], (char *) key_buffer
, 128,
95 &fake_vts
[curr_fake_vt
]);
97 for (int j
= 0; j
< ELEMENTS_PER_MAP
; j
++)
99 temp_array
[j
] = &fake_vts
[curr_fake_vt
];
104 __VLTRegisterSetDebug ((void **) &maps
[i
], (char *) key_buffer
, 128, 100,
105 (void **) &temp_array
);
107 __VLTRegisterSet ((void **) &maps
[i
], (char *) key_buffer
, 128, 100,
108 (void **) &temp_array
);
110 __VLTChangePermission(__VLTP_READ_ONLY
);
114 old_value
= threads_completed_it
;
115 } while (!__sync_bool_compare_and_swap(&threads_completed_it
, old_value
, old_value
+ 1));
117 if (old_value
== (NUM_THREADS
- 1)) // Only one thread will do this.
119 threads_completed_it
= 0;
120 printf("%c%d", 13, current_map
+ 1);
133 pthread_t thread_ids
[NUM_THREADS
];
137 for (int t
= 0; t
< NUM_THREADS
; t
++ )
138 if (pthread_create(&thread_ids
[t
], NULL
, do_register_pairs
, NULL
) != 0)
140 printf("failed pthread_create\n");
144 current_map
= 0; // start the work on the other threads
146 for (int t
= 0; t
< NUM_THREADS
; t
++)
147 if (pthread_join(thread_ids
[t
], NULL
) != 0)
149 printf("failed pthread_join\n");