From 39b05f5172189ed6e81a6efb3410a9b4b08fbed8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 24 Aug 2012 12:46:10 +0100 Subject: [PATCH] tuning, sort out demand hints and disable extract_area seq mode --- ChangeLog | 2 ++ libvips/conversion/extract.c | 6 ++---- libvips/conversion/sequential.c | 4 ++-- libvips/conversion/tilecache.c | 27 +++++++++++++++++---------- libvips/foreign/jpeg2vips.c | 2 +- libvips/foreign/tiff2vips.c | 17 ++++------------- libvips/foreign/vipspng.c | 3 +-- libvips/resample/shrink.c | 2 +- 8 files changed, 30 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index db28a956..854ec995 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ - VipsSequential has an integrated cache and stalls out of order threads - add a line cache ... sizes up dynamically with request size - tilecache / linecache use a hash table not a linear list +- due to out of order stalling, extract_area is no longer a sequential + operation, sadly 20/7/12 started 7.30.0 - support "rs" mode in vips7 diff --git a/libvips/conversion/extract.c b/libvips/conversion/extract.c index d1b334e0..a14df039 100644 --- a/libvips/conversion/extract.c +++ b/libvips/conversion/extract.c @@ -170,8 +170,8 @@ vips_extract_area_build( VipsObject *object ) return( 0 ); } -/* xy range we sanity check on ... just to stop crazy numbers from 1/0 etc. - * causing g_assert() failures later. +/* xy range we sanity check on ... just to stop crazy numbers from divide by 0 + * etc. causing g_assert() failures later. */ #define RANGE (100000000) @@ -191,8 +191,6 @@ vips_extract_area_class_init( VipsExtractAreaClass *class ) vobject_class->description = _( "extract an area from an image" ); vobject_class->build = vips_extract_area_build; - operation_class->flags = VIPS_OPERATION_SEQUENTIAL; - VIPS_ARG_IMAGE( class, "input", 0, _( "Input" ), _( "Input image" ), diff --git a/libvips/conversion/sequential.c b/libvips/conversion/sequential.c index e308625e..ac76e7e6 100644 --- a/libvips/conversion/sequential.c +++ b/libvips/conversion/sequential.c @@ -102,7 +102,7 @@ vips_sequential_generate( VipsRegion *or, VipsRect *r = &or->valid; VipsRegion *ir = (VipsRegion *) seq; - VIPS_DEBUG_MSG( "thread %p request for %d lines from at line %d\n", + VIPS_DEBUG_MSG( "thread %p request for %d lines, start line %d\n", g_thread_self(), r->height, r->top ); if( sequential->trace ) @@ -184,7 +184,7 @@ vips_sequential_build( VipsObject *object ) if( vips_image_copy_fields( conversion->out, t ) ) return( -1 ); vips_demand_hint( conversion->out, - VIPS_DEMAND_STYLE_FATSTRIP, t, NULL ); + VIPS_DEMAND_STYLE_THINSTRIP, t, NULL ); if( vips_image_generate( conversion->out, vips_start_one, vips_sequential_generate, vips_stop_one, t, sequential ) ) diff --git a/libvips/conversion/tilecache.c b/libvips/conversion/tilecache.c index c5b742a5..5d2a19ac 100644 --- a/libvips/conversion/tilecache.c +++ b/libvips/conversion/tilecache.c @@ -48,8 +48,8 @@ */ /* - */ #define VIPS_DEBUG + */ #ifdef HAVE_CONFIG_H #include @@ -400,8 +400,6 @@ vips_tile_destroy( VipsTile *tile ) static void vips_block_cache_init( VipsBlockCache *cache ) { - printf( "vips_block_cache_init\n" ); - cache->tile_width = 128; cache->tile_height = 128; cache->max_tiles = 1000; @@ -645,6 +643,11 @@ vips_line_cache_build( VipsObject *object ) VipsBlockCache *block_cache = (VipsBlockCache *) object; VipsLineCache *cache = (VipsLineCache *) object; + int tile_width; + int tile_height; + int nlines; + int nstrips; + VIPS_DEBUG_MSG( "vips_line_cache_build\n" ); if( VIPS_OBJECT_CLASS( vips_line_cache_parent_class )-> @@ -656,6 +659,17 @@ vips_line_cache_build( VipsObject *object ) block_cache->tile_width = block_cache->in->Xsize; block_cache->tile_height = 1; + /* Enough lines for two complete buffers. + * + * This can go up with request size, see vips_line_cache_gen(). + */ + vips_get_tile_size( block_cache->in, + &tile_width, &tile_height, &nlines ); + block_cache->max_tiles = 2 * nlines; + + VIPS_DEBUG_MSG( "vips_line_cache_build: max_tiles = %d\n", + block_cache->max_tiles ); + if( vips_image_pio_input( block_cache->in ) ) return( -1 ); @@ -692,13 +706,6 @@ vips_line_cache_class_init( VipsLineCacheClass *class ) static void vips_line_cache_init( VipsLineCache *cache ) { - printf( "vips_line_cache_init\n" ); - - /* This adjust with request size, see vips_line_cache_gen(). - */ - ((VipsBlockCache *) cache)->max_tiles = 1000; - - ((VipsBlockCache *) cache)->strategy = VIPS_CACHE_SEQUENTIAL; } /** diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 31a0ffc2..fd681710 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -737,7 +737,7 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) interpretation, xres, yres ); - vips_demand_hint( out, VIPS_DEMAND_STYLE_SMALLTILE, NULL ); + vips_demand_hint( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL ); /* Interlaced jpegs need lots of memory to read, so our caller needs * to know. diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index d5b1c343..26860cc0 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -1097,12 +1097,6 @@ parse_header( ReadTiff *rtiff, VipsImage *out ) (VipsCallbackFn) vips_free, data_copy, data_length ); } - /* Offer the most restrictive style. This can be changed downstream if - * necessary. - */ - vips_demand_hint( out, - VIPS_DEMAND_STYLE_THINSTRIP, NULL ); - return( 0 ); } @@ -1270,14 +1264,12 @@ read_tilewise( ReadTiff *rtiff, VipsImage *out ) if( parse_header( rtiff, raw ) ) return( -1 ); - /* Process and save as VIPS. - * - * Even though this is a tiled reader, we hint thinstrip since with + /* Even though this is a tiled reader, we hint thinstrip since with * the cache we are quite happy serving that if anything downstream * would like it. */ - vips_demand_hint( raw, - VIPS_DEMAND_STYLE_THINSTRIP, NULL ); + vips_demand_hint( raw, VIPS_DEMAND_STYLE_THINSTRIP, NULL ); + if( vips_image_generate( raw, tiff_seq_start, tiff_fill_region, tiff_seq_stop, rtiff, NULL ) ) @@ -1392,8 +1384,7 @@ read_stripwise( ReadTiff *rtiff, VipsImage *out ) if( parse_header( rtiff, t[0] ) ) return( -1 ); - vips_demand_hint( t[0], - VIPS_DEMAND_STYLE_FATSTRIP, NULL ); + vips_demand_hint( t[0], VIPS_DEMAND_STYLE_THINSTRIP, NULL ); if( !tfget32( rtiff->tiff, TIFFTAG_ROWSPERSTRIP, &rtiff->rows_per_strip ) ) diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 205c8003..690e2f41 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -316,8 +316,7 @@ png2vips_header( Read *read, VipsImage *out ) /* We're always supposed to set dhint. */ - vips_demand_hint( out, - VIPS_DEMAND_STYLE_FATSTRIP, NULL ); + vips_demand_hint( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL ); /* Fetch the ICC profile. @name is useless, something like "icc" or * "ICC Profile" etc. Ignore it. diff --git a/libvips/resample/shrink.c b/libvips/resample/shrink.c index 747bdd6b..698e0d6e 100644 --- a/libvips/resample/shrink.c +++ b/libvips/resample/shrink.c @@ -332,7 +332,7 @@ vips_shrink_build( VipsObject *object ) * sequentiality. */ vips_demand_hint( resample->out, - VIPS_DEMAND_STYLE_THINSTRIP, resample->in, NULL ); + VIPS_DEMAND_STYLE_ANY, resample->in, NULL ); /* Size output. Note: we round the output width down! */