WO2014180446A1 - 一种网络设备写表方法及装置 - Google Patents

一种网络设备写表方法及装置 Download PDF

Info

Publication number
WO2014180446A1
WO2014180446A1 PCT/CN2014/079890 CN2014079890W WO2014180446A1 WO 2014180446 A1 WO2014180446 A1 WO 2014180446A1 CN 2014079890 W CN2014079890 W CN 2014079890W WO 2014180446 A1 WO2014180446 A1 WO 2014180446A1
Authority
WO
WIPO (PCT)
Prior art keywords
space
memory address
kernel
kernel space
user
Prior art date
Application number
PCT/CN2014/079890
Other languages
English (en)
French (fr)
Inventor
姜海明
王治春
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2014180446A1 publication Critical patent/WO2014180446A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • G06F9/4411Configuring for operating with peripheral devices; Loading of device drivers

Definitions

  • the present invention relates to the field of communications, and in particular, to a network device writing table method and apparatus.
  • ASIC Application Specific Integrated Circuit
  • P Network Processor
  • the peripheral interface of the network chip is very rich, such as static random access memory (SRAM), ternary content addressable memory (TCAM), and synchronous dynamic random access memory (Synchronous Dynamic Random Access Memory). SDRAM), etc., these memories store various service items, such as port table, medium access control (MAC) table, routing table, etc.
  • the chip includes a large number of registers.
  • the control layer software frequently interacts with the chip, for example, the service configuration.
  • the main thing is to read and write the chip memory and internal registers.
  • many network device entries and register configurations are implemented by a CPU (Central Processing Unit) and a chip for message interaction.
  • the Linux operating system is widely used in network device drivers.
  • the Linux system is divided into two levels: user mode and kernel mode.
  • the chip driver hierarchy is shown in Figure 1.
  • the Linux system device driver software hierarchy diagram The current practice of the network device driver to send messages is that the user mode applies for memory and fills the message into the user state memory, because the actual interaction with the chip is the kernel layer.
  • the present invention provides a method and device for writing a network device to solve the above technical problem.
  • an embodiment of the present invention provides a network device write table method, where the method includes: a kernel space pre-applying memory, mapping a kernel space memory to a user space, and obtaining a user space memory address; The space applies the foregoing kernel space memory to the kernel space to obtain a corresponding user space memory address; the user space memory address and the message size are recorded in the buffer buffer descriptor and transmitted to the kernel space; the kernel space uses the user space memory The address is converted to a kernel space memory address, and the message is written to the chip through a Direct Memory Access (DMA) controller.
  • DMA Direct Memory Access
  • the kernel space maps the kernel space memory to the user space
  • the method further includes: calculating, by the kernel space, the offset of the user space memory address relative to the kernel space memory address according to the user space memory address.
  • the above offset kernel space memory address - user space memory address.
  • the user space applies the foregoing kernel space memory to the kernel space, and obtains the user space memory address, including: the user space applies for kernel space memory to the kernel space, and obtains a kernel space memory address; the user space is based on the offset and the kernel.
  • the space memory address calculated as the user space memory address.
  • the kernel space writes the message to the chip by using the DMA controller
  • the method includes: the kernel space transfers the kernel space memory address and the message size to the DMA controller, and the driver of the kernel space writes the message by using the DMA controller.
  • the user space stores the user space memory address to be released into the buffer descriptor and transfers it to the kernel space; the kernel space calculates the kernel space memory address according to the offset and the user space memory address; the kernel space will be The above kernel space memory address is passed to the kernel space driver; the kernel space driver releases the buffer descriptor.
  • the kernel space maps the kernel space memory to the user space, including: The kernel space maps the kernel space memory to the user space through the mmap.
  • an embodiment of the present invention further provides a network device write table device, which is applied to a kernel space
  • the device includes: a memory application module, configured to pre-apply memory, and map the kernel space memory to User space, get user space memory address; message writing module, set to receive user empty After passing the user space memory address, the above user space memory address is converted into a kernel space memory address, and the message is written to the chip through the direct memory access DMA controller.
  • the apparatus further includes: a release module configured to obtain a kernel space memory address according to a user space memory address transmitted by the user space through the buffer buffer descriptor; and the kernel space memory address is transmitted to the kernel space driver, so that The above driver releases the buffer descriptor.
  • an embodiment of the present invention further provides a network device write table device, which is applied to a user space, where the device includes: applying for a memory module, and setting to apply for kernel space memory to a kernel space, and obtaining a corresponding The user space memory address; the descriptor passing module is configured to record the above user space memory address and message size in the buffer buffer descriptor and pass it to the kernel space.
  • the foregoing application memory module includes: a first processing unit configured to apply for kernel space memory to the kernel space to obtain a kernel space memory address thereof; and a second processing unit configured to calculate according to the offset and the kernel space memory address Obtaining a user space memory address; wherein the offset is an offset of the user space memory address relative to the kernel space memory address, and the offset is a kernel space memory address and a user space memory address.
  • the kernel state memory is applied in advance, and the kernel state memory is mapped to the user state by using the zero copy technology, and the user state memory address is directly obtained by the buffer descriptor when the user state sends the message, so that User mode can be avoided to apply for memory, and only a small buffer descriptor needs to be passed between user mode and kernel mode, which saves a lot of memory copy operations.
  • the problem that the network device writing table method has a large burden on the CPU in the related art is solved, and the message transfer between the kernel driver and the chip adopts the DMA mechanism, thereby reducing the burden on the CPU.
  • FIG. 1 is a schematic diagram of a Linux system device driver software hierarchy according to the related art
  • FIG. 2 is a flowchart of a network device write table method according to an embodiment of the present invention
  • FIG. 3 is a software hierarchy diagram according to an embodiment of the present invention
  • 4 is a flowchart of an open system call according to an embodiment of the present invention
  • FIG. 5 is a schematic diagram of memory mapping of a user space and a kernel space memory unit according to an embodiment of the present invention
  • FIG. 6 is a flow chart of message transmission according to an embodiment of the present invention
  • 7 is a structural block diagram of a network device write table device applied to a kernel space according to an embodiment of the present invention
  • FIG. 8 is a structural block diagram of a network device write table device applied to a user space according to an embodiment of the present invention.
  • the present invention provides a method and device for writing a network device.
  • the present invention further details the present invention with reference to the accompanying drawings and embodiments. Description.
  • FIG. 2 is a flowchart of a network device write table method according to an embodiment of the present invention.
  • the method includes the following steps (step S202-step S206): Step S202, the kernel space applies for memory in advance, and maps the kernel space memory to the user space to obtain a user space memory address.
  • the kernel space maps kernel space memory to the user space via mmap.
  • Step S204 the user space applies for kernel space memory to the kernel space, and obtains a corresponding user space memory address; and records the user space memory address and the message size in the buffer buffer descriptor and transfers the space to the kernel space.
  • the user space applies for kernel space memory to the kernel space, and obtains the user space memory address, which can be implemented by the following preferred implementation manner: User space applies for kernel space memory to the kernel space, and obtains its kernel space memory address; The shift and kernel space memory addresses are calculated and the user space memory address is calculated.
  • Step S206 the kernel space converts the user space memory address into a kernel space memory address, and writes the message to the chip through the direct memory access DMA controller.
  • the kernel space passes the kernel space memory address and message size to the DMA controller, and the kernel space driver writes the message to the chip through the DMA controller.
  • This embodiment further provides a preferred implementation manner, which introduces a memory release process, that is, a user space memory address to be released by the user space, which is recorded in the buffer descriptor and transmitted to the kernel space; The amount and user space memory address, calculate the kernel space memory address; the kernel space transfers the kernel space memory address to the kernel space driver; the kernel space driver releases the buffer descriptor.
  • FIG. 3 is a schematic diagram of a software hierarchy according to an embodiment of the present invention.
  • the kernel space pre-applies for kernel state memory, and uses zero copy technology to map the kernel state memory to the user state.
  • the user state When the user state sends a message, the user directly obtains the user through the buffer descriptor. State memory address, this can avoid the user mode to apply for memory, and only a small buffer descriptor needs to be passed between the user state and the kernel state, which saves a lot of memory copy operations.
  • the problem that the network device writing table method has a large burden on the CPU in the related art is solved, and the message transmission between the kernel driver and the chip adopts the DMA mechanism, which reduces the burden on the CPU.
  • the performance of the write table can be greatly improved, and the efficiency of writing the device driven by Linux is effectively improved.
  • the chip driver is a character device driver, that is, the driver operates the chip as a file, and the user mode driver and the kernel mode driver interact through the file stream.
  • the chip driver first initializes the file_operation structure for the chip.
  • the structure includes the open, close, write, control (ioctl), and map (mmap) methods of the character device. Specifically, 1. Map (mmap) method: Provides an interface that maps kernel space memory to user space memory; 2. Open method: Apply kernel state memory, and map memory blocks to user space through mmap mapping. And the divided memory block is N memory units buf.
  • the operation process is as shown in the open system call flow chart shown in FIG. 4, as shown in FIG. 4, the flow includes the following steps (step S402-step S410).
  • Step S410 ending.
  • the user space gets a shadow map associated with the kernel space.
  • the memory space of the user space and kernel space memory unit is schematic.
  • Each buffer unit in the kernel space has a unique user space address in the user space.
  • control (ioctl) method Provide user interface program to apply for, release the interface. Enter the buffer descriptor.
  • the Buffer descriptor consists of two pieces of information, the user mode address and the message size.
  • the kernel space calculates the corresponding kernel space address based on the address offset 0.
  • Addr_kernel Addr usr + 0. Pass the Addr_kernel to the kernel driver, which is responsible for "freeing" the buffer unit.
  • the "application” and “release” are just for the purpose of understanding the use. It is not true to apply for the release of memory to the operating system. Instead, the kernel driver manages the buffer unit of the kernel and records whether each buffer unit is in use. A state in the middle. In fact, the application and release of memory will only occur in the opening and closing of the device.
  • the write table message sending interface is implemented by two system calls ioctl and write. Both system calls pass the user space address and message length through a buffer descriptor. Since the mmap mapping is adopted, the user space does not need to apply for memory. It only needs to call the ioctl interface to apply for the free buffer of the kernel space, and fill in the message content to the user space address mapped with the kernel buffer address.
  • Step S602 an application for memory. Apply the kernel mode memory unit through the IOCTL interface to obtain the corresponding user space address.
  • step S604 the message is filled. The message content is copied into the user space address, and the message size and the user space address are filled in the buffer descriptor in step S606, and the message is sent. The buffer descriptor is passed to the kernel space via the write interface.
  • FIG. 7 is a structural block diagram of a network device write table device applied to a kernel space according to an embodiment of the present invention. As shown in FIG. 7, the device includes: a memory application module 10 and a message writing module 12. The structure is described in detail below.
  • the memory application module 10 is configured to pre-apply memory, map the kernel space memory to the user space, and obtain the user space memory address; the message writing module 12 is connected to the memory application module 10, and is set to receive the user space transmitted by the user space. After the memory address, the user space memory address is converted to the kernel space memory address, and the message is written to the chip through the direct memory access DMA controller.
  • the apparatus further includes: a release module configured to obtain a kernel space memory address according to a user space memory address passed by the user space through the buffer buffer descriptor; and the kernel space memory address is transmitted to the driver of the kernel space, so that The driver releases the buffer descriptor.
  • FIG. 8 is a structural block diagram of a network device write table device applied to a user space according to an embodiment of the present invention.
  • the device includes: an application memory module 20 and a descriptor delivery module 22.
  • the structure is described in detail below.
  • the memory module 20 is configured to apply for kernel space memory to the kernel space to obtain a corresponding user space memory address.
  • the descriptor delivery module 22 is connected to the application memory module 20 and configured to record the user space memory address and the message size in the buffer.
  • the buffer descriptor is passed to the kernel space.
  • the embodiment of the present invention applies for memory in the kernel space in advance, and is divided into memory units, and the mapping relationship between the user space virtual address and the kernel space memory address is established through mmap.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)
  • Bus Control (AREA)

Abstract

公开了一种网络设备写表方法及装置。其中,该方法包括:内核空间预先申请内存,将内核空间内存映射到用户空间,得到用户空间内存地址;用户空间向内核空间申请内核空间内存,得到对应的用户空间内存地址;将用户空间内存地址和消息大小记录在buffer描述符中传递给内核空间;内核空间将用户空间内存地址转换为内核空间内存地址,通过DMA控制器将消息写入芯片。解决了相关技术中网络设备写表方法对CPU的负担较大的问题,内核驱动和芯片之间的消息传递采用DMA机制,减少了CPU的负担。在网络设备驱动层面大量发送写表消息的应用中,可以极大提高写表性能,有效改进Linux下设备驱动的写表效率。

Description

一种网络设备写表方法及装置 技术领域 本发明涉及通信领域, 特别是涉及一种网络设备写表方法及装置。 背景技术 现今网络发展速度惊人, 网络流量的增长及新业务的出现, 需要网络设备具有线 速和灵活的处理能力。 目前网络芯片包括集成电路 (Application Specific Integrated Circuit, 简称为 ASIC) 和 P (网络处理器) 两大类。 网络芯片***接口非常丰富, 如静态随机存储器 (Static RAM, 简称为 SRAM)、 三态内容寻址存储器 (ternary content addressable memory, 简称为 TCAM)、 同步动态 随机存储器(Synchronous Dynamic Random Access Memory, 简称为 SDRAM) 等, 这 些存储器存放着各种业务表项, 如端口表、 介质访问控制 (medium access control, 简 称为 MAC) 表、 路由表等; 另外, 芯片内部包括大量的寄存器。 网络设备运行过程中, 控制层软件会频繁的与芯片进行交互, 比如下发业务配置 等。 对芯片而言, 主要就是读写芯片存储器和内部寄存器。 目前很多网络设备表项、 寄存器配置是通过 CPU (中央处理器) 与芯片进行消息交互实现的。 目前 Linux操作***广泛应用于网络设备驱动中, Linux***分为用户态和内核态 两个层面。 芯片驱动层次如图 1所示的 Linux***设备驱动软件层次示意图, 目前网 络设备驱动发送消息的通常做法是用户态申请内存并将消息填充到用户态内存中, 由 于实际与芯片交互的是内核层, 因此必须将消息从用户态的内存拷贝到内核态的内存 中, 然后从内核态的内存通过总线写入硬件芯片中。 由于网络交换设备中消息交互非常频繁,极限情况每秒钟可能有上万条消息发送, 因此这涉及了大量的内存申请,以及用户态、内核态的拷贝操作。这对网络设备的 CPU 是一个很大的负担, 影响了网络设备的写表效率。 针对相关技术中网络设备写表方法对 CPU的负担较大的问题, 目前尚未提出有效 的解决方案。 发明内容 针对相关技术中网络设备写表方法对 CPU的负担较大的问题,本发明实施例提供 了一种网络设备写表方法及装置, 用以解决上述技术问题。 根据本发明的一个方面, 本发明实施例提供了一种网络设备写表方法, 其中, 该 方法包括: 内核空间预先申请内存, 将内核空间内存映射到用户空间, 得到用户空间 内存地址; 上述用户空间向上述内核空间申请上述内核空间内存, 得到对应的用户空 间内存地址; 将上述用户空间内存地址和消息大小记录在缓冲区 buffer描述符中传递 给上述内核空间; 上述内核空间将上述用户空间内存地址转换为内核空间内存地址, 通过直接内存存取 (Direct Memory Access, 简称为 DMA) 控制器将消息写入芯片。 优选地, 内核空间将内核空间内存映射到用户空间,得到用户空间内存地址之后, 上述方法还包括: 内核空间根据上述用户空间内存地址, 计算上述用户空间内存地址 相对于内核空间内存地址的偏移量;其中,上述偏移量 =内核空间内存地址一用户空间 内存地址。 优选地, 用户空间向内核空间申请上述内核空间内存, 得到上述用户空间内存地 址, 包括: 用户空间向内核空间申请内核空间内存, 得到其内核空间内存地址; 用户 空间根据上述偏移量和上述内核空间内存地址, 计算得到用户空间内存地址。 优选地, 内核空间通过上述 DMA控制器将消息写入芯片, 包括: 内核空间将上 述内核空间内存地址和上述消息大小, 传递给上述 DMA控制器, 内核空间的驱动通 过上述 DMA控制器将消息写入芯片。 优选地, 用户空间将待释放的用户空间内存地址, 记录到上述 buffer描述符中传 递给内核空间; 内核空间根据上述偏移量和上述用户空间内存地址, 计算得到内核空 间内存地址; 内核空间将上述内核空间内存地址传递给内核空间的驱动; 内核空间的 驱动释放上述 buffer描述符。 优选地, 内核空间将上述内核空间内存映射到用户空间, 包括: 内核空间将上述 内核空间内存, 通过 mmap映射到用户空间。 根据本发明的另一方面, 本发明实施例还提供了一种网络设备写表装置, 应用于 内核空间, 其中, 该装置包括: 内存申请模块, 设置为预先申请内存, 将内核空间内 存映射到用户空间, 得到用户空间内存地址; 消息写入模块, 设置为在接收到用户空 间传递的用户空间内存地址后, 将上述用户空间内存地址转换为内核空间内存地址, 通过直接内存存取 DMA控制器将消息写入芯片。 优选地, 上述装置还包括: 释放模块, 设置为根据用户空间通过缓冲区 buffer描 述符传递的用户空间内存地址, 得到内核空间内存地址; 将该内核空间内存地址传递 给内核空间的驱动, 以使上述驱动释放上述 buffer描述符。 根据本发明的又一方面, 本发明实施例还提供了一种网络设备写表装置, 应用于 用户空间, 其中, 该装置包括: 申请内存模块, 设置为向内核空间申请内核空间内存, 得到对应的用户空间内存地址; 描述符传递模块, 设置为将上述用户空间内存地址和 消息大小记录在缓冲区 buffer描述符中传递给内核空间。 优选地, 上述申请内存模块包括: 第一处理单元, 设置为向内核空间申请内核空 间内存, 得到其内核空间内存地址; 第二处理单元, 设置为根据偏移量和上述内核空 间内存地址, 计算得到用户空间内存地址; 其中, 上述偏移量是上述用户空间内存地 址相对于内核空间内存地址的偏移量,上述偏移量 =内核空间内存地址一用户空间内存 地址。 通过本发明实施例提供的技术方案, 预先申请内核态内存, 并利用零拷贝技术, 将内核态的内存映射到用户态, 用户态发送消息时, 直接通过 buffer描述符获得用户 态内存地址, 这样可以避免用户态申请内存, 而且用户态、 内核态之间只需要传递一 个很小的 buffer描述符, 省去了大量的内存拷贝操作。 解决了相关技术中网络设备写 表方法对 CPU的负担较大的问题, 内核驱动和芯片之间的消息传递采用 DMA机制, 减少了 CPU的负担。在网络设备驱动层面大量发送写表消息的应用中, 可以极大提高 写表性能, 有效改进 Linux下设备驱动的写表效率。 上述说明仅是本发明技术方案的概述, 为了能够更清楚了解本发明的技术手段, 而可依照说明书的内容予以实施, 并且为了让本发明的上述和其它目的、 特征和优点 能够更明显易懂, 以下特举本发明的具体实施方式。 附图说明 图 1 是根据相关技术的 Linux***设备驱动软件层次示意图; 图 2 是根据本发明实施例的网络设备写表方法的流程图; 图 3 是根据本发明实施例的软件层次示意图; 图 4 是根据本发明实施例的 open***调用流程图; 图 5 是根据本发明实施例的用户空间和内核空间内存单元内存映射示意图; 图 6 是根据本发明实施例的消息发送流程图; 图 7 是根据本发明实施例的应用于内核空间的网络设备写表装置的结构框图; 以 及 图 8 是根据本发明实施例的应用于用户空间的网络设备写表装置的结构框图。 具体实施方式 为了解决现有技术中网络设备写表方法对 CPU的负担较大的问题,本发明提供了 一种网络设备写表方法及装置, 以下结合附图以及实施例, 对本发明进行进一步详细 说明。 应当理解, 此处所描述的具体实施例仅仅用以解释本发明, 并不限定本发明。 本实施例提供了一种网络设备写表方法, 图 2是根据本发明实施例的网络设备写 表方法的流程图, 如图 2所示, 该方法包括以下步骤 (步骤 S202-步骤 S206): 步骤 S202, 内核空间预先申请内存, 将内核空间内存映射到用户空间, 得到用户 空间内存地址。 优选地, 内核空间将内核空间内存, 通过 mmap映射到用户空间。 在 此之后, 内核空间根据用户空间内存地址, 计算用户空间内存地址相对于内核空间内 存地址的偏移量; 其中, 偏移量 =内核空间内存地址一用户空间内存地址。 步骤 S204, 用户空间向内核空间申请内核空间内存, 得到对应的用户空间内存地 址; 将用户空间内存地址和消息大小记录在缓冲区 buffer描述符中传递给内核空间。 在该步骤中, 用户空间向内核空间申请内核空间内存, 得到用户空间内存地址, 可以通过以下优选实施方式实现: 用户空间向内核空间申请内核空间内存, 得到其内 核空间内存地址; 用户空间根据偏移量和内核空间内存地址, 计算得到用户空间内存 地址。 步骤 S206, 内核空间将用户空间内存地址转换为内核空间内存地址, 通过直接内 存存取 DMA控制器将消息写入芯片。 具体地, 内核空间将内核空间内存地址和消息 大小, 传递给 DMA控制器, 内核空间的驱动通过 DMA控制器将消息写入芯片。 本实施例还提供了一种优选实施方式, 来介绍内存释放过程, 即用户空间将待释 放的用户空间内存地址, 记录到 buffer描述符中传递给内核空间; 内核空间根据偏移 量和用户空间内存地址, 计算得到内核空间内存地址; 内核空间将内核空间内存地址 传递给内核空间的驱动; 内核空间的驱动释放 buffer描述符。 图 3是根据本发明实施例的软件层次示意图, 内核空间预先申请内核态内存, 并 利用零拷贝技术,将内核态的内存映射到用户态,用户态发送消息时, 直接通过 buffer 描述符获得用户态内存地址, 这样可以避免用户态申请内存, 而且用户态、 内核态之 间只需要传递一个很小的 buffer描述符, 省去了大量的内存拷贝操作。 解决了相关技 术中网络设备写表方法对 CPU的负担较大的问题,内核驱动和芯片之间的消息传递采 用 DMA机制,减少了 CPU的负担。在网络设备驱动层面大量发送写表消息的应用中, 可以极大提高写表性能, 有效改进 Linux下设备驱动的写表效率。 下面对芯片驱动程序的具体操作进行介绍。 芯片驱动程序为字符设备驱动, 即驱动程序将芯片作为文件进行操作, 用户态驱 动程序和内核态驱动程序通过文件流进行交互。 芯片驱动首先要为芯片初始化 file_operation结构, 该结构包括该字符设备的打开(open)、关闭(close)、 写(write)、 控制 (ioctl)、 映射 (mmap) 方法。 具体地讲, 1、 映射 (mmap) 方法: 提供将内核空间内存映射到用户空间内存的接口; 2、 打开 (open) 方法: 申请内核态内存, 并通过 mmap映射将内存块映射到用户空间, 并且分割内存块 为 N个内存单元 buf。 该操作过程如图 4所示的 open***调用流程图, 如图 4所示, 该流程包括以下步骤 (步骤 S402-步骤 S410)。 步骤 S402, 申请内核内存块, 内核态内存起始地址为!^ 步骤 S404, 调用 mmap接口将内核空间内存映射到用户空间, 得到的用户态内存 起始地址为 U。 步骤 S406,计算用户空间地址相对于内核空间地址的偏移量 0。 0=K-U。通常的, 内核空间地址范围为 3G~4<¾用户空间地址范围为 0~3G。 步骤 S408, 内存块分割。 由于 Linux为多进程操作***, 同一时刻可能有多个进程进行写表, 为了提升内 核内存的利用率及写表性能, 将内核内存块分割成一个一个小的 buffer ( buf0、 bufl, ...bum) . 由内核驱动程序管理维护这些 buffer单元。 步骤 S410, 结束。 经过 open***调用后, 用户空间得到了与内核空间相关联 shadow映射。 如图 5 所示的用户空间和内核空间内存单元内存映射示意图, 内核空间每个 buffer单元在用 户空间都有唯一确定的一个用户空间地址。
3、 关闭 (close) 方法: 释放软件资源, 将内核态申请的内存释放。 4、 控制 (ioctl) 方法: 为用户态程序提供申请、 释放内存的接口。 入参为 buffer描述符。 Buffer描述符 包括两个信息, 用户态地址和消息大小。 申请内存时, 向内核驱动程序 "申请 " 空闲 buffer 单元, 得到其内核态地址 Addr kernel, 根据用户空间地址和内核空间地址偏移量 0, 计算得到其用户空间地址 Addr usr = Addr kernel - 0, 并将 Addr_usr记录到 buffer描述符返回给用户空间。 释放内存,用户空间将待释放的用户空间地址通过 buffer描述符传递给内核空间。 内核空间根据地址偏移量 0计算得到相应的内核空间地址 Addr_kernel = Addr usr + 0。 将 Addr_kernel传递给内核驱动程序, 内核驱动负责 "释放 "该 buffer单元。 注: 这里的 "申请"、 "释放"只是为了便于理解使用的说法, 并不是真实的向操作系 统申请释放内存, 而是内核驱动程序为了管理内核 buffer单元, 记录每个 buffer单元 的是否在使用中的一个状态。 实际上, 内存的申请、 释放只会发生在设备的打开、 关 闭调用中。
5、 写 (write) 方法: 用户程序将用户空间地址及消息大小通过 buffer描述符传递给内核空间。 内核空 间将用户地址转换成内核空间地址 (Addr_kemel = Addr usr + 0), 将 Addr_kernel和 消息大小传递给 DMA控制器, 内核驱动通过 DMA将消息快速写入芯片。 写表消息发送接口借助 ioctl和 write两个***调用实现, 这两个***调用都通过 一个 buffer描述符传递用户空间地址及消息长度。 由于采用了 mmap映射, 用户空间 不需要申请内存, 只需要调用 ioctl接口申请内核空间的空闲 buffer, 将消息内容填写 到与内核 buffer地址映射的用户空间地址。填写完成, 调用 write接口, 内核态程序将 用户空间地址进行转换得到内核态地址, 从而通过 DMA写入芯片, 如图 6所示的消 息发送流程图, 该流程包括以下步骤 (步骤 S602-步骤 S610)。 步骤 S602, 内存申请。 通过 IOCTL接口申请内核态内存单元, 获取相应的用户 空间地址。 步骤 S604, 消息填充。 将消息内容拷贝到用户空间地址中, 并将消息大小和用户 空间地址填到 buffer描述符中 步骤 S606, 消息发送。 通过 write接口, 将 buffer描述符传递给内核空间。 内核 驱动将用户空间地址和消息大小传递给 DMA控制器, 通过 DMA快速写入芯片 步骤 S608, 内存释放。 通过 IOCTL接口释放内核态内存单元, 记录内核空间中 相应 buffer单元为可用状态。 步骤 S610, 结束。 对应于上述实施例介绍的网络设备写表方法, 本实施例提供了一种网络设备写表 装置, 该装置可以应用于内核空间, 用以实现上述实施例。 图 7是根据本发明实施例 的应用于内核空间的网络设备写表装置的结构框图, 如图 7所示, 该装置包括: 内存 申请模块 10和消息写入模块 12。 下面对该结构进行详细介绍。 内存申请模块 10, 设置为预先申请内存, 将内核空间内存映射到用户空间, 得到 用户空间内存地址; 消息写入模块 12,连接至内存申请模块 10,设置为在接收到用户空间传递的用户 空间内存地址后, 将用户空间内存地址转换为内核空间内存地址, 通过直接内存存取 DMA控制器将消息写入芯片。 优选地, 该装置还包括: 释放模块, 设置为根据用户空间通过缓冲区 buffer描述 符传递的用户空间内存地址, 得到内核空间内存地址; 将该内核空间内存地址传递给 内核空间的驱动, 以使驱动释放 buffer描述符。 对应于上述实施例介绍的网络设备写表方法, 本实施例提供了一种网络设备写表 装置, 该装置可以应用于用户空间, 用以实现上述实施例。 图 8是根据本发明实施例 的应用于用户空间的网络设备写表装置的结构框图, 如图 8所示, 该装置包括: 申请 内存模块 20和描述符传递模块 22。 下面对该结构进行详细介绍。 申请内存模块 20, 设置为向内核空间申请内核空间内存, 得到对应的用户空间内 存地址; 描述符传递模块 22,连接至申请内存模块 20,设置为将用户空间内存地址和消息 大小记录在缓冲区 buffer描述符中传递给内核空间。 优选地, 上述申请内存模块 10包括: 第一处理单元, 设置为向内核空间申请内核 空间内存, 得到其内核空间内存地址; 第二处理单元, 设置为根据偏移量和内核空间 内存地址, 计算得到用户空间内存地址; 其中, 偏移量是用户空间内存地址相对于内 核空间内存地址的偏移量, 偏移量 =内核空间内存地址一用户空间内存地址。 从以上的描述中可以看出, 本发明实施例预先在内核空间申请内存, 并划分为一 个个的内存单元,通过 mmap建立用户空间虚拟地址和内核空间内存地址的映射关系。 这样用户空间和内核空间都不需要在消息过程中申请内存, 并且避免了内存空间内存 和内核空间内存的大量拷贝操作。 内核驱动和芯片之间的消息传递采用 DMA机制, 减少了 CPU的负担。在网络设备驱动层面大量发送写表消息的应用中, 可以极大提高 写表性能。 尽管为示例目的, 已经公开了本发明的优选实施例, 本领域的技术人员将意识到 各种改进、 增加和取代也是可能的, 因此, 本发明的范围应当不限于上述实施例。

Claims

权 利 要 求 书 、 一种网络设备写表方法, 包括:
内核空间预先申请内存, 将内核空间内存映射到用户空间, 得到用户空间 内存地址;
所述用户空间向所述内核空间申请所述内核空间内存, 得到对应的用户空 间内存地址; 将所述用户空间内存地址和消息大小记录在缓冲区 buffer描述符 中传递给所述内核空间;
所述内核空间将所述用户空间内存地址转换为内核空间内存地址, 通过直 接内存存取 DMA控制器将消息写入芯片。 、 如权利要求 1所述的方法, 其中, 内核空间将内核空间内存映射到用户空间, 得到用户空间内存地址之后, 所述方法还包括:
内核空间根据所述用户空间内存地址, 计算所述用户空间内存地址相对于 内核空间内存地址的偏移量; 其中, 所述偏移量 =内核空间内存地址一用户空 间内存地址。 、 如权利要求 2所述的方法,其中,用户空间向内核空间申请所述内核空间内存, 得到所述用户空间内存地址, 包括:
用户空间向内核空间申请内核空间内存, 得到其内核空间内存地址; 用户空间根据所述偏移量和所述内核空间内存地址, 计算得到用户空间内 存地址。 、 如权利要求 1所述的方法, 其中, 内核空间通过所述 DMA控制器将消息写入 芯片, 包括:
内核空间将所述内核空间内存地址和所述消息大小, 传递给所述 DMA控 制器, 内核空间的驱动通过所述 DMA控制器将消息写入芯片。 、 如权利要求 2所述的方法, 其中, 所述方法还包括:
用户空间将待释放的用户空间内存地址, 记录到所述 buffer描述符中传递 给内核空间; 内核空间根据所述偏移量和所述用户空间内存地址, 计算得到内核空间内 存地址;
内核空间将所述内核空间内存地址传递给内核空间的驱动;
内核空间的驱动释放所述 buffer描述符。 、 如权利要求 1所述的方法, 其中, 内核空间将所述内核空间内存映射到用户空 间, 包括:
内核空间将所述内核空间内存, 通过 mmap映射到用户空间。 、 一种网络设备写表装置, 应用于内核空间, 所述装置包括:
内存申请模块, 设置为预先申请内存, 将内核空间内存映射到用户空间, 得到用户空间内存地址;
消息写入模块, 设置为在接收到用户空间传递的用户空间内存地址后, 将 所述用户空间内存地址转换为内核空间内存地址, 通过直接内存存取 DMA控 制器将消息写入芯片。 、 如权利要求 7所述的装置, 其中, 所述装置还包括:
释放模块, 设置为根据用户空间通过缓冲区 buffer描述符传递的用户空间 内存地址, 得到内核空间内存地址; 将该内核空间内存地址传递给内核空间的 驱动, 以使所述驱动释放所述 buffer描述符。 、 一种网络设备写表装置, 应用于用户空间, 所述装置包括:
申请内存模块, 设置为向内核空间申请内核空间内存, 得到对应的用户空 间内存地址;
描述符传递模块, 设置为将所述用户空间内存地址和消息大小记录在缓冲 区 buffer描述符中传递给内核空间。 0、 如权利要求 9所述的装置, 其中, 所述申请内存模块包括:
第一处理单元, 设置为向内核空间申请内核空间内存, 得到其内核空间内 存地址;
第二处理单元, 设置为根据偏移量和所述内核空间内存地址, 计算得到用 户空间内存地址; 其中, 所述偏移量是所述用户空间内存地址相对于内核空间 内存地址的偏移量, 所述偏移量 =内核空间内存地址一用户空间内存地址。
PCT/CN2014/079890 2013-12-23 2014-06-13 一种网络设备写表方法及装置 WO2014180446A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310717789.8A CN104731711A (zh) 2013-12-23 2013-12-23 一种网络设备写表方法及装置
CN201310717789.8 2013-12-23

Publications (1)

Publication Number Publication Date
WO2014180446A1 true WO2014180446A1 (zh) 2014-11-13

Family

ID=51866826

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/079890 WO2014180446A1 (zh) 2013-12-23 2014-06-13 一种网络设备写表方法及装置

Country Status (2)

Country Link
CN (1) CN104731711A (zh)
WO (1) WO2014180446A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109688058A (zh) * 2018-12-19 2019-04-26 迈普通信技术股份有限公司 报文处理方法、装置及网络设备
CN110069422A (zh) * 2018-01-23 2019-07-30 普天信息技术有限公司 基于mips多核处理器的内存缓冲区回收方法

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105323184A (zh) * 2015-10-08 2016-02-10 盛科网络(苏州)有限公司 节约ram资源实现流量统计的方法及装置
CN106775462A (zh) * 2016-11-30 2017-05-31 郑州云海信息技术有限公司 一种读写过程中减少内存拷贝的方法和装置
CN112272111A (zh) * 2020-10-16 2021-01-26 苏州浪潮智能科技有限公司 一种snmp数据的处理方法、***及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090092057A1 (en) * 2007-10-09 2009-04-09 Latis Networks, Inc. Network Monitoring System with Enhanced Performance
CN102082698A (zh) * 2009-11-26 2011-06-01 上海大学 基于改进型零拷贝技术的高性能内核的网络数据处理***
CN102375789A (zh) * 2010-08-09 2012-03-14 上海中标软件有限公司 一种通用网卡非缓存的零拷贝方法及零拷贝***
CN102467473A (zh) * 2010-11-03 2012-05-23 Tcl集团股份有限公司 一种在用户空间和内核之间传输数据的方法和装置
CN103391256A (zh) * 2013-07-25 2013-11-13 武汉邮电科学研究院 一种基于Linux***的基站用户面数据处理优化方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090092057A1 (en) * 2007-10-09 2009-04-09 Latis Networks, Inc. Network Monitoring System with Enhanced Performance
CN102082698A (zh) * 2009-11-26 2011-06-01 上海大学 基于改进型零拷贝技术的高性能内核的网络数据处理***
CN102375789A (zh) * 2010-08-09 2012-03-14 上海中标软件有限公司 一种通用网卡非缓存的零拷贝方法及零拷贝***
CN102467473A (zh) * 2010-11-03 2012-05-23 Tcl集团股份有限公司 一种在用户空间和内核之间传输数据的方法和装置
CN103391256A (zh) * 2013-07-25 2013-11-13 武汉邮电科学研究院 一种基于Linux***的基站用户面数据处理优化方法

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110069422A (zh) * 2018-01-23 2019-07-30 普天信息技术有限公司 基于mips多核处理器的内存缓冲区回收方法
CN110069422B (zh) * 2018-01-23 2021-06-18 普天信息技术有限公司 基于mips多核处理器的内存缓冲区回收方法
CN109688058A (zh) * 2018-12-19 2019-04-26 迈普通信技术股份有限公司 报文处理方法、装置及网络设备
CN109688058B (zh) * 2018-12-19 2021-03-02 迈普通信技术股份有限公司 报文处理方法、装置及网络设备

Also Published As

Publication number Publication date
CN104731711A (zh) 2015-06-24

Similar Documents

Publication Publication Date Title
WO2016078313A1 (zh) 数据写入方法及装置
WO2014180446A1 (zh) 一种网络设备写表方法及装置
US11249938B2 (en) Programmed input/output mode
US10719463B1 (en) Hardware handling memory write request during memory data migration
US20160294983A1 (en) Memory sharing using rdma
WO2020247042A1 (en) Network interface for data transport in heterogeneous computing environments
WO2019161557A1 (zh) 一种通信的方法及装置
WO2015000302A1 (zh) 一种数据传输方法、设备及***
WO2021164262A1 (zh) 虚拟网络的流量采集方法、装置、计算机设备及存储介质
KR100758272B1 (ko) 데이터 무 복사 파일 이동 방법
WO2018041074A1 (zh) 一种内存设备的访问方法、装置和***
US20210326177A1 (en) Queue scaling based, at least, in part, on processing load
Marinos et al. Disk| Crypt| Net: rethinking the stack for high-performance video streaming
WO2023115852A1 (zh) 基于pcie的通信方法、装置、计算机设备和可读存储介质
WO2022132278A1 (en) Network interface device with flow control capability
CN113127139B (zh) 一种基于数据面开发套件dpdk的内存分配方法和装置
WO2020083067A1 (zh) 资源管理的方法和装置
KR100936918B1 (ko) 정적 파일 전송 시스템콜 처리 toe 장치 및 방법
US11237981B1 (en) Memory scanner to accelerate page classification
CN110471627B (zh) 一种共享存储的方法、***及装置
WO2023030195A1 (zh) 缓存管理方法和装置、控制程序及控制器
WO2023065809A1 (zh) Cdn网元容器配置方法、读写方法、装置、设备及存储介质
CN116070239A (zh) 文件加密、解密方法、装置、设备及存储介质
WO2023033962A1 (en) Packet transmission scheduling
CN113422792B (zh) 数据传输方法、装置、电子设备及计算机存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14795293

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14795293

Country of ref document: EP

Kind code of ref document: A1