MAM example

VMM application package offers capability to dynamically manage memory shared between multiple 
clients via Memory Allocation Manager (MAM). MAM helps to simulate HW memory usage patterns and 
guarantees memory block allocation based on constraints. This utility is a set of four base 
classes with configurable memory address range and allocation scheme.


1. vmm_cfg: This class is used to specify the memory managed by an instance of a "vmm_mam" 
memory allocation manager class.


2. vmm_mam: This class is a memory allocation management utility similar to C's malloc() and 
free(). A single instance of this class is used to manage a single, contiguous address space.


3. vmm_mam_allocator: An instance of this class is randomized to determine the starting offset 
of a randomly allocated memory region. This class can be extended to provide additional 
constraints on the starting offset.


4. vmm_mam_region: This class is used by the memory allocation manager to describe allocated 
memory regions. Instances of this class should not be created directly.




VMM MAM Flow:


* "vmm_mam" class uses "vmm_cfg" class handle to determine the minimum, maximum addresses 
and difference allocation schemes (mode and locality) of a memory space. A memory space can 
be reconfigured with new min, max and allocation scheme at run-time through "vmm_cfg" class 
with exception that number of bytes per memory location cannot be modified once a "vmm_mam" 
instance has been constructed and all currently allocated regions must fall within the new 
address space.
 
* On every call of request_region() function "vmm_mam" randomize "vmm_mam_allocator" instance 
to determine start_offset of randomly allocated memory region. This region is represented by 
an instance of "vmm_mam_region" class.


* Now if this "vmm_mam" is associated with a "vmm_ral_mem" instance, randomly allocation 
"vmm_mam_region" can be used to perform read/write operation on actual memory block.




In cases default selection constraints work fines but user might want to add new variables 
to "vmm_mam_region" and has additionally constraints (in "vmm_mam_allocator") to start_offset 
of memory region. Also for debugging purpose it could be require printing out values of user 
defined variables along with address range of randomly allocated region. The attached example 
demonstrates three possible user requirements:


1. Additional constraints over start_offset by adding new variables.
   This can be easily done by extending "vmm_mam_allocator" class and then pass instance of extended 
class to vmm_mam::request_region() function to replace default allocator.


   class cust_allocator extends vmm_mam_allocator;
     bus_width attribute;
     ...
     constraint cust_allocator_attri{
       (this.attribute==BIT16)->this.start_offset[0:0]==1'b0;
     ...




2. Has a customized vmm_mam::request_region() function which can take user defined variables as 
input arguments to constraint "vmm_mam_region" allocation.
   In this example customized vmm_mam::request_region() got a wrapper around it to have user defined 
variables as argument. Internally it construct a allocator and calls super.request_region(). User 
vmm_mam class keep a track of allocated regions which will get queried while calling release_region().


   class cust_mam extends vmm_mam;
     function cust_mam_region cust_request_region(bus_width attribute=...);
       ...
       region=super.request_region(...);
       cust_request_region = new(region.get_start_offset(),...);
       ...
       this.cust_in_use.push_back(cust_request_region);
     ...


     function void release_region(cust_mam_region cust_region);
       ...
       foreach(this.in_use[i]) begin
         ... 
         super.release_region(this.in_use[i]);
         this.cust_in_use.delete(i);
   ...




3. Adding new variables to "vmm_mam_region" and overwrite psdisplay() of  "vmm_mam" and "vmm_mam_region" 
to print out values of these variable for debugging purpose.
   These variables (in example owner for a memory region) are added by extending "vmm_mam_region" and 
populated in extension of "vmm_mam" after getting a "vmm_mam_region" from request_region() function. 
Even instances of new "mam_region" class should not be created directly. Both vmm_mam_region::psdisplay() 
and vmm_mam::psdisplay() needs to be overridden for this purpose. In vmm_mam_region::psdisplay() print 
values of user variables and then just call super.psdisplay(). New implementation of  vmm_mam::psdisplay()
will just call psdisplay() for all allocated regions.


   class cust_mam_region extends vmm_mam_region;
     function string psdisplay(string prefix = "");
       ... 
       psdisplay ={$psprintf("[%s]: ",attribute.name),
       $psprintf("[%s]",super.psdisplay())};
   ...


   class cust_mam extends vmm_mam;
     function string psdisplay(string prefix="");
       foreach (this.cust_in_use[i]) begin
       $sformat(psdisplay, "%s%s   %s\n", psdisplay, prefix, this.cust_in_use[i].psdisplay());
   ...




Adding only constraint to start_offset is very simple in MAM as explain above and doesn't need extension 
of any class other than "vmm_mam_allocator". Adding user define variables requires overriding of few 
functions, as shown in example, and rest can be used at it is. There is absolutely no change in use model.




Example:
MAM is build inside vmm_subenv to re-use it from block level to system level. Note that a memory does NOT 
actually exist in this example. The intent of the example is to show the how MAM can be customized to 
have additional constraints and user variables.  Attached tarball (mam.tar.gz).




To run it:
>  make run


At first 10 regions will be allocated, then after releasing all these regions MAM is reconfigured to new 
min/max addresses and again allocates new regions. Regions are requested on the basic of allocator 
instance or by the custom made function which takes user variables as arguments.




Cust_mam.sv
This file has customized classes extended from vmm_mam_region, vmm_mam and vmm_mam_allocator.




tb_subenv.sv
Subenv access vmm_mam handle via constructor and exercise all MAM function/tasks.
内容概要:本文详细介绍了CCF-GESP认证的学习资源与知识点指南,分为官方资源与平台、知识点学习与解析、备考策略与工具、实战项目与进阶资源以及学习工具推荐五个部分。官方资源包括CCF数字图书馆提供的免费真题库、一站式学习平台和GESP官网的最新真题下载及考试环境说明。知识点学习部分涵盖Python、C++和图形化编程(Scratch)的核心内容与实战案例。备考策略方面,提出了基础、强化和冲刺三个阶段的分阶段计划,并强调了在线题库模拟测试与社区交流的重要性。实战项目与进阶资源则为不同编程语言提供了具体的应用场景,如Python的智能客服机器人和C++的并行编程与嵌入式开发。最后,推荐了多种学习工具,如代码编辑器VS Code、模拟考试平台和社区支持渠道。 适合人群:准备参加CCF-GESP认证考试的考生,特别是对Python、C++或Scratch编程语言有兴趣的学习者。 使用场景及目标:①帮助考生系统化地学习官方资源,熟悉考试形式和内容;②通过分阶段的备考策略,提高应试能力和编程技能;③利用实战项目和进阶资源,增强实际编程经验和解决复杂问题的能力。 阅读建议:建议考生按照文章中的分阶段备考策略逐步推进学习进度,充分利用官方提供的资源进行练习和模拟测试,并积极参与社区交流以获取更多备考经验和疑难解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值