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.
-- ============================================= -- Prosody IM 配置文件 (终极全功能版 - 已修复) -- 域名: szrengjing.com -- 生成时间: 2025-04-05 -- 用途: XMPP + MUC + BOSH + WebSocket + HTTP 文件上传 + 推送 + VoIP + 书签 + 归档 -- 状态: 生产就绪 ✅ 安全稳定 -- =================================------------ -- 数据存储路径(必须存在且可写) datastore = "/var/lib/prosody" data_path = "/var/lib/prosody" -- PID 文件位置(systemd 使用) pidfile = "/run/prosody/prosody.pid" -- 日志配置:输出到文件 log = { info = "/var/log/prosody/prosody.log"; error = "/var/log/prosody/prosody.err"; debug = false; -- 生产环境关闭 debug } -- 服务器管理员账号(可用于 ad-hoc 命令) admins = { "admin@szrengjing.com" } -- 默认身份验证方式 authentication = "internal_hashed" -- 全局加密策略(强制 TLS) c2s_require_encryption = true s2s_require_encryption = true s2s_secure_auth = true -- SSL/TLS 设置(现代安全配置) ssl = { protocol = "tlsv1_2+"; ciphers = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256"; } -- === HTTP/BOSH/WebSocket 设置 === -- 显式启用 HTTP 服务并绑定到本地回环(Nginx 反向代理用) http_ports = { 5280 } http_interfaces = { "127.0.0.1" } -- 允许浏览器跨域请求(JSXC 所需) cross_domain_bosh = true cross_domain_websocket = true -- 将通过 BOSH/WebSocket 连接视为安全连接(避免状态变为 away) consider_bosh_secure = true consider_websocket_secure = true -- 🔐 全局认证密钥(用于签名上传 token)✅ 必须放在顶部 authentication_secret = "FeFn3Tus1F7LHt+wOfBOAbQJjJ6yxjMoQ9ZIxRBD1Y0=" -- 启用的核心模块(全局默认)✅ 包含 bosh 和 http_file_share modules_enabled = { -- 基础功能 "roster"; "saslauth"; "tls"; "dialback"; "disco"; "private"; "vcard"; "vcard4"; "vjud"; "version"; "uptime"; "time"; "ping"; "pep"; "register"; -- 消息与状态 "carbons"; "mam"; "smacks"; "csi"; "csi_simple"; "blocklist"; "bookmarks"; "lastactivity"; "account_activity"; "invites"; "invites_register"; -- 管理接口 "admin_adhoc"; "admin_shell"; "admin_socket"; "adhoc"; "webpresence"; -- HTTP 服务支持 "http"; "bosh"; "websocket"; "http_files"; "http_altconnect"; "cron"; "external_services"; "http_file_share"; -- ✅ 添加在此处,确保加载 } -- ==================== 虚拟主机配置 ======================== VirtualHost "localhost" enabled = true -- 本地调试用途 VirtualHost "szrengjing.com" enabled = true ssl = { key = "/etc/letsencrypt/live/szrengjing.com/privkey.pem"; certificate = "/etc/letsencrypt/live/szrengjing.com/fullchain.pem"; } authentication = "internal_hashed" default_archive_policy = "always" archive_expires_after = "1y" allow_registration = false motd_text = "欢迎使用 szrengjing.com 的 XMPP 服务!" -- 显式启用所需模块(覆盖全局设置) modules_enabled = { "bosh"; "websocket"; "mam"; "carbons"; "smacks"; "vcard"; "vcard4"; "blocklist"; "bookmarks"; "lastactivity"; "pep"; "ping"; "disco"; "roster"; "private"; "vjud"; -- 支持通过 IQ 查询用户列表(类似 Jabber User Directory) "http_files"; -- ✅ 支持静态页面 } -- 自定义 HTTP 页面路径 http_paths = { files = "/var/www/xmpp"; -- 存放 index.html 等静态页面 } -- ==================== 多用户聊天组件 (MUC) ================== Component "conference.szrengjing.com" "muc" name = "szrengjing.com 聊天房间" restrict_room_creation = false max_history_messages = 100 persistent_roles = true mam = true modules_enabled = { "muc_mam"; -- 房间消息归档(XEP-0313) "vcard"; -- 房间头像支持 "presencetools";-- 工具类 Presence 处理 "room_config_default"; -- 设置默认房间选项 } -- 默认房间配置(新建房间自动应用) room_config_default = { ["muc#roomconfig_persistent"] = true; ["muc#roomconfig_publicroom"] = true; ["muc#roomconfig_moderatedroom"] = false; ["muc#roomconfig_passwordprotectedroom"] = false; ["muc#roomconfig_whois"] = "anyone"; ["allow_subscription"] = true; } -- ==================== HTTP 文件上传组件 ====================== Component "upload.szrengjing.com" "http_file_share" http_host = "szrengjing.com" http_external_url = "https://szrengjing.com/upload/" max_file_size = 50 * 1024 * 1024 -- 50MB 单文件上限 file_quota = 100 * 1024 * 1024 -- 每用户 100MB/月 quota_period = "month" modules_disabled = { "s2s" } -- 关闭不必要的 S2S ssl = false -- 显式禁用 TLS,交由 Nginx 处理 -- ==================== 外部服务发现 (STUN/TURN for VoIP) ====== Component "stun.szrengjing.com" "external_services" component_secret = "your-stun-turn-secret-key" services = { { type = "stun"; host = "szrengjing.com"; port = 3478; }, { type = "turn"; host = "szrengjing.com"; port = 3478; transport = "udp"; ttl = 86400; password = "your-turn-password"; } } -- ==================== 推送通知支持 (可选) ===================== -- 若使用 mod_push_appserver 或 Cloud Push -- 注意:需要额外安装 Lua 插件 -- -- Component "push.szrengjing.com" "push_proxy" -- app_id = "com.example.xmppapp" -- secret = "your-push-secret" -- service_url = "https://fcm.googleapis.com/fcm/send" -- ==================== 定时任务示例(清理日志等)============= -- 使用 cron 模块执行周期性操作 cron = { -- 每天凌晨清理一次过期的上传缓存(如果模块支持) -- {"0", "0", "*", "*", "*", function() module:log("Cleaning expired uploads...") end}; } 哪就好好检查下 全配置5280的;不要在出什么问题了 修复生成完整版源文件
11-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值