comparison read_cache.c @ 46:654705f4e7af src

Add some readcache profiling code.
author jcdutton
date Tue, 25 Jun 2002 20:36:04 +0000
parents 7bf97b8922b4
children 12628fdcc18a
comparison
equal deleted inserted replaced
45:7bf97b8922b4 46:654705f4e7af
26 #endif 26 #endif
27 27
28 #include "dvdnav.h" 28 #include "dvdnav.h"
29 #include "read_cache.h" 29 #include "read_cache.h"
30 #include <pthread.h> 30 #include <pthread.h>
31 #include <sys/time.h>
32 #include <time.h>
33
34 /*
35 #define DVDNAV_PROFILE
36 */
31 37
32 /* Read-ahead cache structure. */ 38 /* Read-ahead cache structure. */
33 #if 0 39 #if 0
34 /* #if _MULTITHREAD_ */ 40 /* #if _MULTITHREAD_ */
35 41
344 350
345 self->cache_start_sector = -1; 351 self->cache_start_sector = -1;
346 self->cache_valid = 0; 352 self->cache_valid = 0;
347 } 353 }
348 354
355 #ifdef DVDNAV_PROFILE
356 //#ifdef ARCH_X86
357 __inline__ unsigned long long int dvdnav_rdtsc()
358 {
359 unsigned long long int x;
360 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
361 return x;
362 }
363 //#endif
364 #endif
365
349 /* This function is called just after reading the NAV packet. */ 366 /* This function is called just after reading the NAV packet. */
350 void dvdnav_pre_cache_blocks(read_cache_t *self, int sector, size_t block_count) { 367 void dvdnav_pre_cache_blocks(read_cache_t *self, int sector, size_t block_count) {
351 int result; 368 int result;
369 #ifdef DVDNAV_PROFILE
370 struct timeval tv1, tv2, tv3;
371 unsigned long long p1, p2, p3;
372 #endif
352 373
353 if(!self) 374 if(!self)
354 return; 375 return;
355 376
356 if(!self->dvd_self->use_read_ahead) { 377 if(!self->dvd_self->use_read_ahead) {
357 self->cache_valid = 0; 378 self->cache_valid = 0;
358 self->cache_start_sector = -1; 379 self->cache_start_sector = -1;
359 return; 380 return;
360 } 381 }
361 382 /* We start with a sensible figure for the first malloc of 500 blocks.
383 * Some DVDs I have seen venture to 450 blocks.
384 * This is so that fewer realloc's happen if at all.
385 */
362 if (self->cache_buffer) { 386 if (self->cache_buffer) {
363 if( block_count > self->cache_malloc_size) { 387 if( block_count > self->cache_malloc_size) {
364 self->cache_buffer = realloc(self->cache_buffer, block_count * DVD_VIDEO_LB_LEN); 388 self->cache_buffer = realloc(self->cache_buffer, block_count * DVD_VIDEO_LB_LEN);
389 dprintf("libdvdnav:read_cache:pre_cache DVD read realloc happened\n");
365 self->cache_malloc_size = block_count; 390 self->cache_malloc_size = block_count;
366 } 391 }
367 } else { 392 } else {
368 self->cache_buffer = malloc(block_count * DVD_VIDEO_LB_LEN); 393 self->cache_buffer = malloc((block_count > 500 ? block_count : 500 )* DVD_VIDEO_LB_LEN);
369 self->cache_malloc_size = block_count; 394 self->cache_malloc_size = (block_count > 500 ? block_count : 500 );
395 dprintf("libdvdnav:read_cache:pre_cache DVD read malloc %d\n", (block_count > 500 ? block_count : 500 ));
370 } 396 }
371 self->cache_start_sector = sector; 397 self->cache_start_sector = sector;
372 self->cache_block_count = block_count; 398 self->cache_block_count = block_count;
399 #ifdef DVDNAV_PROFILE
400 gettimeofday(&tv1, NULL);
401 p1 = dvdnav_rdtsc();
402 #endif
373 result = DVDReadBlocks( self->dvd_self->file, sector, block_count, self->cache_buffer); 403 result = DVDReadBlocks( self->dvd_self->file, sector, block_count, self->cache_buffer);
404 #ifdef DVDNAV_PROFILE
405 p2 = dvdnav_rdtsc();
406 gettimeofday(&tv2, NULL);
407 timersub(&tv2, &tv1, &tv3);
408 dprintf("libdvdnav:read_cache:pre_cache DVD read %ld us, profile = %lld, block_count = %d\n", tv3.tv_usec, p2-p1, block_count);
409 #endif
374 self->cache_valid = 1; 410 self->cache_valid = 1;
375 } 411 }
376 412
377 /* This function will do the cache read once implemented */ 413 /* This function will do the cache read once implemented */
378 int dvdnav_read_cache_block( read_cache_t *self, int sector, size_t block_count, uint8_t *buf) { 414 int dvdnav_read_cache_block( read_cache_t *self, int sector, size_t block_count, uint8_t *buf) {