Date: Tue, 9 Sep 2003 00:49:59 +0800 (KRAST) From: Eugene Grosbein <eugen@grosbein.pp.ru> To: FreeBSD-gnats-submit@FreeBSD.org Subject: ports/56597: bad startup perfomance of mpg123 with pcm/oss/dsp Message-ID: <200309081649.h88GnxTf004604@grosbein.pp.ru> Resent-Message-ID: <200309081700.h88H0TT6090363@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 56597 >Category: ports >Synopsis: bad startup perfomance of mpg123 with pcm/oss/dsp >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Sep 08 10:00:28 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Eugene Grosbein >Release: FreeBSD 4.9-PRERELEASE i386 >Organization: Svyaz Service JSC >Environment: System: FreeBSD grosbein.pp.ru 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #19: Fri Sep 5 23:33:57 KRAST 2003 eu@grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV i386 mpg123-0.59r_9 is built without NAS/ESD/etc, with OSS only. >Description: mpg123 from ports runs an initialization cycle at startup that calls lots of pcm(4) ioctl()'s. Their performance is very bad and that produces significant delay before opening of media file. During this delay mpg123 may consime all available CPU cycles even CPU is idle later while playback. >How-To-Repeat: 1. Add the following patch to /usr/ports/audio/mpg123/files. It computes system time consumed by a function audio_capabilities() from audio.c 2. Make sure you have not NAS or esound installed or just delete corresponding delection code from /usr/ports/audio/mpg123/files/Makefile, leave "ALL_TARGET= freebsd" alone. 3. run 'make' 4. cd into the working directory and run time ./mpg123 t Where 't' in nonexising file. Here are results for Celeron-900E. High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3. Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp. Uses code from various people. See 'README' for more! THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! SPEED : 1.619771 for 120 STEREO: 3.081828 for 120 SETFMT: 3.081443 for 120 t: No such file or directory 7,85 real 0,00 user 7,83 sys We have 7.8 seconds spent for processing of ioctls SNDCTL_DSP_SPEED, SNDCTL_DSP_STEREO and SNDCTL_DSP_SETFMT. Now lets see results for Pentium-90 that easily plays MP3's after initial 22s (!) delay: High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3. Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp. Uses code from various people. See 'README' for more! THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! SPEED : 6.247190 for 120 STEREO: 7.795631 for 120 SETFMT: 7.795866 for 120 t: No such file or directory 22,26 real 0,07 user 22,14 sys The mentioned patch follows. --- audio.c.orig Tue Apr 6 23:53:05 1999 +++ audio.c Tue Sep 9 00:22:57 2003 @@ -1,4 +1,5 @@ +#include <sys/time.h> #include "mpg123.h" void audio_info_struct_init(struct audio_info_struct *ai) @@ -64,6 +65,9 @@ static char capabilities[NUM_CHANNELS][NUM_ENCODINGS][NUM_RATES]; +extern struct timeval ausage[]; +extern int acount[]; + void audio_capabilities(struct audio_info_struct *ai) { int fmts; @@ -99,6 +103,10 @@ } } } + + fprintf(stderr,"SPEED : %ld.%06ld for %d\n",ausage[0].tv_sec,ausage[0].tv_usec,acount[0]); + fprintf(stderr,"STEREO: %ld.%06ld for %d\n",ausage[1].tv_sec,ausage[1].tv_usec,acount[1]); + fprintf(stderr,"SETFMT: %ld.%06ld for %d\n",ausage[2].tv_sec,ausage[2].tv_usec,acount[2]); audio_close(&ai1); --- audio_oss.c.orig Tue Sep 9 00:21:21 2003 +++ audio_oss.c Tue Sep 9 00:23:25 2003 @@ -1,5 +1,7 @@ #include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> @@ -114,6 +116,33 @@ return 0; } +struct timeval ausage[3]={ {0L,0L}, {0L,0L}, {0L,0L} }; +static struct rusage tus; +int acount[3] = { 0, 0, 0 }; + +static void account_start(void) +{ + getrusage(RUSAGE_SELF,&tus); +} + +static void account_usage(what) +{ + struct rusage now; + + getrusage(RUSAGE_SELF,&now); + + ausage[what].tv_usec+=(now.ru_stime.tv_usec-tus.ru_stime.tv_usec); + ausage[what].tv_sec+=(now.ru_stime.tv_sec-tus.ru_stime.tv_sec); + if(ausage[what].tv_usec<0) { + ausage[what].tv_usec+=1000000; + ausage[what].tv_sec--; + } + else if(ausage[what].tv_usec>=1000000) { + ausage[what].tv_usec-=1000000; + ausage[what].tv_sec++; + } + acount[what]++; +} int audio_rate_best_match(struct audio_info_struct *ai) { @@ -122,7 +151,9 @@ if(!ai || ai->fn < 0 || ai->rate < 0) return -1; dsp_rate = ai->rate; + account_start(); ret = ioctl(ai->fn, SNDCTL_DSP_SPEED,&dsp_rate); + account_usage(0); if(ret < 0) return ret; ai->rate = dsp_rate; @@ -136,7 +167,9 @@ if(ai->rate >= 0) { dsp_rate = ai->rate; + account_start(); ret = ioctl(ai->fn, SNDCTL_DSP_SPEED,&dsp_rate); + account_usage(0); } return ret; } @@ -149,7 +182,9 @@ if(ai->channels < 0) return 0; + account_start(); ret = ioctl(ai->fn, SNDCTL_DSP_STEREO, &chan); + account_usage(1); if(chan != (ai->channels-1)) { return -1; } @@ -195,7 +230,9 @@ return -1; #endif sf = fmts; + account_start(); ret = ioctl(ai->fn, SNDCTL_DSP_SETFMT, &fmts); + account_usage(2); if(sf != fmts) { return -1; } >Fix: Unknown for me. Eugene Grosbein >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200309081649.h88GnxTf004604>