translation cache policies for dynamic binary translation
DESCRIPTION
TRANSCRIPT
![Page 1: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/1.jpg)
National School of Computer Sciences
Translation cache policies for dynamic binary translation
Saber FERJANI
TIMA Laboratory - SLS Group
18 Avril 2013
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 1 / 25
![Page 2: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/2.jpg)
Who I am ?
Academic & Professional Cursus2010-2013 : Student at National School of Computer Sciences - Tunisia.2011/2012 : Robotic team leader, participation to many competitions.June-July 2011 : Intern at Alpha Technology, Design of many PCB layoutincluding QFP, SO, SMT and through hole components.July-August 2012 : Intern at STMicroelectronics : Developing software for aHygrometer and an Altimeter, for STM32F3 microcontroller
http ://about.me/ferjani
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 2 / 25
![Page 3: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/3.jpg)
Context
Why ?Hardware design is taking more and more time,Software development should start earlier,Instruction Set Simulators (ISS) handles the simulation of processors, namedtarget, on a machine with a different architecture, named host.
How?Cross Compilation.Interpretive translation.Dynamic Binary Translation.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 3 / 25
![Page 4: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/4.jpg)
Context
Why ?Hardware design is taking more and more time,Software development should start earlier,Instruction Set Simulators (ISS) handles the simulation of processors, namedtarget, on a machine with a different architecture, named host.
How?Cross Compilation.Interpretive translation.Dynamic Binary Translation.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 3 / 25
![Page 5: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/5.jpg)
Terminology
Simulator : just duplicate the behavior of the system.
Emulator : duplicate the inner workings of the system.
TB : Translated Bloc.
IR : Intermediate representation (also called op-code)
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 4 / 25
![Page 6: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/6.jpg)
Outline
1 Introduction
2 Cache Algorithms
3 Qemu internals
4 Preliminary Results
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 5 / 25
![Page 7: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/7.jpg)
I- Introduction
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 6 / 25
![Page 8: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/8.jpg)
Qemu OverviewGeneric and open source machine emulator and virtualizer,Created by Fabrice Bellard in 2003,uses portable dynamic translation,Supported Targets : x86, arm, mips, sh4, cris, sparc, powerpc, nds32...
Qemu FeaturesJust-in-time (JIT) compilation support,Self-modifying code support,Direct block chaining.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 7 / 25
![Page 9: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/9.jpg)
Subject
ProblematicSimulation speed is mainly affected by reuse of TB,Current policy just flush the entire cache when it is full,We need to enhance translation cache policy in order to maximize TB reuse.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 8 / 25
![Page 10: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/10.jpg)
II- Cache Algorithms
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 9 / 25
![Page 11: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/11.jpg)
Optimal cache algorithmEvict entry that will not be used for the longest time.Unfeasible in practice, since we cannot really know future !
First In First OutMost simple cache replacement policy,Entry remain in memory a constant duration.
Least Recently UsedEnhancement to FIFO.Each time an entry is referenced, it is moved to the end of the queue.
Least Frequently UsedExploit the overall popularity rather than temporal locality.Least referenced entry is always chosen for eviction.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 10 / 25
![Page 12: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/12.jpg)
Optimal cache algorithmEvict entry that will not be used for the longest time.Unfeasible in practice, since we cannot really know future !
First In First OutMost simple cache replacement policy,Entry remain in memory a constant duration.
Least Recently UsedEnhancement to FIFO.Each time an entry is referenced, it is moved to the end of the queue.
Least Frequently UsedExploit the overall popularity rather than temporal locality.Least referenced entry is always chosen for eviction.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 10 / 25
![Page 13: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/13.jpg)
Optimal cache algorithmEvict entry that will not be used for the longest time.Unfeasible in practice, since we cannot really know future !
First In First OutMost simple cache replacement policy,Entry remain in memory a constant duration.
Least Recently UsedEnhancement to FIFO.Each time an entry is referenced, it is moved to the end of the queue.
Least Frequently UsedExploit the overall popularity rather than temporal locality.Least referenced entry is always chosen for eviction.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 10 / 25
![Page 14: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/14.jpg)
Optimal cache algorithmEvict entry that will not be used for the longest time.Unfeasible in practice, since we cannot really know future !
First In First OutMost simple cache replacement policy,Entry remain in memory a constant duration.
Least Recently UsedEnhancement to FIFO.Each time an entry is referenced, it is moved to the end of the queue.
Least Frequently UsedExploit the overall popularity rather than temporal locality.Least referenced entry is always chosen for eviction.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 10 / 25
![Page 15: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/15.jpg)
III- Qemu internals
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 11 / 25
![Page 16: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/16.jpg)
Dynamic Binary Translation in Qemu
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 12 / 25
![Page 17: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/17.jpg)
Dynamic Binary Translation in Qemu
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 12 / 25
![Page 18: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/18.jpg)
Dynamic Binary Translation in Qemu
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 12 / 25
![Page 19: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/19.jpg)
Bloc chaining
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 13 / 25
![Page 20: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/20.jpg)
Bloc chaining
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 13 / 25
![Page 21: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/21.jpg)
lookup tbby target pc
Cached ? Translate onebasic block
execute tbchain itto existedbasic block
Exceptionhandling
no
yes
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 14 / 25
![Page 22: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/22.jpg)
lookup tbby target pc
Cached ? Translate onebasic block
execute tbchain itto existedbasic block
Exceptionhandling
no
yes
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 15 / 25
![Page 23: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/23.jpg)
Focus on (Translate one basic block)
try to allocatespace for tb
sucess ?Flush entiretranslation
cache
generate op& host code
allocatespace for tb(cannot fail!)
no
yes
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 16 / 25
![Page 24: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/24.jpg)
Implementation constraints
Variable TB sizeIn basics cache algorithms, evicting one entry is always sufficient to bring an other,but in our case, TB size is not only variable, but also unknown during allocation.
Self modifying codeWhen the executed code modify it self, the TB is re-translated into differentspace. thus result in many memory allocation while only the last one is needed.
Low overheadWe need to predict if the the replacement cache overhead remain below the costof cache flush, otherwise, we should simply flush the entire cache.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 17 / 25
![Page 25: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/25.jpg)
Implementation constraints
Variable TB sizeIn basics cache algorithms, evicting one entry is always sufficient to bring an other,but in our case, TB size is not only variable, but also unknown during allocation.
Self modifying codeWhen the executed code modify it self, the TB is re-translated into differentspace. thus result in many memory allocation while only the last one is needed.
Low overheadWe need to predict if the the replacement cache overhead remain below the costof cache flush, otherwise, we should simply flush the entire cache.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 17 / 25
![Page 26: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/26.jpg)
Implementation constraints
Variable TB sizeIn basics cache algorithms, evicting one entry is always sufficient to bring an other,but in our case, TB size is not only variable, but also unknown during allocation.
Self modifying codeWhen the executed code modify it self, the TB is re-translated into differentspace. thus result in many memory allocation while only the last one is needed.
Low overheadWe need to predict if the the replacement cache overhead remain below the costof cache flush, otherwise, we should simply flush the entire cache.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 17 / 25
![Page 27: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/27.jpg)
IV- Preliminary Results
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 18 / 25
![Page 28: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/28.jpg)
GoalsSimulate LRU & LFU Algorithms,Compare cache hit ratio,Evaluate overhead of each algorithm.
AssumptionsWe ignore TB size & cache size,Quota of retained entries is 1/5,Cache size is just limited by number of TB,
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 19 / 25
![Page 29: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/29.jpg)
GoalsSimulate LRU & LFU Algorithms,Compare cache hit ratio,Evaluate overhead of each algorithm.
AssumptionsWe ignore TB size & cache size,Quota of retained entries is 1/5,Cache size is just limited by number of TB,
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 19 / 25
![Page 30: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/30.jpg)
Execution ratio = (executions/translation)
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 20 / 25
![Page 31: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/31.jpg)
LFU cache hit ratio
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 21 / 25
![Page 32: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/32.jpg)
LRU cache hit ratio
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 22 / 25
![Page 33: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/33.jpg)
Perspectives
find a suitable cache replacement policy that take care of implementationconstraints.use a dynamically variable quota for retained entries.add small op-code buffer to optimize re-translation of self modifying code.divide translation cache into multiple space to optimize partial cache flush.
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 23 / 25
![Page 34: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/34.jpg)
Bibliography
QEMU Just-In-Time Code Generator and System Emulation - cmchao(March 15,2010).QEMU internals - Chad D. Kersey (January 28, 2009).QEMU, a Fast and Portable Dynamic Translator - Fabrice Bellard (USENIX2005 Annual).Performance Evaluation of Traditional Caching Policies on A Large Systemwith Petabytes of Data - 2012 IEEE Seventh International Conference onNetworking, Architecture, and Storage
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 24 / 25
![Page 35: Translation Cache Policies for Dynamic Binary Translation](https://reader034.vdocuments.mx/reader034/viewer/2022051209/548177ff5906b5f06c8b4681/html5/thumbnails/35.jpg)
Thanks for your attention !
Feel free to ask any question !
Saber F. (TIMA SLS ) ENSI 18 Avril 2013 25 / 25