Emit a warning if the OutputThread fails to get realtime scheduling
This only applies to linux systems. Here, sched_setscheduler() is called to get realtime scheduling. With this patch, the return value of this function is now checked and a warning / error message is generated if it fails.
This commit is contained in:
		
				
					committed by
					
						
						Max Kellermann
					
				
			
			
				
	
			
			
			
						parent
						
							e7b211f2c0
						
					
				
				
					commit
					3392cbbd91
				
			@@ -593,7 +593,12 @@ AudioOutput::Task()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	FormatThreadName("output:%s", name);
 | 
						FormatThreadName("output:%s", name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SetThreadRealtime();
 | 
						Error error;
 | 
				
			||||||
 | 
						if(!SetThreadRealtime(error)) {
 | 
				
			||||||
 | 
							LogError(error);
 | 
				
			||||||
 | 
							LogWarning(output_domain,
 | 
				
			||||||
 | 
								"OutputThread could not get realtime scheduling, continuing anyway");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	SetThreadTimerSlackUS(100);
 | 
						SetThreadTimerSlackUS(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex.lock();
 | 
						mutex.lock();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,6 +30,8 @@
 | 
				
			|||||||
#ifndef THREAD_UTIL_HXX
 | 
					#ifndef THREAD_UTIL_HXX
 | 
				
			||||||
#define THREAD_UTIL_HXX
 | 
					#define THREAD_UTIL_HXX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "util/Error.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __linux__
 | 
					#ifdef __linux__
 | 
				
			||||||
#include <sched.h>
 | 
					#include <sched.h>
 | 
				
			||||||
#include <sys/syscall.h>
 | 
					#include <sys/syscall.h>
 | 
				
			||||||
@@ -81,9 +83,11 @@ SetThreadIdlePriority()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Raise the current thread's priority to "real-time" (very high).
 | 
					 * Raise the current thread's priority to "real-time" (very high).
 | 
				
			||||||
 | 
					 * @param[out]	error	Receives error information on failure
 | 
				
			||||||
 | 
					 * @return	true on success (always true on non-linux systems)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static inline void
 | 
					static inline bool
 | 
				
			||||||
SetThreadRealtime()
 | 
					SetThreadRealtime(Error& error)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifdef __linux__
 | 
					#ifdef __linux__
 | 
				
			||||||
	struct sched_param sched_param;
 | 
						struct sched_param sched_param;
 | 
				
			||||||
@@ -94,8 +98,15 @@ SetThreadRealtime()
 | 
				
			|||||||
	policy |= SCHED_RESET_ON_FORK;
 | 
						policy |= SCHED_RESET_ON_FORK;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sched_setscheduler(0, policy, &sched_param);
 | 
						if(sched_setscheduler(0, policy, &sched_param)==0) {
 | 
				
			||||||
#endif
 | 
							return true;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							error.FormatErrno("sched_setscheduler failed");
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
						return true; // on non-linux systems, we pretend it worked
 | 
				
			||||||
 | 
					#endif	// __linux__
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user