Lightweight Software Transactions for Games

Lightweight Software Transactions for Games

Lightweight Software Transactions for Games Alexandro Baldassin Sebastian Burckhardt State University of Campinas, Brazil Microsoft Research, Redmond [email protected] [email protected] Abstract hardware, software or a mix of both) is responsible for de- To realize the performance potential of multiple cores, soft- tecting conflicts and providing a consistent (serializable or ware developers must architect their programs for concur- linearizable) execution of the transactions. rency. Unfortunately, for many applications, threads and Transactional memory is an active research field and the locks are difficult to use efficiently and correctly. Thus, re- approach seems promising: benchmarks show that transac- searchers have proposed transactional memory as a simpler tional memory can improve the performance of some code, alternative. such as scientific algorithms or concurrent data type im- To investigate if and how software transactional mem- plementations. Nevertheless, how to successfully integrate ory (STM) can help a programmer to parallelize applica- transactional memory into more mainstream applications re- tions, we perform a case study on a game application called mains an open question [10]. We believe that programmers SpaceWars3D. After experiencing suboptimal performance, will adopt TM only if it can deliver both a substantially we depart from classic STM designs and propose a program- simplified programming experience and competitive perfor- ming model that uses long-running, abort-free transactions mance compared to traditional lock-based designs. that rely on user specifications to avoid or resolve conflicts. To address this general challenge, we conducted a par- With this model we achieve the combined goal of competi- allelization case study on a full-featured game application, tive performance and improved programmability. SpaceWars3D [3]. We first restructured the sequential code into cleanly separated modules dealing with the different aspects of the game (Fig.1). Then we tried to parallelize 1. Introduction the tasks performed in each frame (such as rendering the With the exponential growth in power dissipation and lim- screen, updating positions of game objects, detecting col- itations on the microarchitectural level, the semiconductor lisions, etc.). We quickly realized that traditional synchro- industry has shifted its focus towards multicore architec- nization (locks and critical sections) is cumbersome to use. tures. Unfortunately, many applications are not designed to For more convenient programming, we tried to execute each exploit true concurrency available on a multicore processor task as a transaction, provided by an STM. Unfortunately, and thus no longer get the benefit of steady performance performance was poor because of (1) frequent conflicts and improvements with the succession of new chip generations. rollbacks, and (2) the large overhead of transactional execu- The task of filling in the gap between hardware and software tion. and bringing concurrent programming to the mainstream is To resolve these problems, we departed from standard being regarded as one of the greatest challenges in computer STM designs and developed a novel programming model. science in the last 50 years [5], with companies such as Mi- It replicates the shared data so that each task can access crosoft and Intel investing heavily in academic research in its local replica without synchronization. The replicas are this area. reconciled by propagating updates between frames. The key The most common concurrent programming model today design decisions are (1) tasks never abort, and (2) data is based on a shared memory architecture wherein a thread is consistency requirements are specified by the programmer the unit of concurrency. Threads communicate through reads using object-oriented techniques. and writes from/to shared memory and, to avoid conflicts, The user plays an active role in controlling concurrency. they synchronize using locks. Often, locks are used to con- First, she may restrict concurrency by enforcing specific task struct so-called critical sections, areas of code that can not orderings using task barriers. Second, she may enable con- be entered by more than one thread at a time. An alterna- current modifications of certain objects by specifying how to tive to lock-based synchronization is known as transactional reconcile conflicts (using priorities or a general merge func- memory [4]. In this model programmers specify transac- tion). tions, blocks of code that appears to execute atomically and in isolation. The underlying runtime system (implemented in This final strategy performed well. Although we ask the Screen programmer to think quite a bit about data sharing and data consistency, we feel that there is a substantial value to the View Controller exercise as it leads to a more declarative and more concurrent Audio Network programming style than traditional approaches. Most of the task conflicts found and reported during runtime were either Controller MODEL Controller easily eliminated (some even helped us to find bugs in the View View code), or revealed an important dependency between tasks that we had not detected before. Physics Input 1.1 Contributions Controller Controller Our main contributions are (1) that we report on the chal- lenges we encountered when parallelizing a game applica- Figure 1. Our Model-View-Controller (MVC) design tion, and (2) that we propose a programming model (based on long-running, abort-free transactions with user-specified merge-based consistency) that achieves good programmabil- ity and competitive performance. teroids to the gameplay. Asteroids may collide with other game objects. By varying the number of asteroids (we used 1.2 Related Work around 1500 in our experiments) we can conveniently adjust There are two main works reporting on experiences in us- the workload. ing TM to parallelize large applications. Scott et al. [8] em- ploy a mix of barriers and transactions to create a parallel 2.1 Model-View-Controller Design implementation of Delaunay triangulation. Watson et al. [9] investigate how Lee’s routing algorithm can be made par- As a first step we rearchitected the code following the allel by using transactions. Where our work differs from Model-View-Controller (MVC) design. MVC has been theirs is in the application domain (we have a game appli- widely used in many different environments. In our case, cation) and in how we solved the performance problem im- its role is to express concurrency between the controllers, posed by long-running transactions. Blundell et al. [2] de- and to separate shared data (the model) from controller-local vise unrestricted transactions as a mean of allowing transac- data (the views). tions to perform I/O. Aydonat and Abdelrahman [1] propose Our MVC architecture is shown in Fig. 1. It has a model conflict-serializability in order to reduce the abort rate of at the center, surrounded by several modules. Each module long-running transactions. Our solution allows both I/O and handles one game aspect (sound, graphics, input, physics, long-running transactions by completely avoiding aborts. network). The model encapsulates the essential game state. Rhalibi et al. [6] present a framework for modeling games In our case, it consists of hierarchically organized game as cyclic-task-dependency graphs and a runtime scheduler. objects (player ships, asteroids, projectiles). The model is However, their framework does not use replication; rather passive — it does not contain any threads, but its objects it is based on the classic lock-based synchronization primi- may be read and updated by the modules. tives. The modules are the gateways between the model and the As in our work, Rinard and Diniz [7] use object repli- external world; they respond to external events (incoming cation for better concurrency. However, they apply it in a network packets, user input) by updating the model, and they different context (a parallelizing compiler). in turn send information about the model to external entities (such as the screen, or to remote players). A module con- 2. The Game tains exactly one controller and may contain one or more views. Controllers are active (they may contain one or more Our starting point was a enhanced 3D Windows version threads). Views encapsulate data relating to a particular ex- of the classic game Spacewars, as described in a tutorial ternal interface. We now describe the modules in turn: book [3] and with source code available on the web.1 In a nutshell, the game consists of two starships shooting one an- • The screen controller renders the game state once each other in space. It is coded in C# and uses the ManagedDi- frame, using the DirectX interface to the graphics card. rectX API. Developed to teach game programming, it fea- Parameters and data related to this interface (such as tures many realistic details including 3D rendered graphics, meshes or textures) are encapsulated in the screen view. sound, and a network connection. • Because the original game lacked sufficiently heavy com- The physics controller performs two tasks each frame. putation to challenge our machine, we added moving as- One handles collisions between game objects; the other updates the object positions based on their speed and the 1 www.apress.com/book/downloadfile/1486 elapsed time. • The input controller processes mouse and keyboard in- public class PhysicsController : Controller put, firing shots and changing the position and speed of { public void Start() the player

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us