高性能的ASN.1编译器 毕业论文翻译内容.doc

上传人:韩长文 文档编号:3978116 上传时间:2019-10-11 格式:DOC 页数:13 大小:67KB
返回 下载 相关 举报
高性能的ASN.1编译器 毕业论文翻译内容.doc_第1页
第1页 / 共13页
高性能的ASN.1编译器 毕业论文翻译内容.doc_第2页
第2页 / 共13页
高性能的ASN.1编译器 毕业论文翻译内容.doc_第3页
第3页 / 共13页
高性能的ASN.1编译器 毕业论文翻译内容.doc_第4页
第4页 / 共13页
高性能的ASN.1编译器 毕业论文翻译内容.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《高性能的ASN.1编译器 毕业论文翻译内容.doc》由会员分享,可在线阅读,更多相关《高性能的ASN.1编译器 毕业论文翻译内容.doc(13页珍藏版)》请在三一文库上搜索。

1、附录附录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 th

2、at 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; ho

3、wever, 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 decodin

4、g 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 l

5、ongjmp 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 dec

6、oding 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

7、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 f

8、rom 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

9、 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 def

10、ined 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 buff

11、er 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

12、 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

13、 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 rout

14、ines 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 gener

15、ated 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 fol

16、lows:#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 th

17、e 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 de

18、coded 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 u

19、sed 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

20、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 lengt

21、hs 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.

22、 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 O

23、F 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, B

24、Enc 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 ab

25、ove 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 B

26、EncContent (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

27、(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 insta

28、nce (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 AsnAn

29、y 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 d

30、ecoding 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 decodi

31、ng.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 enc

32、oders 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 pres

33、entation 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 representati

34、on 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

35、 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 d

36、ata 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

37、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

38、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 a

39、rchiving 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.

40、 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 c

41、an 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 nec

42、essary.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 fro

43、m the Canadian Institute for Telecommunications Research.附录B 高性能的ASN.1编译器Michael Sample 和 Gerald Neufeld错误管理错误管理是非常重要的,在常见的没有错误的情况下,它的实施必须不会产生太大的成本。一个简化的错误管理方法是假设解码值总是正确的。但这不是一个可靠的实施方法。为了实现一个完整的轻量级错误管理方案,我们使用了setjmp和longjmp函数。在此之前,这些功能的可用性视每一个系统而定,然而,它们现在是ANS.1 C标准库的一部分。在解码开始之前,调用setjmp来记录当前运行的环境(处理

44、器寄存器等)。当前环境变量通过setjmp来设置,然后传递到解码程序。每个解码程序都需要这个参数。当解码程序遇到了严重的错误时,例如内存溢出,则调用longjmp函数,获取当前环境下的错误代码,然后直接返回到错误代码出现的地方。Setjmp和longjmp的错误管理机制,不会影响正确的编码解码过程(只是多了一个额外的参数)。其他的错误管理技术,例如用回调函数检查错误的代码段,这时可能会影响正确编解码的性能。缓冲管理从缓冲区写入和读取数据的成本很大的影响了编解码的性能。因此,有效的缓冲管理是必要的。现成的集成环境中,编码器和解码器的灵活性也是很重要的。为了具备上述功能特点,可以在缓冲区设置一定量

45、的宏。与编码/解码库函数和一般的代码相比,宏具有更高的优先级。因为几乎所有的缓冲区都是通过编码/解码库函数调用,所以缓冲区的宏代码不应该设置太多。如果一个单一简单的缓冲区类型可以在目标环境中使用,缓冲区宏可以被定义为简单的缓冲区类型。这种类型的宏的调用是在一般的代码编译之后完成,所以不会占用编码和解码函数额外的开销。然而,这也意味着编码和解码库将依赖于缓冲区定义的宏类型来工作。如果在运行时需要同时支持多种缓冲区的格式,缓冲区宏可以定义为类似于ISODE的缓冲区调用形式,其中的缓存区类型包含缓存区指针和缓存区数据类型。这种做法会降低性能,因为每个缓存区的操作将间接的影响函数调用。后续的编码需要使

46、用snacc定义的特殊的缓存区标识,写入缓存区的末尾。解码时需要读取缓存区之前的代码。内存管理如同缓存区的管理,内存管理也是非常重要的提高解码器效率的方法。Snacc解码器分配内存块给解码值,解码后的内存空间通常都释放掉。解码和运行其他库函数的内存空间,都需要使用内存管理机制。解码器分配内存和释放内存也都需要调用ASN.1的内存管理函数。在编译链接库函数跟代码时,所编写的头文件允许用户更改默认的内存管理文件。Snacc提供了一个特别有效的内存管理器,稍后做讨论。内存管理必须提供三种功能:内存分配,内存释放,内存检查。这些代码需要具有以下接口:void* AsnlAlloc(unsigned l

47、ongint 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)

48、free (ptr)#define CheckAsnlAlloc(ptr, env)if (ptr) -NULL)longjmp(env,-27);内存管理系统并不需要在任何时候都调用,所以一般的代码释放就不用调用内存管理系统了。然而,如果你改变了内存管理的配置文件,比如用malloc和free,你就需要使用一般的方法释放掉内存。在默认的情况下,snacc为内存使用计划,提供有效的内存管理。内存管理系统在操作系统中请求一个大的内存块为小的内存请求分配空间。当解码PDU不再被应用程序调用时,通过指针复位,PDU所占用的内存块可以释放掉。而没有必要使用snacc生成代码遍历整个数据结构,释放一个时

49、间片。如果分配和释放内存用于内存管理系统,而不是一小块内存,那么代码运行产生的数据值需要释放掉。所产生的代码,使用深度优先算法分层次释放掉所有的PDU内存。C+设计Snacc的C+后台代码编写在C代码编写完成之后,生成的C+基本模型类似于C,但是具有C+面向对象的特性。有些方案的设计被拒绝,要么是由于其性能表现不佳,要么是可用的C+编译器不能处理某些语言特性。标签和长度会很好的适应自己的类,但是性能大大低于在C模型中使用的技术,因为这个原因,C+模型保留了C的设计。对于错误管理,C+的try和catch被C解码器的setjmp和longjmp代替。不幸的是,这是一个较新的C+功能特性仍然未被支持

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1