[go: up one dir, main page]

CN102467473B - Method and device for transmitting data between user space and kernel - Google Patents

Method and device for transmitting data between user space and kernel Download PDF

Info

Publication number
CN102467473B
CN102467473B CN201010536758.9A CN201010536758A CN102467473B CN 102467473 B CN102467473 B CN 102467473B CN 201010536758 A CN201010536758 A CN 201010536758A CN 102467473 B CN102467473 B CN 102467473B
Authority
CN
China
Prior art keywords
user
space
dma
data
memory
Prior art date
Legal status (The legal status 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 status listed.)
Expired - Fee Related
Application number
CN201010536758.9A
Other languages
Chinese (zh)
Other versions
CN102467473A (en
Inventor
刘亚萍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
TCL Corp
Original Assignee
TCL Corp
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 TCL Corp filed Critical TCL Corp
Priority to CN201010536758.9A priority Critical patent/CN102467473B/en
Publication of CN102467473A publication Critical patent/CN102467473A/en
Application granted granted Critical
Publication of CN102467473B publication Critical patent/CN102467473B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Memory System Of A Hierarchy Structure (AREA)
  • Bus Control (AREA)

Abstract

The invention relates to the field of data transmission and discloses a method and a device for efficiently transmitting data between a user space and a kernel by using a direct memory access (DMA). The invention provides a method of using internal memory mapping and a ring data buffer zone in a combined way and realizes the direct, simple and high-efficiency access to the internal memory of a peripheral from the user space when the DMA transmits data. Since the physical address of the DMA buffer zone is mapped to a user virtual space, a kernel space and the user space can access to the virtual address of the mapped user virtual space, the access speed between the internal memory and the peripheral can be improved when the DMA transmits data, the occupation ratio of central processing unit (CPU) resources is reduced and system resources are saved.

Description

A kind of method and apparatus transmitting data between user's space and kernel
Technical field
The present invention relates to field of data transmission, in particular a kind of method and device using DMA efficient transfer data between user's space and kernel.
Background technology
DMA (Direct MemoryAccess direct memory access) is a kind of hardware mechanisms, and its to allow between peripherals and main memory directly transmission data and without the need to through CPU.In dma mode, CPU need only assign instruction to dma controller, and allow dma controller to process the transmission of data, Data Transfer Done gives CPU information feed back again.And in DMA transmitting procedure, CPU also can carry out other process simultaneously, so just alleviate cpu resource occupation rate to a great extent, greatly can save system resource.
Usually, the DMA data between external unit and internal memory are transmitted to comprise and obtain data to internal memory from peripheral hardware buffer memorys, and (or) the data of internal memory are transferred in the buffer memory of peripheral hardware.As transmission data source or data processing need carry out at user's space, just need user directly can access peripheral hardware internal memory rapidly, at this moment all can use memory-mapped and DMA and map (refer to into a DMA buffer zone and for this buffer generation can by the address of device access) technology.
Owing to being subject to the restriction of DMA buffer size, the DMA of generation buffering can only be mapped to user's space by existing technology in realization, limits DMA transfer rate like this, and add the complexity of user's space and kernel operations with regard to very large.
Therefore, prior art has yet to be improved and developed.
Summary of the invention
The technical problem to be solved in the present invention is, for the above-mentioned defect of prior art, provide a kind of method and apparatus transmitting data between user's space and kernel, improve DMA and transmit in data procedures, the simplicity of the access efficiency between user's space and peripheral hardware, speed and operation.
The technical scheme that technical solution problem of the present invention adopts is as follows:
Between user's space and kernel, transmit a method for data, wherein, comprise step:
A, open peripheral hardware, application DMA buffer zone, configuration dma controller, initialization waiting list;
B, use memory mapping technique make a sector address m1 of user's space internal memory be associated with on peripheral hardware internal memory;
C, the physical address memory of the buffer zone of DMA is mapped to user Virtual Space, make kernel spacing and user's space can access this section mapped after the virtual address of user Virtual Space;
D, at user's space application a slice memory address m2;
E, generation are transmitted desired data source and are stored to user's space memory field m2, use memory copying technology will specify the data copy of number to specify to user's space memory field m1 position in user's space memory field m2, and write pointer that is mobile and adjustment m1 region, user's space memory field, notify that kernel upgrades the write pointer of DMA buffer circle simultaneously;
F, etc. the request of DMA to be launched transmission, if receive DMA to start request, then upgrade DMA transport address and transmission data amount check, start DMA transmission, amendment correlating markings, notify that peripheral hardware prepares to receive data simultaneously, then wait for that DMA is transmitted interruption.
The described method transmitting data between user's space and kernel, wherein, also comprises step:
G, kernel receive DMA interrupt request, first wake-up waiting queue, send request the order of data to user's space, and user's space detects this request, forwards step e to.
The described method transmitting data between user's space and kernel, wherein, also comprises step:
H, peripheral hardware receive the data that DMA transmits, and get back to step F.
Between user's space and kernel, transmit a device for data, wherein, comprising:
DMA buffer zone application unit, for applying for DMA buffer zone, configuration dma controller, initialization waiting list;
First associative cell, makes a sector address m1 of user's space internal memory be associated with peripheral hardware internal memory for using memory mapping technique;
User Virtual Space map unit, the physical address memory for the buffer zone by DMA is mapped to user Virtual Space, make kernel spacing and user's space can access this section mapped after the virtual address of user Virtual Space;
Second user's space internal memory application unit, at user's space application a slice memory address m2;
Transmission data generating unit, for generation of transmitting desired data source and being stored to user's space memory field m2;
Copy control module, to in user's space memory field m2, specify the data copy of number to the position of specifying to user's space memory field m1 for using memory copying technology, and write pointer that is mobile and adjustment m1 region, user's space memory field, notify that kernel upgrades the write pointer of DMA buffer circle simultaneously;
Transmission control unit, for etc. the request of DMA to be launched transmission, if receive DMA to start request, then upgrade DMA transport address and transmission data amount check, start DMA transmission, amendment correlating markings, notify that peripheral hardware prepares to receive data simultaneously, then wait for that DMA is transmitted interruption.
The described device transmitting data between user's space and kernel, wherein, also comprises:
Kernel receiving element, for receiving DMA interrupt request, first wake-up waiting queue, sends request the order of data to user's space.
The described device transmitting data between user's space and kernel, wherein, also comprises:
Peripheral hardware receiving element, for receiving the data that DMA transmits
The method and apparatus transmitting data between user's space and kernel provided by the present invention, propose a kind of method using memory-mapped and loop data buffer to combine, achieve and transmit internal memory that is direct from user's space in the process of data, simple, efficient access peripheral hardware at DMA; Owing to adopting the physical address map of DMA buffer zone to user Virtual Space, make kernel spacing and user's space can access the virtual address of this section of mapped rear user Virtual Space, can improve DMA transmits in data procedures, access rate between internal memory and peripheral hardware, and then alleviate cpu resource occupation rate, save system resource.
Accompanying drawing explanation
Fig. 1 is the method flow diagram transmitting data between user's space and kernel of the embodiment of the present invention;
Fig. 2 is the user's space access peripheral hardware internal storage structure schematic diagram of the embodiment of the present invention;
Fig. 3 is the DMA Buffer mapping schematic diagram of the embodiment of the present invention;
Fig. 4 is the principle of device block diagram transmitting data between user's space and kernel of the embodiment of the present invention.
Embodiment
A kind of method and apparatus transmitting data between user's space and kernel provided by the present invention, for making object of the present invention, technical scheme and advantage clearly, clearly, developing simultaneously referring to accompanying drawing, the present invention is described in more detail for embodiment.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
A kind of method transmitting data between user's space and kernel of the embodiment of the present invention, wherein, the DMA transmitting procedure related to is write in peripheral hardware buffer memory by internal storage data, and when data in EMS memory needs to produce from user's space, as shown in Figure 1, described method mainly comprises the following steps:
Step S110: open peripheral hardware, application DMA buffer zone, configuration dma controller, initialization waiting list etc.
Wherein, for being referred to as DMA buffer zone with one piece of region of peripheral hardware interaction data in internal memory, application DMA buffer zone, namely applies in internal memory that one piece for the region with peripheral hardware interaction data.
Step S120: use memory mapping technique to make a sector address m1 of user's space internal memory be associated with on peripheral hardware internal memory, as shown in Figure 2.
Step S130: the physical address memory of DMA buffer zone is mapped to user Virtual Space, as shown in Figure 3, makes kernel spacing and user's space can access the virtual address of this section of mapped rear user Virtual Space.
Step S140: at user's space application a slice memory address m2.
Step S150: produce transmission desired data source and be stored to user's space memory field m2, as shown in Figure 2, memory copying technology is used to specify the data copy of number to the position of specifying to user's space memory field m1 in user's space memory field m2, and write pointer that is mobile and adjustment m1 region, user's space memory field, notify that kernel upgrades the write pointer of DMA buffer circle simultaneously.
Wherein, described buffer circle is notional, also namely virtual, only need to increase by one at kernel spacing and read (writing) pointer, then go to upgrade (movement) this pointer after each DMA is transmitted, when this pointer movement is to the stem be also just equivalent to when end, buffer zone in buffer zone, namely join end to end, at this time this pointer has just pointed to the stem of buffer zone again.So buffer circle can by safeguarding that a read-write pointer realizes.
Step S160: wait the request that DMA to be launched transmits, if receive DMA to start request, then upgrades DMA transport address and transmission data amount check, start DMA transmission, by hardware controls, amendment correlating markings, notifies that peripheral hardware prepares to receive data simultaneously, then waits for that DMA is transmitted interruption.
Step S170: kernel receives DMA interrupt request, first wake-up waiting queue, sends request the order of data to user's space, and user's space detects this request, forwards step S150 to;
Step S180: peripheral hardware receives the data that DMA transmits, and gets back to step S160.
For example, user's space needs to transmit batch image data real-time to kernel spacing, now just can be realized the transfer of data by method of the present invention, and just can export to display system by peripheral hardware DMA at once after these data are transferred to kernel.
Certainly, in image acquisition process, peripheral hardware is by the data DMA of collection to kernel spacing, and user's space carries out real-time analysis and display as needed this batch data, and method of the present invention also can be used to realize data transfer efficient, real-time from kernel spacing to user's space.
Therefore, embodiments provide a kind of method using DMA efficient transfer data between user's space and kernel, DMA can be improved and transmit in data procedures, the access rate between internal memory and peripheral hardware, and then alleviate cpu resource occupation rate, save system resource.
Based on the method transmitting data between user's space and kernel of above-described embodiment, the embodiment of the present invention additionally provides a kind of device transmitting data between user's space and kernel, as shown in Figure 4, comprising:
DMA buffer zone application unit 410, for applying for DMA buffer zone, configuration dma controller, initialization waiting list.
First associative cell 420, makes a sector address m1 of user's space internal memory be associated with peripheral hardware internal memory for using memory mapping technique.
User Virtual Space map unit 430, the physical address memory for the buffer zone by DMA is mapped to user Virtual Space, make kernel spacing and user's space can access this section mapped after the virtual address of user Virtual Space.
Second user's space internal memory application unit 440, at user's space application a slice memory address m2;
Transmission data generating unit 450, for generation of transmitting desired data source and being stored to user's space memory field m2.
Copy control module 460, to in user's space memory field m2, specify the data copy of number to the position of specifying to user's space memory field m1 for using memory copying technology, and write pointer that is mobile and adjustment m1 region, user's space memory field, notify that kernel upgrades the write pointer of DMA buffer circle simultaneously.
Transmission control unit 470, for etc. the request of DMA to be launched transmission, if receive DMA to start request, then upgrade DMA transport address and transmission data amount check, start DMA transmission, amendment correlating markings, notify that peripheral hardware prepares to receive data simultaneously, then wait for that DMA is transmitted interruption.
Kernel receiving element 480, for receiving DMA interrupt request, first wake-up waiting queue, sends request the order of data to user's space.
Peripheral hardware receiving element 490, for receiving the data that DMA transmits
In sum, the method and apparatus transmitting data between user's space and kernel provided by the present invention, propose a kind of method using memory-mapped and loop data buffer to combine, achieve and transmit internal memory that is direct from user's space in the process of data, simple, efficient access peripheral hardware at DMA; Owing to adopting the physical address map of DMA buffer zone to user Virtual Space, make kernel spacing and user's space can access the virtual address of this section of mapped rear user Virtual Space, can improve DMA transmits in data procedures, access rate between internal memory and peripheral hardware, and then alleviate cpu resource occupation rate, save system resource.
Should be understood that, application of the present invention is not limited to above-mentioned citing, for those of ordinary skills, can be improved according to the above description or convert, and all these improve and convert the protection domain that all should belong to claims of the present invention.

Claims (2)

1. between user's space and kernel, transmit a method for data, it is characterized in that, comprise step:
A, open peripheral hardware, application DMA buffer zone, configuration dma controller, initialization waiting list;
B, use memory mapping technique make a sector address m1 of user's space internal memory be associated with on peripheral hardware internal memory;
C, the physical address memory of the buffer zone of DMA is mapped to user Virtual Space, make kernel spacing and user's space can access this section mapped after the virtual address of user Virtual Space;
D, at user's space application a slice memory address m2;
E, generation are transmitted desired data source and are stored to user's space memory field m2, use memory copying technology will specify the data copy of number to specify to user's space memory field m1 position in user's space memory field m2, and write pointer that is mobile and adjustment m1 region, user's space memory field, notify that kernel upgrades the write pointer of DMA buffer circle simultaneously;
F, etc. the request of DMA to be launched transmission, if receive DMA to start request, then upgrade DMA transport address and transmission data amount check, start DMA transmission, amendment correlating markings, notify that peripheral hardware prepares to receive data simultaneously, then wait for that DMA is transmitted interruption;
G, kernel receive DMA interrupt request, first wake-up waiting queue, send request the order of data to user's space, and user's space detects this request, forwards step e to;
H, peripheral hardware receive the data that DMA transmits, and get back to step F;
By the physical address map of DMA buffer zone to user Virtual Space, make kernel spacing and user's space can access the virtual address of this section of mapped rear user Virtual Space, improving DMA transmits in data procedures, access rate between internal memory and peripheral hardware, alleviate cpu resource occupation rate, save system resource.
2. between user's space and kernel, transmit a device for data, it is characterized in that, comprising:
DMA buffer zone application unit, for applying for DMA buffer zone, configuration dma controller, initialization waiting list;
First associative cell, makes a sector address m1 of user's space internal memory be associated with peripheral hardware internal memory for using memory mapping technique;
User Virtual Space map unit, the physical address memory for the buffer zone by DMA is mapped to user Virtual Space, make kernel spacing and user's space can access this section mapped after the virtual address of user Virtual Space;
Second user's space internal memory application unit, at user's space application a slice memory address m2;
Transmission data generating unit, for generation of transmitting desired data source and being stored to user's space memory field m2;
Copy control module, to in user's space memory field m2, specify the data copy of number to the position of specifying to user's space memory field m1 for using memory copying technology, and write pointer that is mobile and adjustment m1 region, user's space memory field, notify that kernel upgrades the write pointer of DMA buffer circle simultaneously;
Transmission control unit, for etc. the request of DMA to be launched transmission, if receive DMA to start request; then upgrade DMA transport address and transmission data amount check, start DMA transmission, amendment correlating markings; notify that peripheral hardware prepares to receive data simultaneously, then wait for that DMA is transmitted interruption;
Kernel receiving element, for receiving DMA interrupt request, first wake-up waiting queue, sends request the order of data to user's space;
Peripheral hardware receiving element, for receiving the data that DMA transmits;
Described device by the physical address map of DMA buffer zone to user Virtual Space, make kernel spacing and user's space can access the virtual address of this section of mapped rear user Virtual Space, improving DMA transmits in data procedures, access rate between internal memory and peripheral hardware, alleviate cpu resource occupation rate, save system resource.
CN201010536758.9A 2010-11-03 2010-11-03 Method and device for transmitting data between user space and kernel Expired - Fee Related CN102467473B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201010536758.9A CN102467473B (en) 2010-11-03 2010-11-03 Method and device for transmitting data between user space and kernel

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201010536758.9A CN102467473B (en) 2010-11-03 2010-11-03 Method and device for transmitting data between user space and kernel

Publications (2)

Publication Number Publication Date
CN102467473A CN102467473A (en) 2012-05-23
CN102467473B true CN102467473B (en) 2015-02-11

Family

ID=46071124

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201010536758.9A Expired - Fee Related CN102467473B (en) 2010-11-03 2010-11-03 Method and device for transmitting data between user space and kernel

Country Status (1)

Country Link
CN (1) CN102467473B (en)

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104731711A (en) * 2013-12-23 2015-06-24 中兴通讯股份有限公司 Table filling method and device of network equipment
CN105335309B (en) * 2014-05-30 2018-09-11 华为技术有限公司 A kind of data transmission method and computer
CN104239248B (en) * 2014-09-16 2017-06-06 国家计算机网络与信息安全管理中心 PCI E multiple buffer DMA data transfer methods
CN107066395A (en) * 2017-02-04 2017-08-18 上海市共进通信技术有限公司 Peripheral data high-speed transfer and the method for processing are realized based on linux system
CN108810181A (en) * 2017-05-03 2018-11-13 普天信息技术有限公司 A kind of address conversion method based on Intel DPDK
CN108228490B (en) * 2018-01-26 2022-11-01 武汉精测电子集团股份有限公司 Driving method based on PCIE card high-speed data transmission
CN110515872B (en) * 2018-05-21 2020-07-31 阿里巴巴集团控股有限公司 Direct memory access method, device, special computing chip and heterogeneous computing system
CN110033780B (en) * 2019-04-07 2020-12-08 西安电子科技大学 Audio and video data transmission method based on FFmpeg and EMIF driver
CN111817818A (en) * 2019-04-11 2020-10-23 中国移动通信集团四川有限公司 Method and device for transmitting data packet
CN111143851B (en) * 2019-12-11 2023-08-08 上海交通大学 Detection method and system suitable for kernel object address leakage of operating system
CN111431757B (en) * 2020-02-18 2023-03-24 平安科技(深圳)有限公司 Virtual network flow acquisition method and device
CN111371759B (en) * 2020-02-25 2022-06-21 深信服科技股份有限公司 Network data packet reading method, device, equipment and readable storage medium
CN112416815B (en) * 2020-12-09 2023-05-23 中船重工(武汉)凌久电子有限责任公司 High-speed storage playback method based on SRIO
CN112631975B (en) * 2020-12-09 2024-06-04 珠海全志科技股份有限公司 SPI transmission method based on Linux
CN114860467A (en) * 2021-02-04 2022-08-05 京东科技信息技术有限公司 Data transmission method, device and equipment based on kernel space and mobile robot
CN114745325B (en) * 2022-03-28 2024-07-23 合肥边缘智芯科技有限公司 MAC layer data exchange method and system based on PCIe bus
CN118113475A (en) * 2024-03-14 2024-05-31 广州翼辉信息技术有限公司 Intelligent image data transmission and display optimization method based on ARM+FPGA platform

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1996271A (en) * 2006-12-30 2007-07-11 华为技术有限公司 System and method for transmitting data
CN101150488A (en) * 2007-11-15 2008-03-26 曙光信息产业(北京)有限公司 A receiving method for zero copy network packet
CN101267361A (en) * 2008-05-09 2008-09-17 武汉飞思科技有限公司 A high-speed network data packet capturing method based on zero duplication technology
CN101826031A (en) * 2009-03-06 2010-09-08 王钟 Implementation method for capturing PCM (Pulse Code Modulation) stream based on Linux system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1996271A (en) * 2006-12-30 2007-07-11 华为技术有限公司 System and method for transmitting data
CN101150488A (en) * 2007-11-15 2008-03-26 曙光信息产业(北京)有限公司 A receiving method for zero copy network packet
CN101267361A (en) * 2008-05-09 2008-09-17 武汉飞思科技有限公司 A high-speed network data packet capturing method based on zero duplication technology
CN101826031A (en) * 2009-03-06 2010-09-08 王钟 Implementation method for capturing PCM (Pulse Code Modulation) stream based on Linux system

Also Published As

Publication number Publication date
CN102467473A (en) 2012-05-23

Similar Documents

Publication Publication Date Title
CN102467473B (en) Method and device for transmitting data between user space and kernel
JP7412438B2 (en) Virtualization that makes external memory local to machine learning accelerators
CN103200128B (en) The methods, devices and systems that a kind of network packet processes
CN103019838B (en) Multi-DSP (Digital Signal Processor) platform based distributed type real-time multiple task operating system
CN114662136B (en) PCIE (peripheral component interface express) channel-based high-speed encryption and decryption system and method for multi-algorithm IP (Internet protocol) core
US20120290763A1 (en) Method and system of complete mutual access of multiple-processors
CN105917311A (en) System and method for synchronous task dispatch in a portable device
WO2015180513A1 (en) Data transmission method and computer
WO2019141157A1 (en) Inter-core data transmission apparatus and method
WO2013152593A1 (en) Method and apparatus of data processing
WO2013095640A1 (en) Methods and apparatus for efficient communication between caches in hierarchical caching design
CN106933760A (en) A kind of dma controller and data uploading method based on AXI protocol
CN114817965B (en) High-speed encryption and decryption system and method for implementing MSI interrupt processing based on multi-algorithm IP core
CN102291298A (en) Efficient computer network communication method oriented to long message
CN103324599A (en) Inter-processor communication method and system on chip
WO2018205105A1 (en) Apparatus and method for implementing sensor of virtual machine
WO2022032990A1 (en) Command information transmission method, system, and apparatus, and readable storage medium
US8891523B2 (en) Multi-processor apparatus using dedicated buffers for multicast communications
TW200945033A (en) Memory allocation and access method and device using the same
US9075795B2 (en) Interprocess communication
US20140250285A1 (en) Inter-domain memory copy method and apparatus
US9652560B1 (en) Non-blocking memory management unit
CN115328832B (en) Data scheduling system and method based on PCIE DMA
CN104239248A (en) PCI-E (peripheral component interconnect-express) multi-buffer DMA (direct memory access) data transmission method
CN103218344A (en) Data communication circuit arranged among a plurality of processors and adopting data driving mechanism

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20150211

CF01 Termination of patent right due to non-payment of annual fee