general failuree Trace怎么定位到错误

專利 CN1786926A - Method for using buffer memory area in processor - Google 專利CN1786926 A申請CN 日日日.6, CN 1786926 A, CN 1786926A, CN , CN-A-1786926, CN1786926 A, CN1786926A, CN, CN.6, ,
(3) , Method for using buffer memory area in processorCN 1786926 A The invention discloses a method for using buffer areas in a processor, firstly setting a buffer area descriptor comprising buffer area state
as applying for a buffer area, obtaining an idle buffer area as the current buffer area according to t then modifying the buffer area descriptor in the as releasing a buffer area, releasing the current buffer area according to the buffer area descriptor. By setting buffer area state and user information in the buffer area descriptor, as the user applies for and releases the buffer area, it firstly checks if the buffer area state is an error state and dynamically records the course of the user using the buffer area resources. At the time of failure, i.e. the buffer area state is an error state, it can making accurate location according to the user information.
1.一种处理器中使用缓冲区的方法,其特征在于,包括步骤:(1)设置缓存区描述符,所述缓存区描述符的信息包括缓存区状态和使用者信息;(2)当申请缓存区时,根据所述缓存区状态获取空闲缓存区,并作为当前缓存区;(3)修改所述当前缓存区中缓存区描述符的信息;(4)当释放缓存区时,根据所述缓存区描述符的信息释放当前缓存区。 1 A buffer used in the processor, characterized by comprising the steps of: (1) Set the buffer descriptor, the descriptor cache buffer status information includes info (2) when application cache, depending on the state of the cache buffer for free, and a (3) changes in said current buffer descripto (4) when the release buffer zone, depending on the said buffer descriptor information release the current cache.
2.根据权利要求1所述的处理器中使用缓存区的方法,其特征在于,所述缓存区状态包括:正常状态和错误状态。 (2) as claimed in claim 1, wherein the processor using the buffer zone, characterized in that the buffer state includes: the normal state and the error state.
3.根据权利要求2所述的处理器中使用缓存区的方法,其特征在于,步骤2)的获取过程具体为:获取所述缓存区状态为正常状态的空闲缓存区。 3 according to claim 2, wherein the processor using the buffer zone, characterized in that step 2) is specific for the process: access to the cache state is the normal state of the idle cache.
4.根据权利要求2所述的处理器中使用缓存区的方法,其特征在于,步骤3)的修改过程具体为:动态记录所述使用者信息;若当前缓存区出现错误处理,则将所述缓存区状态设置为错误状态。 As claimed in claim 2, wherein the buffer used in the processor of the method characterized in that step 3) The modification process specific to: the dynamic recording of
if the current cache error handling, then the said cache state is set to an error state.
5.根据权利要求4所述的处理器中使用缓存区的方法,其特征在于,步骤5)的释放过程具体为:若缓存区状态为正常状态,则释放当前缓存区,并清空缓存区描述符中的信息;若缓存区状态为错误状态,则释放当前缓存区,并保留所述缓存区状态和使用者信息。 5 according to claim 4, wherein the processor using the buffer zone, characterized in that step 5) The release process in particular: if the buffer state is the normal state, the release of the current buffer, and clears the buffer described characte cache state if an error state, the release of the current buffer, and retain the buffer zone status and user information.
6.根据权利要求5所述的处理器中使用缓存区的方法,其特征在于,所述步骤还包括:若缓存区状态为错误状态,则根据所述使用者信息定位错误源。 As claimed in claim 5, wherein the processor using the buffer zone, characterized in that said step further comprises: if the buffer status is an error condition, then according to positioning errors of the user information source.
7.根据权利要求5所述的处理器中使用缓存区的方法,其特征在于,步骤1)中所述缓存区描述符的信息还包括:使用状态信息,用于标识缓存区是否处于空闲状态;所述申请缓存区时和所述释放缓存区时,还包括更新所述使用状态信息。 As claimed in claim 5, wherein the processor using the buffer zone, characterized in that, in step 1) of the buffer descriptor information further comprises: using the state information is used to identify the buffer
said application buffer zone buffer zone and the release also includes updated information on the use of state.
8.根据权利要求5所述的处理器中使用缓冲区的方法,其特征在于,步骤1)所述所述缓存区描述符的信息还包括:错误类型信息;若缓存区状态为错误状态,则填写所述故障类型信息,并在释放当前缓存区时,保留所述错误类型信息。 As claimed in claim 5, wherein the buffer used in the processor, characterized in that step 1) of the said buffer descriptor information further comprises: er if the cache status to error state, then fill in the fault type information, and in the release of the current buffer, the retention of the wrong type information.
9.根据权利要求5所述的处理器中使用缓冲区的方法,其特征在于,步骤1)所述所述缓存区描述符的信息还包括:申请者信息和释放者信息;所述申请缓存区时,还包括:填写所述申请者信息;若所述缓存区状态为正常状态时,则释放所述当前缓存区时,还包括清空所述释放者信息;若所述缓存区状态为正常状态时,则释放所述当前缓存区时,还包括保留所述释放者信息。 (10) according to claim 5, wherein the buffer used in the processor, characterized in that step 1) of the said buffer descriptor information further comprises: applicant information and d said application cache area, further comprising: Fill the a if the cache state is the normal state, then release the current cache area, also includes emptying the d if the cache is in normal state state, the release of the current buffer area, further comprising retaining said deliverer information.
一种处理器中使用缓存区的方法 A processor cache method used
技术领域 Technology
本发明涉及计算机领域,尤其涉及处理器缓存区的使用方法。 The present invention relates to the computer field, in particular the use of the processor cache.
背景技术 BACKGROUND
处理器今天已得到广泛应用,它在各种网络业务和不同性能级别的应用中担任着不同的任务。 Processor has been widely used today, it is different in a variety of network services and applications as performance levels with different tasks. 网络技术及应用的发展,对网络设备的容量及单板的处理能力的要求越来越高。 Network technology and application development, network equipment capacity and processing power boards have become increasingly demanding. 在处理器中通常需要多个协处理器同时并行工作,一个数据包的处理要经过多个模块,由几个协处理器协同完成。 The processor typically require multiple co-processors work in parallel, processing of a packet to go through a plurality of modules to complete the coordination number of the coprocessor. 为了缓和不同模块间速度不匹配的矛盾,减少对各模块中CPU的中断频率,以及提高CPU和输入/输出单元之间的并行性,需要引入缓冲,对各模块的收发数据进行缓存。 In order to alleviate speed mismatch between different modules contradiction in each module to reduce CPU interrupt frequency, and increase the CPU and the input / output unit of the parallelism between the need to introduce a buffer of each cache data transceiver module.
通常,对通信设备内部缓冲区的管理按照以下三种方式:(1)静态分配的管理方式。 Typically, the internal buffer management communication equipment following three ways: (1) static allocation approach to management. 在设计时对设备内每个模块分配固定大小的缓存区作为数据发送和接收时的专用缓冲区,在数据收发过程中反复使用。 In the design of each module is assigned to the device a fixed-size buffer as the data sending and receiving a special buffer, the data transceiver during repeated use.
这种静态分配方式虽然处理简单,但由于各模块处理功能和处理速度不同,其数据流量也处于不断变化之中,因此可能会使得某些缓存区空间长时间空闲,而有些缓存区空间又会拥挤,甚至溢出,严重时还会引起正常数据的丢失。 Although this static allocation process is simple, but because each module processing functions and processing speed is different, the data traffic is also in flux, so it may make some buffer space for a long time idle, and some buffer space will crowded, even overflow, can also cause severe loss of normal data. 当发生数据丢失等错误时,由于没有相关的信息,对造成数据丢失的原因无法追溯。 When data loss occurs when an error such as the absence of relevant information, the reason for the loss of data can not be traced back.
(2)动态分配的管理方式。 (2) dynamic allocation of management. 为了提高缓冲区的利用率,设计一个缓冲区池,将所有可利用的缓冲区空间放入该缓冲区池,池中的缓冲区可供多个模块共享。 In order to improve the utilization of the buffer to design a buffer pool, all available buffer space into the buffer pool, the buffer pool shared by multiple modules.
当某模块发送数据时,首先向缓冲区池申请缓存空间,从空缓冲队列中为其分配缓存空间,并将该缓存空间链接到输出队列中;当下一个模块接收该数据时,向缓冲区池申请缓存空间,从空缓冲队列中为其分配缓存空间,并根据输出队列从对应的缓存空间读取该数据并写到为其分配的缓存空间,同时,将输出队列中对应的缓存空间释放并链接到空缓冲队列中,将写入数据后的缓存空间链接到输入队列中。 When a module is sending data, the first buffer space for the buffer pool from the buffer queue is assigned an empty buffer space, and the buffer space is linked moment when a module receives the data, the buffer pool application cache space, from an empty buffer cache space assigned to the queue, and according to the corresponding output queue buffer space from the data is read and written to the buffer space allocated for the same time, the output queue corresponding cache space is freed and Link to empty the buffer queue, after the write data buffer space linked to the input queue.
由于多个模块共享缓冲区池,因此,有可能会因某个模块出现故障而造成缓存区碎片,严重时还可能会耗尽系统的资源。 Because multiple modules shared buffer pool, therefore, may be due to a failure of a module cache fragmentation caused serious cases may run out of system resources. 而且,当设备内模块较多时,对缓冲区的管理实现复杂,出现问题难以定位。 Moreover, when the equipment module is large, the buffer management of complex, difficult to locate the problem.
(3)静态和动态相结合的管理方式。 (3) a combination of static and dynamic management. 该方法采用在配置时动态分配缓冲区的数量,处理中静态操作的方式。 The method uses dynamic allocation when configuring the number of buffers to deal with the way in static operation. 首先动态配置相邻模块间所需缓冲区;然后将每个所述缓冲区划分为预定个数的子缓冲区,设置每个子缓冲区对应的缓冲区描述符,并根据所述缓冲区描述符的信息建立环形链表。 First, a dynamic configuration of the buffer requ then each of said buffer is divided into a predetermined number of sub-buffers, each sub-set corresponding to the buffer descriptor buffer, and in accordance with the buffer descriptor information to establish the circular linked list. 该缓冲区配置好后,对其进行的存取操作是静态的,不需要申请释放过程,具体来说,当相邻模块收/发数据需要缓冲区时,顺次从所述环形链表中获取相应的子缓冲区读出/写入数据。 The buffer is configured, its access operation is static, not for the release process, in particular, when the adjacent modules transmit / receive data to buffer sequentially to obtain the list of the ring corresponding sub-buffer read / write data.
由于不需要申请释放过程,一旦某个模块出现问题不会影响到整个系统,而且通过对不同模块及缓冲区建立对应关系,一定程度的改善了出现问题时定位的难度。 Since no application release process, once a problem with the module will not affect the entire system, but also through different modules and establishing a correspondence between the buffer, the degree of improvement when problems occur positioning difficult. 但是该方法链表中某个子缓存区出现错误时,将由于无法形成完整的缓存链而导致整个缓存区的混乱,并且,由于缺少相关信息,无法准确定位到问题代码,因此,该方法当缓存区资源出现错误时仍然存在问题难以定位的缺陷。 However, this method in a sub-buffer linked list when an error occurs, the inability to form a complete chain in the entire cache buffer confusion, and, due to lack of information, the code can not accurately locate the problem, therefore, this method when the cache area resource problem still exists when an error occurs difficult to locate defects.
发明内容 SUMMARY OF THE INVENTION
本发明要解决的技术问题在于:提供一种处理器中使用缓冲区的方法,能够简单有效地对缓冲区进行可靠管理,并能够准确定位到发生故障的缓存区资源。 The present invention is to solve the technical problems in that: the buffer used in the processor to provide a method that can easily and effectively manage the buffer reliable and can accurately locate the faulty cache resources.
为解决上述技术问题,本发明提供一种处理器中使用缓冲区的方法,包括步骤: To solve the above technical problem, the present invention provides a buffer used in the processor, the method comprising steps of:
(1)设置缓存区描述符,所述缓存区描述符的信息包括缓存区状态和使用者信息;(2)当中请缓存区时,根据所述缓存区状态获取空闲缓存区,并作为当前缓存区;(3)修改所述当前缓存区中缓存区描述符的信息;(4)当释放缓存区时,根据所述缓存区描述符的信息释放当前缓存区。 (1) Set the buffer descriptor, the buffer descriptor information includes cache state
(2) Please buffer zone which, according to the state of the buffer cache for free, and as the current cache D (3) modify the current buffer zone buffer de (4) When you release the buffer when the buffer descriptor based on the information release the current cache.
其中,所述缓存区状态包括:正常状态和错误状态。 Wherein the buffer states include: normal status and error status.
其中,步骤2)的获取过程具体为:获取所述缓存区状态为正常状态的空闲缓存区。 Wherein step 2) is specific for the process: access to the cache state is the normal state of the idle cache.
其中,步骤3)的修改过程具体为:动态记录所述使用者信息;若当前缓存区出现错误处理,则将所述缓存区状态设置为错误状态。 Wherein step 3) The modification process specific to: the dynamic recording of
if the current error handling cache, then the cache state to an error state.
其中,步骤5)的释放过程具体为:若缓存区状态为正常状态,则释放当前缓存区,并清空缓存区描述符中的信息;若缓存区状态为错误状态,则释放当前缓存区,并保留所述缓存区状态和使用者信息。 Wherein step 5) the release process specifically: If the buffer state is the normal state, then release the current buffer, and clears the cache de cache state if an error state, the release of the current buffer, and keep the cache state and user information.
其中,所述步骤还包括:若缓存区状态为错误状态,则根据所述使用者信息定位错误源。 Wherein said step further comprises: If the cache state is an error state, then according to the information of the user locate the source of errors.
其中,步骤1)中所述缓存区描述符的信息还包括:使用状态信息,用于标识缓存区是否处于空闲状态;所述申请缓存区时和所述释放缓存区时,还包括更新所述使用状态信息。 Wherein step 1) in the buffer descriptor of the information further comprises: using the state information is used to identify the buffer said application and said release buffer zone buffer zone, further comprising updating said Use status information.
其中,步骤1)所述所述缓存区描述符的信息还包括:错误类型信息;若缓存区状态为错误状态,则填写所述故障类型信息,并在释放当前缓存区时,保留所述错误类型信息。 Wherein step a) wherein said buffer descriptor information also includes: Er if the cache state is an error state, then fill out the fault type information, and in the release of the current buffer, the retention of the error type information.
其中,步骤1)所述所述缓存区描述符的信息还包括:申请者信息和释放者信息;所述申请缓存区时,还包括:填写所述申请者信息;若所述缓存区状态为正常状态时,则释放所述当前缓存区时,还包括清空所述释放者信息;若所述缓存区状态为正常状态时,则释放所述当前缓存区时,还包括保留所述释放者信息。 Wherein step a) wherein said buffer descriptor information also includes: Applicant Information and d said application buffer zone, further comprising: Fill the a if the cache state is normal state, then release the current cache area, also includes emptying the d if the cache state is the normal state, then release the current buffer zone, but also retained the deliverer information .
与现有技术相比,本发明的有益效果是:通过在缓存区描述符中设置缓存区状态和使用者信息,当用户在申请和释放缓存区时首先检验缓存区状态是否为错误状态,并且用使用者信息对缓存区资源的使用过程进行动态记录,当发生故障时,从而当缓存区状态为错误状态时,能够根据使用者信息能够进行准确定位。 Compared with the prior art, the present invention has the advantages that: by setting the buffer descriptor buffer state and user information when the user application and release the buffer cache when first examined whether the state is an error state, and a user information cache dynamic resource use recording process, when a failure occurs, so that when the buffer status is an error condition, according to the user information can be accurately positioned.
进一步,本发明还设置了缓存区使用状态信息,能够根据此信息定期检测缓存区是否存在故障泄漏,并在发生故障泄漏时,根据使用者信息能够准确定位到出现泄漏的缓存区。 Further, the present invention is also provided with a buffer status information can be detected based on this information is regularly leaking cache is faulty, and in the event of leakage failure, based on the user information can accurately locate the leak buffer area.
进一步,本发明还设置了申请者信息、释放者信息和错误类型信息,能够追溯故障的来源,并记录错误原因,便于问题定位和跟踪。 Further, the present invention sets the applicant information, dropper and error type information to trace the source of failure, and the cause of the error record, locate the problem and tracking.
另外,由于本发明和缓存区的管理方式无关,因此对于静态管理、动态管理和静态动态相结合的缓存区管理方式均适用。 In addition, because of the present invention and the cache management style has nothing to do, so for static management, dynamic management and a combination of static dynamic buffer management methods are applicable.
附图说明 BRIEF DESCRIPTION
图1是静态分配的管理方式示意图图2是动态分配的管理方式示意图。 Figure 1 is a schematic view of the management of static allocation Figure 2 is a schematic diagram of dynamic allocation approach to management.
具体实施方式 Specific embodiments
对于缓存资源的管理方式主要有静态管理、动态管理和静态动态相结合的管理方式。 For cache resource management methods are mainly static management, dynamic management and static dynamic combination of management. 本发明的核心在于在缓存资源中保存错误状态和缓存区使用者信息,对内存资源进行快速准确的定位,以便在发生故障时进行问题定位。 The core of the invention is that the resources saved in the cache buffer error status and user information on memory resources for fast and accurate positioning, so that when a failure occurs locate the problem. 本发明对于各种缓存区管理方式均适用。 The present invention for a variety of buffer management are applicable.
具体来说,利用本发明进行缓存区管理时,首先设置缓存区描述符,所述缓存区描述符的信息包括缓存区状态和使用者信息;当申请缓存区时,根据所述缓存区状态获取空闲缓存区,并作为当前缓存区;当缓存区描述符中的信息发生改变时,修改所述当前缓存区中缓存区描述符的信息;当释放缓存区时,根据所述缓存区描述符的信息释放当前缓存区。 Specifically, the present invention is to cache area management, first set the buffer descriptor, the buffer descriptors and status information includes a us when the application buffer, according to the state of the cache access idle buffer area, and a when buffer descriptor information is changed, the modified region in the current cache buffer de buffer zone when released, according to the descriptor cache Information release the current cache. 以下对本发明的实施过程进行详细介绍。 The following implementation process of the present invention will be described in detail.
首先设置缓存区描述符,所述缓存区描述符的信息包括缓存区状态和使用者信息;在本发明中,为了便于理解,将缓存区状态定义为Error,同时定义Error的值为1时表示缓存区发生错误,Error的值为0时表示缓存区目前处于正常状态;将缓存区使用者信息定义为Last_user_ID。 First set the buffer descriptor, the buffer descriptor information includes cache state
In the present invention, in order to facilitate understanding, the buffer state is defined as Error, and defines the value of 1 indicates Error cache error occurs, Error value of 0 means that the cache is current cache user information will be defined as Last_user_ID. 对于Error的值为1的情况包括:申请缓存区时,若所述缓存区处于正在使用状态;释放缓存区时,若所述缓存区处于未使用状态,和缓存区在使用中出现处理错误时。 For Error is 1 case includes: application cache, if the cache releasing buffer, if the buffer is not in use, and the cache is in use when an error occurs processing .
同时,本发明还设置了缓存区使用状态标识Using,以标明缓存区的使用状态,并用Using=0表示缓存区处于未使用状态,Using=1表示缓存区处于使用状态。 Meanwhile, the invention is also provided with a buffer status indicator Using, to indicate the state of use of the cache, and use Using = 0 means that the buffer is not in use, Using = 1 means that the cache is being used. 此字段的存在可以加速系统的处理流程。 The presence of this field is the system processing speed. 当某模块申请缓存区时,首先检测Using是否为1,如果是,则直接报告异常,而不必再检查Error的值,如果否,则继续检查Error的值,当Error为1时报告异常;为了能够对缓存资源的使用过程从源头进行跟踪,本发明还设置了申请者Applier_ID字段,但此字段是否存在并不影响故障时的问题定位。 When a module application cache, the first detection Using whether one, if it is, then the direct reporting anomalies, without having to check the Error value, if not, continue to check the Error value is 1 when the Error R order resources to the process of using the cache for tracking the source, the present invention also sets the applicants Applier_ID field, but this field does not affect the existence of the fault location fault. 当Error和Using的值均为0时,将该缓存区分配给该模块,申请成功后,填写Applier_ID字段;对于所有使用该缓存区的模块,需要将本模块的标识写入Last_user_ID,以便缓存区出现故障时能够定位到申请该缓存区的模块。 When the Error and Using a value of 0, the buffer assigned to the module, the application is successful, fill Applier_ID For all use of the cache module, this module identifies the need to write Last_user_ID, in order to buffer fails to locate to apply for the cache module. Last_user_ID是一个随着缓存区的使用过程动态变化的字段,每一个处理该缓存区的模块,在进入时将该字段填写为自身的标识,随后,随着中间过程以及释放过程中的对该缓存区块的使用者的变化情况进行相应的改变;为了能够更好的了解因此缓存区错误的原因,本发明还设置了用于显示错误类型的错误码Error_code,本发明中,该错误码支持64种错误,例如:包长超过限制、发现循环校验码错误等。 Last_user_ID a buffer zone with dynamic changes during use of a field, each processing module of the buffer zone, the field is filled at the time of entry for their own identity, and then, as the middle of the process and the release process of the cache changes in the user block the
in order to better understand the cause of the error so that the cache area, the present invention is also set for the type of error the error code Error_code, the present invention, the error code 64 kinds of errors, such as: packet length exceeds the limit, find cyclic checksum errors. 在缓存区的使用过程中,如果出现异常处理,则将Error置为1,同时由发现错误的模块填写相应的Error_code;另外,本发明还设置了释放者标识Releaser_ID字段,在缓存区释放时由释放该缓存区的模块填写;当使用完该缓存区,释放不存在故障的缓存区时,将上述所有的字段全部清零;释放存在故障的缓存区时,为了对错误进行定位,保持Error、Error_code、Last_user_ID、Releaser_ID、Applier_ID字段,并更新Using字段;以上介绍了利用本发明进行申请和释放缓存区的过程。 In the process of using the cache, if there is exception handling, the Error is set to 1, and also by the wrong module found fill in the appropriate Error_ addition, the present invention also set up a deliverer logo Releaser_ID field, when released in the buffer zone by the release th when finished using the cache, there is no fault in the release buffer zone, all the ab released when there is a fault in the cache, in order to locate errors, maintaining Error, Error_code, Last_user_ID, Releaser_ID, Applier_ID field and update U above describes the use of the present invention to apply and release the cache process. 下面将介绍当发生错误对各种故障进行故障定位的过程。 The following describes the various fault when an error occurs on the fault location process.
一,缓存区重复申请的定位:当申请缓存区时,如果发现using字段没有清0,则将该缓存区的Error置为1,确认该缓存区为重复申请,并根据Last_user_ID字段检测正在使用的模块,从而判断该模块存在乱释放缓存区的错误。 First, the positioning of multiple applications cache: When the application cache, if found using field is not cleared, then the buffer zone Error is set to 1, to confirm that the buffer zone is repeated application and field testing under Last_user_ID being used module to determine if the module is present chaos release cache errors.
二,处理流程异常时的检测:缓存区在申请者和释放者之间的中间环节需要检查Error标志,如果置为1,则表明存在错误处理,然后可以根据Error_code得知故障原因,并通过Last_user_ID定位到发生故障的模块。 Second, detection of abnormal processes: buffer between the applicant and the deliverer of the intermediate links need to check the Error flag, if set to 1, it indicates that there is an error handling, and can Error_code know the cause, and through Last_user_ID Locate the faulty module. 可以在调试代码中添加打印功能,将故障原因和发现故障的模块打印出来,大大方便问题定位和跟踪。 You can add debug code printing capabilities, the fault causes and find the faulty module print out greatly facilitate locating and tracking problems.
三,重复释放的错误检测:在释放一块缓存区时,需要检测Using的值是否0,如果是,则表明该缓存区被重复释放,然后根据Last_user_ID定位到重复释放的模块。 Third, the double free error detection: the release of a buffer area, the need to detect whether the value 0 Using, if so, indicates that the buffer is repeatedly released, and then locate the duplicate Last_user_ID release of the module. 同样可以增加打印功能,打印出正在运行的模块名和重复释放的缓存区供定位。 Can also increase the print function to print out the name of the module and the running buffer for the release of repeated positioning.
四,缓存区泄漏的检测:缓存区泄漏即缓存区忘记释放,导致无法被继续使用。 Fourth, the buffer leak detection: ie buffer cache leakage forget to release, resulting in not continue to be used. 如果因为流程错误产生缓存区泄漏,时间长了,可能会导致缓存区耗尽,而导致系统异常甚至死机。 If an error occurs because the flow cache leakage, a long time may cause buffer depletion, resulting in abnormal or even crash the system.
在调试时,可以启动一个任务,定期检测所有的缓存区资源,如果某个缓存区块长期没有释放,即Using始终为1,可以根据Last_user_ID判断最终使用的模块,从而将忘记释放的错误定位到模块。 When debugging, you can start a task on a regular basis to detect all of the cache resources, if not release a cache block long, namely Using always 1, according to Last_user_ID determine end-use modules, which will release the positioning error to forget modules. 该检测过程可以只是作为调试代码,也可以在正式代码中存在,作为异常恢复的方法,定期为不能释放的缓存区强制释放,保证系统可以长期稳定工作。 The detection process can be just as debugging code, you can also exist in a formal code, as an exception and recovery methods, on a regular basis can not release the buffer zone to force the release of long-term stability to ensure the system can work.
以上各种检测错误以及定位的方法,可以只是作为调试代码,也可以在正式代码中存在,用于异常检测和恢复。 All of the above methods to detect errors and positioning, can be just as debugging code, you can also exist in the official code for anomaly detection and recovery.
本发明提供的管理缓存区的方法与缓存区的管理方式无关,也就是说,本发明适用于静态分配、动态分配、以及静态动态相结合的管理方式。 The present invention provides a method of management of the cache buffer zone independent of management, that is, the present invention is applicable to static allocation, dynamic allocation, a combination of dynamic and static management. 以下将静态分配和动态分配作为作为两个具体实施例进行详细介绍。 The following static allocation and dynamic allocation as two specific embodiments as described in more detail.
第一实施例:静态分配缓存资源的管理方式。 First Embodiment: statically allocated cache resources are managed.
这种分配方式在设计时对每个模块分配固定大小的缓存区作为数据发送和接收时的专用缓存区,在数据收发过程中反复使用。 This distribution in the design of each module is assigned a fixed-size buffer as the data sending and receiving a special buffer in the data sending and receiving process repeatedly. 图1为该种分配方式下的缓存区管理的示意图。 Figure 1 for the kind of buffer allocation under the management of Fig. 如图所示,系统将所有的缓存资源划分为N个内存片,并且每个内存片用一个缓存区描述符进行标识,每个缓存区描述符中包含的信息数据包括:位移量、长度、以及本发明增加申请者、释放者、使用状态标识、错误标识和错误码字段。 As shown, the system will cache all memory resources are divided into N slices, and each memory chip by a buffer descriptor is identified, each buffer descriptor contains information data includes: shift amount, the length, and the present invention is to increase the applicant, deliverer, the use of state identification, error identification and error code field. 通过指针实现对每个缓存区描述符的管理。 Achieved through a pointer for each buffer descriptor management. 系统维持两个指针:头指针headptr、尾指针tailptr。 System maintains two pointers: head pointer headptr, tail pointer tailptr. HeadPtr指向当前可以使用的内存片,TailPtr指向当前需要释放的内存片,当两个指针重合时,没有内存片可以使用。 HeadPtr points to the current use of memory chip, TailPtr pointing to the current need to release the memory chip, when the two pointers overlap, there is no memory chip can be used. 静态分配的管理方式要求必须按照顺序进行缓存区的使用和释放,每个缓存区对应的缓存区描述符区域必须是连续的。 Static allocation of management requirements must be performed in the order of use and release of the buffer, each buffer descriptor cache corresponding to the area must be continuous.
在需要申请新的缓存时,首先根据头指针HeadPtr指向的缓存区描述符找到对应的内存片,然后检查Using的值,Error以及Error_code的值,如果为1,表明该内存片存在故障,则上报错误报告。 The need to apply the new cache, the first point under the head pointer HeadPtr find the corresponding descriptor cache memory chip, and then check Using the values, Error and Error_code value, if 1, indicating that the memory chip is faulty, then the reported error reporting. 如果为0,则将数据写入HeadPtr指向的内存片,然后HeadPtr下移;在使用过程中,随时记录Last_user,如果出现异常处理,则将Error的值置为1,同时填写相应的Error_code;当使用完该缓存区需要释放时,TailPtr指针指向当前需要释放的内存片,然后检查Using的值是否为1,Error以及Error_code的值是否为0,如果是,则释放该内存片,并将全部字段清零;如果否,则释放该模块后保存Error、Error_code、Last_user_ID、Realese_ID、Applier_ID字段,更新Using字段。 If 0, the data is written to the memory pointed HeadPtr piece, then HeadP During use, keep records Last_user, if there is exception handling, the Error value is set to 1, and fill in the appropriate Error_ when finished using the buffer zone needs to release when, TailPtr pointer to the current needs of freed memory chip, and then check Using the value is 1, Error and Error_code whether the value is 0, if it is, then release the memory chip, and the If not, the release of the module and save Error, Error_code, Last_user_ID, Realese_ID, Applier_ID field, update Using field.
故障定位:由于HeadPtr指向的缓存区描述符所对应的内存片为处于空闲状态的内存片,因此,如果申请内存时Using值为1,则表示该内存片存在重复申请,当需要对出现重复申请的内存片进行问题定位时,可以根据Last_user_ID检测到正在使用该内存片的模块。 Fault location: Because HeadPtr buffer descriptor pointing to the corresponding memory chip is in an idle state memory chip, so if the application memory Using a value of 1, it indicates that there is duplication of the memory chip applications, when the need for duplicate application Memory chip locate the problem, you can detect under Last_user_ID is using the memory-chip modules.
同样,由于TailPtr指向的缓存区描述符所对应的内存片为处于占用状态将要释放的内存片,因此,如果申请内存时Using值为0,则表示该内存片存在重复释放,当需要对出现重复释放的内存片进行问题定位时,可以根据Last_user_ID检测到重复释放的模块,并可以根据Realese_ID、Applier_ID字段进行追溯。 Similarly, because TailPtr buffer descriptor pointed to the corresponding piece is occupied memory will be freed memory chip, so if the application memory Using a value of 0, it means that there is duplication of the memory chip release, when the need for duplicate freed memory chip locate the problem, you can detect duplicate according Last_user_ID release module and can Realese_ID, Applier_ID field retrospective.
处理器可以设定周期,定期遍历所有内存片,当检测到某个内存片对应的缓存区描述符的Using值的值超过预定时间时,则判断为出现内存泄漏,根据Last_user_ID以及Realese_ID、Applier_ID定位到忘记释放内存片的模块。 Processor cycles can be set to regularly traverse all the memory chip, when detected corresponding to a memory chip cache descriptor Using the value exceeds a predetermined time, it is determined that a memory leak, according to Last_user_ID and Realese_ID, Applier_ID positioning to forget to release the memory chip modules.
第二实施例:动态分配缓存资源的管理方式。 Second Embodiment: dynamically allocate cache resource management.
图2为该方式下缓存区管理的示意图。 Figure 2 mode cache management for schematic. 系统同样将所有的缓存资源划分为N个内存片,并且每个内存片用一个缓存区描述符进行标识,每个缓存区描述符中包含的信息数据包括:位移量、长度、以及本发明增加申请者、释放者、使用状态标识、错误标识和错误码字段,和静态分配缓存的管理方式不同,动态分配的管理方式的缓存区描述符中存在链表指针NextBufHandle指针。 System also caches all the memory resources are divided into N slices, and each memory chip by a buffer descriptor is identified, each buffer descriptor contains information data includes: shift amount, length, and the present invention is to increase applicants, Emancipator, use of state identification, error identification and error code field, and statically allocated cache management in different ways, the management of dynamically allocated buffer zone descriptor list pointers NextBufHandle pointer exists. 通过指针实现对每个缓存区描述符的管理。 Achieved through a pointer for each buffer descriptor management. 这种管理方式对空闲缓存区采用动态链表的方式,系统维持2个指针head,tail,分别指向链表的头尾,tail指针最初指向的缓存区描述符的NextBufHandle域值为0,当某个内存片需要释放时,将需要释放的缓存区描述符中NextBufHandle域的值替换原来的0值。 This management approach for idle cache dynamically linked list, system maintains two pointers head, tail, head and tail, respectively, pointing to the list, tail pointer initially points to the buffer descriptor NextBufHandle domain is 0, when a memory need to release the film, it will need to release the buffer descriptor NextBufHandle field value to replace the original value of 0. 指针唯一指向一个缓存区描述符地址,每个缓存区描述符唯一对应于一段缓存区。 The only pointer points to a buffer descriptor addresses, each buffer descriptor uniquely corresponds to a cache. 缓存区描述符的结构如下表所示: Buffer descriptor structure as follows:
其中,NextBufHandle指向下一个缓存区的缓存区描述符地址,Offset指示包数据第一个字节的位置,Length指示整个包的长度。 Which, NextBufHandle points to the next buffer zone buffer descriptor address, Offset packet data indicating the location of the first byte, Length indicates the length of the entire package.
当某个模块需要申请缓存区时,将链表头部的缓存区取出,同时head指针指向该缓存区的缓存区描述符中NextBufHandle域指向的缓存区描述符;然后检查Using,Error以及Error_code的值,如果为1,表明该内存片存在故障,则上报错误报告。 When a module needs to apply cache, it will list out the head of the buffer zone, while head pointer to the buffer zone buffer descriptor NextBufHandle domain pointing to t Then check Using, Error and Error_code value , if 1, indicating that the memory chip is faulty, then the reported error report. 如果为0,则将数据写入缓存区描述符对应的缓存区,然后NextBufHandle下移;在使用过程中,随时记录Last_user,如果出现异常处理,则将Error的值置为1,同时填写相应的Error_code;当使用完该缓存区需要释放时,先将Tail指针指向的缓存区描述符的NextBufHandle域改为当前缓存区的缓存区描述符地址,然后tail指针指向当前释放的内存片的缓存区描述符地址,同时填写释放者标识Releaser_ID,修改使用状态标识Using。 If 0, the data is written to the buffer descriptor corresponding cache, then NextBufH During use, keep records Last_user, if there is exception handling, the Error value is set to 1, and fill in the appropriate Error_ When finished using the buffer zone needs to release, the first Tail pointer to the buffer descriptor NextBufHandle domain into the current buffer zone buffer descriptor address, and then tail pointer to the current release of memory-chip cache area Description Fu address, and fill deliverer logo Releaser_ID, modify the use of state identification Using.
如果因为某些原因,链表中某个缓存区描述符的NextBufHandle域错误,时,导致某些内存片区永远得不到使用,即缓存区泄漏,或者多次使用即缓存区重复使用。 If for some reason, the list of a buffer descriptor NextBufHandle domain error, time, causing some memory patches never get to use that buffer leakage, or multiple uses that cache reuse. 使用本发明进行故障定位的过程是:一,缓存区重复申请的定位:当申请缓存区时,由于Head指针指向的是欲分配的空闲内存片,因此如果发现Using字段没有清0,可以确认为缓存区重复申请,则根据Last_user_ID字段可以检测正在使用的模块,从而判断该模块存在乱释放缓存区的错误。 Fault location using the present invention is the process: First, the positioning of multiple applications cache: When the application cache, because Head pointer is allocated free memory chip desire, so if you find Using field is not cleared to 0, as can be confirmed cache multiple applications, the field can be detected according to Last_user_ID module is being used to determine if the module is present chaos release cache errors.
二,处理流程异常时的检测:缓存区在申请者和释放者之间的中间环节需要检查Error标志,如果置为1,则表明存在错误处理,然后可以根据Error_code得知故障原因,并通过Last_user_ID定位到发生故障的模块。 Second, detection of abnormal processes: buffer between the applicant and the deliverer of the intermediate links need to check the Error flag, if set to 1, it indicates that there is an error handling, and can Error_code know the cause, and through Last_user_ID Locate the faulty module. 。 .
三,重复释放的错误检测:在释放一块缓存区时,由于Tail指针指向的是欲释放的内存片,因此如果Using的值为0,则表明该缓存区被重复释放,然后根据Last_user_ID定位到重复释放的模块。 Third, the double free error detection: the release of a buffer zone, the Tail pointer to the memory chip to be released, so if Using a value of 0, it indicates that the buffer is repeatedly released, and then locate the duplicate Last_user_ID the release of the module. 同样可以增加打印功能,打印出正在运行的模块名和重复释放的缓存区供定位。 Can also increase the print function to print out the name of the module and the running buffer for the release of repeated positioning.
四,缓存区泄漏的检测:在调试时,可以启动一个任务,定期检测所有的缓存区资源,如果某个缓存区块在预定时间内没有释放,即Using始终为1,可以根据Last_user_ID判断最终使用的模块,从而将忘记释放的错误定位到模块。 Fourth, the buffer leak detection: When debugging, you can start a task on a regular basis to detect all the cache resources, if a cache block is not released within a predetermined time, namely Using always 1, according to Last_user_ID determine end-use The module, which will forget to release the module positioning errors.
以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以作出若干改进和润饰,这些改进和润饰也应视为本发明的保护范围。 The above description is only preferred embodiments of the present invention, it should be noted that for the technical field of ordinary skill in the principle of the invention without departing from the premise, but also a number of improvements and modifications can be made, these improvements and modifications should also be as the scope of the invention. 中兴通讯股份有限公司Method for detecting descriptor resource of network processing system and system thereof成都市华为赛门铁克科技有限公司Buffer management method and apparatus, data forwarding system大唐移动通信设备有限公司一种串行Rapid IO链路数据传输的方法及装置成都市华为赛门铁克科技有限公司Data processing method, device and data processing system國際專利分類號C14GrantedC10Request of examination as to substanceC06Publication旋轉&2012 Google

我要回帖

更多关于 general failure 的文章

 

随机推荐