This commit is contained in:
Gregory Burd 2024-05-20 20:28:45 -04:00
parent 5afb6c6f0d
commit 4dbb7cec61

View file

@ -552,7 +552,7 @@ __sm_count(void *handle)
/* midl ------------------------------------------------------------------ */ /* midl ------------------------------------------------------------------ */
static bool __midl_validate(void *handle); //static bool __midl_validate(void *handle);
static void * static void *
__midl_alloc(size_t capacity) __midl_alloc(size_t capacity)
@ -572,7 +572,7 @@ __midl_free(void *handle)
static pgno_t static pgno_t
__midl_set(void **handle, pgno_t pg) __midl_set(void **handle, pgno_t pg)
{ {
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
MDB_IDL *_list = (MDB_IDL *)handle, list = *_list; MDB_IDL *_list = (MDB_IDL *)handle, list = *_list;
if (list[0] + 1 == list[-1]) { if (list[0] + 1 == list[-1]) {
assert(mdb_midl_need(_list, list[-1] + 1) == 0); assert(mdb_midl_need(_list, list[-1] + 1) == 0);
@ -581,7 +581,7 @@ __midl_set(void **handle, pgno_t pg)
mdb_midl_xappend(list, pg); mdb_midl_xappend(list, pg);
mdb_midl_sort(list); mdb_midl_sort(list);
// assert(mdb_midl_insert(list, pg) == 0); // assert(mdb_midl_insert(list, pg) == 0);
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
return pg; return pg;
} }
@ -596,7 +596,7 @@ __midl_is_set(void *handle, pgno_t pg)
static pgno_t static pgno_t
__midl_clear(void **handle, pgno_t pg) __midl_clear(void **handle, pgno_t pg)
{ {
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
MDB_IDL list = *(MDB_IDL *)handle; MDB_IDL list = *(MDB_IDL *)handle;
unsigned len = list[0]; unsigned len = list[0];
list[0] = len -= 1; list[0] = len -= 1;
@ -606,7 +606,7 @@ __midl_clear(void **handle, pgno_t pg)
for (unsigned j = len + 1; j <= list[-1]; j++) for (unsigned j = len + 1; j <= list[-1]; j++)
list[j] = 0; list[j] = 0;
#endif #endif
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
return pg; return pg;
} }
@ -642,7 +642,7 @@ search_done:;
static bool static bool
__midl_take_span(void **handle, pgno_t pg, unsigned len) __midl_take_span(void **handle, pgno_t pg, unsigned len)
{ {
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
MDB_IDL list = *(MDB_IDL *)handle; MDB_IDL list = *(MDB_IDL *)handle;
int i = list[list[0]] == pg ? list[0] : mdb_midl_search(list, pg); int i = list[list[0]] == pg ? list[0] : mdb_midl_search(list, pg);
unsigned j, num = len; unsigned j, num = len;
@ -657,14 +657,14 @@ __midl_take_span(void **handle, pgno_t pg, unsigned len)
for (j = mop_len + 1; j <= mop[-1]; j++) for (j = mop_len + 1; j <= mop[-1]; j++)
mop[j] = 0; mop[j] = 0;
#endif #endif
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
return true; return true;
} }
static bool static bool
__midl_release_span(void **handle, pgno_t pg, unsigned len) __midl_release_span(void **handle, pgno_t pg, unsigned len)
{ {
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
MDB_IDL *_list = (MDB_IDL *)handle, list = *_list; MDB_IDL *_list = (MDB_IDL *)handle, list = *_list;
if (list[0] + len >= list[-1]) { if (list[0] + len >= list[-1]) {
assert(mdb_midl_need(_list, list[-1] + len) == 0); assert(mdb_midl_need(_list, list[-1] + len) == 0);
@ -675,7 +675,7 @@ __midl_release_span(void **handle, pgno_t pg, unsigned len)
// assert(mdb_midl_insert(list, i) == 0); // assert(mdb_midl_insert(list, i) == 0);
} }
mdb_midl_sort(list); mdb_midl_sort(list);
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
return true; return true;
} }
@ -689,7 +689,7 @@ __midl_is_span(void *handle, pgno_t pg, unsigned len)
return false; return false;
if (len == 1) if (len == 1)
return true; return true;
if (list[len] + 1 != list[len - 1]) if (list[idx] + len - 1 != list[idx - len + 1])
return false; return false;
return true; return true;
} }
@ -710,7 +710,7 @@ __midl_is_empty(void *handle, pgno_t pg, unsigned len)
static bool static bool
__midl_merge(void **handle, void *other_handle) __midl_merge(void **handle, void *other_handle)
{ {
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
MDB_IDL *_list = (MDB_IDL *)handle, list = *_list, other = (MDB_IDL)other_handle; MDB_IDL *_list = (MDB_IDL *)handle, list = *_list, other = (MDB_IDL)other_handle;
if (list[0] + other[0] >= list[-1]) { if (list[0] + other[0] >= list[-1]) {
assert(mdb_midl_need(_list, list[-1] + other[0]) == 0); assert(mdb_midl_need(_list, list[-1] + other[0]) == 0);
@ -718,7 +718,7 @@ __midl_merge(void **handle, void *other_handle)
} }
mdb_midl_xmerge(list, other_handle); mdb_midl_xmerge(list, other_handle);
mdb_midl_sort(*_list); mdb_midl_sort(*_list);
assert(__midl_validate(*handle)); // assert(__midl_validate(*handle));
return true; return true;
} }
@ -907,7 +907,7 @@ elapsed(struct timespec *s, struct timespec *e)
static pgno_t static pgno_t
__stats_set(td_histogram_t *stats, void *fn, void **handle, pgno_t pg) __stats_set(td_histogram_t *stats, void *fn, void **handle, pgno_t pg)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
pgno_t retval = ((pgno_t(*)(void **, pgno_t))fn)(handle, pg); pgno_t retval = ((pgno_t(*)(void **, pgno_t))fn)(handle, pg);
@ -921,7 +921,7 @@ __stats_set(td_histogram_t *stats, void *fn, void **handle, pgno_t pg)
static bool static bool
__stats_is_set(td_histogram_t *stats, void *fn, void *handle, pgno_t pg) __stats_is_set(td_histogram_t *stats, void *fn, void *handle, pgno_t pg)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void *, pgno_t))fn)(handle, pg); bool retval = ((bool (*)(void *, pgno_t))fn)(handle, pg);
@ -935,7 +935,7 @@ __stats_is_set(td_histogram_t *stats, void *fn, void *handle, pgno_t pg)
static pgno_t static pgno_t
__stats_clear(td_histogram_t *stats, void *fn, void **handle, pgno_t pg) __stats_clear(td_histogram_t *stats, void *fn, void **handle, pgno_t pg)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
pgno_t retval = ((pgno_t(*)(void **, pgno_t))fn)(handle, pg); pgno_t retval = ((pgno_t(*)(void **, pgno_t))fn)(handle, pg);
@ -949,7 +949,7 @@ __stats_clear(td_histogram_t *stats, void *fn, void **handle, pgno_t pg)
static pgno_t static pgno_t
__stats_find_span(td_histogram_t *stats, void *fn, void *handle, unsigned len) __stats_find_span(td_histogram_t *stats, void *fn, void *handle, unsigned len)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
pgno_t retval = ((pgno_t(*)(void *, unsigned))fn)(handle, len); pgno_t retval = ((pgno_t(*)(void *, unsigned))fn)(handle, len);
@ -963,7 +963,7 @@ __stats_find_span(td_histogram_t *stats, void *fn, void *handle, unsigned len)
static bool static bool
__stats_take_span(td_histogram_t *stats, void *fn, void **handle, pgno_t pg, unsigned len) __stats_take_span(td_histogram_t *stats, void *fn, void **handle, pgno_t pg, unsigned len)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len); bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len);
@ -977,7 +977,7 @@ __stats_take_span(td_histogram_t *stats, void *fn, void **handle, pgno_t pg, uns
static bool static bool
__stats_release_span(td_histogram_t *stats, void *fn, void **handle, pgno_t pg, unsigned len) __stats_release_span(td_histogram_t *stats, void *fn, void **handle, pgno_t pg, unsigned len)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len); bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len);
@ -991,7 +991,7 @@ __stats_release_span(td_histogram_t *stats, void *fn, void **handle, pgno_t pg,
static bool static bool
__stats_is_span(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsigned len) __stats_is_span(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsigned len)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len); bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len);
@ -1005,7 +1005,7 @@ __stats_is_span(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsign
static bool static bool
__stats_is_empty(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsigned len) __stats_is_empty(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsigned len)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len); bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len);
@ -1019,7 +1019,7 @@ __stats_is_empty(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsig
static bool static bool
__stats_is_first(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsigned len) __stats_is_first(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsigned len)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len); bool retval = ((bool (*)(void *, pgno_t, unsigned))fn)(handle, pg, len);
@ -1033,7 +1033,7 @@ __stats_is_first(td_histogram_t *stats, void *fn, void *handle, pgno_t pg, unsig
static bool static bool
__stats_merge(td_histogram_t *stats, void *fn, void **handle, void *other_handle) __stats_merge(td_histogram_t *stats, void *fn, void **handle, void *other_handle)
{ {
if (stats) { if (statistics && stats) {
struct timespec s, e; struct timespec s, e;
ts(&s); ts(&s);
bool retval = ((bool (*)(void **, void *))fn)(handle, other_handle); bool retval = ((bool (*)(void **, void *))fn)(handle, other_handle);
@ -1427,7 +1427,7 @@ main(int argc, char *argv[])
checkpoint(types); checkpoint(types);
left -= len; left -= len;
if (toss(15) > 13) { if (toss(7) == 6) {
do { do {
pgno_t pgno; pgno_t pgno;
size_t len, retries = amt / 10; size_t len, retries = amt / 10;
@ -1447,18 +1447,19 @@ main(int argc, char *argv[])
checkpoint(types); checkpoint(types);
foreach(types) foreach(types)
{ {
assert(invoke(type, is_span, pgno, len) == false); assert(invoke(type, is_empty, pgno, len));
assert(mutate(type, release_span, pgno, len)); assert(mutate(type, release_span, pgno, len));
assert(invoke(type, is_span, pgno, len) == true); assert(invoke(type, is_span, pgno, len));
cast(type, validate); cast(type, validate);
} }
checkpoint(types); checkpoint(types);
left += len; left += len;
} }
} while (amt - left > amt / 100); } while (toss(4) < 3);
} }
if (toss(10) > 8) { // if (toss(10) > 8) {
if (0) {
size_t new_offset, new_amt; size_t new_offset, new_amt;
pgno_t max; pgno_t max;
larger_please: larger_please:
@ -1491,6 +1492,7 @@ main(int argc, char *argv[])
containers[type].free(new_handles[type]); containers[type].free(new_handles[type]);
} }
} }
if (statistics) { if (statistics) {
const float dists[] = { 0.5, 0.75, 0.90, 0.99, 0.999 }; const float dists[] = { 0.5, 0.75, 0.90, 0.99, 0.999 };
fprintf(stats_fp, "%f,%zu,", nsts(), iteration); fprintf(stats_fp, "%f,%zu,", nsts(), iteration);