已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
附录附录a high-performance asn.1 compilermichael sample and gerald neufelderror managementerror management is important, but it must be implemented without incurring too much cost for the common case where there are no errors. one method of streamlining error management is to eliminate it by assuming that the decoded values are always correct. this is not acceptable for a reliable implementation.to implement a complete yet light-weight error management scheme for the decoders, we used the setjmp and longjmp functions 23. previously, the availability of these functions was very system dependent; however, they are now part of the ansi standard c library. before decoding begins, set jmp is called to record the current environment (processor registers,etc.). the environment value set by setjmp is then passed into the decoding routine. every decoding routine takes this parameter. when the decoding routines encounter a serious error such as running out of memory for the decoded value, they call longjmp with the environment value they were given as a parameter, along with a unique error code. this returns execution directly to where setjmp was called along with the error code.the setjmp and longjmp based error management is simple and does not impact on the performance of decoding correctly encoded values (other than an extra parameter to each decoding routine). other error management techniques, such as passing back error codes, that the calling functions must check will affect the decoding performance even for correctly encoded values.buffer managementencoding and decoding performance is greatly affected by the cost of writing to and reading from buffers. thus, efficient buffer management is necessary. flexibility is also important to allow integration of the generated encoders and decoders into existing environments. to provide both of these features, the calls to the buffer routines are actually macros that can be configured as desired. they must be configured prior to compiling the encode/decode library and the generated code. since virtually all buffer calls are made from the encode/decode library routines, bufler routine macros should not bloat code size significantly. if a single, simple buffer type can be used in the target environment, the buffer routine macros can be defined to call the macros for the simple buffer type. this results in the buffer type being bound at the time the generated code is compiled, with no function call overhead from the encode or decode routines. however, this also means that the encode and decode library will only work with that buffer type.if multiple buffer formats must be supported at runtime, the buffer macros can be defined like the isode buffer calls, where a buffer type contains pointers to the buffer routines and data of user defined buffer type. this approach will hurt performance since each buffer operation will be an indirect function call. the backwards encoding technique used by snacc requires special buffer primitives that write from the end of the buffer towards the front. the decoder routines require forward buffer reading routines.memory managementlike buffer management, memory management is very important for efficient decoders. snacc decoders allocate memory to hold the decoded value. after the decoded value has been processed it is usually freed. the decoding and freeing routines in the library and the ones generated by snacc both use the memory manager. the decoders allocate memory with the asnlalloc routine and the freeing routines call asnlfree.the configuration header file allows the user to change the default memory manager prior to compiling the library and the generated code. snacc provides a particularly efficient memory manager, discussed shortly, called nibble memory.the memory manager must provide three routines: asnlalloc, asnlfr ee and checkasnlalloc. these memory routines should have the following interfaces:void * asnlalloc(unsigned longint size);void anslfree(void * ptr);int checkasnlalloc(void * ptr, env type env);the decoders assume that asnlalloc returns a zeroed block of memory. this saves explicit initialization of optional elements with null in the generated decoders. the env type parameter is used with the error management system for calls to longjmp.to change the memory management system the configuration file needs to be edited. for example, ifperformance is not an issue and you want to use calloc and free, the configuration file would be as follows:#include malloc.h#define asnlalloc(size) calloc(l, size)#define asnlfree(ptr) free (ptr)#define checkasnlalloc(ptr, env)if (ptr)-null)longjmp(env,-27);the nibble memory system does not need explicit flees of each component so the generated free routines are not needed. however, if you change the memory management to use something like malloc and free you should use the generated free routines. by default, snacc uses a nibble memory scheme to provide efficient memory management. nibble memory works by getting a large block of memory from the o/s for allocating smaller requests. when the decoded pdu is no longer required by the application the entire space allocated to the pdu can be freed by calling a routine that simply resets a pointer. there is no need to use the snacc generated free routines to traverse the entire data structure, freeing a piece at a time.if calloc and free are used for memory management instead of nibble memory, the generated free routines must be used to free the values. the generated free routines hierarchically free all of a pdus memory using a depth first algorithm.c+ designthe c+ backend of snacc was designed after the c backend had been written. the basic model that the generated c+ uses is similar to that of the generated c, but benefits from the object oriented features of c+.some cleaner designs were rejected either due to their poor performance or the inability of the available c+ compiler to handle certain language features. tags and lengths would fit nicely into their own classes, but performance was considerably worse than the technique used in the c model. the c design was retained in the c+ model for this reason. for error management, c+s try and catch 22 are obvious replacements for the setjmp and longjmp used by the c decoders. unfortunately, this is a newer c+ feature and was not yet supported. c+ templates are very attractive for type safe lists (for set of and sequence of) without duplicating code. since template support was weak in the available c+ compiler, templates were rejected. instead, each set of and sequence of type generates its own new class with all of the standard list routines.every asn. 1 type is represented by a c+ class with the following characteristics:1. inherits from the asntype base class.2. has a parameterless constructor.3. has a clone method, clone.4. has a pdu encode and decode method, benc and bdec.5. has a content encode and decode method, benc- content and bdeccontent.6. has top level interfaces to the pdu encode and decode methods (handles the setjmp, etc.) for the user, bencpdu and bdecpdu.7. has print method, pr int.the foliowing c+ fragment shows the class features listed above in greater detail: class foo: public asntype./ data memberspublic :foo() ;/ requires parameterless/ constructor/ pdu (tags/lengths/content) encode/ and decode routinesasnlen benc (buf_type b) ;void bdec(buf_type b, asnlen& bytesdecoded, env_type env) ;/ content encode and decode routinesasnlen benccontent (buf_type b) ;void bdeccontent(buf_type b, asntag tag, asnlen elmtlen, asnlen& bytesdecoded, env_type env) ;/ methods most likely to be used by/ your code./ returns non-zero for successint bencpdu(buf_type b, asnlen& bytesencoded) ;int bdecpdu(buf_type b, asnlen& bytesdecoded) ;void print(ostream& os) ;asntype* clone() ;in brief, the asntype provides a base class that has virtual benc, bmec and clone routines. the purpose of this class is to provide a generic asn. 1 type class that can be used to handle any and any defined by types. the clone* routine is used to generate a new instance (not a copy) by calling the constructor of the object that it is invoked on. this allows the any defined by type decoder to create a new, initialized object of the correct type from one stored in a hash table when decoding. the virtual bdec method of the newly created object is called from asnany classs bdec method. when encoding, the asnany objects call the virtual bdec method of the type they contain.conclusionsour study revealed that the majority of encoding and decoding time is spent in the following areas: writing to the send buffer during encoding reading from a receive buffer when decoding memory allocation for the decoded values data structure freeing the decoded data structure.each of these areas is examined to determine how they can be improved. however, even after optimization, these areas still consume a significant portion of the processor time during encoding and decoding.the results of the analysis indicate that the majority of time is being spent in primitive type encoding and decoding routines (which contain most of the calls to the buffer and memory routines) rather than the routines generated by the compilers. it is clear from these results that efficient encoders and decoders must be tuned to work well with the buffer structure and memory model being used. even highly tuned encoding rules such as per92 only achieved about 12 mbit/s on a mips r3260. either faster processors and memory or faster encoding and decoding techniques are necessary for the presentation layer to keep up with the potential rate at which data can arrive on todays high-speed networks. our results suggest several design rules that can aid in the development of efficient encoders and decoders: avoid intermediate representations such as idx buffers between the local representation and the fully encoded representation. choose the simplest buffer management system that your encoding rules and environment will allow. using inline procedures or macros is a significant advantage. choose a memory allocation/flee model that supports cheap allocations and frees. avoid hierarchical freeing if possible. design local data structures that minimize the number of allocations by eliminating unnecessary pointers. use a simple pre-encoding length calculation if the abstract syntax, protocol or encoding rules permit, to simplify buffer management for encoders.for the personnelrecord data structure, per92 is better than ber in performance and compression. however, the extent of the improvement greatly depends on the abstract syntax of the values being processed. abstract syntaxes that use subtyping may allow per92 to produce smaller encodings possibly at the cost of encoding and decoding speed.one-pass forward per92 encoders can be implemented; this allows performance and streaming to transport connections. finally, both ber and per encoders and decoders performed well in comparison to xdr and ndr encoders and decoders. however, the ber and per performance will decrease as the data becomes more numerically oriented.the snacc tool generates useful, efficient implementations, obvious future development would include handling the new language features of asn. i 92 and supporting different encoding rules such as per, xdr, and possibly c-based encoding rules (useful when archiving to disk). the snacc generated type tables need to be improved such that they contain subtyping information; subtyping information is necessary for per encoders and decoders.in general, the maximum throughput of encoding rules is limited by the lower bound of a simple memory copy of the pdu. in certain, limited cases, such as cbased encoding rules, this can be irrlproved upon by encoding in place.future research on the performance of encoding rulesis necessary. perhaps parallelism can be used to improve their throughput. c based encoding rules demonstrated that if certain assumptions can be made, a large performance increase can be had. for example, if hardware producers could use a common machine data representation standard then this type of performance improvement could be made. the translation of primitive types, which can be expensive (e.g. ber real values), would not be necessary.support for commonly used data structure features, such as multiple references to the same value and even cyclic references, should be examined. perhaps asn.1 can be extended with new language features and encoding rules to support this.acknowledgementthis work was made possible by grants from the canadian institute for telecommunications research.附录b 高性能的asn.1编译器michael sample 和 gerald neufeld错误管理错误管理是非常重要的,在常见的没有错误的情况下,它的实施必须不会产生太大的成本。一个简化的错误管理方法是假设解码值总是正确的。但这不是一个可靠的实施方法。为了实现一个完整的轻量级错误管理方案,我们使用了setjmp和longjmp函数。在此之前,这些功能的可用性视每一个系统而定,然而,它们现在是ans.1 c标准库的一部分。在解码开始之前,调用setjmp来记录当前运行的环境(处理器寄存器等)。当前环境变量通过setjmp来设置,然后传递到解码程序。每个解码程序都需要这个参数。当解码程序遇到了严重的错误时,例如内存溢出,则调用longjmp函数,获取当前环境下的错误代码,然后直接返回到错误代码出现的地方。setjmp和longjmp的错误管理机制,不会影响正确的编码解码过程(只是多了一个额外的参数)。其他的错误管理技术,例如用回调函数检查错误的代码段,这时可能会影响正确编解码的性能。缓冲管理从缓冲区写入和读取数据的成本很大的影响了编解码的性能。因此,有效的缓冲管理是必要的。现成的集成环境中,编码器和解码器的灵活性也是很重要的。为了具备上述功能特点,可以在缓冲区设置一定量的宏。与编码/解码库函数和一般的代码相比,宏具有更高的优先级。因为几乎所有的缓冲区都是通过编码/解码库函数调用,所以缓冲区的宏代码不应该设置太多。如果一个单一简单的缓冲区类型可以在目标环境中使用,缓冲区宏可以被定义为简单的缓冲区类型。这种类型的宏的调用是在一般的代码编译之后完成,所以不会占用编码和解码函数额外的开销。然而,这也意味着编码和解码库将依赖于缓冲区定义的宏类型来工作。如果在运行时需要同时支持多种缓冲区的格式,缓冲区宏可以定义为类似于isode的缓冲区调用形式,其中的缓存区类型包含缓存区指针和缓存区数据类型。这种做法会降低性能,因为每个缓存区的操作将间接的影响函数调用。后续的编码需要使用snacc定义的特殊的缓存区标识,写入缓存区的末尾。解码时需要读取缓存区之前的代码。内存管理如同缓存区的管理,内存管理也是非常重要的提高解码器效率的方法。snacc解码器分配内存块给解码值,解码后的内存空间通常都释放掉。解码和运行其他库函数的内存空间,都需要使用内存管理机制。解码器分配内存和释放内存也都需要调用asn.1的内存管理函数。在编译链接库函数跟代码时,所编写的头文件允许用户更改默认的内存管理文件。snacc提供了一个特别有效的内存管理器,稍后做讨论。内存管理必须提供三种功能:内存分配,内存释放,内存检查。这些代码需要具有以下接口:void* asnlalloc(unsigned longint size);void anslfree(void*ptr);int checkasnlalloc(void*ptr, env type env);该解码器假定asn1alloc返回一个长度为0的内存块,这样可以节省带有关键字optional和null初始化的代码空间。对env类型参数通过调用longjmp使用错误管理系统。可以通过编辑配置文件来更改内存管理系统。例如,如果不考虑性能的影响,你想分配和释放内存,配置文件可以写成如下:#include malloc.h#defineasnlalloc(size) calloc(l, size)#defineasnlfree(ptr) free (ptr)#define checkasnlalloc(ptr, env)if (ptr) -null)longjmp(env,-27);内存管理系统并不需要在任何时候都调用,所以一般的代码释放就不用调用内存管理系统了。然而,如果你改变了内存管理的配置文件,比如用malloc和free,你就需要使用一般的方法释放掉内存。在默认的情况下,snacc为内存使用计划,提供有效的内存管理。内存管理系统在操作系统中请求一个大的内存块为小的内存请求分配空间。当解码pdu不再被应用程序调用时,通过指针复位,pdu所占用的内存块可以释放掉。而没有必要使用snacc生成代码遍历整个数据结构,释放一个时间片。如果分配和释放内存用于内存管理系统,而不是一小块内存,那么代码运行产生的数据值需要释放掉。所产生的代码,使用深度优先算法分层次释放掉所有的pdu内存。c+设计snacc的c+后台代码编写在c代码编写完成之后,生成的c+基本模型类似于c,但是具有c+面向对象的特性。有些方案的设计被拒绝,要么是由于其性能表现不佳,要么是可用的c+编译器不能处理某些语言特性。标签和长度会很好的适应自己的类,但是性能大大低于在c模型中使用的技术,因为这个原因,c+模型保留了c的设计。对于错误管理,c+的try和catch被c解码器的setjmp和longjmp代替。不幸的是,这是一个较新的c+功能特性仍然未被支持。c+模板在重复代码的安全性上具有非凡的吸引力(例如序列和集合)。由于模板的支撑性比可用的c+编译器弱,我们没采用这个模板。相反,每个序列和集合类型,都可以生成自己的标准代码列表的类每个asn.1类型被转换成c+的类,都具有系列特点:1) 继承了asntype基类;2) 有一个无参数构造函数constructor;3) 有一个克隆方法,clone;4) 有一个pdu的编码和解码方法,benc和bdec;5) 有一个内容编码和解码方法,benc,内容和bdeccontent;6) 为用户提供了到pdu编码和解码方法(处理setjmp的句柄)的最高级别接口,bencpdu和bdecpdu;7) 具有输出函数,print。下面的c+代码显示了更详细的类功能:class foo: public asntype./数据成员public :foo() ;/ 参数要求/ 构造函数/ pdu 编码(标签/长度/内容)/ 解码程序asnlen benc (buf_type b) ;void bdec(buf_type b, asnlen& bytesdecoded, env_type env) ;/内容编码和解码函数asnlen benccontent (buf_type b) ;void bdeccon
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电池制造中的品牌推广与企业形象塑造考核试卷
- 危险品仓储的紧急情况应急预案制定考核试卷
- 搪瓷制品的节能效果与环保意义考核试卷
- DB11T 270-2014 生活垃圾卫生填埋场运行管理规范
- 筑堡工程课件教学课件
- 法国概述课件教学课件
- 兵团精神课件教学课件
- 淮阴工学院《工程项目管理2》2023-2024学年第一学期期末试卷
- 2024届黑龙江省部分学校高三年级下册第五次模拟考试语文试题(解析版)
- 高性能玻璃微珠相关项目投资计划书范本
- 机械设备:低空经济系列报告(一):他山之石-Joby的前世今生
- 信息化作战平台
- 特种设备安全风险日管控、周排查、月调度管理制度及相关表格
- 【物理】万有引力定律的应用、人类对太空的不懈探索课件-2023-2024学年高一下鲁科版(2019)必修第二册
- 环境测评行业分析
- 贷款业务三查培训课件
- 做改革创新生力军
- 员工法律意识培训课件
- 风湿热护理查房
- 2024年北方华锦化学工业集团有限公司招聘笔试参考题库含答案解析
- 新版中小学生守则和日常行为规范
评论
0/150
提交评论