X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=lib%2Fflist_sort.c;h=1c91cc457ca97ea091ad2b9287c3379b0e995e66;hb=4b919f7740f4875d73c0619a08d269d5c679e19f;hp=6c7c4c0310de016c65de02a541c1826d4f3f92f6;hpb=d29cd59a489ab6ad8121bff784e2a6bc3423c4c8;p=fio.git diff --git a/lib/flist_sort.c b/lib/flist_sort.c index 6c7c4c03..1c91cc45 100644 --- a/lib/flist_sort.c +++ b/lib/flist_sort.c @@ -1,14 +1,9 @@ +#include #include -#include - #include "../flist.h" -#include "../flist_sort.h" - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif +#include "../log.h" -#define MAX_LIST_LENGTH_BITS 65 +#define MAX_LIST_LENGTH_BITS 20 /* * Returns a list organized in an intermediate format suited @@ -74,7 +69,7 @@ static void merge_and_restore_back_links(void *priv, * element comparison is needed, so the client's cmp() * routine can invoke cond_resched() periodically. */ - cmp(priv, tail, tail); + (*cmp)(priv, tail->next, tail->next); tail->next->prev = tail; tail = tail->next; @@ -85,8 +80,8 @@ static void merge_and_restore_back_links(void *priv, } /** - * flist_sort - sort a list - * @priv: private data, opaque to flist_sort(), passed to @cmp + * list_sort - sort a list + * @priv: private data, opaque to list_sort(), passed to @cmp * @head: the list to sort * @cmp: the elements comparison function * @@ -125,8 +120,15 @@ void flist_sort(void *priv, struct flist_head *head, cur = merge(priv, cmp, part[lev], cur); part[lev] = NULL; } - if (lev > max_lev) - assert(lev < ARRAY_SIZE(part) - 1); + if (lev > max_lev) { + if (lev >= MAX_LIST_LENGTH_BITS) { + log_err("fio: list passed to" + " list_sort() too long for" + " efficiency\n"); + lev--; + } + max_lev = lev; + } part[lev] = cur; }