Low-Latency Audio on Linux by Means of Real-Time Scheduling ∗
Total Page:16
File Type:pdf, Size:1020Kb
Low-Latency Audio on Linux by Means of Real-Time Scheduling ∗ Tommaso CUCINOTTA and Dario FAGGIOLI and Giacomo BAGNOLI Scuola Superiore Sant'Anna Via G. Moruzzi 1, 56124, Pisa (Italy) ft.cucinotta, [email protected], [email protected] Abstract audio collections and running the proper mixing In this paper, we propose to use resource reserva- software. tions scheduling and feedback-based allocation tech- In fact, developing complex multimedia appli- niques for the provisioning of proper timeliness guar- cations on GNU/Linux allows for the exploita- antees to audio processing applications. This al- tion of a multitude of OS services (e.g., network- lows real-time audio tasks to meet the tight tim- ing), libraries (e.g., sophisticated multimedia ing constraints characterizing them, even if other in- compression libraries) and media/storage sup- teractive activities are present in the system. The port (e.g., memory cards), as well as comfort- JACK sound infrastructure has been modified, lever- able and easy-to-use programming and debug- aging the real-time scheduler present in the Adaptive ging tools. However, contrarily to a Real-Time Quality of Service Architecture (AQuoSA). The ef- Operating System (RTOS), a GPOS is not gen- fectiveness of the proposed approach, which does not erally designed to provide scheduling guarantees require any modifiction to existing JACK clients, is to the running applications. This is why either validated through extensive experiments under dif- large amount of buffering is very likely to oc- ferent load conditions. cur, with an unavoidable impact on response time and latencies, or the POSIX fixed-priority Keywords (e.g., SCHED FIFO) real-time scheduling is uti- JACK, real-time, scheduling, time-sensitive, re- lized, but this turns out to be difficult when source reservation there is more than one time-sensitive applica- tion in the system. Though, on a nowadays 1 Introduction and Related Work GNU/Linux system, we may easily find a vari- There is an increasing interest in considering ety of applications with tight timing constraints General Purpose Operating Systems (GPOSes) that might benefit from precise scheduling guar- in the context of real-time and multimedia ap- antees, in order to provide near-professional plications. In the Personal Computing domain, quality of the user experience, e.g., audio acqui- multimedia sharing, playback and processing re- sition and playback, multimedia (video, gaming, quires more and more mechanisms allowing for etc.) display, video acquisition (v4l2), just to low and predictable latencies even in presence cite a few of them. In such a challenging sce- of background workloads nearly saturating the nario in which we can easily find a few tens of available resources, e.g., network links and CPU threads of execution with potentially tight real- power. In the professional multimedia domain, time requirements, an accurate set-up of real- spotting on stages, it is becoming quite common time priorities may easily become cumbersome, to see a digital keyboard attached to a common especially for the user of the system, who is usu- laptop running GNU/Linux. DJs and VJs are ally left alone with such critical decisions as set- moving to computer based setups to the point ting the real-time priority of a multimedia task. that mixing consoles have turned from big decks More advanced scheduling services than just into simple personal computers, only containing priority based ones have been made available for Linux during the latest years, among the others ∗ The research leading to these results has received fund- by [Palopoli et al., 2009; Faggioli et al., 2009; ing from the European Community's Seventh Framework Checconi et al., 2009; Anderson and Students, Programme FP7 under grant agreement n.214777 \IR- MOS { Interactive Realtime Multimedia Applications on 2006; Kato et al., 2010]. Such scheduling poli- Service Oriented Infrastructures" and n.248465 \S(o)OS cies are based on a clear specification that needs { Service-oriented Operating Systems." to be made by the application about what is the computing power it needs and with what time ers, samplers, tuners, and many others. These granularity (determining the latency), and this clients run as independent system processes, but scheme is referred to as resource reservations. they all must have an audio processing thread This is usually done in terms of a reservation handling the specific computation they make on budget of time units to be guaranteed every pe- the audio stream in real-time, and using the riod. The reservation period may easily be set JACK API for data exchanging. equal to the minimum activation period of the On its hand, JACK is in direct contact with application. Identifying the reservation budget the audio infrastructure of the OS (i.e., ALSA may be a more involved task, due to the need for on Linux) by means of a component referred to a proper benchmarking phase of the application, as (from now on) the JACK driver or just the and it is even worse in case of applications with driver. By default, double-buffering is used, so significant fluctuations of the workload (such as the JACK infrastructure is required to process it often happens in multimedia ones). Rather, audio data and filling a buffer, while the under- it is more convenient to engage adaptive reser- lying hardware is playing the other one. Each vation scheduling policies, where the schedul- time a new buffer is not yet available in time, ing parameters are dynamically changed at run- JACK logs the occurrence of an xrun event. time by an application-level control-loop. This acts by monitoring some application-level met- 3 AQuoSA Resource Reservation rics and increasing or decreasing the amount of Framework allocated computing resources depending on the The Adaptive Quality of Service Architec- instantaneous application workload. Some ap- ture (AQuoSA2) is an open-source frame- proaches of this kind are constituted by [Segovia work enabling soft real-time capabilities and et al., 2010; Abeni et al., 2005; Nahrstedt et al., QoS support in the Linux kernel. It in- 1998], just to mention a few. cludes: an deadline-based real-time sched- uler; temporal encapsulation provided via the 1.1 Contribution of This Paper CBS [Abeni and Buttazzo, 1998] algorithm; var- This work focuses on how to provide enhanced ious adaptive reservation strategies for building timeliness guarantees to low-latency real-time feedback-based scheduling control loops [Abeni audio applications on GNU/Linux. We use et al., 2005]; reclamation of unused bandwidth adaptive reservations within the JACK au- through the SHRUB [Palopoli et al., 2008] al- dio framework, i.e., we show how we modi- gorithm; a simple hierarchical scheduling capa- fied JACK in order to take advantage of AQu- bility which allows for Round Robin schedul- oSA [Palopoli et al., 2009], a software architec- ing of multiple tasks inside the same reser- ture we developed for enriching the Linux kernel vation; a well-designed admission-control log- with resource reservation scheduling and adap- ics [Palopoli et al., 2009] allowing controlled ac- tive reservations. Notably, in the proposed ar- cess to real-time scheduling capabilities of the chitecture, JACK needs to be patched, but au- system for unprivileged applications. For more dio applications using it do not require to be details about AQuoSA, the reader is referred modified nor recompiled. We believe the discus- to [Palopoli et al., 2009]. sion reported in this paper constitutes a valu- able first-hand experience on how it is possible 4 Integrating JACK with AQuoSA to integrate real-time scheduling policies into Adaptive reservations have been applied to multimedia applications on a GPOS. JACK as follows. In JACK, an entire graph of end-to-end computations is activated with 2 JACK: Jack Audio Connection Kit buffersize a periodicity equal to samplerate and it must JACK 1 is a well-known low-latency audio complete within the same period. Therefore, a server for POSIX conforming OSes (including reservation is created at the start-up of JACK, Linux) aiming at providing an IPC infrastruc- and all of the JACK clients, comprising the real- ture for audio processing where sound streams time threads of the JACK server itself (the au- may traverse multiple independent processes dio \drivers"), have been attached to such reser- running on the platform. Typical applications vation, exploiting the hierarchical capability of | i.e., clients | are audio effects, synthesis- AQuoSA. The reservation period has been set 1Note that the version 2 of JACK is used for this 2More information is available at: http://aquosa. study sourceforge.net. equal to the period of the JACK work-flow acti- The per-cycle consumed CPU time values vation. The reservation budget needs therefore were used to feed the AQuoSA predictor and to be sufficiently large so as to allow for com- apply the control algorithm to adjust the reser- pletion of all of the JACK clients within the pe- vation budget. riod, i.e., if the JACK graph comprises n clients, the execution time needed by all of the JACK 5 Experimental Results clients are c1; : : : cn, and the JACK period is The proposed modifications to JACK have T , then the reservation will have the following been validated through an extensive experi- budget Q and period P : mental evaluation conducted over the imple- 8 Pn mented modified JACK running on a Linux sys- <Q = i=1 ci (1) tem. All experiments have been performed on :P = T a common consumer PC (Intel(R) [email protected] GHz) with CPU dynamic voltage-scaling dis- Beside this, an AQuoSA QoS control-loop abled, and with a Terratec EWX24/96 PCI was used for controlling the reservation budget, sound card. The modified JACK framework based on the monitoring of the budget actu- and all the tools needed in order to reproduce ally consumed at each JACK cycle.