DSP学习笔记(一)| Xtensa 使用例程记录

1,163 阅读6分钟

Dhrystone Example

Using the Active Set to Vary Test Runs

Question 1

Once the simulation is complete, look at the Console view at the bottom of the Xplorer window. What is the Dhrystone MIPS/MHz of the sample_config processor? Assuming that the processor operates at 200MHz, what is the MIPS rating?

企业微信截图_17058941397851.png

Answer:
Approx. 1.4 MIPS/MHz, about 280 MIPS @ 200Mhz.

Question 2

We will now benchmark other sample processor configurations. To perform the benchmark across other processor targets, change the active processor configuration and click Run (the build is done automatically). What is the MIPS/Mhz rating of the following processor configurations:

  • sample_controller
  • sample_flix

Answer:
For sample_controller:

sample_controller.png

For sample_flix:

image.png

Go to the System Overview, and see the configuration build details then HTML single page processor build overview.

Dhrystone benchmark 包含许多program loops, 因此有zero-overhead loop hardware的处理比没有这个的会有更好的性能。同样地,支持8-byte instruction words的处理器可以对指令多重操作,可以用指令级的并行性。

Question 3

Use the System Overview, examine each configuration build details of the configuration you used. Find which processor configurations have zero-overahead loops and support 8-byte instruction widths. Why does the sample_controller have the lowest performance? Why does the sample_flix have the best performance?

Answer:
sample_config has Zero overhead loops selected.
sample_config has Max instruction width 3.

sample_controller hasn't Zero overhead loops selected.
sample_controller has Max instruction width 3.
Futhermore, the sample_controller has no cache at all, while sample_config has both I- and D-cacha.
Hence, it has the lowest performance.

image.png

sample_flix has Zero overhead loops selected.
sample_flix has Max instruction width 8.

Creating a Build Target

  • Optimization Level at O3
    企业微信截图_17058941397851.png

  • Optimization Level at O1

image.png

  • Optimization Level at HiOpt
    Optimization Level: O3
    Enable interprocedural optimization: Yes
    Include debug information: g

Question 4

What performance increase percentage is achieved using the HiOpt build target?

image.png

Answer:
HiOpt boosts performance in the range of 60%-100%.

Profiling

详细的运行时统计数据可以通过指令集模拟器的内置profiling特性获得。

Benchmark

  • Profile(cycles): 此视图显示了一个程序函数表以及每个函数对应的循环计数。
  • Profile disassembly: 此视图显示了用每个指令的周期计数注释的反汇编代码。
  • Pipeline: 通过处理器pipeline显示所选函数的instruction flow.

Question 5

The first l32r instruction show a 3-cycle bubble(the R stage is extended by three additional cycles/R阶段被延长了额外的三个周期). The following s32i instruction shows a 1-cycle bubble. What are the sources of these bubbles(hint- try hovering)?

image.png

image.png
l32r的3个周期气泡是由于前一个调用指令的分支惩罚(the branch penalty of the previous call instruction)。s32i的1个周期气泡是由于前一个读取指令的数据依赖性联锁(data dependency interlock of the previous load instruction)。

Notes on the profile view

  • 请记住,在Profile视图中的Profile(cycles)窗口中单击一个函数名,如main,对于在中间窗口中查看函数的源码,以及在Profile disassembly窗口中查看函数的反汇编是非常重要的。此外,除非Build Target设置了“Include debug information”属性,否则不会在源码视图上注释周期计数,并在Profile disassembly中注释周期计数将为0.
  • 此外,当在“Profile”视图中单击source窗口中的source line时,它将不会在Profile disassembly视图中上下滚动。它将高亮显示与source line相对应的反汇编行,但你必须手动上下滚动才能看到它们高亮显示。

Creating a Launch

学习如何创建用于调试、运行或配置分析的启动程序。
Xtensa Xplorer使用launch(也称为run configuration)的概念来记住二进制文件是如何执行的。它收集所有的运行时设置(例如,ISS设置、profiling和命令行参数),并为它们提供一个名称,以便您可以轻松地运行(或调试)再次启动。

单击Run/Profile/Debug这些按钮中的任何一个将启动Xplorer创建的默认运行启动,称为该按钮的自动启动
与"Run"按钮关联的自动启动将在ISS上执行应用程序的二进制文件,不需要profiling和memory modeling(没有memory modeling,则cycle counts和profiling info假设所有的指令和数据访问都在本地内存之外. Enables memory modeling and runs the simulation with zero read/write delay)。与"Profile"按钮关联的自动启动将启用配置分析,与"Debug"按钮相关的自动启动将启动调试器。

但是,如果代码/数据resides在非本地内存中(即跨PIF连接的内存),我们将需要创建一个能够实现内存建模的启动程序。

Profile - Profile Congiguration - Simulator具有一个Fast-Funtional模式(也称为TurboXim),这将大大加快模拟时间。假设在Fast-Funtional模式下运行时,模拟器跟踪指令(track instructions),而不是跟踪cycles,并反馈假设每个周期执行一条指令的运行时结果。

Debugging

Xtensa Xplorer调试器构建在命令行调试器xt-gdb之上。调试器的启动定义与为执行而创建的启动定义相同。当使用调试器时,最好将编译器的优化级别设置为零。这是因为编译器优化策略会创建二进制代码,这使得调试器很难映射回C源代码中。

Command Line

Xtensa工具提供了一个基于LLVM项目的C/C++编译器,称为XT-CLANG。

Linker Support Packages

Memory Map

在System Overview -- Configurations -- sample_controller下,双击sample_controller.
查看Configuration details

Identifying the different Sections in the Compiled Code example.out

了解一个典型的Xtensa程序的各个部分。

image.png

The sections that constitute the program: ending with .text .data .bss .rodata...

  • .text部分,其中包含指令代码。
  • .data部分,其中包含初始化的全局变量。
  • .bss部分(或-common block),其中包含未初始化(或零初始化)的全局变量。
  • .rodata部分,其中包含只读全局变量、常量、跳转表等。
  • .literal部分,包含代码中使用的literals(32位常量)。这些部分是特定于Xtensa体系结构的。

Using Linker Support Packages

调查各种可用的LSP,并学习如何选择一个。
链接器支持软件包(LSP)包含内存映射、自动链接的代码/库和ROMING(read-only target image)选项。随Xtensa工具附带的常用LSP列表如下所示

  • sim
    sim LSP用于构建一个要在指令集模拟器(ISS)上执行的应用程序。sim LSP是一个功能齐全的LSP,它包含完整的newlib库和XTOS/HAL支持。如果没有指定任何,则这是默认的LSP。
  • sim-local
    sim-local LSP用于构建一个完全从本地指令和数据内存中执行的应用程序。这与之前在实验中所做的事情类似。但是,启动代码也被放置在本地内存中。
  • min-rt
    min-rt LSP用于构建一个可以在大多数系统或模拟中运行的应用程序。这个LSP使用XTOS/HAL,但没有任何board-specific的库支持,如字符I/O。
  • tiny
  • nort
    nort LSP用于构建不使用XTOS/HAL或库的应用程序。所有正在运行的代码和库都必须被显式地链接起来。
  • gdbio