1.å¦ä½ä½¿ç¨oprofile对软件åprofiling
å¦ä½ä½¿ç¨oprofile对软件åprofiling
ããå ³äºXilinx Zynq-带æ¥çæ°çç³»ç»è®¾è®¡æè·¯ï¼ä»¥åProfilingç对象libjpegï¼åæå·²ç»æè¿°è¿äºï¼åæ¤ä¸åèµè¿°ã
ããä¸. Oprofileç®ä»
ããProfilingæ¯å¯¹ä¸åæ§è½ç¹å¾çæ°æ®çå½¢å¼åæ»ç»æåæï¼å®é常以å¾å½¢å表çå½¢å¼åºç°ãå®æä¾ä¸ºç¹å®çå¤çå¨äºä»¶æ¶éçéæ ·ç¾åæ°ææ° éï¼æ¯å¦cache miss rateãTLB miss rateççãä¸è¬æ¥è¯´ï¼ä¸»è¦ç®çæ¯ä¸ºäºæ¾åºè½¯ä»¶ä¸çæ§è½ç¶é¢ï¼ç¶åæé对æ§çä¼å以æå软件çæ´ä½æ§è½ã
ããOprofile æ¯ç¨äº Linux çè¥å¹²ç§è¯æµåæ§è½çæ§å·¥å ·ä¸çä¸ç§ãå®å¯ä»¥å·¥ä½å¨ä¸åçä½ç³»ç»æä¸ï¼å æ¬ARM,paraview源码解析 PowerPC, MIPS, IA, IA å AMD Athlonççãå®çå¼éå¾å°ï¼ä»Linux 2.6 çèµ·ï¼å®è¢«å å«è¿äºLinuxå æ ¸ä¸ã
ããOprofileå¯ä»¥æ¶éæå ³å¤çå¨äºä»¶çä¿¡æ¯ï¼å¸®å©ç¨æ·è¯å«è¯¸å¦å¾ªç¯çå±å¼ãcacheç使ç¨çä½ãä½æçç±»å转æ¢ååä½æä½ãé误é¢æµè½¬ç§» çé®é¢ãOprofileæ¯ä¸ç§ç»ç²åº¦çå·¥å ·ï¼å¯ä»¥ä¸ºæ令éæè 为å½æ°ãç³»ç»è°ç¨æä¸æå¤çä¾ç¨æ¶ééæ ·ãOprofile éè¿åæ ·æ¥å·¥ä½ã使ç¨æ¶éå°çè¯æµæ°æ®ï¼ç¨æ·å¯ä»¥å¾å®¹æå°æ¾åºæ§è½é®é¢ã
ããéè¿çå¯CPUçhardware eventsï¼oprofileå¯ä»¥å¨è¿è¡ç¶æä¸å¯¹æ´ä¸ªLinuxç³»ç»è¿è¡profilingãProfilingç对象å¯ä»¥æ¯Linux kernel (å æ¬modulesåinterrupt handlers), shared librariesæè åºç¨ç¨åºã
ããä»0.9.8çæ¬å¼å§ï¼oprofileæ¯æPerf_events profiling mode模å¼ãåºç¨ç¨åºoperf被ç¨æ¥æ§å¶profilingè¿ç¨;èå¨legacy modeä¸ï¼æ¯éè¿opcontrolèæ¬åoprofiled daemonæ¥å®æçãOperfä¸å象legacy modeé£æ ·éè¦OProfile kernel driverï¼å®ç´æ¥åLinux Kernel Performance Events Subsystemæ交éã使ç¨operfï¼å°±å¯ä»¥ç¨æ®éç¨æ·ç身份æ¥profilingç¨æ·çåºç¨ç¨åºäºï¼å½ç¶å¦æéè¦å¯¹æ´ä¸ªç³»ç»æ¥profiling çæ¶åè¿æ¯éè¦rootæéçã
ããå¦æ硬件ä¸æ¯æOProfile使ç¨performance countersï¼OProfileå°±åªè½å·¥ä½å¨Timer Modeä¸äºãTimer Modeåªè½å¨legacy profiling modeä¸ä½¿ç¨ï¼å³åªè½éè¿opcontrolèæ¬æ¥æ§å¶ã
ããOprofileçwebsite为ï¼piled (JIT) code
ãã? å¯ä»¥å¯¹æ´ä¸ªç³»ç»åprofiling
ãã? å¯ä»¥è§å¯CPUå é¨çç»èï¼ä¾å¦cache miss rate
ãã? å¯ä»¥å¤æºä»£ç åannotation
ãã? å¯ä»¥æ¯æinstruction-levelçprofiling
ãã? å¯ä»¥çæcall-graph profiles
ããä¸è¿OProfileä¹ä¸æ¯ä¸è½çï¼å®ä¹æèªå·±çå±éæ§ï¼
ãã? åªè½å¨x, ARM, åPowerPCæ¶æä¸çæcall graph profiles
ãã? ä¸æ¯æ%精确çinstruction-level profiling
ãã? 对dynamically compiled (JIT) code profilingçæ¯æè¿ä¸å®åã
ããæ 论å¦ä½ï¼Oprofileçåè½é½æ¯gprofè¦å¼ºå¾å¤ï¼ä»£ä»·æ¯é 置起æ¥ä¼æ¯è¾éº»ç¦ã
ããäº. ç¼è¯Oprofile
ããé¦å æ好å¨Linux kerneléé¢éä¸Oprofile driverï¼ä»¥è·å¾å ¨é¢çæ¯æã
ããä¸è½½Linux kernel Sourceï¼ä»/Xilinx/linux-xlnx å¯ä»¥ä¸è½½å°Xilinxæä¾çéªè¯å¥½çå æ ¸ãå¦æä¸æ¹ä¾¿ä½¿ç¨Linuxä¸çgitå·¥å ·ï¼å¯ä»¥åå»é¡µé¢ä¸çreleasesæ¾å°ç¸åºççæ¬ä¸è½½tar ballãä¸è½½çæ¶åæ好étar.gzæ ¼å¼çï¼èä¸æ¯zipæ ¼å¼çï¼å 为åè å¨å¤çsymbol linkçæ¶åæå¯è½ä¼åºé®é¢ã
ããå 为ç¬è 使ç¨çæ¯Xilinx Linux pre-built .7ï¼æ以è¿éä¸è½½çæ¯linux-xlnx-xilinx-v.7.tar.gz
ãã解å缩åï¼ç¨ä»¥ä¸å½ä»¤è°åºLinux kernelçé ç½®çé¢ï¼
ããexport ARCH=arm
ããexport CROSS_COMPILE=arm-xilinx-linux-gnueabi-
ããmake xilinx_zynq_defconfig
ããmake xconfig æè make menuconfig
ããå¨é ç½®çé¢ä¸å°ä»¥ä¸ä¸¤é¡¹å¾ä¸ï¼
ããGeneral setup --->
ãã[*] Profiling support
ãã<*> OProfile system profiling
ããç¶åmake uImageå³å¯çææ°çuImageï¼ç¨æ¥æ¿æ¢Xilinx Linux pre-built .7ä¸çLinux kernel imageãåæ¶æ们ä¹éè¦vmlinuxæ¥æ£æ¥profilingçç»æã
ããOprofileéè¦popt, bfd, libertyåºï¼è¦å¨åµå ¥å¼åæ¿ä¸ä½¿ç¨è¿äºåºï¼éè¦æå·¥å®æ交åç¼è¯ã
ããé对popt 1.7ï¼ç¨ä»¥ä¸å½ä»¤å®æç¼è¯ï¼
ãã./configure --prefix=/home/wave/xilinx/oprofileprj/rootfs --host=arm-xilinx-linux-gnueabi --with-kernel-support --disable-nls && make && make install
ããé对binutils 2.ï¼ç¨ä»¥ä¸å½ä»¤å®æç¼è¯ï¼
ãã./configure --host=arm-xilinx-linux-gnueabi --prefix=/home/wave/xilinx/oprofileprj/rootfs --enable-install-libbfd --enable-install-libiberty --enable-shared && make && make install
ããä¸è¿--enable-install-libiberty没æææï¼æ以éè¦æå·¥ælibiberty.aålibiberty.hæ·è´å°ç¸åºçä½ç½®ã
ããé对oprofile 0.9.9ï¼ç¨ä»¥ä¸å½ä»¤å®æç¼è¯ï¼
ãã./configure --host=arm-xilinx-linux-gnueabi --prefix=/home/wave/xilinx/oprofileprj/rootfs --with-kernel-support --with-binutils=/home/wave/xilinx/oprofileprj/rootfs && make && make install
ããé ç½®è¿ç¨ç»æåå¯è½ä¼æ以ä¸æ示ï¼å 为没ææç®ç¨GUIåprofile JITed codeï¼æ以ç´æ¥å¿½è§ä¹ã
ããconfig.status: executing libtool commands
ããWarning: QT version 3 was requested but not found. No GUI will be built.
ããWarning: The user account 'oprofile:oprofile' does not exist on the system.
ããTo profile JITed code, this special user account must exist.
ããPlease ask your system administrator to add the following user and group:
ããuser name : 'oprofile'
ããgroup name: 'oprofile'
ããThe 'oprofile' group must be the default group for the 'oprofile' user.
ããå°ç¼è¯å®æçuImageï¼vmlinuxï¼oprofile binaryï¼éæ°ç¼è¯ç没æ-pgçlibjpeg binary以åtool chainçlibcæå æ¾å°SDå¡ä¸ï¼åå¤å¨ZCå¼åæ¿ä¸å°è¯profile djpegã
ããä¸. è¿è¡Oprofile
ããæ£å¸¸å¯å¨åµå ¥å¼Linuxåï¼å¨å¼åæ¿çconsoleä¸ä¸æ¬¡è¾å ¥ä»¥ä¸å½ä»¤ï¼
ããmount /dev/mmcblk0p1 /mnt
ããmkdir -p /home/root/work
ããcd /home/root/work
ããtar zxvf /mnt/jpeg-bin-nopg.tar.gz
ããcd jpeg-bin/bin
ããcp /mnt/park-x.jpg .
ããexport LD_LIBRARY_PATH=/home/root/work/jpeg-bin/lib
ããcd /home/root/work
ããtar zxvf /mnt/rootfs.tar.gz
ããcd rootfs
ããchown root:root -R
*ããcp -R bin/* /usr/bin
ããcp -R lib/* /lib
ããcp /bin/which /usr/bin
ããcp /bin/dirname /usr/bin
ããmkdir -p /home/wave/xilinx/oprofileprj/rootfs/share
ããcp -R ./rootfs/* /home/wave/xilinx/oprofileprj/rootfs
ããcd /home/root/work
ããtar zxvf /mnt/libc.tar.gz
ããcp ./lib/libstdc*.* /lib
ããmkdir -p /home/wave/xilinx/libjpeg
ããcd /home/wave/xilinx/libjpeg
ããtar zxvf /mnt/jpeg-9.tar.gz
ããcp /mnt/vmlinux /home/root/work
ããcd /home/root/work/jpeg-bin/bin
ããopcontrol --init
ããopcontrol --vmlinux=/home/root/work/vmlinux
ããopcontrol --setup --event=CPU_CYCLES:::0:1 --session-dir=/home/root/
ããoperf --vmlinux /home/root/work/vmlinux ./djpeg -bmp park-x.jpg > result.bmp
ããopreport -l ./djpeg
ããå®æè¿ä¸æ¥åï¼æ们就å¯ä»¥çå°profilingçç»æäºï¼å¨ç¬è çå¹³å°ä¸çå°çå 容ç主è¦é¨åå¦ä¸ï¼
ããroot@zynq:~/work/jpeg-bin/bin# opreport -l ./djpeg
ããUsing /home/root/work/jpeg-bin/bin/oprofile_data/samples/ for samples directory.
ããCPU: ARM Cortex-A9, speed MHz (estimated)
ããCounted CPU_CYCLES events (CPU cycle) with a unit mask of 0x (No unit mask) count
ããsamples % image name symbol name
ãã . libc-2..so /lib/libc-2..so
ãã 7. libjpeg.so.9.0.0 ycc_rgb_convert
ãã 7. libjpeg.so.9.0.0 jpeg_idct_x
ãã 7. libjpeg.so.9.0.0 decode_mcu
ãã 6. libjpeg.so.9.0.0 jpeg_idct_islow
ãã 6. djpeg finish_output_bmp
ãã 2. libjpeg.so.9.0.0 jpeg_fill_bit_buffer
ãã 1. djpeg put_pixel_rows
ãã 0. vmlinux __copy_from_user
ãã 0. libjpeg.so.9.0.0 decompress_onepass
ãã 0. libjpeg.so.9.0.0 jpeg_huff_decode
ãã 0. vmlinux get_page_from_freelist
ãã 0. vmlinux __memzero
ãã 0. vmlinux __copy_to_user_std
ãã 0. vmlinux _raw_spin_unlock_irqrestore
ãã 0. vmlinux do_page_fault
ãã 0. vmlinux __generic_file_aio_write
ãã 0. vmlinux _raw_spin_unlock_irq
ãã 0. vmlinux free_hot_cold_page
ãã 0. vmlinux vector_swi
ãã 0. vmlinux handle_pte_fault
ããä»ç»æä¸æ们å¯ä»¥çå°libjpeg.so.9.0.0, djpegåvmlinuxä¸çsymbol nameå·²ç»å¯ä»¥è¢«æ£ç¡®ç解æåºæ¥äºï¼ågprofçç»æåºæ¬ä¸è´ãç¸æ¯gprofï¼oprofileå¯ä»¥å¨æ´å¤§çèå´å å®æprofilingã
ããæ们è¿å¯ä»¥ç¨ä»¥ä¸å½ä»¤è§å¯æºä»£ç ä¸ç¹å®è¡çæ§è¡æ¶é´ï¼è¿ä¸æ¥ç¼©å°ä¼åçèå´ï¼è¾¾å°äºåååçææã
ããopannotate --source ./djpeg > opannotate.txt
ããå. å°ç»
ããéè¿å®éªï¼æ们å¯ä»¥çå°Oprofileå¯ä»¥æä¾æ´ä¸°å¯çprofilingç»æï¼å¯ä»¥æ´å¥½ç帮å©å¼åè æ¾å°ç¶é¢ï¼éè¿æé对æ§çä¼åæå软件 æ§è½;profilingçç»æä¹å¯ä»¥å¸®å©å¼åè å°æ§è½ç¶é¢ä»£ç éè¿Xilinx HLSå·¥å ·ç¨ç¡¬ä»¶å éå¨æ¥å®ç°ï¼ä»è为è¿ä¸æ¥æåæ´ä¸ªåµå ¥å¼ç³»ç»çæ§è½æå¼äºå¤§é¨ã
2024-11-23 08:13
2024-11-23 06:57
2024-11-23 06:53
2024-11-23 06:48
2024-11-23 06:41
2024-11-23 06:33
2024-11-23 06:05
2024-11-23 06:05