[go: up one dir, main page]

CN115827506A - Data writing method, data reading method, device, processing core and processor - Google Patents

Data writing method, data reading method, device, processing core and processor Download PDF

Info

Publication number
CN115827506A
CN115827506A CN202211261106.8A CN202211261106A CN115827506A CN 115827506 A CN115827506 A CN 115827506A CN 202211261106 A CN202211261106 A CN 202211261106A CN 115827506 A CN115827506 A CN 115827506A
Authority
CN
China
Prior art keywords
data
message
storage area
address pointer
shared 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.)
Pending
Application number
CN202211261106.8A
Other languages
Chinese (zh)
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.)
CICTCI Technology Co Ltd
Original Assignee
CICTCI Technology Co Ltd
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 CICTCI Technology Co Ltd filed Critical CICTCI Technology Co Ltd
Priority to CN202211261106.8A priority Critical patent/CN115827506A/en
Publication of CN115827506A publication Critical patent/CN115827506A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Multi Processors (AREA)

Abstract

The invention provides a data writing method, a data reading device, a processing core and a processor, belonging to the technical field of computers, wherein the data writing method is applied to a sending end processing core, and the method comprises the following steps: determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core; and writing target message data into a preset first storage area indicated by the first data address pointer, and writing the message length of the target message data into the first message length storage area. According to the scheme of the invention, the mode of storing the data address pointer and the message length of the target message data by the shared memory is adopted, and compared with the mode of directly writing the target message data into the shared memory, the data processing amount during multi-core communication is reduced, and the real-time performance of inter-core communication is improved.

Description

Data writing method, data reading method, device, processing core and processor
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a data writing method, a data reading device, a processing core, and a processor.
Background
Vehicle to anything (V2X) refers to Vehicle to Everything wireless communication. V2X systems aim to improve the safety, comfort and convenience of a vehicle by allowing the vehicle to communicate with almost everything detectable.
In the V2X in-vehicle device, a System On Chip (SOC) is a core component of the communication Chip. Due to the limitation of semiconductor technology, the continuous manufacture of high-performance single-core processors becomes a difficult threshold to overcome. The associated power consumption and heat dissipation problems are also difficult to solve. Under such circumstances, more and more semiconductor manufacturers tend to produce lower power, performance-balanced multi-core processors to improve the overall performance of the processors. According to whether the core architectures are the same or not, the method can be divided into multi-core isomorphism and multi-core isomerism. The multi-core heterogeneous mode can realize the best use of chips, under the multi-core heterogeneous mode, one part of processors are used for managing and scheduling, the other part of processors are used for specific performance acceleration, and cores of each processor are set according to different requirements, so that the computing performance and the real-time performance of application can be improved.
Therefore, the communication chip SOC in the V2X in-vehicle device adopts a multi-core processor to support the calculation force required by V2X to support the development of the V2X Application instance performed by the upper layer, wherein an Application (APP) and a Medium Access Control (MAC) protocol process are executed on an embedded processor (Advanced RISC Machines, ARM), and a physical layer process is executed on a Digital Signal Processor (DSP).
With the application of multi-core processors, the communication requirement between processing cores on a chip is increased. However, in the inter-core communication process of the conventional multi-core processor, when a sending-end processing core sends data to a receiving-end processing core, data copying needs to be performed twice, so that the data processing amount during multi-core communication is large, and the real-time performance of inter-core communication is affected.
Disclosure of Invention
Embodiments of the present invention provide a data writing method, a data reading device, a processing core, and a processor, so as to solve a problem in the prior art that data processing amount is large during multi-core communication, which affects real-time performance of inter-core communication.
In order to solve the above technical problem, an embodiment of the present invention provides the following technical solutions:
in a first aspect, an embodiment of the present invention provides a data writing method, which is applied to a sending-end processing core, where the method includes:
determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core;
and writing target message data into a preset first storage area indicated by the first data address pointer, and writing the message length of the target message data into the first message length storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the first data address pointer and the first message length storage area are a data address pointer in one of the data frames and a message length storage area corresponding to the data address pointer.
Optionally, the determining a first data address pointer in the shared memory and a first message length storage area corresponding to the first data address pointer includes:
acquiring the read index and the write index;
determining whether the message data storage area is full according to the index value of the read index and the index value of the write index;
and under the condition that the message data storage area is not full, determining a first data address pointer corresponding to the write index value and a first message length storage area corresponding to the first data address pointer according to the index value of the write index.
Optionally, the method further comprises:
and generating alarm information under the condition that the message data storage area is full.
Optionally, after writing the target message data into the preset first storage area indicated by the first data address pointer and writing the message length of the target message data into the first message length storage area, the method further includes:
and modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area.
Optionally, before determining a first data address pointer in the shared memory and a first message length storage area corresponding to the first data address pointer, the method further includes:
acquiring the mutual exclusion lock;
after modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area, the method further includes:
and releasing the mutual exclusion lock.
In a second aspect, an embodiment of the present invention further provides a data reading method, which is applied to a receiving-end processing core, where the method includes:
reading a first data address pointer in a shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer;
sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving end processing core; the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
before the reading of the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the method further includes:
initializing the shared memory frame header;
and initializing the message data storage area.
Optionally, the reading a first data address pointer in the shared memory and a message length of target message data written in a first message length storage area corresponding to the first data address pointer includes:
acquiring the read index and the write index;
determining whether unread data frames exist in the shared memory according to the index value of the read index and the index value of the write index;
under the condition that unread data frames exist in the shared memory, reading the first data address pointer and the message length of target message data written in a first message length storage area corresponding to the first data address pointer according to the index value of the read index;
wherein the unread data frame includes the first data address pointer.
Optionally, the method further comprises:
and generating first indication information under the condition that the unread data frame does not exist in the shared memory.
Optionally, after the sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving end processing core, the method further includes:
applying for a new first storage area;
pointing the first data address pointer to the new first storage area;
and setting the value of the message length in the first message length storage area corresponding to the first data address pointer to 0.
Optionally, after the sending the first data address pointer and the message length of the target message data to the upper layer user of the receiving end processing core, the method further includes:
and modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area.
Optionally, before reading the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the method further includes:
acquiring the mutual exclusion lock;
after modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area, the method further includes:
and releasing the mutual exclusion lock.
In a third aspect, an embodiment of the present invention further provides a data writing apparatus, which is applied to a sending-end processing core, where the apparatus includes:
the first determining module is used for determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core;
and the writing module is used for writing target message data into a preset first storage area indicated by the first data address pointer and writing the message length of the target message data into the first message length storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the first data address pointer and the first message length storage area are a data address pointer in one of the data frames and a message length storage area corresponding to the data address pointer.
Optionally, the first determining module includes:
a first obtaining unit configured to obtain the read index and the write index;
a first determining unit, configured to determine whether the message data storage area is full according to an index value of the read index and an index value of the write index;
and a second determining unit, configured to determine, according to the index value of the write index, a first data address pointer corresponding to the write index value and a first message length storage area corresponding to the first data address pointer under the condition that the message data storage area is not full.
Optionally, the first determining module further includes:
and the first generating unit is used for generating alarm information under the condition that the message data storage area is full.
Optionally, the apparatus further comprises:
and the first modification module is used for modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area.
Optionally, the apparatus further comprises:
the first acquisition module is used for acquiring the mutual exclusion lock;
and the first releasing module is used for releasing the mutual exclusion lock.
In a fourth aspect, an embodiment of the present invention further provides a data reading apparatus, which is applied to a receiving end processing core, where the apparatus includes:
the reading module is used for reading a first data address pointer in the shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer;
a sending module, configured to send the first data address pointer and the message length of the target message data to an upper-layer user of the receiving-end processing core; the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the device further comprises:
the first processing module is used for carrying out initialization processing on the shared memory frame header;
and the second processing module is used for carrying out initialization processing on the message data storage area.
Optionally, the reading module includes:
a second obtaining unit configured to obtain the read index and the write index;
a third determining unit, configured to determine whether an unread data frame exists in the shared memory according to the index value of the read index and the index value of the write index;
a processing unit, configured to, when an unread data frame exists in the shared memory, read the first data address pointer and a message length of target message data written in a first message length storage area corresponding to the first data address pointer according to an index value of the read index;
wherein the unread data frame includes the first data address pointer.
Optionally, the reading module further includes:
a second generating unit, configured to generate the first indication information when there is no unread data frame in the shared memory.
Optionally, the apparatus further comprises:
the application module is used for applying for a new first storage area;
a third processing module, configured to point the first data address pointer to the new first storage area;
and the fourth processing module is used for setting the value of the message length in the first message length storage area corresponding to the first data address pointer to 0.
Optionally, the apparatus further comprises:
and the second modification module is used for modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area.
Optionally, the apparatus further comprises:
the second acquisition module is used for acquiring the mutual exclusion lock;
and the second releasing module is used for releasing the mutual exclusion lock.
In a fifth aspect, an embodiment of the present invention further provides a processor, including a sending end processing core, a receiving end processing core, and a shared memory;
wherein the sending-end processing core is configured to execute the data writing method according to any one of the first aspect;
the receiving-end processing core is configured to execute the data reading method according to any one of the second aspect.
In a sixth aspect, the present invention further provides a readable storage medium, where a program is stored, and the program, when executed by a processor, implements the steps in the data writing method according to any one of the first aspect, or implements the steps in the data reading method according to any one of the second aspect.
The beneficial effects of the invention are:
the scheme of the invention writes the target message data into the preset first storage area indicated by the first data address pointer and writes the message length of the target message data into the first message length storage area by determining the first data address pointer and the first message length storage area corresponding to the first data address pointer in the shared memory of the sending end processing core and the receiving end processing core, rather than directly writing the target message data into the shared memory, and the shared memory stores the message lengths of the data address pointer and the target message data, thereby reducing the data processing amount during multi-core communication and improving the real-time performance of inter-core communication.
Drawings
FIG. 1 is a flow chart of a data writing method according to an embodiment of the present invention;
fig. 2 is a schematic diagram illustrating data contents stored in a shared memory according to an embodiment of the present invention;
FIG. 3 is a flow chart of a data reading method according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of a data writing apparatus according to an embodiment of the present invention;
FIG. 5 is a schematic structural diagram illustrating a data reading method according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a processor according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
Before the description of the embodiments, the following description is first made:
the shared memory is a physical basis of multi-core communication, the shared memory is a very effective mode for allowing a plurality of processing cores in a multi-core processor to access the same physical memory, and the inter-core communication of the multi-core processor is performed through the shared memory.
In the existing multi-core communication scheme, a larger shared memory is used as a circular buffer, a frame header is added in the circular buffer, the length of data to be transmitted and received is judged by a read-write pointer of the frame header, one party writes in the data to be read, a one-way terminal notification mode is used between cores, and a sender notifies the other party by interruption after sending data. For example: the method comprises the steps that an A core (a sending end processing core) sends data to a B core (a receiving end processing core), the A core firstly judges whether a shared memory of the B core has a free space, if the free space meets requirements, the A core copies the data to be sent to a write pointer position of the shared memory received by the B core, the write pointer is modified, the A core sends an interrupt notification to the B core, and after the B core obtains the interrupt notification, the B core reads the data with the effective length at the read pointer position of the shared memory and copies the data to a user memory. That is, in the existing inter-core communication scheme, when an a core sends data to a B core, two data copies need to be performed, first, the a core copies the data to be sent to a shared memory of a target core (B core), and then the B core copies the data from the shared memory to a user memory corresponding to the B core. This shared memory storage space must be contiguous and reserved according to the maximum data communication requirements in the application. However, in actual use, the inter-core communication data volume of each processing core may not reach the reserved maximum storage space, which may cause waste of the storage space, and in the above multi-core communication scheme, if the message data size of the multi-core data communication is modified, the shared memory storage space of each processing core needs to be re-planned, which may increase the complexity of implementing the multi-core data communication and is not easy to code shift. In the existing multi-core communication scheme, two data copies are needed when the a core sends data to the B core, the a core copies the data to be sent to the shared memory of the target core first, and then the B core copies the sent data from the shared memory to the user memory, which increases the throughput of multi-core data communication and affects the real-time performance of communication among the multiple cores.
The invention provides a data writing method, a data reading device, a processing core and a processor, aiming at the problems that the data processing capacity is large during multi-core communication and the real-time performance of inter-core communication is influenced in the prior art.
As shown in fig. 1, an embodiment of the present invention provides a data writing method, which is applied to a sending-end processing core, where the method includes:
step 101: determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core.
In this step, the shared memory is used as a circular buffer. The shared memory stores a data address pointer and a message length storage area corresponding to the data address pointer. The storage area pointed by the data address pointer is applied in advance by the receiving end processing core, and the data address pointer and the message length storage area are placed in the shared memory.
The sending end processing core and the receiving end processing core are two different processing cores in a multi-core processor.
When a sending-end processing core sends message data to be sent (target message data), a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer are determined.
Step 102: and writing target message data into a preset first storage area indicated by the first data address pointer, and writing the message length of the target message data into the first message length storage area.
In this step, the sending-end processing core writes the target message data into a preset first storage area corresponding to the first data pointer, and writes the message length of the target message data into a first message length storage area corresponding to the first data pointer.
It should be noted that, when writing target message data, it is necessary to sequentially write the message data into the preset storage area corresponding to each data address pointer according to the arrangement sequence of the data address pointers and the corresponding message length storage areas in the shared memory, and therefore, when determining the first data address pointer, it is the next data address pointer of the data address pointer corresponding to the preset storage area of the last written message data. It should be noted that, when the shared memory is a circular buffer (buffer), and the data address pointer corresponding to the preset storage area of the last written message data is the data address pointer corresponding to the maximum number of messages in the shared memory, the next data address pointer is the most initial data address pointer (that is, the data address pointer corresponding to the number of messages 0 in the shared memory).
It should be further noted that, after the sending-end processing core finishes sending the target message data, that is, after the target message data is written into the preset first storage area indicated by the first data address pointer and the message length of the target message data is written into the first message length storage area, the sending-end processing core notifies the receiving-end processing core through an interrupt, that is, a shared memory and a one-way interrupt synchronization mechanism are used to manage and send and receive the data.
In the embodiment of the invention, the first data address pointer and the first message length storage area corresponding to the first data address pointer in the shared memory of the sending end processing core and the receiving end processing core are determined, the target message data are written into the preset first storage area indicated by the first data address pointer, and the message length of the target message data is written into the first message length storage area, but the target message data are not directly written into the shared memory, namely the message data are not managed in the shared memory, but the message lengths of the data address pointer and the target message data are stored, so that the data processing amount in multi-core communication is reduced, and the real-time performance of inter-core communication is improved. And only the data address pointer and the message length need to be saved in the shared memory, so that the waste of the storage space of the shared memory is avoided, and when data communication is performed among multiple cores, if the message data for performing inter-core communication is changed, the size of the shared memory does not need to be modified or slightly changed, so that the complexity of realizing the inter-core communication is reduced, and the code transplantation is facilitated.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the first data address pointer and the first message length storage area are a data address pointer in one of the data frames and a message length storage area corresponding to the data address pointer.
Referring to fig. 2, the data content stored in the shared memory provided by the embodiment of the present invention includes a shared memory frame header and a message data storage area.
Specifically, the shared memory frame header in the shared memory includes a message number storage area, a mutex lock, a read index, and a write index. And the shared memory frame header in the shared memory is used for maintaining each parameter value realized by the communication between the multi-core cores. The message number storage area in the shared memory frame header is used for storing the preset maximum message number of inter-core communication, wherein the maximum message number is the number of data address pointers capable of storing message data and the number of corresponding message length storage areas (the message number is counted from 0, and the maximum message number is n in fig. 2), and the maximum message number is set according to the actual requirement of a user and only once when the inter-core communication is initialized; the mutual exclusion lock is used for realizing resource mutual exclusion access protection, and the mutual exclusion lock is used for ensuring that the mutual exclusion protection of the core accessing the shared memory is not subjected to cross-core mutual exclusion protection; the read index points to the frame reading position of the receiving end processing core, and the data is filled after the receiving end processing core reads the data once, namely the receiving end processing core returns the received data to an upper layer caller (an upper layer user) in a data address pointer mode according to the read index value in the frame header of the shared memory, and the upper layer releases the memory after finishing processing the data; the write index points to the frame write position of the sending end processing core, and the sending end processing core writes the data after writing the data once, namely the sending end processing core writes the sending data into the specified memory address according to the write index value in the shared memory frame header.
The shared memory further includes a message data storage area, where the message data storage area includes a data address pointer for storing message data and a message length storage area for storing a message length of the message data, and the data address pointer and the message length storage area exist in the form of data frames, that is, the message data storage area includes a plurality of data frames, and a frame structure of each data frame includes a data address pointer and a message length storage area, that is, as shown in fig. 2, the shared memory provided in the embodiment of the present invention includes two frame formats in total, that is, a shared memory header and each data frame, and the data address pointer is an address pointer for storing the message data, and is filled in each data frame of the shared memory after being applied by a receiving-end processing core. After the receiving end processing core reads one frame, a new memory needs to be applied again and assigned to the pointer. The message length storage area is the message length of the target message data actually written in the data frame by the sending-end processing core, and the receiving-end processing core reads the value as the message length of the actual target message data of the frame. The sending end processing core needs to fill in the parameter after writing a data frame.
Optionally, the determining a first data address pointer in the shared memory and a first message length storage area corresponding to the first data address pointer includes:
acquiring the read index and the write index;
determining whether the message data storage area is full according to the index value of the read index and the index value of the write index;
and under the condition that the message data storage area is not full, determining a first data address pointer corresponding to the write index value and a first message length storage area corresponding to the first data address pointer according to the index value of the write index.
The method comprises the steps of obtaining an index value of a read index and an index value of a write index in a shared memory, judging whether a buffer of a message data storage area in the shared memory is full according to the index value of the read index and the index value of the write index, if not, obtaining the position of a data frame corresponding to target message data in the message data storage area according to the index value of the write index, wherein a data address pointer in the data frame is a first data address pointer, copying the target message data to a preset first storage area pointed by the first data address pointer in the data frame, and writing the message length of the target message data to the first message storage area in the data frame corresponding to the first data address pointer.
It should be noted that when the index value of the read index and the index value of the write index in the frame header of the shared memory are equal, the buffer may be full or empty, and the processing core at the receiving end cannot determine the buffer. To avoid this, when the sending-end processing core calculates the free space in the message data storage area, it should be ensured that the sending-end processing core is not fully loaded, and at least one free data frame size is reserved, so that it is ensured that when the index value of the read index and the index value of the write index in the frame header of the shared memory are equal, the buffer of the shared memory is empty. Since the shared memory is a circular buffer, (the index value of the write index + 1) = the index value of the read index, which indicates that the buffer of the message data storage area in the shared memory is full.
Optionally, the method further comprises:
and generating alarm information under the condition that the message data storage area is full.
And if the buffer of the message data storage area in the shared memory is judged to be full according to the index value of the read index and the write index value, returning alarm information.
Optionally, after writing the target message data into the preset first storage area indicated by the first data address pointer and writing the message length of the target message data into the first message length storage area, the method further includes:
and modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area.
After the sending-end processing core copies the target message data to a preset first storage area indicated by the first data address pointer and writes the message length of the target message data into the first message length storage area, the index value of the current write index is modified to be (the index value of the write index + 1)% of the maximum message number, wherein,% represents the remainder.
Optionally, before determining a first data address pointer in the shared memory and a first message length storage area corresponding to the first data address pointer, the method further includes:
acquiring the mutual exclusion lock;
after the modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area, the method further includes:
and releasing the mutual exclusion lock.
The method comprises the steps that target message data are copied to a preset first storage area indicated by a first data address pointer at a processing core of a sending end, before the message length of the target message data is written into the first message length storage area, a mutual exclusion lock in a shared memory is obtained, the first data address pointer in the shared memory and the first message length storage area corresponding to the first data address pointer are determined in a mutual exclusion access mode, the target message data are copied to the preset first storage area indicated by the first data address pointer in a subsequent mode, the message length of the target message data is written into the first message length storage area, the index value of a write index is modified according to the maximum message number stored in the maximum message number storage area in the subsequent mode, and after the process is completed, the mutual exclusion lock is released.
As shown in fig. 3, an embodiment of the present invention further provides a data reading method, which is applied to a receiving-end processing core, where the method includes:
step 301: reading a first data address pointer in a shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer;
in this step, after the receiving-end processing core receives the interrupt notification sent by the sending-end processing core, the receiving-end processing core reads the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer.
Step 302: sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving end processing core; the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
In this step, the receiving-end processing core returns the first data address pointer and the message length of the target message data to an upper-layer caller (upper-layer user) of the receiving-end processing core, and the upper-layer user calls the target message data in a preset first storage area pointed by the first data address pointer according to the message length of the target message data.
In the embodiment of the invention, the sending end processing core writes target message data into a first data address pointer of a shared memory, the receiving end processing core reads the message length of the target message data written in a first message length storage area corresponding to the first data address pointer and the first data address pointer, and sends the message length of the first data address pointer and the target message data to an upper layer user of the receiving end processing core, so that the upper layer user copies the target message data from a preset first storage area according to the first data address pointer and uses the target message data, the message data copying times are reduced, and the real-time performance of inter-core data communication is improved.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
before the reading of the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the method further includes:
initializing the shared memory frame header;
and initializing the message data storage area.
After the shared memory shared by the receiving-end processing core and the sending-end processing core is configured, the receiving-end processing core needs to initialize the shared memory, and after the receiving-end processing core initializes the shared memory, subsequent inter-core data communication of data written by the sending-end processing core and data read by the receiving-end processing core can be performed.
The operation of initializing the shared memory includes:
shared memory frame header initialization, comprising: and setting the maximum message number, zero clearing of a mutex lock flag, zero clearing of an index value of a read index and an index value of a write index in a maximum message number storage area.
Initializing a message data storage area, including: initializing all data frames in the message data storage area, namely, a receiving end processing core writes a pre-applied storage area and a pre-applied memory address pointer into a data address pointer of each data frame in the shared memory, and the length value of the message length storage area corresponding to each data address pointer is assigned as an initial value of 0.
Optionally, the reading a first data address pointer in the shared memory and a message length of target message data written in a first message length storage area corresponding to the first data address pointer includes:
acquiring the read index and the write index;
determining whether unread data frames exist in the shared memory according to the index value of the read index and the index value of the write index;
under the condition that unread data frames exist in the shared memory, reading the first data address pointer and the message length of target message data written in a first message length storage area corresponding to the first data address pointer according to the index value of the read index;
wherein the unread data frame includes the first data address pointer.
Before a receiving end processing core reads a first data address pointer and the message length of target message data written in a first message length storage area corresponding to the first data address pointer, an index value of a read index and an index value of a write index in a shared memory are obtained, whether unread data frames exist in the shared memory is judged according to the index value of the read index and the index value of the write index, under the condition that the unread data frames exist in the shared memory, the position of the data frame, which has received the target message data, in the shared memory is determined according to the index value of the read index, and the first data address pointer in the data frame and the message length of the target message data written in the first message length storage area are read according to the position of the data frame.
Optionally, the method further comprises:
and generating first indication information under the condition that the unread data frame does not exist in the shared memory.
Under the condition that the shared memory is judged to have no unread data frame according to the index value of the read index and the index value of the write index in the shared memory, first indication information is generated, namely the first indication information is used for indicating that the shared memory has no unread data address pointer and message length of message data.
Optionally, after the sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving end processing core, the method further includes:
applying for a new first storage area;
pointing the first data address pointer to the new first storage area;
and setting the value of the message length in the first message length storage area corresponding to the first data address pointer to 0.
And sending the first data address pointer and the message length of the target message data to an upper layer user at a receiving end processing core, so that the upper layer user calls the target message data in a first storage area pointed by the first data address pointer according to the message length of the target message data and then releases the first storage area, the receiving end processing core re-applies for a new first storage area, assigns the address pointer of the newly applied new first storage area to the first data address pointer, namely, the first data address pointer points to the new first storage area, and sets the message length value in the first message length storage area corresponding to the first data address pointer to be 0.
Optionally, after the sending the first data address pointer and the message length of the target message data to the upper layer user of the receiving end processing core, the method further includes:
and modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area.
After the receiving end processing core sends the first data address pointer and the message length of the target message data to the upper layer user according to the index value of the read index, the index value of the current read index is modified to be (the index value of the read index + 1)% of the maximum message number, wherein,% represents the remainder.
Optionally, before reading the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the method further includes:
acquiring the mutual exclusion lock;
after modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area, the method further includes:
and releasing the mutual exclusion lock.
Before a receiving end processing core reads a first data address pointer in a shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer, acquiring a mutual exclusion lock in the shared memory, reading the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer in a mutual exclusion access mode, subsequently sending the first data address pointer correspondence and the message length of the target message data to an upper layer user of the receiving end, subsequently modifying an index value of a read index according to the maximum message number stored in the maximum message number storage area, and releasing the mutual exclusion lock after the modification is completed.
As shown in fig. 4, an embodiment of the present invention further provides a data writing apparatus, which is applied to a sending-end processing core, where the apparatus includes:
a first determining module 401, configured to determine a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core;
a writing module 402, configured to write target message data into a preset first storage area indicated by the first data address pointer, and write a message length of the target message data into the first message length storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the first data address pointer and the first message length storage area are a data address pointer in one of the data frames and a message length storage area corresponding to the data address pointer.
Optionally, the first determining module 401 includes:
a first obtaining unit configured to obtain the read index and the write index;
a first determining unit, configured to determine whether the message data storage area is full according to an index value of the read index and an index value of the write index;
and a second determining unit, configured to determine, according to the index value of the write index, a first data address pointer corresponding to the write index value and a first message length storage area corresponding to the first data address pointer under the condition that the message data storage area is not full.
Optionally, the first determining module 401 further includes:
and the first generating unit is used for generating alarm information under the condition that the message data storage area is full.
Optionally, the apparatus further comprises:
and the first modification module is used for modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area.
Optionally, the apparatus further comprises:
the first acquisition module is used for acquiring the mutual exclusion lock;
and the first releasing module is used for releasing the mutual exclusion lock.
It should be noted that, the data writing device provided in the embodiments of the present invention is a device capable of executing the data writing method, and all the embodiments of the data writing method described above are applicable to the device and can achieve the same or similar technical effects.
As shown in fig. 5, an embodiment of the present invention further provides a data reading apparatus, which is applied to a receiving-end processing core, where the apparatus includes:
a reading module 501, configured to read a first data address pointer in a shared memory and a message length of target message data written in a first message length storage area corresponding to the first data address pointer;
a sending module 502, configured to send the first data address pointer and the message length of the target message data to an upper-layer user of the receiving-end processing core; the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the device further comprises:
the first processing module is used for carrying out initialization processing on the shared memory frame header;
and the second processing module is used for carrying out initialization processing on the message data storage area.
Optionally, the reading module 501 includes:
a second obtaining unit configured to obtain the read index and the write index;
a third determining unit, configured to determine whether an unread data frame exists in the shared memory according to the index value of the read index and the index value of the write index;
a processing unit, configured to, when an unread data frame exists in the shared memory, read the first data address pointer and a message length of target message data written in a first message length storage area corresponding to the first data address pointer according to an index value of the read index;
wherein the unread data frame includes the first data address pointer.
Optionally, the reading module 501 further includes:
a second generating unit, configured to generate the first indication information when there is no unread data frame in the shared memory.
Optionally, the apparatus further comprises:
the application module is used for applying for a new first storage area;
a third processing module, configured to point the first data address pointer to the new first storage area;
and the fourth processing module is used for setting the value of the message length in the first message length storage area corresponding to the first data address pointer to 0.
Optionally, the apparatus further comprises:
and the second modification module is used for modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area.
Optionally, the apparatus further comprises:
the second acquisition module is used for acquiring the mutual exclusion lock;
and the second releasing module is used for releasing the mutual exclusion lock.
It should be noted that the data reading apparatus provided in the embodiments of the present invention is an apparatus capable of executing the data reading method, and all the embodiments of the data reading method described above are applicable to the apparatus and can achieve the same or similar technical effects.
As shown in fig. 6, an embodiment of the present invention further provides a processor 600, where the processor is a multi-core processor and includes a sending-end processing core 601, a receiving-end processing core 602, and a shared memory 603;
the sending-end processing core 601 is configured to perform:
determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core;
and writing target message data into a preset first storage area indicated by the first data address pointer, and writing the message length of the target message data into the first message length storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the first data address pointer and the first message length storage area are a data address pointer in one of the data frames and a message length storage area corresponding to the data address pointer.
Optionally, the sending-end processing core 601 is specifically configured to:
acquiring the read index and the write index;
determining whether the message data storage area is full according to the index value of the read index and the index value of the write index;
and under the condition that the message data storage area is not full, determining a first data address pointer corresponding to the write index value and a first message length storage area corresponding to the first data address pointer according to the index value of the write index.
Optionally, the sending-end processing core 601 is further specifically configured to:
and generating alarm information under the condition that the message data storage area is full.
Optionally, the sending-end processing core 601 is further specifically configured to:
and modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area.
Optionally, before the sending-end processing core 601 determines the first data address pointer in the shared memory and the first message length storage area corresponding to the first data address pointer, the sending-end processing core is further configured to:
acquiring the mutual exclusion lock;
after the sending-end processing core 601 modifies the index value of the write index according to the maximum message number stored in the maximum message number storage area, the sending-end processing core is further configured to:
and releasing the mutual exclusion lock.
The receive-side processing core 602 is configured to perform:
reading a first data address pointer in a shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer;
sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving end processing core; and the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
Optionally, the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the receiving-end processing core 602 is further configured to:
initializing the shared memory frame header;
and initializing the message data storage area.
Optionally, the read-receiving-end processing core 602 is specifically configured to:
acquiring the read index and the write index;
determining whether unread data frames exist in the shared memory according to the index value of the read index and the index value of the write index;
under the condition that unread data frames exist in the shared memory, reading the first data address pointer and the message length of target message data written in a first message length storage area corresponding to the first data address pointer according to the index value of the read index;
wherein the unread data frame includes the first data address pointer.
Optionally, the receiving end processing core 602 is further specifically configured to:
and generating first indication information under the condition that the unread data frame does not exist in the shared memory.
Optionally, the read-receive-end processing core 602 is further configured to:
applying for a new first storage area;
pointing the first data address pointer to the new first storage area;
and setting the value of the message length in the first message length storage area corresponding to the first data address pointer to 0.
Optionally, the read-receive-end processing core 602 is further configured to:
and modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area.
Optionally, before the read receiving end processing core 602 reads the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the read receiving end processing core is further configured to:
acquiring the mutual exclusion lock;
the read receiving end processing core 602, after modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area, is further configured to:
and releasing the mutual exclusion lock.
Specific embodiments of the present invention also provide a readable storage medium, on which a program is stored, where the program, when executed by a processor, implements the steps in the data writing method described in any of the above, or implements the steps in the data reading method described in any of the above.
While the preferred embodiments of the present invention have been described, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention as defined in the following claims.

Claims (17)

1. A data writing method is applied to a sending end processing core, and the method comprises the following steps:
determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core;
and writing target message data into a preset first storage area indicated by the first data address pointer, and writing the message length of the target message data into the first message length storage area.
2. The data writing method according to claim 1, wherein the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
the first data address pointer and the first message length storage area are a data address pointer in one of the data frames and a message length storage area corresponding to the data address pointer.
3. The data writing method according to claim 2, wherein the determining a first data address pointer in the shared memory and a first message length storage area corresponding to the first data address pointer comprises:
acquiring the read index and the write index;
determining whether the message data storage area is full according to the index value of the read index and the index value of the write index;
and under the condition that the message data storage area is not full, determining a first data address pointer corresponding to the write index value and a first message length storage area corresponding to the first data address pointer according to the index value of the write index.
4. The data writing method according to claim 3, further comprising:
and generating alarm information under the condition that the message data storage area is full.
5. The data writing method according to claim 3, wherein after writing the target message data into the preset first storage area indicated by the first data address pointer and writing the message length of the target message data into the first message length storage area, the method further comprises:
and modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area.
6. The data writing method according to claim 5, wherein before determining the first data address pointer in the shared memory and the first message length storage area corresponding to the first data address pointer, the method further comprises:
acquiring the mutual exclusion lock;
after modifying the index value of the write index according to the maximum message number stored in the maximum message number storage area, the method further includes:
and releasing the mutual exclusion lock.
7. A data reading method is applied to a receiving end processing core, and the method comprises the following steps:
reading a first data address pointer in a shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer;
sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving end processing core; the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
8. The data reading method according to claim 7, wherein the shared memory includes a shared memory frame header and a message data storage area;
the shared memory frame header comprises a maximum message number storage area, a mutual exclusion lock, a read index and a write index;
the message data storage area comprises a target number of data frames; each data frame comprises a data address pointer and a message length storage area corresponding to the data address pointer; the target number is the maximum message number stored in the maximum message storage area;
before the reading of the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the method further includes:
initializing the shared memory frame header;
and initializing the message data storage area.
9. The data reading method according to claim 8, wherein the reading of the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer comprises:
acquiring the read index and the write index;
determining whether unread data frames exist in the shared memory according to the index value of the read index and the index value of the write index;
under the condition that unread data frames exist in the shared memory, reading the first data address pointer and the message length of the target message data written in a first message length storage area corresponding to the first data address pointer according to the index value of the read index;
wherein the unread data frame includes the first data address pointer.
10. A method for reading data according to claim 9, the method further comprising:
and generating first indication information under the condition that the unread data frame does not exist in the shared memory.
11. The data reading method according to claim 8, wherein after the sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving processing core, the method further comprises:
applying for a new first storage area;
pointing the first data address pointer to the new first storage area;
and setting the value of the message length in the first message length storage area corresponding to the first data address pointer to 0.
12. The data reading method according to claim 9, wherein after the sending the first data address pointer and the message length of the target message data to an upper layer user of the receiving-end processing core, the method further comprises:
and modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area.
13. The data reading method according to claim 12, wherein before reading the first data address pointer in the shared memory and the message length of the target message data written in the first message length storage area corresponding to the first data address pointer, the method further comprises:
acquiring the mutual exclusion lock;
after modifying the index value of the read index according to the maximum message number stored in the maximum message number storage area, the method further includes:
and releasing the mutual exclusion lock.
14. A data writing apparatus, applied to a sending-end processing core, the apparatus comprising:
the first determining module is used for determining a first data address pointer in a shared memory and a first message length storage area corresponding to the first data address pointer; the shared memory is a shared memory of the sending end processing core and the receiving end processing core;
and the writing module is used for writing target message data into a preset first storage area indicated by the first data address pointer and writing the message length of the target message data into the first message length storage area.
15. A data reading apparatus, applied to a receiving-end processing core, the apparatus comprising:
the reading module is used for reading a first data address pointer in the shared memory and the message length of target message data written in a first message length storage area corresponding to the first data address pointer;
a sending module, configured to send the first data address pointer and the message length of the target message data to an upper-layer user of the receiving-end processing core; and the first data address pointer and the message length of the target message data are used for indicating the upper layer user to acquire the target message data in a preset first storage area.
16. A processor is characterized by comprising a sending end processing core, a receiving end processing core and a shared memory;
wherein the sending-end processing core is configured to execute the data writing method according to any one of claims 1 to 6;
the receiving-end processing core is configured to perform the data reading method according to any one of claims 7 to 13.
17. A readable storage medium, characterized in that the readable storage medium has stored thereon a program which, when executed by a processor, implements the steps in the data writing method according to any one of claims 1 to 6, or implements the steps in the data reading method according to any one of claims 7 to 13.
CN202211261106.8A 2022-10-14 2022-10-14 Data writing method, data reading method, device, processing core and processor Pending CN115827506A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211261106.8A CN115827506A (en) 2022-10-14 2022-10-14 Data writing method, data reading method, device, processing core and processor

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211261106.8A CN115827506A (en) 2022-10-14 2022-10-14 Data writing method, data reading method, device, processing core and processor

Publications (1)

Publication Number Publication Date
CN115827506A true CN115827506A (en) 2023-03-21

Family

ID=85524769

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211261106.8A Pending CN115827506A (en) 2022-10-14 2022-10-14 Data writing method, data reading method, device, processing core and processor

Country Status (1)

Country Link
CN (1) CN115827506A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116841952A (en) * 2023-09-01 2023-10-03 北京智芯微电子科技有限公司 Inter-core communication system, method, apparatus, device, chip, and readable storage medium
CN117407356A (en) * 2023-12-14 2024-01-16 芯原科技(上海)有限公司 Inter-core communication method and device based on shared memory, storage medium and terminal

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116841952A (en) * 2023-09-01 2023-10-03 北京智芯微电子科技有限公司 Inter-core communication system, method, apparatus, device, chip, and readable storage medium
CN117407356A (en) * 2023-12-14 2024-01-16 芯原科技(上海)有限公司 Inter-core communication method and device based on shared memory, storage medium and terminal
CN117407356B (en) * 2023-12-14 2024-04-16 芯原科技(上海)有限公司 Inter-core communication method and device based on shared memory, storage medium and terminal

Similar Documents

Publication Publication Date Title
CN111930676A (en) Method, device, system and storage medium for communication among multiple processors
CN111190854B (en) Communication data processing method, device, equipment, system and storage medium
CN115827506A (en) Data writing method, data reading method, device, processing core and processor
CN107797848B (en) Process scheduling method and device and host equipment
CN111294792A (en) Buffer status reporting method, terminal and computer storage medium
CN112698959A (en) Multi-core communication method and device
CN113986134B (en) Method for storing data, method and device for reading data
CN112256460A (en) Inter-process communication method and device, electronic equipment and computer readable storage medium
CN116303173B (en) Method, device and system for reducing RDMA engine on-chip cache and chip
CN110474851A (en) A kind of access method and device recycling storage organization
CN115712394A (en) Data reading and writing method and device, computer equipment and readable storage medium
CN118152154B (en) Communication control method, system and readable storage medium based on shared memory development
CN114490459A (en) Data transmission method, apparatus, device, receiver and storage medium
CN108874560B (en) Method and communication device for communication
CN111435323B (en) Information transmission method, device, terminal, server and storage medium
CN110990169B (en) Structure and method for inter-process byte stream communication by using shared memory
CN116601616A (en) A data processing device, method and related equipment
CN111913815A (en) Call request processing method and device, electronic equipment and readable storage medium
CN106776393B (en) uninterrupted serial port data receiving method and device
CN111767154B (en) Method for realizing non-lock ring queue for non-blocking communication
CN103294560A (en) Method and device for character string across process transmission
KR20150048028A (en) Managing Data Transfer
CN112214337A (en) TTFC network transmission cache design method, computer equipment and storage medium
US20190004963A1 (en) Dual pointer for memory mapped interface communication
CN115242898B (en) Communication method and device between protocol stack and physical layer process

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination