@@ -318,48 +318,7 @@ PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void
318318
319319 if ( rtSched )
320320 {
321- #if 0
322- if ( self -> useWatchdog )
323- {
324- int err ;
325- struct sched_param wdSpm = { 0 };
326- /* Launch watchdog, watchdog sets callback thread priority */
327- int prio = PA_MIN ( self -> rtPrio + 4 , sched_get_priority_max ( SCHED_FIFO ) );
328- wdSpm .sched_priority = prio ;
329-
330- PA_UNLESS ( !pthread_attr_init ( & attr ), paInternalError );
331- PA_UNLESS ( !pthread_attr_setinheritsched ( & attr , PTHREAD_EXPLICIT_SCHED ), paInternalError );
332- PA_UNLESS ( !pthread_attr_setscope ( & attr , PTHREAD_SCOPE_SYSTEM ), paInternalError );
333- PA_UNLESS ( !pthread_attr_setschedpolicy ( & attr , SCHED_FIFO ), paInternalError );
334- PA_UNLESS ( !pthread_attr_setschedparam ( & attr , & wdSpm ), paInternalError );
335- if ( (err = pthread_create ( & self -> watchdogThread , & attr , & WatchdogFunc , self )) )
336- {
337- PA_UNLESS ( err == EPERM , paInternalError );
338- /* Permission error, go on without realtime privileges */
339- PA_DEBUG (( "Failed bumping priority\n" ));
340- }
341- else
342- {
343- int policy ;
344- self -> watchdogRunning = 1 ;
345- PA_ENSURE_SYSTEM ( pthread_getschedparam ( self -> watchdogThread , & policy , & wdSpm ), 0 );
346- /* Check if priority is right, policy could potentially differ from SCHED_FIFO (but that's alright) */
347- if ( wdSpm .sched_priority != prio )
348- {
349- PA_DEBUG (( "Watchdog priority not set correctly (%d)\n" , wdSpm .sched_priority ));
350- PA_ENSURE ( paInternalError );
351- }
352- }
353- }
354- else
355- #endif
356- PA_ENSURE ( BoostPriority ( self ) );
357-
358- {
359- int policy ;
360- struct sched_param spm ;
361- pthread_getschedparam (self -> thread , & policy , & spm );
362- }
321+ PA_ENSURE ( BoostPriority ( self ) );
363322 }
364323
365324 if ( self -> parentWaiting )
@@ -424,23 +383,6 @@ PaError PaUnixThread_Terminate( PaUnixThread* self, int wait, PaError* exitResul
424383 {
425384 * exitResult = paNoError ;
426385 }
427- #if 0
428- if ( watchdogExitResult )
429- * watchdogExitResult = paNoError ;
430-
431- if ( th -> watchdogRunning )
432- {
433- pthread_cancel ( th -> watchdogThread );
434- PA_ENSURE_SYSTEM ( pthread_join ( th -> watchdogThread , & pret ), 0 );
435-
436- if ( pret && pret != PTHREAD_CANCELED )
437- {
438- if ( watchdogExitResult )
439- * watchdogExitResult = * (PaError * ) pret ;
440- free ( pret );
441- }
442- }
443- #endif
444386
445387 /* Only kill the thread if it isn't in the process of stopping (flushing adaptation buffers) */
446388 /* TODO: Make join time out */
@@ -563,164 +505,3 @@ PaError PaUnixMutex_Unlock( PaUnixMutex* self )
563505error :
564506 return result ;
565507}
566-
567-
568- #if 0
569- static void OnWatchdogExit ( void * userData )
570- {
571- PaAlsaThreading * th = (PaAlsaThreading * ) userData ;
572- struct sched_param spm = { 0 };
573- assert ( th );
574-
575- PA_ASSERT_CALL ( pthread_setschedparam ( th -> callbackThread , SCHED_OTHER , & spm ), 0 ); /* Lower before exiting */
576- PA_DEBUG (( "Watchdog exiting\n" ));
577- }
578-
579- static void * WatchdogFunc ( void * userData )
580- {
581- PaError result = paNoError , * pres = NULL ;
582- int err ;
583- PaAlsaThreading * th = (PaAlsaThreading * ) userData ;
584- unsigned intervalMsec = 500 ;
585- const PaTime maxSeconds = 3. ; /* Max seconds between callbacks */
586- PaTime timeThen = PaUtil_GetTime (), timeNow , timeElapsed , cpuTimeThen , cpuTimeNow , cpuTimeElapsed ;
587- double cpuLoad , avgCpuLoad = 0. ;
588- int throttled = 0 ;
589-
590- assert ( th );
591-
592- /* Execute OnWatchdogExit when exiting */
593- pthread_cleanup_push ( & OnWatchdogExit , th );
594-
595- /* Boost priority of callback thread */
596- PA_ENSURE ( result = BoostPriority ( th ) );
597- if ( !result )
598- {
599- /* Boost failed, might as well exit */
600- pthread_exit ( NULL );
601- }
602-
603- cpuTimeThen = th -> callbackCpuTime ;
604- {
605- int policy ;
606- struct sched_param spm = { 0 };
607- pthread_getschedparam ( pthread_self (), & policy , & spm );
608- PA_DEBUG (( "%s: Watchdog priority is %d\n" , __FUNCTION__ , spm .sched_priority ));
609- }
610-
611- while ( 1 )
612- {
613- double lowpassCoeff = 0.9 , lowpassCoeff1 = 0.99999 - lowpassCoeff ;
614-
615- /* Test before and after in case whatever underlying sleep call isn't interrupted by pthread_cancel */
616- pthread_testcancel ();
617- Pa_Sleep ( intervalMsec );
618- pthread_testcancel ();
619-
620- if ( PaUtil_GetTime () - th -> callbackTime > maxSeconds )
621- {
622- PA_DEBUG (( "Watchdog: Terminating callback thread\n" ));
623- /* Tell thread to terminate */
624- err = pthread_kill ( th -> callbackThread , SIGKILL );
625- pthread_exit ( NULL );
626- }
627-
628- PA_DEBUG (( "%s: PortAudio reports CPU load: %g\n" , __FUNCTION__ , PaUtil_GetCpuLoad ( th -> cpuLoadMeasurer ) ));
629-
630- /* Check if we should throttle, or unthrottle :P */
631- cpuTimeNow = th -> callbackCpuTime ;
632- cpuTimeElapsed = cpuTimeNow - cpuTimeThen ;
633- cpuTimeThen = cpuTimeNow ;
634-
635- timeNow = PaUtil_GetTime ();
636- timeElapsed = timeNow - timeThen ;
637- timeThen = timeNow ;
638- cpuLoad = cpuTimeElapsed / timeElapsed ;
639- avgCpuLoad = avgCpuLoad * lowpassCoeff + cpuLoad * lowpassCoeff1 ;
640- /*
641- if( throttled )
642- PA_DEBUG(( "Watchdog: CPU load: %g, %g\n", avgCpuLoad, cpuTimeElapsed ));
643- */
644- if ( PaUtil_GetCpuLoad ( th -> cpuLoadMeasurer ) > .925 )
645- {
646- static int policy ;
647- static struct sched_param spm = { 0 };
648- static const struct sched_param defaultSpm = { 0 };
649- PA_DEBUG (( "%s: Throttling audio thread, priority %d\n" , __FUNCTION__ , spm .sched_priority ));
650-
651- pthread_getschedparam ( th -> callbackThread , & policy , & spm );
652- if ( !pthread_setschedparam ( th -> callbackThread , SCHED_OTHER , & defaultSpm ) )
653- {
654- throttled = 1 ;
655- }
656- else
657- PA_DEBUG (( "Watchdog: Couldn't lower priority of audio thread: %s\n" , strerror ( errno ) ));
658-
659- /* Give other processes a go, before raising priority again */
660- PA_DEBUG (( "%s: Watchdog sleeping for %lu msecs before unthrottling\n" , __FUNCTION__ , th -> throttledSleepTime ));
661- Pa_Sleep ( th -> throttledSleepTime );
662-
663- /* Reset callback priority */
664- if ( pthread_setschedparam ( th -> callbackThread , SCHED_FIFO , & spm ) != 0 )
665- {
666- PA_DEBUG (( "%s: Couldn't raise priority of audio thread: %s\n" , __FUNCTION__ , strerror ( errno ) ));
667- }
668-
669- if ( PaUtil_GetCpuLoad ( th -> cpuLoadMeasurer ) >= .99 )
670- intervalMsec = 50 ;
671- else
672- intervalMsec = 100 ;
673-
674- /*
675- lowpassCoeff = .97;
676- lowpassCoeff1 = .99999 - lowpassCoeff;
677- */
678- }
679- else if ( throttled && avgCpuLoad < .8 )
680- {
681- intervalMsec = 500 ;
682- throttled = 0 ;
683-
684- /*
685- lowpassCoeff = .9;
686- lowpassCoeff1 = .99999 - lowpassCoeff;
687- */
688- }
689- }
690-
691- pthread_cleanup_pop ( 1 ); /* Execute cleanup on exit */
692-
693- error :
694- /* Shouldn't get here in the normal case */
695-
696- /* Pass on error code */
697- pres = malloc ( sizeof (PaError ) );
698- * pres = result ;
699-
700- pthread_exit ( pres );
701- }
702-
703- static void CallbackUpdate ( PaAlsaThreading * th )
704- {
705- th -> callbackTime = PaUtil_GetTime ();
706- th -> callbackCpuTime = PaUtil_GetCpuLoad ( th -> cpuLoadMeasurer );
707- }
708-
709- /*
710- static void *CanaryFunc( void *userData )
711- {
712- const unsigned intervalMsec = 1000;
713- PaUtilThreading *th = (PaUtilThreading *) userData;
714-
715- while( 1 )
716- {
717- th->canaryTime = PaUtil_GetTime();
718-
719- pthread_testcancel();
720- Pa_Sleep( intervalMsec );
721- }
722-
723- pthread_exit( NULL );
724- }
725- */
726- #endif
0 commit comments