From e7c0c0153d013843852a1444245ff64a075ccbc2 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 10 Sep 2007 19:47:03 +0200 Subject: [PATCH] Implemented ThreadChunk limit. --- lib/sorter/array.c | 21 +++++++++++++++++---- lib/sorter/common.h | 3 ++- lib/sorter/config.c | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/sorter/array.c b/lib/sorter/array.c index 26b4a1b5..d724f841 100644 --- a/lib/sorter/array.c +++ b/lib/sorter/array.c @@ -214,7 +214,8 @@ rs_finish(struct worker_thread *thr UNUSED, struct work *ww) { struct rs_work *w = (struct rs_work *) ww; - DBG("Thread %d: Finishing %d items, shift=%d", thr->id, w->num_elts, w->shift); + if (thr) + DBG("Thread %d: Finishing %d items, shift=%d", thr->id, w->num_elts, w->shift); if (w->shift < ASORT_MIN_SHIFT || w->num_elts < sorter_radix_threshold) { w->ctx->quicksort(w->in, w->num_elts); @@ -223,7 +224,8 @@ rs_finish(struct worker_thread *thr UNUSED, struct work *ww) } else asort_radix(w->ctx, w->in, w->out, w->num_elts, w->shift, w->swap_output); - DBG("Thread %d: Finishing done", thr->id); + if (thr) + DBG("Thread %d: Finishing done", thr->id); } static void @@ -298,6 +300,8 @@ rs_radix(struct asort_context *ctx, void *array, void *buffer, uns num_elts, uns for (uns i=0; ielt_size < sorter_thread_threshold) { struct rs_work *w = ep_alloc(ctx->eltpool); @@ -309,8 +313,17 @@ rs_radix(struct asort_context *ctx, void *array, void *buffer, uns num_elts, uns w->num_elts = n; w->shift = shift; w->swap_output = !swapped_output; - clist_add_tail(&ctx->rs_bits, &w->w.n); - DBG("Scheduling block %d+%d", pos, n); + if (n * ctx->elt_size < sorter_thread_chunk) + { + DBG("Sorting block %d+%d inline", pos, n); + rs_finish(NULL, &w->w); + ep_free(ctx->eltpool, w); + } + else + { + clist_add_tail(&ctx->rs_bits, &w->w.n); + DBG("Scheduling block %d+%d", pos, n); + } } else rs_radix(ctx, buffer, array, n, shift, !swapped_output); diff --git a/lib/sorter/common.h b/lib/sorter/common.h index f67f9bf9..cd8053e1 100644 --- a/lib/sorter/common.h +++ b/lib/sorter/common.h @@ -16,7 +16,8 @@ extern uns sorter_trace, sorter_stream_bufsize; extern uns sorter_debug, sorter_min_radix_bits, sorter_max_radix_bits; extern uns sorter_min_multiway_bits, sorter_max_multiway_bits; -extern uns sorter_threads, sorter_thread_threshold, sorter_radix_threshold; +extern uns sorter_threads, sorter_thread_threshold, sorter_thread_chunk; +extern uns sorter_radix_threshold; extern u64 sorter_bufsize; extern struct fb_params sorter_fb_params; diff --git a/lib/sorter/config.c b/lib/sorter/config.c index 75d8fa49..cc4bb3e6 100644 --- a/lib/sorter/config.c +++ b/lib/sorter/config.c @@ -21,7 +21,8 @@ uns sorter_max_radix_bits; uns sorter_min_multiway_bits; uns sorter_max_multiway_bits; uns sorter_threads; -uns sorter_thread_threshold; +uns sorter_thread_threshold = 1048576; +uns sorter_thread_chunk = 4096; uns sorter_radix_threshold = 4096; struct fb_params sorter_fb_params; @@ -38,6 +39,7 @@ static struct cf_section sorter_config = { CF_UNS("MaxMultiwayBits", &sorter_max_multiway_bits), CF_UNS("Threads", &sorter_threads), CF_UNS("ThreadThreshold", &sorter_thread_threshold), + CF_UNS("ThreadChunk", &sorter_thread_chunk), CF_UNS("RadixThreshold", &sorter_radix_threshold), CF_END } -- 2.39.2