WO2014110702A1 - Cooperative concurrent message bus, driving member assembly model and member disassembly method - Google Patents

Cooperative concurrent message bus, driving member assembly model and member disassembly method Download PDF

Info

Publication number
WO2014110702A1
WO2014110702A1 PCT/CN2013/001371 CN2013001371W WO2014110702A1 WO 2014110702 A1 WO2014110702 A1 WO 2014110702A1 CN 2013001371 W CN2013001371 W CN 2013001371W WO 2014110702 A1 WO2014110702 A1 WO 2014110702A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
active component
layer
operator
bus
Prior art date
Application number
PCT/CN2013/001371
Other languages
French (fr)
Chinese (zh)
Inventor
龙建
Original Assignee
Long Jian
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 Long Jian filed Critical Long Jian
Publication of WO2014110702A1 publication Critical patent/WO2014110702A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/547Messaging middleware

Definitions

  • the invention belongs to the technical field of computers, and particularly relates to a collaborative concurrent message bus, an active component assembly model and a component splitting method. Background technique
  • the corresponding concurrent technology implementation mechanism is provided, and a special concurrent service interface is provided externally, so that the upper program can complete concurrent activities.
  • the upper-level application calls these concurrent service interfaces to render itself as one or more concurrent tasks.
  • Scheduling operations for operating systems, software buses, etc.
  • concurrent entities tasks, processes, threads, fibers, etc.
  • deprivation scheduling is common
  • Stacking space problem Deprivation scheduling may interrupt the execution process of concurrent entities at any time. Therefore, it is necessary to protect and restore the concurrent entity running environment (at least including instruction registers, etc.), which requires RAM heap space. In normal operating situations (such as PCs), this problem is not outstanding. However, in the case of a large number of concurrent entities (such as a microcontroller with thousands of network connections), the problem will become quite prominent; in special cases where RAM is scarce (such as WSN applications), scheduling will become infeasible.
  • TinyOS is a microkernel operating system developed by UC Berkeley for the wireless sensor network WSN (Wireless Sensor Network).
  • the two-tier scheduling mode of TinyOS is: task scheduling and hardware transaction scheduling.
  • Hardware transaction scheduling is activated by hardware interrupts, which can preempt ordinary tasks and is mainly used for high-priority fast real-time response. It is basically the same as the general interrupt handler. The slight difference is that it can send signals to the task schedule to activate common tasks. At the same time, it can also be used.
  • the asynchronous ability of the nesC keyword async directly calls into the nesC component system, calls the command handler in the component, and sends asynchronous events to the component.
  • TinyOS The basic task of TinyOS is a parameterless function. Task scheduling uses a collaborative first-in, first-out (FIFO) algorithm, where tasks do not preempt each other and there is no priority. Once a task has acquired the processor, it runs straight to the end. Generally used for time-critical applications, it is essentially a Deferred Procedure Call (DPC) mechanism.
  • DPC Deferred Procedure Call
  • the TinyOS 2. x scheduler can be customized and replaced by the user.
  • the TinyOS 2.x core PCB is a fixed-length byte array that forms a FIFO-ready task queue and a waiting task pool.
  • Each task in the system is represented by a byte of task ID, numbered ( ⁇ 255, where 255 represents the empty task NO-TASK: that is, the task does not exist. Therefore, the system can accommodate up to 255 valid tasks.
  • the actual number of tasks in the application system ie the actual length of the byte array, is automatically generated by the compiler during source code compilation.
  • This byte array holds the task ready flag. If a task ID does not receive an event and does not need to be added to the FIFO ready queue, the NO-TASK flag is stored and the waiting task pool is entered. If an event occurs in the task ID and the activation enters the ready state, the task ID byte stores the next ready task, indicating that the ID has entered the FIFO ready task queue and is waiting for execution.
  • the blocking critical section protection method is adopted. If the ID is already in the state, the busy flag is returned, otherwise it is added to the ready queue from the end of the queue. Since only one byte of ID is enqueued, the critical section can pass at high speed, which does not affect the interrupt response speed. This algorithm can avoid the potential problem of multiple IDs entering the queue: If the same ID can occupy multiple byte positions, in some cases, it may fill up the byte array, causing other tasks to fail to join the system and the system to die.
  • the blocking critical section protection method is also used. If there is no ready task, a signal is sent to the power saver to enter the power save state. Otherwise, the entry address of the task is retrieved and the task is executed. Because there is only a task ID in the scheduler, there are no additional parameters, so the task must be a parameterless function. At the same time, the task is collaborative, and the previous task must be completely exited (the stack is empty) before the next task can be executed. Therefore, all tasks share the same memory heap space.
  • TinyOS 2 All basic tasks are parameterless functions. Each basic task only assigns a task ID of one byte. This byte stores the task ready flag and has no space for other parameters. So, in essence, it is just a signal light system. There are several weaknesses compared to message systems that can be accompanied by several parameters. The trials are as follows:
  • Self-counting module implemented with tasks.
  • the sent message can only be notified to the receiving task that a message has occurred, but it cannot be fully expressed at one time. Therefore, the task of receiving information needs to rely on a specific information exchange method, and adopts a pull mode mechanism to retrieve specific information content by function calling. This is a fatal limitation (for reasons to be described later) for implementing fully reusable modules and fully transparent distributed computing systems, which is difficult to compensate.
  • TinyOS 2.X uses the blocking critical section protection method when the task ID is entered in parallel and serially dequeued. Since only one byte of ID is enqueued, the critical section can pass at high speed, which does not affect the interrupt response speed and system performance. This is due to its very simple signalling mechanism. If you want to switch to the message mechanism according to the system requirements, in addition to the known blocking type of synchronous deadlock, priority inversion, interrupt can not be locked, critical sections can not be concurrent, and other issues, there are other problems, the test is as follows:
  • TinyOS 1. x and the general-purpose operating system directly store the entry address of the task function in its scheduler data structure. When the scheduler selects the task and completes the necessary preparations, it jumps directly to the address to execute the task code. There are several disadvantages compared to the way in which the task ID and the ID address mapping table are used.
  • the entry address has a single meaning: it cannot contain other meaningful information (such as static priority).
  • TinyOS 2.X uses a one-byte base task ID to make the scheduling kernel simple and efficient. However, this limits the maximum number of tasks it can accommodate to 255. For systems that are slightly larger and have more tasks, they cannot accommodate processing and affect system scalability.
  • TinyOS 2.X uses a one-byte base task ID, as both a FIFO ready queue pointer and a task ready flag. This, like most other operating systems, has a non-zero-length task PCB table stored in RAM memory. With a number of weaknesses, try to enumerate as follows:
  • the state is changed to the ready state.
  • the execution of this part of the scheduling code must be increased.
  • very lightweight scheduling such as TinyOS
  • the increased execution time relative to the overall execution time of the schedule is extraordinarily significant, which affects the execution efficiency of lightweight scheduling.
  • the TinyOS 2.x task uses the ID scheme, and its components use the address scheme.
  • the predefined ID component scheme makes it easier to reference, change, replace, and maintain code, making it easier to implement single-block or overall code hot upgrades.
  • TinyOS structured programming
  • modular programming object-oriented programming
  • component programming and many other techniques are all done in a function call when assembled into smaller modules using small module links. This approach has a fatal flaw and is one of the core issues that make software modules difficult to reuse in complex software systems. The following details:
  • the Pull mode and the Push mode are originally used to indicate a way of disseminating information on the Internet.
  • Pull means that the user actively browses the website information and retrieves the information from the website he is interested in (pull).
  • Push means that the website actively sends (push) messages to certain users.
  • This function call which is the information acquisition process, is similar to the process of pulling information on the Internet, so it is also called pull mode.
  • one module is a concurrent entity (thread, etc.)
  • another concurrent entity sends a message. This process of sending a message is similar to the process of pushing information on the Internet, so it is also called push mode.
  • Pull mode and push mode the most significant difference is: each time you pull, the user needs to specify the object to be pulled, and the specific conditions of the pull (content); and each time you push, you do not need any user Actions (of course, before doing this, you need to do some one-off work, such as booking, etc.).
  • the D module represents the called module, except D All other parts of the module are modules that make active function calls.
  • a functional equivalent decomposition of the above calling module is performed.
  • In represents the input parameters (messages) required by the module
  • Out represents the information (message) output by the module
  • F module is the core function that the module must complete
  • B module is another part of the function completed by the module. Therefore, in essence, the function of F+B is the meaning of the existence of this module.
  • the C module represents a direct function call, which is equivalent to the assembled CALL instruction, after which the execution right of the CPU is directly transferred to the D module. In the pull mode, this is a must-have.
  • the D module requires a certain parameter Pm. This parameter is obtained through the A module: that is, the parameter is transformed, and is transmitted to the D module when the C module is called.
  • the A module performs parameter conversion, mainly for the input parameter In, combined with other variables 1, to perform parameter format conversion and matching, and obtain the parameter Pm necessary for the C module and the parameter Pc necessary for the F module.
  • the parameter conversion in the A module must obtain another part of the information Pb. This part of the information Pb must be obtained while completing some of the module functions (B pre-function). Therefore, the pre-function of the B module is a non-essential module that may not exist. However, if it exists, the parameter Pf is obtained from the A module, part of the predetermined module function is completed, and then the information Pb is fed back to the A module, and at the same time, the possible parameter P is provided to the F module if the F core module requires it.
  • the information 0d returned from the called function of the D module, combined with the variable 2, is sorted by the E module information, and then converted into a parameter Pr that can be directly utilized by the F module, and transmitted to the F core function module.
  • the F module After obtaining the parameters Pc, Pr, and P, the F module completes the core function and obtains the output information 0ut.
  • the parameters Pc and Pm may be exactly the same as the parameter In, so that the A module may not need to exist.
  • the information returned by the D module after the called function is 0d, which may be identical to the parameter Pr, so that the E module may not need to exist.
  • the function call of the C module is a link that must exist in the pull mode.
  • the parameter transformation in the A module in the figure and the function call in the C module have nothing to do with the function of the module itself.
  • the code has to be placed. From the perspective of module cohesion, their presence reduces the cohesion of the calling module.
  • the pre-function of the B module from the perspective of pure code reuse and module cohesion, it is also preferable to strip out the calling module.
  • the E module performs information sorting. In some cases, it can be retained to meet the interface requirements, but it is best to strip it. From a design point of view, there should generally be another solution to strip out the B and E modules.
  • only the F core function module remains, as the only code to call the module. In this way, the highest reusability of the module can be achieved. And portability.
  • the problem is that the calling module and the called module represented by the D module generally have other subordinate modules. Unless all the subordinate modules (that is, a subtree starting from the calling module) are all transplanted and reused, otherwise Facing the adaptation and adaptation of the subordinate modules. At the same time, whether the business logic of the new project can exactly and completely need this whole subtree is still a big problem. In this way, the application scope of the subtree transplant reuse scheme is greatly narrowed, and it is suitable only in very similar projects, and is not universal.
  • the module is not analyzed or modified, and only the input, output, and corresponding functions of the D module are simulated.
  • the present invention provides a cooperative concurrent message bus, an active component assembly model, and a component splitting method, which can effectively overcome the weakness of the existing "concurrent" implementation technology, and implement the "concurrent” technology efficiently and reliably.
  • Parallel programming with a series of advantages such as universality, low cost, high efficiency, reliability, energy saving, multiplexing, transparent distribution, microkernel, and intrinsic support object technology.
  • the technical solution adopted by the present invention is as follows -
  • the present invention provides a cooperative concurrent message bus, comprising: an information acquisition module, a parallel ring distributor, a linear memory block, a message filling module, a parallel enqueue, a message queue pool, and a queue order management. , entry maps, and system stacks;
  • the information obtaining module is configured to obtain a target operator ID and a message length value from the received external parallel message to be processed; wherein the target operator ID is an operator identifier for processing the message; An additional management message length value for obtaining an additional management message, and then calculating a sum of the additional management message length value and the obtained message length value to obtain a message occupied space value; wherein the additional management message length value
  • the parallel ring distributor is a non-blocking parallel space ring allocator for continuously and dynamically cutting the linear memory block according to the ring division principle according to the message occupation space value acquired by the information acquisition module. Non-blocking in parallel to get a blank message slot with the same message footprint value;
  • the message filling module is configured to fill the blank message slot allocated by the parallel ring distributor with the message and the additional management message to obtain a non-blank message slot;
  • the parallel enroller is configured to perform a non-blocking parallel enqueue operation on the blank message slot or the non-blank message slot;
  • the message queue pool is used to cache an queried message that has not been processed
  • the queuing sequence manager is configured to select a specified message to be processed from the message queue pool according to a preset scheduling policy, and perform a coordinated dequeuing operation on the specified message;
  • the entry mapping table searches the entry mapping table according to the target operator ID to obtain a function entry address corresponding to the target operator ID; and according to the function entry address and the specified message slot address of the specified message Calling the corresponding operator execution function to process the specified message of the team;
  • the system stacking is a stacking space shared by all the operators in the message bus; the system stacking space shared by each operator overlaps each other, and is overlapped, that is, non-cascading;
  • the operator in the message bus only has a ready state, even if there is no message in the message bus, the operator in the message bus is still in the ready state; once the message arrives in the message bus When, and when the operator corresponding to the message is scheduled, the operator to be dispatched immediately obtains the processor.
  • the message is a fixed length message or a variable length message.
  • the parallel ring distributor scribes a blank message slot at the end of the linear memory block, if the remaining free space of the least end of the linear memory block is smaller than the message space value, directly discarding The remaining free space in the most end, the remaining free space in the last end forms a discarding slot.
  • the message filling module first fills the message and the additional management message to the blank message slot allocated by the parallel ring distributor to obtain a non-blank message slot; then the parallel enqueue pair
  • the non-blocking parallel enqueue operation of the non-blank message slot is specifically as follows:
  • the parallel ring distributor is configured with a first head pointer and a first tail pointer.
  • a new blank message slot needs to be allocated, the same space as the message occupied space value is directly drawn after the first tail pointer of the current position. Obtaining the new blank message slot, and then moving the first tail pointer non-blocking parallel to the tail of the new blank message slot;
  • the parallel enqueue is configured with a second head pointer and a second tail pointer; performing non-blocking parallel enqueue operation on the non-blank message slot by non-blocking parallel movement of the second tail pointer;
  • first head pointer and the first tail pointer of the parallel ring distributor configuration are different from the second head pointer and the second tail pointer of the parallel enqueue configuration.
  • the parallel enroller first performs a non-blocking parallel enqueue operation on the blank message slot, and then the message filling module fills the blank message slot of the enqueue with the message and the additional management.
  • the message is specifically - the parallel ring distributor shares the same head pointer and tail pointer with the parallel enqueue, and when the parallel ring distributor allocates a blank message slot from the linear memory block, the blank The message slot is also enqueued by the parallel enqueue; the message padding module then populates the message and the additional management message with the blank message slot enqueued.
  • the blank message slot is pre-sleeped, wherein the sleep state is in a sleep state.
  • the blank message slot is called a dormant message slot; then the message padding module fills the dormant message slot with the message and the additional management message, and when the padding message slot is activated, the padding message is changed to An active state, wherein the active message slot is called an active message slot; wherein, the dormant message slot is a message slot that is not scheduled to be executed by the message bus to the operator; the active message slot is scheduled to belong to the message bus.
  • the dormant message slot and the active message slot are distinguished by whether the message length parameter written in the message slot is 0; when the message length parameter written in the message slot is 0, The message slot is the dormant message slot; when the message length parameter written in the message slot is not 0, the message slot is the active message slot.
  • the method further includes: a monitoring management center; the monitoring management center is configured to perform centralized monitoring, analysis, control, filtering, and management on messages within the message bus.
  • the method further includes: a space reclamation module; the space reclamation module is configured to recover the dequeued message itself and the message slot in the message bus.
  • the method further includes: a power saving device; the power saving device is configured to: immediately notify an application system using the message bus to perform energy saving scheduling when there is no message in the message bus.
  • Each of the active components of each layer in the set P conforms to the same protocol.
  • the layer 1 active component in the set P includes: the message bus, an interface operator ID mapping table, an alias link table, and one or more operators; wherein the interface operator ID mapping table is used for storing Corresponding relationship between the interface operator ID and the entry function; the alias link table is configured to store a correspondence between the reference operator ID and the interface operator ID; wherein the interface operator ID is the active component itself An operator identifier; the reference operator ID is an operator identifier that is attached to an active component on the message bus;
  • Each of the active components of the second-layer active component subset to the n-th active component subset of the set P includes: the virtual message bus, the interface operator ID mapping table, the alias link table, and a The above operator.
  • each active component in the n-th active component subset is assembled according to the n-th virtual message bus, and a single active component in the n-1th active component subset is obtained, where n 3 is specifically - each active component in the nth active component subset includes an nth layer virtual message bus, an nth layer interface operator ID mapping table, an nth layer alias link table, and one or more nth layer operators;
  • the single active component in the n-1th active component subset obtained after component assembly includes the n-1th layer virtual message bus, the n-1th interface operator ID mapping table, and the n-1th layer alias link table. And more than one n-1th layer operator;
  • each of the nth layer virtual message bus is bus-fused to obtain an n-1th layer virtual message bus; and each of the nth layer interface operator ID mapping tables is table-fused to obtain a nth a layer 1 interface operator ID mapping table; table fusion of each of the nth layer alias link tables to obtain an n-1th layer alias link table; and fusing each of the nth layer operators to obtain an nth- 1 layer operator.
  • each active component in the second layer active component subset is assembled according to the message bus, and the first layer active component is specifically - each of the second layer active component subsets
  • the active component includes the layer 2 virtual message bus, the layer 2 interface operator ID mapping table, the layer 2 alias link table, and one or more layer 2 operators, respectively; and the first layer active component obtained after component assembly
  • the message bus, a layer 1 interface operator ID mapping table, a layer 1 alias link table, and one or more layer 1 operators are included;
  • each of the second layer virtual message buses is bus-fused to obtain the message bus; each of the layer 2 interface operator ID mapping tables is table-fused to obtain a layer 1 interface operator. ID mapping table; table fusion of each of the second layer alias link tables to obtain a first layer alias link table; and fusing each of the second layer operators to obtain a first layer operator.
  • the correspondence between the reference operator ID and the interface operator ID stored in the alias link table is an equivalence mapping relationship.
  • the present invention also provides a component splitting method for the active component assembly model obtained as described above.
  • the method includes the following steps:
  • the component splitting rule is preset, and when the active component assembly model satisfies the component splitting rule, the active component assembly model is split according to the component splitting rule.
  • the component splitting rule is: when the scheduler of the message bus is executed by two or more cores or processors, splitting the message bus into the same number of the cores or the number of processors a distributed peer-to-peer sub-bus; each of the active components of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus; or
  • the component splitting rule is: dynamically counting the load of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset load balancing principle; Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus; or
  • the component splitting rule is: dynamically counting energy efficiency ratios of the active components in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset energy-saving principle; Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus; or
  • the component splitting rule is: dynamically counting the failure rate of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset reliability principle Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
  • the collaborative concurrent message bus, the active component assembly model and the component splitting method provided by the invention can effectively overcome the weakness of the existing "concurrent” implementation technology, and realize the "concurrency” technology and parallel programming efficiently and reliably, and have universality and low cost.
  • a series of advantages such as high efficiency, reliability, energy saving, reuse, transparent distribution, microkernel, and intrinsic support object technology.
  • FIG. 1 is a schematic structural diagram of a TinyOS 2.x basic task scheduler provided by the prior art
  • FIG. 2 is a schematic diagram of an equivalent model of a function call in a pull mode provided by the prior art
  • FIG. 3 is a schematic diagram of a general model of a collaborative concurrent message bus provided by the present invention.
  • FIG. 4 is a schematic diagram of a specific application model of a collaborative concurrent message bus provided by the present invention
  • FIG. 5 is a schematic diagram of an assembly example of a component provided by the present invention. detailed description
  • the present invention provides a cooperative concurrent message bus.
  • the concurrent common model of the message bus is: parallel enqueue, coordinated dequeue, that is, a multi-entry and single-out model.
  • Messages are non-blocking parallel operations before entering the message queue pool; after entering the message queue pool, they are cooperative serial operations. These include: information extraction module, parallel ring distributor, linear memory block, message filling module, parallel enqueue, message queue pool, queue order manager, entry map, and system stack.
  • the information obtaining module is configured to obtain the target operator ID and the message length value from the received external parallel message to be processed; wherein the target operator ID is an operator identifier for processing the message. And obtaining an additional management message length value of the additional management message, and then calculating a sum of the additional management message length value and the obtained message length value to obtain a message occupied space value; wherein the additional management message length value 0.
  • an operator is a more lightweight concurrent entity than a task, process, or thread, and is more heavyweight than a callback function. Equivalent to fiber, coroutine, slightly lighter than fiber and coroutine.
  • the operator in the message bus has only the ready state, even when there is no message in the message bus, the operator in the message bus is still in the ready state; once the message arrives in the message bus When, and when the operator corresponding to the message is scheduled, the operator to be dispatched immediately obtains the processor.
  • the target operator IDs may be simply arranged in order, or may imply some other meaning, such as: priority, fixed service number, distributed ID number, and the like. For example: You can simply split the target operator ID into two parts: the external bus node number and the operator number in the message bus. With this structure, simply replacing the referenced target operator ID, it is easy to abandon the reference to the local operator, and instead refer to the operator existing on another external node, to achieve transparent distributed computing and transfer. More complicated division In this way, even more complex distributed application logic can be realized by borrowing the concept of IP address division similar to the Internet.
  • the target operator ID in the message is usually hidden with other useful information (such as the external node number). Therefore, it is necessary to explicitly convert the correct local target operator ID.
  • Several other parameters contained within the message may also require uniform format matching and conversion. Therefore, parameter extraction and format conversion are required. The normal result is that you get a correct target operator ID and the first address of the message (slot).
  • the parallel ring distributor is a non-blocking parallel space ring allocator for continuously and dynamically scribing the linear memory block according to the ring division principle according to the message occupation space value acquired by the information acquisition module, and is non-blocking In parallel, a blank message slot with the same message footprint value is obtained.
  • the parallel ring distributor dynamically divides the linear memory block into multiple message slots (Slots), each message slot accommodating a complete message.
  • Slots message slots
  • the message slot It can also accommodate other additional information for system management.
  • These message slots are continuously allocated and reclaimed adjacent to each other. Therefore, logically, the linear memory block becomes a circular slot space.
  • the parallel ring distributor scribes a blank message slot at the end of the linear memory block, if the remaining free space of the least end of the linear memory block is smaller than the message occupied space value, directly discarding the most The remaining free space at the end, the remaining free space at the end of the end forms a discarding slot, thereby ensuring that the space used by each message slot is plane, linear, and not wrap-around, so that the operator and the application to the slot space
  • the logical view is simple, clean, and natural.
  • the parallel ring distributor is an efficient and compact non-blocking parallel space ring distributor, which eliminates deadlock, priority inversion, interruption cannot be locked, and critical sections cannot be concurrent with respect to the blocking type distributor; Free software-only method for lock-free allocation; low-cost hardware method for efficient allocation of single assembly instructions without waiting.
  • the interrupt mask, CAS/CAS2, LL/SC processor primitives, etc. can be used to perform the allocation by a software-only method through a lock-free algorithm; or the hardware can be used to directly implement the same function.
  • the effect of the Wait-Free algorithm while achieving the effect of high efficiency allocation: a single assembly instruction can complete the space allocation.
  • the lock-free algorithm implemented in pure software is left to be described later.
  • This linear memory block acts as a message buffer and should be large enough.
  • Modern routine application except In addition to fixed-length memory allocation, common behavioral logic and guidelines are: All the remaining memory RAM space is allocated as heap space.
  • the stack size of the application system should be fixed first, and then the remaining memory RAM space should be all allocated as a message buffer. This is because a large number of concurrent operator Actors are the main components of the system, so there are a large number of uncertain messages, requiring a large number of uncertain message buffers.
  • the level of functions called by each operator is not particularly large, and generally it is only a very simple direct call, and the stacking space of all operators overlaps each other because of collaborative execution. Therefore, it is easy to estimate the maximum RAM stack space that needs to be used, so it can be allocated as a fixed-length RAM memory.
  • the application system is responsible for processing; or re-expanding the message buffer, or modifying the processing logic of the application system, or directly stopping the application system, and the like. This is exactly the same as the modern routine application's troubleshooting solution for system heap overflows.
  • the message bus is unloaded with a responsibility that should be guaranteed by the user: Unconditionally guarantee that the application system is not washed by large amounts of data. This greatly simplifies the design logic and code of the message bus, and obtains the widest range of software and hardware adaptability and portability.
  • the invention only makes a minimum specification for the internal structure of the message transmitted on the message bus: the message is divided into a fixed length message and a variable length message; for an application system of fixed length messages, generally Used in relatively specific application environments, such as ATM switches and the like. For variable-length messaging applications, it is the most widely used and has the most common use value.
  • the target operator ID For fixed-length messages and variable-length messages, the target operator ID must be included; in addition, for fixed-length messages, the message length value is defined by the specific application system and its message bus, and does not have to explicitly appear in the message structure; Messages, message length values must be explicitly present in the message structure.
  • the message length value and the length of the target operator ID itself are closely related to the processor word length, and are defined by the specific application system and its message bus. Generally, it is recommended to be 1, 2, 4, 8, or 16 bytes, but not It is mandatory to specify which length to use.
  • the total length of a single message, whether it contains other management information (such as dynamic priority), etc., is also defined by the specific application system and its message bus.
  • the message filling module is configured to fill the message and the additional management message to the parallel ring
  • the blank message slot allocated by the shape allocator obtains a non-blank message slot.
  • the parallel ring distributor spatially distributes and allocates a message slot for any message i in parallel, the message slot space is privately occupied by the message. Therefore, the message slot can be arbitrarily processed. At this point, the message filling operation can be performed. Even if this phase has a very long time delay, it has no effect on the rest of the system.
  • the message filling module can use the following two schemes for message filling:
  • the message filling module first fills the message and the additional management message to the blank message slot allocated by the parallel ring distributor to obtain a non-blank message slot; then the parallel enroller pairs the non-blank message
  • the non-blocking parallel enqueue operation of the blank message slot is specifically as follows:
  • the parallel ring distributor is configured with a first head pointer and a first tail pointer.
  • a new blank message slot needs to be allocated, the same space as the message occupied space value is directly drawn after the first tail pointer of the current position. Obtaining the new blank message slot, and then moving the first tail pointer non-blocking parallel to the tail of the new blank message slot;
  • the parallel enqueue is configured with a second head pointer and a second tail pointer; performing non-blocking parallel enqueue operation on the non-blank message slot by non-blocking parallel movement of the second tail pointer;
  • first head pointer and the first tail pointer of the parallel ring distributor configuration are different from the second head pointer and the second tail pointer of the parallel enqueue configuration.
  • the parallel enroller first performs a non-blocking parallel enqueue operation on the blank message slot, and then the message filling module fills the blank message slot of the enqueue with the message and the additional management message as follows:
  • the parallel ring distributor shares the same head pointer and tail pointer with the parallel enqueue, and when the parallel ring distributor allocates a blank message slot from the linear memory block, the blank message slot is also
  • the parallel enroller performs an enqueue operation; then the message filling module populates the blank message slot enqueued with the message and the additional management message.
  • the blank message slot is pre-sleeped, wherein the blank message slot in the sleep state is called Sleeping the message slot; then the message filling module populates the dormant message slot with the message and the additional management message, and when the padding message is activated, the sleep message slot is activated An active state, wherein the active message slot is called an active message slot; wherein, the dormant message slot is a message slot that is not scheduled to be executed by the message bus to the operator; the active message slot is normal to the message bus The message slot of the dispatch scope.
  • the dormant message slot and the active message slot are generally distinguished by adding a management flag in the message slot.
  • the dormant message slot and the active message slot are distinguished by whether the message length parameter written in the message slot is 0; when the message When the message length parameter written in the slot is 0, the message slot is the dormant message slot; when the message length parameter written in the message slot is not 0, the message slot is the active message slot. In this way, the message slot can be activated by simply writing the message length parameter into the message slot.
  • the parallel enroller is configured to perform a non-blocking parallel enqueue operation on the blank message slot or the non-blank message slot.
  • the parallel enqueue is a key component of message parallel-to-serial, which requires very careful parallelism of the preemptive behavior of the encoding operations, and then turns into a very easy collaborative serial behavior.
  • the message bus is a multi-input and single-out model, when the parallel enqueue is implemented, in most applications, the model can be simplified according to the actual situation.
  • Parallel enqueue is an efficient and concise non-blocking parallel enqueue component. Compared with blocking enqueue, it eliminates deadlock, priority inversion, interrupt can not be locked, and critical section can not be concurrent.
  • the pure software method the realization of lock-free team; with cheap hardware methods, to achieve efficient single-assembly instructions without waiting for the queue.
  • you can use the interrupt mask, CAS/CAS2, LL/SC processor primitives, etc. to implement the lock-free algorithm for the enqueue operation using pure software methods.
  • Non-blocking, especially lock-free operation of linked lists there have been many public papers, and will not be repeated here.
  • the specific implementation of the parallel enqueue is closely related to the specific structure and implementation of the message queue pool inside the bus.
  • a single or multiple singly linked list with head and tail pointers is operated, and the tail parallel enqueue operation is completed.
  • a dedicated single-linked list queue can also be arranged for the parallel-to-serial enqueue operation; after that, the parallel-serial queue is subsequently managed.
  • a special succinct model will be described later.
  • the message queue pool is used to cache queued messages that have not yet been processed.
  • the message queue pool is the core data structure area of the message bus. It is used to cache all the queued messages that have not been processed, and cooperate with filtering, management, scheduling, and picking up messages that should be processed first. Since it is completely coordinated at this time, various scheduling management algorithms can be designed simply and naturally.
  • the specific implementation of the message queue pool is closely related to the specific application system. Usually, it is a single-linked list with head and tail pointers, which can implement simple scheduling algorithms, such as: FIFO FIFO (First
  • EDF Erarliest Deadline First
  • the communication bus has the widest adaptability. More critical, it can save RAM space.
  • zero PCB makes the number of operators unrelated to the occupation of RAM space. No matter how many operators exist, the RAM space occupied by them is unchanged. In this way, the message bus can be easily applied to various RAM scarce situations, such as: WSN application system.
  • Zero PCB means that the operator can no longer dynamically express multiple states of its tasks, so the convention: The operators in the bus no longer have a wait state, but only the ready state and the running state. Even if there are no messages in the message bus, the operators in the message bus are in the ready state. When the message arrives in the message bus, the operators in the message bus get the processor immediately after sorting, and thus become the running state. Therefore, whether the entire application system is in a wait state depends on whether there is a message inside the message bus. This has laid a profound theoretical and technical support point for system energy saving.
  • Zero PCB means that general operators can be dynamically expressed without RAM space. However, this does not exclude some special-purpose operators or queues, which can take up a lot of RAM space, that is, using a non-zero PCB. For example: In the EDF queue, record the deadline for each real-time operator.
  • the zero-length task control block PCB of the RAM that is, the zero PCB, reduces the scheduling execution time relative to the non-zero-length task PCB in the RAM memory, and forms an efficient, concise, unified concurrent basic model, which reduces the RAM space. Occupancy, making this concurrent base model universally applicable to any existing computer body Department.
  • the queuing sequence manager is configured to select a specified message to be processed from the message queue pool according to a preset scheduling policy, and perform a coordinated dequeuing operation on the specified message.
  • the queuing sequence manager utilizes a message queue pool, various scheduling algorithms, and the like to perform scheduling management on all unprocessed enqueue messages. For example: Set the priority of the message, put the highest priority message at the beginning of the team, and facilitate the message to leave the team. Among them, when selecting the head of the queue, it is very easy to extract the message from the head of the queue. If there are multiple queues, you need to select the highest priority queue first. Since the message format is generally complex and unpredictable, it is also possible to simply extract the address of the message slot as the message address. For the simplest FIFO algorithm, the Queueing Sequence Manager can even be implemented in a clear, independent form, but implicitly in other relevant organizations and code. By placing the queued sequence manager behind the parallel queue, you can avoid complex, cumbersome, and dangerous parallel preemption operations. Since it is completely cooperative operation at this time, various scheduling management algorithms can be designed simply and naturally.
  • An entry mapping table searching the entry mapping table according to the target operator ID, obtaining a function entry address corresponding to the target operator ID; calling according to the function entry address and the specified message slot address of the specified message The corresponding operator executes the function to process the specified message of the team.
  • the entry mapping table is used to store the mapping relationship between the operator ID and the function entry address, and the entry mapping table is searched according to the target operator ID, and the function entry address corresponding to the target operator ID can be obtained, so that the next step is to jump to the entry and execute The function of this operator.
  • This is actually an assembly level indirect address jump mechanism.
  • the entry mapping table is generally an address table arranged in order of operator IDs, from small to large, and the operator ID itself does not explicitly appear inside the table. In order to compress the size of the task entry table and make full use of the space, the operator ID is generally encoded in a continuous manner.
  • the entry mapping table can be stored in the ROM.
  • the entry mapping table may also implicitly or explicitly list other useful information, such as: static priority of the operator, and the like. Since it is a cooperative operation at this time, the entry mapping table can be easily and consistently modified even during the running of the program to implement hot upgrade during the running of the system code. This is of great practical value for a 24 hour*7 day/week, continuously operating, highly reliable system.
  • the entry mapping table stores the mapping relationship between the operator ID and the function entry address. For the scheme using the task entry address, the parallel operator can be indicated across the computer to directly support the completely transparent distributed parallel computing. stand by Hot code upgrade during runtime.
  • the system stacks the stacking space shared by all the operators in the message bus; the system stacking space shared by each operator overlaps each other and is overlapped, that is, non-cascading.
  • the execution function of the operator is directly called according to the function entry address obtained earlier and the first address of the message (slot). Compared with TinyOS 2. x, the biggest difference is that this technical solution carries a message pointer when it is executed; therefore, it becomes an active message mode, and the information transfer mechanism of the push mode can be realized.
  • the heap space occupied by it is completely emptied. Since all the operators in the system are coordinated, they all share the same system heap space. That is to say, the stacking space of all the operators is overlapped, and the overlapping collaborative system stacking provided by the invention substantially reduces the occupation of the RAM stacking space and makes the system more universal than the stacked task stacking.
  • the message (slot) belongs to the operator that is completely private. Therefore, the operator can arbitrarily process the message without hindering the bus operation. For example: Repeat or prioritize, send, forward, change the message (slot) to improve system efficiency.
  • the monitoring management center is used for centralized monitoring, analysis, control, filtering and management of messages inside the message bus. For example: statistics on the actual running time of all operators in the message bus; clearing certain types of messages sent to an operator; even forcibly terminating the running of an operator that is out of control, and so on. It is mainly used in the system debugging and testing phase, and does not have to exist during the official operation of the system.
  • the space reclamation module is configured to recover the dequeued message itself in the message bus and the message slot, that is, the discarding and recycling of the message itself, and the discarding and recycling of the message slot space.
  • the abandonment of the message itself is a dequeue operation in the multi-entry and single-out mode of the parallel enqueue. In a very simple application system, it can be uniformly performed when the team leader selects, so that when the operator is running, the discarding flag can be easily eliminated and the message can be reused. Recycling of the message slot space: Under normal circumstances, the space reclamation operation in the multiple-input single-out mode belonging to the parallel ring distributor can also be implemented by hardware.
  • the specific implementation of the power saving device is closely related to the application system hardware. Since the message bus can know whether the system is in a waiting state according to whether there is a message internally or not. Therefore, when there is no message inside the bus, the application system using the message bus is immediately notified to perform energy saving scheduling. When there is a message When it is born, the hardware is notified to resume normal operation.
  • the processor does not have CAS/CAS2 instructions, nor does it have advanced synchronization primitives for parallel operation such as LL/SC. Therefore, similar primitives can only be implemented by means of a switch interrupt. This will reduce the scheduling efficiency of the bus.
  • some simple adaptive changes can be made to the general model to adapt to the specific application environment and improve system efficiency. For example: The bus internal operator generates more messages, while the external interrupt environment generates fewer messages. At this time, you can use this feature to set up 2 bus message buffer spaces. Interrupting messages into the queue is competitive, using switches to implement primitives. Operators Messages are coordinated, eliminating the need for switch interrupts, thus improving scheduling efficiency. Even more efficient technical corrections can be made for interrupt-priority features so that both can share the same message cache.
  • This general collaborative model can be implemented with a slight change in the case of priority scheduling. For very fast, rigorous response times, it can be done directly inside the hardware interrupt handler. For cases where the response time can be slightly delayed and the bus can be scheduled, the operator can be scheduled to run at the highest synergy priority. The enrollment operation is also scheduled at the highest priority, ensuring that there is no waiting for lag when enrolling. At the same time, split all the operators over the specified time. So that the bus can be executed in time for any operator within the specified time. Further, the operator of the highest priority can be scheduled within a predetermined time to complete the hard real-time response. Since this model has a centralized monitoring center, it is easy to monitor the running time of each operator. Therefore, it is easy to locate operators that run beyond the specified time to help complete the design of hard real-time response.
  • the message bus provided by the present invention has a specific and simple and efficient special case.
  • the special case is not particularly well-functioning, but its execution performance is particularly efficient, enabling operator concurrent operations to satisfy a typical concurrent application environment or as a basis for other concurrent applications.
  • its execution efficiency can be the same or very close to that of assembly-level subroutine calls.
  • the parallel ring distributor and the parallel enqueue are combined into one.
  • the dormant message slot and the message activation mechanism are used to implement simple FIFO ordering, and the queuing operation is naturally completed while enqueuing.
  • the specific work steps are -
  • Assembly-level indirect call instructions can be completed. S6, space recycling. Special hardware is completed, a single assembly instruction can be completed.
  • S1 is equivalent to changing the stack pointer
  • S2 is equivalent to parameter compression
  • S5 is equivalent to indirect CALL assembly instruction
  • S6 is equivalent to parameter retirement.
  • S3 does not consume time. Therefore, only S4 is an extra execution time, which is a very simple operation, and a single assembly instruction can be completed. Therefore, the total execution time is only one more assembly instruction time. When the number of messages (or parameters) is large, the proportion of time taken is very small. Therefore, very close execution performance can be achieved. If you optimize your operation and use more complex hardware, you can achieve the same performance.
  • a single-core single-processor microcontroller is commonly used, and no operating system is used.
  • the application software uses structured, modular, sequential programming techniques to assemble the entire application system and run directly in bare metal.
  • the interrupt handler is used to preempt the main program, capture external events, and save the event state at certain pre-agreed specific locations.
  • the main program uses a large endless loop to check if there are external events. If it happens, check the status of the external event according to the prior agreement, and output it after processing.
  • the main loop is always preempted by external interrupts, but the main loop does not preempt external interrupts. That is, as long as there is an external interrupt code running, the main loop will definitely suspend execution.
  • This kind of software execution environment is called the first execution environment, which is simply referred to as "letting the environment first.”
  • LINUX executes the real-time priority scheduling policy, resulting in a real-time thread running environment. When its lowest priority thread acts as the main loop, it constitutes the prior environment.
  • preemptive environment In contrast, in a multi-core processor, or a single-core multi-processor, or a normal time slice preemptive scheduling, the main thread and other threads can preempt each other, or concurrently cross-execution.
  • This software execution environment is called the preemptive execution environment, referred to as the "preemptive environment”.
  • the main loop acts as a scheduler, completing the functions of message dequeue, scheduling, and cooperative operation of the operator; other external interrupts preempt each other and send messages to the system queue.
  • the scheduler and the external interrupts preempt each other and cross-execute. Therefore, the dispatcher is likely to run when the external interrupt fills the message slot but has not been fully populated. At this point, the scheduler has access to the semi-finished incomplete message. Therefore, certain measures need to be taken to ensure that the scheduler does not use the semi-finished message as a normal message.
  • the scheduler In the preemptive environment, when the external interrupt fills the message slot, the scheduler has no chance to be executed. The scheduler either can't see the new message, or it sees an entry. Complete news after the team. With this feature, the parallel enqueue algorithm can be simplified in a pre-emptive environment without having to put a sleep flag on the message (slot).
  • This embodiment can be used for preemptive environment and transparent distribution environment, based on x86 32bit multi-core system.
  • the core technical point of this embodiment is that the parallel ring distributor and the parallel enqueue are combined to operate, and the head and tail pointers of the ring space are regarded as the head and tail pointers of the message queue at the same time. The two queues use the same head and tail pointer. In this way, the message slot has just been allocated from the linear space and into the circular slot space, which means that the message slot has entered the system message queue.
  • the message slot needs to be written with a sleep flag in advance.
  • the sleep flag is implicit in the length parameter of the message slot. When the length is 0, it means the message slot is sleeping, the data has not been filled, and the scheduler should ignore it.
  • the message format is indefinitely long binary data, which is divided into two parts: the message header and the message body.
  • the message body can be any data, any length less than 65536-8 bytes. It is also legal for the message body to be 0 bytes. In this case, the entire message has no message body and only the message header.
  • the header has three parts: 2-byte message length Parameter size, 2 bytes CAS2 counter cas2cnt, 4-byte operator id. A total of 8 bytes, just within one CAS2 operation of the 32BIT x86 CPU.
  • the pre-write sleep flag requires the use of a CAS2 operation.
  • the Cas 2cnt counter is required. The specific principles can be found in related papers, and will not be described here.
  • there is no need to use the sleep flag and there is no need to use the CAS2 operation. Therefore, cas2cnt does not need to exist and can be discarded.
  • the CAS operation is completed with the x86 assembly instruction cmpxchg, which can operate 4 bytes at a time;
  • the CAS2 operation is completed with the assembly instruction cmp XC hg8b, which can operate 8 bytes at a time.
  • the memory bus lock is completed with the assembly instruction lock to complete the CAS/CAS2 operation at the time of multi-core.
  • the 32BIT operator ID number can be easily divided into two parts: node number, operator number.
  • node number When the node number is 0, the subsequent operator number is treated as an operator in the bus.
  • the node number When the node number is not 0, it means that the target operator is not in the bus, but in other external nodes: the subsequent operator number, and therefore is regarded as an operator in the external node. How many BIT bits are occupied by the node number and the operator number, which can be agreed in advance in the application system.
  • Each external node needs a local operator to handle some necessary transactions, such as: forwarding the message to a communication pipe to the external node, and so on. This local operator is called a proxy operator.
  • the circular slot space queue has a head pointer head and a tail pointer tail, which double as the head and tail pointers of the system message queue.
  • head and tail pointers When the head and tail pointers are equal, it means that there is no message (slot) in the ring slot space, which is an empty queue. Regardless of the situation of the annular slot space overflow, such exception faults are handled by the user application itself. Therefore, the tail pointer always points to the free area of the linear memory block.
  • the message slot When the message slot is allocated, directly at the tail pointer, after the 8-byte boundary is aligned, the corresponding length of free space is drawn, and then the tail pointer is moved: This also means that the message slot also enters the system message queue.
  • the linear memory block When the linear memory block is allocated at the very end, the remaining free space may not be able to accommodate a complete message, and the end space is allocated as an obsolete message slot. New messages are continuously allocated in the next free position (the beginning of the linear space). Since the message slot boundary is always 8-byte aligned, it is equal to the length of the message header. Therefore, the last discarded message slot can at least accommodate the header of the message, so that when the CAS2 is operated and the sleep flag is written concurrently, the fault of the super-boundary read/write occurs.
  • the length of the message slot can be directly calculated from the length of the message.
  • the message slots are allocated consecutively, so the length of the message slot actually implies the location of the next message slot. Therefore, no additional information is required and all messages can form a single linked list of FIFOs. Starting from the first pointer, you can traverse all the messages in the queue in the order of enqueue.
  • the message is directly dequeued from the queue head pointer. Then, the queue head pointer head points to the next message slot: This also means that the previous message slot space has been discarded and discarded into a free-free linear space. After the message is used, it can be discarded without leaving the team.
  • the obsolete flag is implicit in the operator ID of the header.
  • An ID of 0 means the message has been discarded and the scheduler is no longer concerned about it.
  • the ID is not 0, which means it is a valid message and needs to be scheduled for execution.
  • the messages entering the queue in parallel are only enqueued from the tail of the queue, and only the tail pointer tail of the queue is modified; and the message of the dequeue is only dequeued from the head of the queue, and only the head of the queue is modified. Therefore, without the use of other critical resource protection measures, it is also natural and easy to complete concurrent competitive entry and exit operations and improve execution efficiency.
  • Al allocate empty slots to enter the queue; A2, submit the activation slot; A3, schedule execution.
  • the external environment or internal operator that needs to send the message invokes the A1 operation to get the dormant private message slot. Then, copy the rest of the message to the message slot. Finally, according to the target operator ID of the message and the length parameter of the message, the A2 operation is invoked to activate the message. Wait for the bus to schedule processing of this message.
  • the bus A3 operation in this case is very simple and intuitive. Just a simple deal with dormancy and waste recycling issues. Among them, the concept of the agent operator, implemented in the scheduler, has great benefits for transparent distribution calculation. In this way, the ID number used in the component can be directly linked to the external node in the link configuration file of the component assembly. Instead of using another encoding to generate a local operator, the operator forwards the message to the external node.
  • the message When the bus A3 is operating, for the ordinary operator, the message is discarded and the target operator corresponding to the message is executed. The reason is that this gives the operator a chance to reuse the message. As long as the operator clears the discard flag, the message can be reused to improve system execution efficiency. For example: In the error handling operator, by changing the ID of the message to another operator, the message can be quickly and preferentially forwarded to the subsequent error handling operator. Since the message is still at the head of the message queue at this time, priority execution can be obtained.
  • the bus A2 operation when the length parameter sz greater than 0 is instantaneously written into the size field of the sleep message header, the sleep message slot is activated (the size field of the header is 0 when the message slot is sleeping).
  • the signal is sent to wake up the sleep scheduler only when the message queue is just empty, that is, when the message is the first message in the message queue.
  • the wake-up signal can also be sent multiple times.
  • the bus A1 operation is a lock-free designation, assignment and enqueue operation, and uses CAS/CAS2 operation.
  • the snap may actually be useless garbage data, or it may be a valid header that it has processed: it may be the header of the flag, or the message being filled, or it may be completely filled. Good news head. It is then compared in real time with the tai l pointer to ensure that the snapshot obtained is taken from the latest tail. After the success of the snap, it is no longer possible to fill or fill the header. Because, in that case, the tai l pointer must have been changed by others.
  • the non-blocking and enrolled collaborative concurrent message bus provided by the invention can effectively overcome the weaknesses of the existing "concurrent” implementation technology, and realize the "concurrency” technology and parallel programming efficiently and reliably, and is universal, cheap, efficient, reliable, and Energy saving, multiplexing, transparent distribution, microkernel, and intrinsic support object technologies. Specifically, it includes the following advantages:
  • Universality Can be widely used in various computer architectures, such as: single processor systems, multi-vector systems, massively parallel systems, symmetric multiprocessing systems, cluster systems, vector machines, supercomputers, embedded System, etc.; can also be widely used in various processor architectures or various CPUs, such as: X86 architecture, RISC architecture, ARM processor, 8051 microprocessor, microcontroller, etc.; can also be widely used in various operating systems, each Software-like systems, such as: IBM 0S/400 systems, Windows systems, Unix systems, iOS systems, vxWorks systems, ucOS II systems, sequential programming, structured programming, modular programming, database systems, and more. For these ever-changing hardware and software environments, a unified concurrency technology model can be implemented.
  • High efficiency High space efficiency: Its core C language source code does not exceed hundreds of lines.
  • High time efficiency Concurrency efficiency is better than existing common thread technology, which can exceed one order of magnitude; if hardware facilities are used and key atomic operations are completed, the concurrency efficiency can reach the same level compared with assembly level subroutine call instructions; That is, a concurrent scheduling operation can be completed in several or dozens of machine instruction cycles.
  • High development efficiency Matching the unique programming model and assembly multiplexing technology, compared with the existing common modular programming and object programming, the development efficiency can exceed one order of magnitude.
  • the core code is very small, it is very easy to check and test correctly; the use of lock-free or no-wait technology to achieve concurrency, the core will never deadlock collapse; using collaborative concurrency technology to eliminate a large number of unnecessary critical condition competition, Avoid application timing failures; use component reuse programming models to reuse proven component assembly systems.
  • Energy-saving features Adopt message and event-driven mechanism.
  • the system can be instant (6) Transparent distribution calculation features. Only the ID number represents the concurrent operator Actor in the system, and the concurrent operator Actor communicates only through the message, and there is no correlation between where the operator is stored and where it is executed. Therefore, the natural multi-processor CMP (Chip Multi-Processor) structure, Symmetrical Multi-Processor (SMP) structure, Asymmetrical Multi-Processor (AMP) structure, non-uniform storage access NUMA (Non_Uniform) Memory Access) Structure, massive parallel processing MPP (Massive Paral Lel Process) structure, computer clustering, distributed computing, etc. Parallel and distributed environments. Easily perform functions such as load balancing and calculation transfer to easily improve computing performance and achieve a globally unified computing environment.
  • CMP Chip Multi-Processor
  • SMP Symmetrical Multi-Processor
  • AMP Asymmetrical Multi-Processor
  • NUMA Non_Uniform) Memory Access
  • Microkernel features The core code is small, and the concurrency mechanism is implemented through an efficient message bus.
  • the operating system can be fully architected on top of it, competing with single-core systems.
  • Each of the active components of each layer in the set P conforms to the same protocol.
  • a plurality of small active members are assembled into members, and finally a large active member having the same component protocol as that of the respective small active members is obtained.
  • the large active component completely eliminates the call dependency on the lower active component, so that there is only loose connection between the components. Can be separated from the specific application environment to complete independent component functions.
  • the components can be reused, reconstructed and combined in a simple and efficient manner, so that the entire component system is highly reusable.
  • the layer 1 active component in the set P includes: the message bus, the interface operator ID mapping table, the alias link table, and one or more operators; wherein the interface operator ID mapping table is used to store the interface Corresponding relationship between the operator ID and the entry function; the alias link table is configured to store a correspondence between the reference operator ID and the interface operator ID; wherein the interface operator ID is an operator of the active component itself An identifier; the reference operator ID is an operator identifier that is attached to an active component on the message bus;
  • the reference operator ID referenced inside the component is only the symbol name to be confirmed by the connection, and after the related components are compiled and connected with the configuration file, those references are used.
  • the operator ID is assigned as a formal ID value or variable.
  • the alias link table is used to store the correspondence between the reference operator ID and the interface operator ID.
  • the correspondence between the reference operator ID and the interface operator ID stored in the alias link table is an equivalence mapping relationship.
  • the alias link table in operation, tells the compiler that the other reference operator IDs referenced within a component should be linked with the interface operator IDs of which components. Essentially, the data communication connection between the component and the component is determined and delineated to complete the predetermined function of the system.
  • the reference operator ID is bound to the predetermined interface operator ID, and the operator's entry function and its parameters and message format are not concerned.
  • the parameters of the two functions are matched with the specific specifications and forms of the message, and the application system determines and decides by itself, thereby giving the component link operation maximum freedom. It can generally be checked by the compiler when the component is statically compiled. It can also be checked and confirmed by the operator when the system is running dynamically.
  • alias link The concrete implementation of the alias link is very simple. Just bind the reference ID variable and the known ID variable to the same value or variable, which can be done by alias operation or assignment operation in the programming language.
  • refld is the reference operator ID
  • calcld is the known interface operator ID.
  • the interface operator ID mapping table is used to store the correspondence between the interface operator ID and the entry function.
  • the message entry function within the component can be separated from the interface operator ID. That is, the function implementation code part of the component may not contain the name of the interface operator ID, but only the code of the entry function.
  • the binding mapping of the two can be lagging behind, and is done with the alias link when the component or system is assembled. Multiple interface operator IDs can be mapped to the same entry function. This is extremely valuable when implementing statically referencing multi-instance objects.
  • Each of the active components of the second-layer active component subset to the n-th active component subset of the set P includes: the virtual message bus, the interface operator ID mapping table, the alias link table, and a The above operator.
  • the virtual message bus is a logical, conceptual bus, without actually concerned about coding, not a separate explicit bus entity.
  • the component is always plugged into a bus, and by calling the bus API function, the component is hard-coded to attach to the bus.
  • the component exists in the form of source code or intermediate library alone, the component is not actually connected to a certain bus, and the code of the bus is not included in the component. Only after the completion of the compiled connection of the entire bus node, or the entire system, the component is connected to the code of a certain bus to become a hook component of the bus.
  • the component assumes that it is operating on a bus, but this bus does not yet exist, so it is called a virtual message bus. It does not exist inside the component and does not affect the independence of the component.
  • the active components in the n-th active component subset are assembled according to the n-th virtual message bus, and a single active component in the n-1th active component subset is obtained, where n 3 is specifically: the nth Each active component in the layer active component subset includes an nth layer virtual message bus, an nth layer interface operator ID mapping table, an nth layer alias link table, and one or more nth layer operators;
  • the single active component in the n-1th active component subset includes an n-1th virtual message bus, an n-1th interface operator ID mapping table, an n-1th alias link table, and more than one N-1 layer operator;
  • each of the nth layer virtual message bus is bus-fused to obtain an n-1th layer virtual message bus; and each of the nth layer interface operator ID mapping tables is table-fused to obtain a nth a layer 1 interface operator ID mapping table; table fusion of each of the nth layer alias link tables to obtain an n-1th layer alias link table; and fusing each of the nth layer operators to obtain an nth- 1 layer operator.
  • Each active component in the second-layer active component subset is assembled based on the message bus, and the first-layer active component is specifically - each active component in the second-layer active component subset includes a a layer 2 virtual message bus, a layer 2 interface operator ID mapping table, a layer 2 alias link table, and one or more layer 2 operators; the first layer active component obtained after component assembly includes the message bus , a layer 1 interface operator ID mapping table, a layer 1 alias link table, and more than one layer 1 operator;
  • each of the second layer virtual message buses is bus-fused to obtain the message bus; each of the layer 2 interface operator ID mapping tables is table-fused to obtain a layer 1 An interface operator ID mapping table; table fusion of each of the second layer alias link tables to obtain a first layer alias link table; and fusing each of the second layer operators to obtain a first layer operator.
  • the virtual message bus is just a logical concept, and there is no need to actually care about coding. Therefore, it is only necessary to complete the interface operator ID mapping table and the alias link table, which can be placed in the same configuration file. Therefore, the component assembly operation simplifies the correspondence to complete a compact configuration file.
  • the actual operator function code can be stored in an operator function library. There is no mutual calling relationship between the operator functions of the library, just a simple list relationship, and everyone exists in the same library in parallel.
  • the contents of the configuration file are simply listed: the correspondence between the interface operator ID and the entry function, and the correspondence between the reference operator ID and the interface operator.
  • the reference, split, modification, reuse, etc. of the components are also just changing the corresponding relationship, which is very simple and clear. When you need to completely include another component and make it a part of itself, simply include the component's configuration file without changing its function code portion.
  • Concurrent operators are the most basic building blocks that can be assembled to form larger, more advanced components. After the formation of larger components, there is still no direct function call relationship between the operators as the basis, only the data communication relationship, and still maintain the communication characteristics of each other through the bus. The data connection and communication relationship between the operators within the component is determined by a partial alias link table. Since the message scheduling efficiency of this message bus is close to or the same as the order-level call call at the assembly level, there are very few operators that exist or do not degrade the efficiency of the system.
  • FIG. 5 a schematic diagram of the assembly of the components provided by the present invention is shown.
  • the members 3 and 4 need to form a large member Ca, and then the components Ca and the members 1 and 2 need to be composed larger.
  • Component Cb The data transfer relationship between the component 1, the component 2, the component 3, and the component 4 is shown in the left half of the figure; the actual component assembly operation structure is shown in the right half of the figure.
  • Component 1, component 2, component 3, component 4 The actual function code, stored in another operator library in parallel, do not care.
  • the configuration file of the component Ca includes: the correspondence between the operator ID3a, ID3b and the entry function in the member 3, the correspondence between the operator ID4 and the entry function in the member 4; the correspondence between the member 3 reference ID4 and the member 4 reference ID3b
  • the operator ID3a and the operator referenced by component 4 are published.
  • the configuration of component Cb is similar and will not be described again.
  • the general model is assembled by the above components, so that the small basic components can be easily assembled into large components, and at the same time, the large components are also easily decomposed.
  • the concurrent operator belongs to the active message component of the push mode. Applying the components of the message bus, the externally presented interface is one or more operators, and each operator is bound with a message entry function, which is represented by an operator ID.
  • the present invention also provides a component splitting method for the above-described active component assembly model, comprising the following steps:
  • the component splitting rule is preset, and when the active component assembly model satisfies the component splitting rule, the active component assembly model is split according to the component splitting rule.
  • the present invention provides the following four component splitting rules:
  • the component splitting rule is: when the scheduler of the message bus is executed by more than two cores or processors, splitting the message bus into distributed peers having the same number of cores or the number of processors a sub-bus; each of the active components of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
  • a bus is only suitable for executing a bus scheduler by one core of one processor, and the same bus scheduler cannot be executed by multiple cores or multiple processors simultaneously.
  • the message load of one bus is very large, it is not enough to execute the scheduler of the bus by only one core of one processor.
  • the bus can be split into two or even multiple sub-buses, and each processor core is responsible for running one sub-bus. In this way, the automatic transfer of the load can be completed.
  • the component splitting rule is: dynamically counting the load of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset load balancing principle; Each of the active components or operators in each layer of the active component assembly model is respectively connected to the pair Should be on the sub-bus.
  • the component splitting rule is: dynamically counting energy efficiency ratios of the active components in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset energy-saving principle; Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
  • the component splitting rule is: dynamically counting the failure rate of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset reliability principle Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
  • the collaborative concurrent message bus, the active component assembly model and the component splitting method provided by the invention can effectively overcome the weakness of the existing "concurrent” implementation technology, and realize the "concurrency” technology and parallel programming efficiently and reliably, and have universality and low cost.
  • a series of advantages such as high efficiency, reliability, energy saving, reuse, transparent distribution, microkernel, and intrinsic support object technology.

Abstract

Provided are a cooperative concurrent message bus, driving member assembly model and member disassembly method, the cooperative concurrent message bus comprising: an information acquisition module, a concurrent annular distributor, a linear memory block, a message filling module, a concurrent queuing device, a message queue pool, a queue sequence manager, an entrance mapping table, and a system stack. The cooperative concurrent message bus, driving member assembly model and member disassembly method provided by the present invention effectively overcome the weakness of an existing "concurrence" implementation technique, and efficiently and reliably realize concurrence technique and concurrent programming, and have not only universal adaptability, low cost, high efficiency, and reliability, but also energy-saving, multiplexing, transparent distribution, micro kernel, and internal supporting for an object technique.

Description

协同并发式消息总线、 主动构件组装模型.及构件拆分方法 本申请要求以下中国专利申请的优先权:  Collaborative concurrent message bus, active component assembly model, and component split method The present application claims the priority of the following Chinese patent application:
于 2013年 01月 18日提交中国专利局, 申请号为 201310020046. 5, 发明名 称为 "协同并发式消息总线、 主动构件组装模型及构件拆分方法"的中国专利申 请, 其全部内容通过引用结合在本申请中。 技术领域  Submitted to the China Patent Office on January 18, 2013, the application number is 201310020046. 5, the invention is entitled "Collaborative Concurrent Message Bus, Active Component Assembly Model and Component Splitting Method" Chinese patent application, the entire contents of which are incorporated by reference. In this application. Technical field
本发明属于计算机技术领域, 具体涉及一种协同并发式消息总线、主动构件 组装模型及构件拆分方法。 背景技术  The invention belongs to the technical field of computers, and particularly relates to a collaborative concurrent message bus, an active component assembly model and a component splitting method. Background technique
众所周知, 软件设计的终极目标为: 真实世界是什么样子, 软件就应当设计 成什么样子, 从而实现通过软件模拟真实世界的目的。 由于真实世界是纷繁复杂 地, 如实地模拟真实世界往往并不容易。前人经过多年的实践发现, 软件系统对 真实世界的每个细节模拟得越逼真, 软件就越容易设计、 理解与维护。 由于面向 对象编程真实地模拟了现实世界的事物, 容易理解、方便维护、容易变更, 因此, 面向对象编程取代了面向过程编程, 成为目前主流的编程方式。  As we all know, the ultimate goal of software design is: What the real world looks like, and what software should be designed to achieve the purpose of simulating the real world through software. Since the real world is complex, it is often not easy to realistically simulate the real world. After years of practice, the predecessors found that the more realistic the software system simulates every detail of the real world, the easier it is to design, understand, and maintain the software. Because object-oriented programming truly simulates real-world things, it is easy to understand, easy to maintain, and easy to change. Therefore, object-oriented programming has replaced process-oriented programming and has become the mainstream programming method.
然而, 由于硬件成本等多种因素的限制, 在现实世界中, 无处不在的、 多个 对象同时动作的 "并行"活动, 在单台计算机中, 却极少能够真实模拟。现代计 算机软件系统中, 绝大部分都只呈现"伪并行"活动: 从宏观上看, 一台计算机 能够同时执行多个任务、 多个程序, 若干对象同时在运行; 但从微观上看, 在任 一瞬间、 任一时刻, 则只有一个程序在运行。 由于处理器速度非常快, 它在几个 程序间来回快速切换,经过稍长一段时间,我们就觉得这几个程序是在同时执行、 同时活动。 这种现象, 通常称之为 "并发", 以区分严格意义上的 "并行"活动。  However, due to various factors such as hardware cost, in the real world, the ubiquitous "parallel" activities of multiple objects moving simultaneously, in a single computer, are rarely realistically simulated. In modern computer software systems, most of them only present "pseudo-parallel" activities: From a macro perspective, a computer can execute multiple tasks, multiple programs at the same time, and several objects are running at the same time; but microscopically, incumbent For a moment, at any time, only one program is running. Because the processor is very fast, it switches back and forth between several programs. After a long period of time, we feel that these programs are executing at the same time and active at the same time. This phenomenon, often referred to as "concurrency", distinguishes between "parallel" activities in the strict sense.
一般在操作系统等中低层软件中, 提供相应的并发技术实现机制, 并对外提 供专门的并发服务接口, 以便上位程序能完成并发活动。 上位应用程序, 则调用 这些并发服务接口, 使自己呈现为一个或多个并发的任务。  Generally, in the middle and low-level software such as the operating system, the corresponding concurrent technology implementation mechanism is provided, and a special concurrent service interface is provided externally, so that the upper program can complete concurrent activities. The upper-level application calls these concurrent service interfaces to render itself as one or more concurrent tasks.
并发实体 (任务、 进程、 线程、 纤程等) 间的调度操作 (用于操作系统、 软 件总线等), 提供了并发技术的实现机制。 现代操作系统中, 剥夺式调度是普遍 采用的调度策略。 但它具有若干致命弱点, 试列举如下: Scheduling operations (for operating systems, software buses, etc.) between concurrent entities (tasks, processes, threads, fibers, etc.) provide an implementation mechanism for concurrent technologies. In modern operating systems, deprivation scheduling is common The scheduling strategy adopted. But it has a number of Achilles heel, and the trials are as follows:
( 1 ) 堆桟空间问题: 剥夺式调度随时可能打断并发实体的执行过程, 因此 需要保护与恢复并发实体运行环境 (最少需要包含指令寄存器等), 这需要 RAM 堆桟空间。在普通运行场合(如 PC机),这个问题不突出。但在大量并发实体(如 单片机在数千网络连接)的情况下, 问题将变得相当突出; 在 RAM稀缺的特殊场 合 (如 WSN应用) 下, 调度将变为不可行。  (1) Stacking space problem: Deprivation scheduling may interrupt the execution process of concurrent entities at any time. Therefore, it is necessary to protect and restore the concurrent entity running environment (at least including instruction registers, etc.), which requires RAM heap space. In normal operating situations (such as PCs), this problem is not outstanding. However, in the case of a large number of concurrent entities (such as a microcontroller with thousands of network connections), the problem will become quite prominent; in special cases where RAM is scarce (such as WSN applications), scheduling will become infeasible.
( 2) 执行效率问题: 由于需要保护与恢复并发实体运行环境, 这部分调代 码的执行是必须增加的。 在非常轻量级调度的情况 (如 TinyOS) 下, 相对 于调度整体执行时间, 它所增加的执行时间是非常可观的, 严重影响了轻量级调 度的执行效率。  (2) Execution efficiency problem: Due to the need to protect and restore the concurrent entity operating environment, the execution of this part of the code must be increased. In the case of very lightweight scheduling (such as TinyOS), the increased execution time relative to the overall execution time of the scheduling is very significant, which seriously affects the execution efficiency of the lightweight scheduling.
( 3)竞争共享问题: 剥夺式调度随时可能打断并发实体的执行过程, 因此, 所有并发实体间共享的数据与资源, 都成为被竞争的对象, 变成临界资源。 如果把所有的这些被竞争对象, 都用临界区或其它统一的通用措施保护起来, 那 么系统的整体运行效率将会降低到不可接受的程度。如果精心设计共享结构, 只 采用通用措施保护部分对象, 则在编程与维护代码时, 稍不当心就会引发临界资 源竞争导致的时序故障 (这类故障还特别难以重现与定位), 对编程人员与维护 人员的职业素养要求将会提高很多,提高了设计与维护成本,降低了系统可靠性。 特别是对于大量无规律的共享并发数据 (如上百个不同的特殊线程), 在编程实 践中, 一般开发人员都望而生畏, 除非特别必要, 均避而远之。  (3) Competition sharing problem: Deprivation scheduling may interrupt the execution process of concurrent entities at any time. Therefore, the data and resources shared by all concurrent entities become the objects of competition and become critical resources. If all of these competing objects are protected by critical sections or other uniform general measures, the overall operational efficiency of the system will be reduced to an unacceptable level. If you carefully design the shared structure and only use common measures to protect some objects, when you program and maintain the code, a little care will lead to timing failure caused by the competition of critical resources (such faults are especially difficult to reproduce and locate). The professional quality requirements of personnel and maintenance personnel will be much improved, the design and maintenance costs will be increased, and the system reliability will be reduced. Especially for a large number of irregular shared concurrent data (such as hundreds of different special threads), in the programming practice, the average developer is daunting, unless it is particularly necessary, to avoid it.
( 4) 竞争复用问题: 前述为了效率提升而进行优化的数据共享设计, 会带 来  (4) Competitive reuse problem: The data sharing design optimized for efficiency improvement will bring
代码复用性问题。 由于针对项目的竞争环境, 采用了针对性地消除竞争的共 享数据保护代码, 这些代码一般不具备普遍的通用性。 即使对于其它非常相似的 项目, 也很有可能面对的是其它不同的数据竞争条件, 因此, 需要做出另外优化 的数据共享设计, 不能直接复用原来模块。  Code reusability issues. Due to the competitive environment for the project, shared data protection codes that specifically eliminate competition are used, and these codes are generally not universally versatile. Even for other very similar projects, it is very likely to face other different data race conditions. Therefore, an optimized data sharing design needs to be made, and the original modules cannot be directly reused.
TinyOS 是加州大学伯克利分校(UC Berkeley)为无线传感器网络 WSN (Wireless Sensor Network)开发的微内核操作系统。 TinyOS 的两层调度方 式为: 任务调度与硬件事务调度。硬件事务调度由硬件中断激活, 可抢占普通任 务, 主要用于高优先级的快速实时响应。 它基本雷同于一般中断处理程序, 稍有 出入的地方在于: 它可以向任务调度发送信号, 激活普通任务; 同时, 还能利用 nesC关键字 async的异步能力, 直接调用进入到 nesC构件系统中, 调用构件中 的命令处理函数, 并给构件发送异步事件。 TinyOS is a microkernel operating system developed by UC Berkeley for the wireless sensor network WSN (Wireless Sensor Network). The two-tier scheduling mode of TinyOS is: task scheduling and hardware transaction scheduling. Hardware transaction scheduling is activated by hardware interrupts, which can preempt ordinary tasks and is mainly used for high-priority fast real-time response. It is basically the same as the general interrupt handler. The slight difference is that it can send signals to the task schedule to activate common tasks. At the same time, it can also be used. The asynchronous ability of the nesC keyword async directly calls into the nesC component system, calls the command handler in the component, and sends asynchronous events to the component.
TinyOS 的基本任务为无参数函数。 任务调度采用协同式的先进先出(FIFO) 算法, 任务之间互不抢占, 没有优先级之分。 一旦一个任务获得了处理器, 就一 直运行到结束。 一般用于对时间要求不高的应用, 本质上是一种延迟计算 DPC (Deferred Procedure Call)机制。 TinyOS 2. x调度器可由用户定制与替换。  The basic task of TinyOS is a parameterless function. Task scheduling uses a collaborative first-in, first-out (FIFO) algorithm, where tasks do not preempt each other and there is no priority. Once a task has acquired the processor, it runs straight to the end. Generally used for time-critical applications, it is essentially a Deferred Procedure Call (DPC) mechanism. The TinyOS 2. x scheduler can be customized and replaced by the user.
如图 1所示, TinyOS 2. x核心 PCB为一个固定长度的字节数组, 组成一个 FIFO 就绪任务队列、 以及一个等待任务池。 系统内的每个任务均由一个字节的 任务 ID表示, 编号为(Γ255, 其中 255表示空任务 NO— TASK: 即任务不存在。 因 此, 系统内最多可容纳 255个有效任务。 具体某个应用系统中的实际任务数, 也 即字节数组的实际长度, 则在源代码编译期间, 由编译器自动生成。  As shown in Figure 1, the TinyOS 2.x core PCB is a fixed-length byte array that forms a FIFO-ready task queue and a waiting task pool. Each task in the system is represented by a byte of task ID, numbered (Γ255, where 255 represents the empty task NO-TASK: that is, the task does not exist. Therefore, the system can accommodate up to 255 valid tasks. The actual number of tasks in the application system, ie the actual length of the byte array, is automatically generated by the compiler during source code compilation.
该字节数组存放的是任务就绪标志。 如果某任务 ID没有收到事件, 不需加 入到 FIFO就绪队列中, 则存放 NO— TASK标志, 进入等待任务池。 如果该任务 ID 有事件发生, 激活进入就绪态, 则该任务 ID字节中存放的是下一个就绪任务, 表示本 ID已进入 FIFO就绪任务队列, 等待执行。  This byte array holds the task ready flag. If a task ID does not receive an event and does not need to be added to the FIFO ready queue, the NO-TASK flag is stored and the waiting task pool is entered. If an event occurs in the task ID and the activation enters the ready state, the task ID byte stores the next ready task, indicating that the ID has entered the FIFO ready task queue and is waiting for execution.
激活任务 ID并行入队时, 采用阻塞式的临界区保护法。如果该 ID已处于就 绪态, 则返回忙标志, 否则从队尾加入到就绪队列。 由于仅有一个字节的 ID入 队, 因此临界区能高速通过, 不太影响中断响应速度。 这个算法可以避免一个 ID多次入队的潜在问题: 如果同一 ID可占用多个字节位置, 在某些情况下, 可 能会占满字节数组, 导致其它任务无法入队而系统假死。  When the activation task ID is entered in parallel, the blocking critical section protection method is adopted. If the ID is already in the state, the busy flag is returned, otherwise it is added to the ready queue from the end of the queue. Since only one byte of ID is enqueued, the critical section can pass at high speed, which does not affect the interrupt response speed. This algorithm can avoid the potential problem of multiple IDs entering the queue: If the same ID can occupy multiple byte positions, in some cases, it may fill up the byte array, causing other tasks to fail to join the system and the system to die.
就绪任务 ID从队首出队时, 同样采用阻塞式的临界区保护法。 如果没有就 绪任务, 则发信号给节电装置,进入节电状态。否则,检索出该任务的入口地址, 执行该任务。 因为调度器中仅有任务 ID, 不存在附加参数, 因此任务必须是无 参数函数。 同时, 任务是协同式的, 前面任务必须完全退出 (此时堆桟为空) 以 后, 才能执行下一任务。 因此, 所有的任务都共享同样的内存堆桟空间。  When the Ready Task ID is dequeued from the team, the blocking critical section protection method is also used. If there is no ready task, a signal is sent to the power saver to enter the power save state. Otherwise, the entry address of the task is retrieved and the task is executed. Because there is only a task ID in the scheduler, there are no additional parameters, so the task must be a parameterless function. At the same time, the task is collaborative, and the previous task must be completely exited (the stack is empty) before the next task can be executed. Therefore, all tasks share the same memory heap space.
TinyOS 2. x 所有基本任务均是无参数函数, 每个基本任务仅固定分配一个 字节的任务 ID, 该字节存放任务就绪标志, 没有空间存放其它参数。 所以, 本 质上它只是一个信号灯系统。相较于可附带若干参数的消息系统而言, 有若干弱 点, 试列举如下:  TinyOS 2. x All basic tasks are parameterless functions. Each basic task only assigns a task ID of one byte. This byte stores the task ready flag and has no space for other parameters. So, in essence, it is just a signal light system. There are several weaknesses compared to message systems that can be accompanied by several parameters. The trials are as follows:
( 1 ) 任务不能携带入口参数: 任务退出执行后, 堆桟清空, 同时信号灯系 统 (1) The task cannot carry the entry parameters: After the task exits execution, the stack is emptied and the signal system is System
无法携带或保存参数。 因此, 限制了任务的适用范围。 只能用额外的措施予 以弥补。 如: 用任务实现的自计数模块。  Unable to carry or save parameters. Therefore, the scope of the task is limited. Only extra measures can be used to make up for it. Such as: Self-counting module implemented with tasks.
( 2) 任务信息不能统一管理: 由于信号灯系统无法携带参数, 外部环境与 各  (2) Task information cannot be managed uniformly: Since the signal system cannot carry parameters, the external environment and each
任务之间的信息交换方式, 完全依赖于外部环境与各任务自行商定, 没有统 一规范化的表示手段。因此,对于外部环境与任务、任务与任务之间交换的信息, 不能直接用统一的手段收集、 监视、 过滤、 控制、 管理。 只能用额外的措施予以 弥补。 这对软件系统的调试、 测试、 控制等, 都是极大的限制。  The way in which information is exchanged between tasks depends entirely on the external environment and the tasks themselves, and there is no unified and standardized means of representation. Therefore, information exchanged between the external environment and tasks, tasks, and tasks cannot be collected, monitored, filtered, controlled, and managed directly by a unified means. It can only be compensated for with additional measures. This is a great limitation on the debugging, testing, control, etc. of the software system.
( 3) 主动消息不能完全表达: 由于信号灯系统无法携带参数, 信息交换方 式  (3) The active message cannot be fully expressed: Since the signal light system cannot carry parameters, the information exchange method
需由环境与任务间另行商定, 不是统一规范。发送出去的消息只能通知接收 任务说有消息发生, 但不能一次性完全表达完毕。 因此, 接收信息的任务需要依 赖于特定的信息交换方式, 采用拉 (Pull)模式机制, 通过函数调用方式, 取回具 体的信息内容。对于实现完全可复用模块、及完全透明的分布式计算系统, 这是 一个致命的限制 (理由后述), 很难弥补。  It needs to be separately agreed between the environment and the task, not a unified norm. The sent message can only be notified to the receiving task that a message has occurred, but it cannot be fully expressed at one time. Therefore, the task of receiving information needs to rely on a specific information exchange method, and adopts a pull mode mechanism to retrieve specific information content by function calling. This is a fatal limitation (for reasons to be described later) for implementing fully reusable modules and fully transparent distributed computing systems, which is difficult to compensate.
TinyOS 2. X在任务 ID并行入队与串行出队时, 均采用阻塞式的临界区保护 法。 由于仅有一个字节的 ID入队, 因此临界区能高速通过, 不太影响中断响应 速度与系统性能。这是由于它采用了非常简易的信号灯机制。如果根据系统需求, 要换用成消息机制,除了公知的阻塞型同步的死锁、优先级倒置、中断不能加锁、 临界区不能并发等问题以外, 还存在有其它问题, 试列出如下:  TinyOS 2.X uses the blocking critical section protection method when the task ID is entered in parallel and serially dequeued. Since only one byte of ID is enqueued, the critical section can pass at high speed, which does not affect the interrupt response speed and system performance. This is due to its very simple signalling mechanism. If you want to switch to the message mechanism according to the system requirements, in addition to the known blocking type of synchronous deadlock, priority inversion, interrupt can not be locked, critical sections can not be concurrent, and other issues, there are other problems, the test is as follows:
( 1 ) 实时性能问题: 相较于单字节的任务 ID, 消息一般较长, 入队、 出队 均  (1) Real-time performance problems: Compared to single-byte task IDs, messages are generally longer, enqueue and dequeue
需要较长时间, 会导致临界区执行时间加长很多。在一般单片机系统中, 临 界区保护一般由关中断完成。这样, 会导致系统中断响应速度变慢, 影响系统实 时性能, 降低系统整体效率。  It takes a long time, which will lead to a much longer execution time in the critical section. In a general-purpose microcontroller system, the protection of the critical area is generally completed by the shutdown. In this way, the system interrupt response speed is slow, which affects the system real-time performance and reduces the overall system efficiency.
( 2) 硬件实现问题: 在各处理器与各软件系统上, 实现并行入队临界区保 护  (2) Hardware implementation issues: Parallel enqueue critical zone protection on each processor and software system
的技术手段变化多端, 不容易导出简洁、高效、统一的并行入队模型。因此, 不容易用硬件实现关键操作、辅佐并行入队,无法提高执行效率或带来其它优势。 TinyOS 1. x 以及一般通用操作系统, 在其调度程序数据结构中, 均直接保 存任务函数的入口地址。 当调度程序选中该任务、 完成必要准备工作后, 就直接 跳到该地址, 以执行任务代码。相对于采用任务 ID、 以及 ID地址映射表的方式, 有若干缺点, 试列举如下: The technical means are varied and it is not easy to export a concise, efficient and unified parallel enrollment model. Therefore, it is not easy to implement key operations in hardware, assist in parallel enqueue, and it is impossible to improve execution efficiency or bring other advantages. TinyOS 1. x and the general-purpose operating system directly store the entry address of the task function in its scheduler data structure. When the scheduler selects the task and completes the necessary preparations, it jumps directly to the address to execute the task code. There are several disadvantages compared to the way in which the task ID and the ID address mapping table are used.
( 1 ) 入口地址含义单一: 不能蕴含其它有意义的信息 (如静态优先级)。  (1) The entry address has a single meaning: it cannot contain other meaningful information (such as static priority).
( 2) 入口地址仅在单机内有意义: 跨越计算机后, 该地址没有任何意义。 因此, 对于要求完全透明的分布式并行任务计算, 是一个致命的限制。  (2) The entry address is meaningful only in a single machine: After crossing a computer, the address has no meaning. Therefore, it is a fatal limitation for distributed parallel task computing that requires complete transparency.
TinyOS 2. X使用一个字节的基本任务 ID, 使得调度内核简洁高效。 但这限 制了它所能容纳的最大任务数为 255, 对稍微大型、 任务数更多的系统, 无法容 纳处理, 影响系统伸缩性。  TinyOS 2.X uses a one-byte base task ID to make the scheduling kernel simple and efficient. However, this limits the maximum number of tasks it can accommodate to 255. For systems that are slightly larger and have more tasks, they cannot accommodate processing and affect system scalability.
TinyOS 2. X使用一个字节的基本任务 ID, 兼作为 FIFO就绪队列指针、 以及 任务就绪标志。这与其它绝大多数操作系统一样, 都具备有存放于 RAM内存中的 非零长度的任务 PCB表。 具有若干弱点, 试列举如下:  TinyOS 2.X uses a one-byte base task ID, as both a FIFO ready queue pointer and a task ready flag. This, like most other operating systems, has a non-zero-length task PCB table stored in RAM memory. With a number of weaknesses, try to enumerate as follows:
( 1 ) 执行效率问题: 由于需要对任务 PCB表进行各种操作 (如把任务从等 待  (1) Execution efficiency problem: Due to the need to perform various operations on the task PCB table (such as waiting for the task)
态转为就绪态), 这部分调度代码的执行是必须增加的。 在非常轻量级调度 的情况 (如 TinyOS ) 下, 相对于调度整体执行时间, 它所增加的执行时间是额 外的、 比较可观的, 影响了轻量级调度的执行效率。  The state is changed to the ready state. The execution of this part of the scheduling code must be increased. In the case of very lightweight scheduling (such as TinyOS), the increased execution time relative to the overall execution time of the schedule is extraordinarily significant, which affects the execution efficiency of lightweight scheduling.
( 2) 硬件实现问题: 在各处理器与各软件系统上, 任务 PCB表的内容、 实 现  (2) Hardware implementation issues: On each processor and each software system, the contents of the task PCB table, implementation
的技术、 优化手段等各种措施千变万化, 不容易导出简洁、 高效、 统一的并 发技术实现模型。 因此, 不容易用硬件实现关键操作、 辅佐并发的实现, 无法提 高执行效率或带来其它优势。  Various measures such as technology and optimization methods are ever-changing, and it is not easy to export a simple, efficient, and unified concurrent technology implementation model. Therefore, it is not easy to implement key operations in hardware, and to implement concurrent implementations, which cannot improve execution efficiency or bring other advantages.
( 3) 空间占用问题: 由于有存放在 RAM内的任务 PCB表, 即便 RAM使用量 非常微小 (如 TinyOS 2. X本质上可以用单个 BIT位表征任务的等待态、 就 绪态), 在 RAM内存稀缺的情况下(如 WSN系统), 如果存在成千上万的大量任务 (案例后述), 会导致系统无法实现并发调度过程, 成为致命的技术缺陷, 限制 了该技术的适用范围。  (3) Space occupation problem: Since there is a task PCB table stored in RAM, even if the RAM usage is very small (such as TinyOS 2. X can essentially characterize the task's wait state and ready state with a single BIT bit), in RAM memory In the case of scarcity (such as WSN system), if there are tens of thousands of tasks (described later in the case), the system will not be able to implement the concurrent scheduling process, which becomes a fatal technical defect and limits the scope of application of the technology.
构建 TinyOS系统时, 用 nesC语言写成构件, 通过接口规范进行构件连接, 并在程序编译期间, 用函数调用的方式进行静态组装。 因此, 在本质上, 其构件 对外公布的是函数名 (链接期有效)与函数地址(运行期有效)。 与公布 ID的构 件方案对比, 有不少弱点, 试列举如下: When building the TinyOS system, the components are written in the nesC language, the components are connected through the interface specification, and statically assembled by function calling during program compilation. Therefore, in essence, its components The function name (link period valid) and function address (valid time) are announced. Compared with the component scheme of the published ID, there are many weaknesses. The trials are as follows:
( 1 ) 模块模型不一致: TinyOS 2. x任务采用 ID方案, 而其构件采用地址 方案。  (1) The module model is inconsistent: The TinyOS 2.x task uses the ID scheme, and its components use the address scheme.
二者不一致, 存在 2种模型, 导致其系统基本模块的模型复杂化。  The two are inconsistent, and there are two models, which complicate the model of the basic modules of the system.
( 2)地址方案适应性弱: ID方案更容易跨语言、跨异质系统, 普适性更好。  (2) The adaptability of the address scheme is weak: the ID scheme is easier to cross-language and cross-heterogeneous systems, and the universality is better.
( 3) 地址方案难以动态适应: 在代码运行期内, 除非特别维护, 函数地址 已  (3) The address scheme is difficult to adapt dynamically: During the code running period, unless it is specially maintained, the function address has been
无从追踪。 而预定义的 ID构件方案, 更容易进行代码的引用、 更改、 替换、 维护, 更容易实现单块或整体代码热升级。  No tracking. The predefined ID component scheme makes it easier to reference, change, replace, and maintain code, making it easier to implement single-block or overall code hot upgrades.
( 4) 函数地址仅在单机内有意义: 跨越计算机后, 该地址没有任何意义。 因  (4) The function address is meaningful only in a single machine: After crossing a computer, the address has no meaning. Cause
此, 对于要求完全透明的分布式并行任务计算, 是一个致命的限制。  This is a fatal limitation for distributed parallel task computing that requires full transparency.
目前的 TinyOS系统、 结构化编程、 模块化编程、 面向对象编程、 构件化编 程 等等各种技术, 在用小模块链接组装成更大模块时, 均采用函数调用的 方式完成。这种方式有致命的缺陷, 是在复杂软件系统中, 导致软件模块难以复 用的最核心问题之一。 下面详细说明:  The current TinyOS system, structured programming, modular programming, object-oriented programming, component programming, and many other techniques are all done in a function call when assembled into smaller modules using small module links. This approach has a fatal flaw and is one of the core issues that make software modules difficult to reuse in complex software systems. The following details:
为了叙述简便, 借用两个术语, 先简单说明下:  For the sake of simplicity, borrow two terms, briefly explain:
拉(Pull )模式和推(Push)模式, 这两个术语原本是用于表示互联网上的 一种信息传播方式。 拉 (Pull ), 是指用户主动浏览网站信息, 把信息从自己感 兴趣的网站上 (拉) 取回来。 推 (Push), 是指网站主动把消息发送 (推) 给某 些特定的用户。  The Pull mode and the Push mode are originally used to indicate a way of disseminating information on the Internet. Pull (Pull) means that the user actively browses the website information and retrieves the information from the website he is interested in (pull). Push means that the website actively sends (push) messages to certain users.
一个模块, 通过调用处于另外一个模块中的函数, 获得了结果。这个函数调 用, 也即信息获取过程, 类似于网上信息拉的过程, 因此也称之为拉模式。 如果 一个模块是并发实体 (线程等), 给另外一个并发实体主动发送消息。 这种发送 消息的过程, 类似于网上信息推送的过程, 因此也称之为推模式。  A module that obtains the result by calling a function in another module. This function call, which is the information acquisition process, is similar to the process of pulling information on the Internet, so it is also called pull mode. If one module is a concurrent entity (thread, etc.), another concurrent entity sends a message. This process of sending a message is similar to the process of pushing information on the Internet, so it is also called push mode.
拉模式与推模式, 最重大意义的区别在于: 每次拉的时候, 用户均需要指定 拉取的对象、 以及拉取(内容) 的具体条件; 而每次推的时候, 不需要用户有任 何动作 (当然在此之前, 需要做些一次性地工作, 如预订等等)。  Pull mode and push mode, the most significant difference is: each time you pull, the user needs to specify the object to be pulled, and the specific conditions of the pull (content); and each time you push, you do not need any user Actions (of course, before doing this, you need to do some one-off work, such as booking, etc.).
参看图 2, 为采用拉模式工作的两个模块。 D模块代表被调用模块, 除了 D 模块之外的其他所有部分, 是进行主动函数调用的模块。为了对调用过程进行分 析, 对上面的调用模块进行了功能等效的分解。 Referring to Figure 2, there are two modules that operate in pull mode. The D module represents the called module, except D All other parts of the module are modules that make active function calls. In order to analyze the calling process, a functional equivalent decomposition of the above calling module is performed.
图中, In表示模块所需要的输入参数 (消息), Out表示模块所输出的信息 (消息), F模块是该模块必须完成的核心功能, B模块是该模块完成的另外一部 分功能。 因此, 从本质上说, F+B的功能是该模块存在的意义所在。  In the figure, In represents the input parameters (messages) required by the module, Out represents the information (message) output by the module, F module is the core function that the module must complete, and B module is another part of the function completed by the module. Therefore, in essence, the function of F+B is the meaning of the existence of this module.
C模块代表直接函数调用, 相当于汇编的 CALL指令, 之后 CPU的执行权直 接转到了 D模块中。拉模式中,这是必须存在的环节。 D模块需要一定的参数 Pm。 该参数经由 A模块: 即参数变换后得到, 在 C模块调用时, 一并传给 D模块。  The C module represents a direct function call, which is equivalent to the assembled CALL instruction, after which the execution right of the CPU is directly transferred to the D module. In the pull mode, this is a must-have. The D module requires a certain parameter Pm. This parameter is obtained through the A module: that is, the parameter is transformed, and is transmitted to the D module when the C module is called.
A模块进行参数转换, 主要是对输入参数 In, 结合其他变量 1, 进行参数格 式转换、 匹配等工作, 得到 C模块所必须的参数 Pm、 以及 F模块所必须的参数 Pc。  The A module performs parameter conversion, mainly for the input parameter In, combined with other variables 1, to perform parameter format conversion and matching, and obtain the parameter Pm necessary for the C module and the parameter Pc necessary for the F module.
在某些情况下, 为了得到参数 Pm与 Pc, A模块中参数转换必须要得到另外 一部分信息 Pb。 这部分信息 Pb, 必须在先完成一部分模块功能 (B前置功能) 的同时得到。 因此, B模块的前置功能是一个可能不存在的非必然模块。 但如果 存在, 则从 A模块获得参数 Pf, 完成部分预定的模块功能, 然后回馈信息 Pb给 A模块, 同时, 在 F核心模块需要的情况下, 把可能的参数 P提供给 F模块。  In some cases, in order to obtain the parameters Pm and Pc, the parameter conversion in the A module must obtain another part of the information Pb. This part of the information Pb must be obtained while completing some of the module functions (B pre-function). Therefore, the pre-function of the B module is a non-essential module that may not exist. However, if it exists, the parameter Pf is obtained from the A module, part of the predetermined module function is completed, and then the information Pb is fed back to the A module, and at the same time, the possible parameter P is provided to the F module if the F core module requires it.
从 D模块的被调用函数返回的信息 0d, 联合有关变量 2, 被 E模块信息整理 后, 变换成 F模块能直接利用的参数 Pr, 传递给 F核心功能模块。  The information 0d returned from the called function of the D module, combined with the variable 2, is sorted by the E module information, and then converted into a parameter Pr that can be directly utilized by the F module, and transmitted to the F core function module.
F模块在得到参数 Pc、 Pr、 P之后, 完成核心功能, 获得输出信息 0ut。 参数 Pc、 Pm有可能与参数 In完全相同, 这样 A模块可能就不需要存在。 D 模块进行被调用函数后返回的信息 0d, 有可能与参数 Pr完全相同, 这样 E模块 可能就不需要存在。 C模块的函数调用是在拉模式中必须存在的环节。  After obtaining the parameters Pc, Pr, and P, the F module completes the core function and obtains the output information 0ut. The parameters Pc and Pm may be exactly the same as the parameter In, so that the A module may not need to exist. The information returned by the D module after the called function is 0d, which may be identical to the parameter Pr, so that the E module may not need to exist. The function call of the C module is a link that must exist in the pull mode.
如前所述, 对于调用模块来说, 图中 A模块中的参数变换、 C模块中的函数 调用与模块本身的功能毫无关系。 纯粹是因为工作在拉模式下, 为了获得信息 Pr, 而不得不放置其中的代码。 从模块内聚度角度观察, 它们的存在, 降低了调 用模块的内聚度。 B模块的前置功能, 从纯粹代码复用与模块内聚的角度看, 最 好也能剥离出调用模块。 E模块进行信息整理,某些情况下, 为了满足接口需求, 也可以保留, 但最好也能剥离。 从设计角度看, 一般也应该存在另外某种解决方 案, 将 B模块、 E模块均剥离出去。 这样, 在不采用拉模式工作时, 仅只剩下有 F核心功能模块, 作为调用模块的唯一代码。 这样, 就可达到模块的最高复用性 与移植性。 As mentioned before, for the calling module, the parameter transformation in the A module in the figure and the function call in the C module have nothing to do with the function of the module itself. Purely because the work is in pull mode, in order to obtain the information Pr, the code has to be placed. From the perspective of module cohesion, their presence reduces the cohesion of the calling module. The pre-function of the B module, from the perspective of pure code reuse and module cohesion, it is also preferable to strip out the calling module. The E module performs information sorting. In some cases, it can be retained to meet the interface requirements, but it is best to strip it. From a design point of view, there should generally be another solution to strip out the B and E modules. Thus, when working in no pull mode, only the F core function module remains, as the only code to call the module. In this way, the highest reusability of the module can be achieved. And portability.
如图 2所示, 在拉模式中, 最为致命的缺点是: 不可分割、 必须存在的 C模 块的函数调用 (否则就不是拉模式了)。 由于 C模块必须明确列出函数名 (或地 址) 与参数 Pm, 这部分代码必须嵌入在调用模块中。 因此, 在调用模块被移植、 复用时, 不得不考虑 D模块对于调用模块的影响。 为了解决这个影响, 典型的存 在 3种方法:  As shown in Figure 2, the most fatal disadvantages in pull mode are: Incomparable, C-block function calls that must exist (otherwise it is not pull mode). Since the C module must explicitly list the function name (or address) and the parameter Pm, this part of the code must be embedded in the calling module. Therefore, when the calling module is ported and reused, the influence of the D module on the calling module has to be considered. To solve this effect, there are three typical methods:
( 1 ) 不分析、 不修改调用模块及 D模块代表的被调用模块, 二者同时整体 复  (1) Do not analyze or modify the called module and the called module represented by the D module.
用。  use.
这是最好的解决方案, 移植复用代价最小, 效率、 可靠性最高。 问题是, 调 用模块及 D模块代表的被调用模块, 一般存在有其它下级模块, 除非把这所有的 下级模块 (也就是从调用模块开始的一棵子树), 全部整体移植复用, 否则还是 要面临下级模块的改编与适应问题。 同时, 新项目的业务逻辑能否恰好完整地需 要这一整棵子树, 仍是一个大问题。 这样, 子树移植复用方案, 适用范围就大大 变窄, 仅在非常类似的项目中才合适, 不具普适性。  This is the best solution, with minimal migration, efficiency and reliability. The problem is that the calling module and the called module represented by the D module generally have other subordinate modules. Unless all the subordinate modules (that is, a subtree starting from the calling module) are all transplanted and reused, otherwise Facing the adaptation and adaptation of the subordinate modules. At the same time, whether the business logic of the new project can exactly and completely need this whole subtree is still a big problem. In this way, the application scope of the subtree transplant reuse scheme is greatly narrowed, and it is suitable only in very similar projects, and is not universal.
( 2 ) 不分析、 不修改调用模块, 仅模拟 D模块的输入、 输出、 以及相应功 能。  (2) The module is not analyzed or modified, and only the input, output, and corresponding functions of the D module are simulated.
这种方式实现相对比较简单,但也要熟悉 D模块所涉及到的专业业务知识与 模型。 如果这个专业知识比较跨越的话, 这本身就是一个不小的负担。  This method is relatively simple to implement, but you should also be familiar with the professional business knowledge and models involved in the D module. If this expertise is crossed, this is a big burden in itself.
同时, 这个方案还有一个大麻烦是, 留下一堆无用的废代码。 浪费空间与时 间, 降低了代码的时空效率。 在系统比较复杂、 且对时空效率要求较高时, 这个 问题更显突出。 极端情况下, 往往会促使设计人员干脆另起炉灶、 重新开发, 不 能利用现有的模块与代码。  At the same time, there is a big problem with this solution, leaving a bunch of useless waste code. Wasting space and time reduces the space-time efficiency of the code. This problem is more prominent when the system is more complex and requires greater time and space efficiency. In extreme cases, designers are often forced to start a new stove, redevelop, and not be able to take advantage of existing modules and code.
( 3 ) 分析、 修改调用模块, 改变 D模块的输入、 输出、 以及功能, 或者干 脆取消。  (3) Analyze, modify the calling module, change the input, output, and function of the D module, or simply cancel.
这种实现比较复杂, 需要详细了解并读懂 A模块、 B模块、 C模块、 E模块 及整个调用模块的代码逻辑, 必须透彻了解调用模块的专业业务知识与模型, 以 及, 熟悉 D模块所涉及到的专业业务知识与模型。如果这 2个专业知识比较跨越 的话, 它就是一个不小的负担。 同时, 分析修改代码, 还与原来的可复用性设计 密切相关。 以往设计不良的代码、 或是经过多次勉强维护后的代码, 会很混乱, 复用性很差。往往会促使设计人员干脆另起炉灶、 重新开发, 不能利用现有的模 块与代码。 发明内容 This kind of implementation is more complicated. You need to understand and understand the code logic of A module, B module, C module, E module and the whole calling module. You must have a thorough understanding of the professional business knowledge and model of the calling module, and familiar with the D module. Professional business knowledge and models. If these two professional knowledge spans, it is a big burden. At the same time, the analysis of the modified code is also closely related to the original reusability design. Badly designed code, or code that has been repeatedly maintained, can be confusing. Reusability is very poor. It often prompts designers to start a new stove, redevelop, and not use existing modules and code. Summary of the invention
针对现有技术存在的缺陷, 本发明提供一种协同并发式消息总线、主动构件 组装模型及构件拆分方法, 能够有效克服现有 "并发"实现技术的弱点, 高效可 靠地实现 "并发"技术、 并行编程, 具有普适、廉价、 高效、可靠、节能、 复用、 透明分布、 微内核、 内在支持对象技术等一系列优点。  In view of the defects existing in the prior art, the present invention provides a cooperative concurrent message bus, an active component assembly model, and a component splitting method, which can effectively overcome the weakness of the existing "concurrent" implementation technology, and implement the "concurrent" technology efficiently and reliably. Parallel programming, with a series of advantages such as universality, low cost, high efficiency, reliability, energy saving, multiplexing, transparent distribution, microkernel, and intrinsic support object technology.
本发明采用的技术方案如下- 本发明提供一种协同并发式消息总线, 包括: 信息获取模块、 并行环形分配 器、 线性内存块、 消息填充模块、 并行入队器、 消息队列池、 排队顺序管理器、 入口映射表和系统堆桟;  The technical solution adopted by the present invention is as follows - The present invention provides a cooperative concurrent message bus, comprising: an information acquisition module, a parallel ring distributor, a linear memory block, a message filling module, a parallel enqueue, a message queue pool, and a queue order management. , entry maps, and system stacks;
其中,所述信息获取模块用于从接收到的待处理的外部并行的消息中获取目 标算子 ID以及消息长度值;其中,所述目标算子 ID为处理所述消息的算子标识; 同时用于获取附加管理消息的附加管理消息长度值,然后计算所述附加管理消息 长度值与获取到的所述消息长度值的和, 得到消息占用空间值; 其中, 所述附加 管理消息长度值  The information obtaining module is configured to obtain a target operator ID and a message length value from the received external parallel message to be processed; wherein the target operator ID is an operator identifier for processing the message; An additional management message length value for obtaining an additional management message, and then calculating a sum of the additional management message length value and the obtained message length value to obtain a message occupied space value; wherein the additional management message length value
所述并行环形分配器为非阻塞式并行的空间环形分配器,用于根据所述信息 获取模块获取到的所述消息占用空间值,按环形划分原则连续动态的划割所述线 性内存块, 非阻塞式并行地得到与消息占用空间值相同的空白消息槽;  The parallel ring distributor is a non-blocking parallel space ring allocator for continuously and dynamically cutting the linear memory block according to the ring division principle according to the message occupation space value acquired by the information acquisition module. Non-blocking in parallel to get a blank message slot with the same message footprint value;
所述消息填充模块用于将所述消息及所述附加管理消息填充到所述并行环 形分配器分配的所述空白消息槽, 得到非空白消息槽;  The message filling module is configured to fill the blank message slot allocated by the parallel ring distributor with the message and the additional management message to obtain a non-blank message slot;
所述并行入队器用于对所述空白消息槽或所述非空白消息槽进行非阻塞式 并行入队操作;  The parallel enroller is configured to perform a non-blocking parallel enqueue operation on the blank message slot or the non-blank message slot;
所述消息队列池用于缓存尚未处理的已入队消息;  The message queue pool is used to cache an queried message that has not been processed;
所述排队顺序管理器用于根据预设调度策略从所述消息队列池中选择需处 理的指定消息, 对所述指定消息进行协同的出队操作;  The queuing sequence manager is configured to select a specified message to be processed from the message queue pool according to a preset scheduling policy, and perform a coordinated dequeuing operation on the specified message;
所述入口映射表, 根据所述目标算子 ID查找所述入口映射表, 获得与所述 目标算子 ID对应的函数入口地址; 根据所述函数入口地址以及所述指定消息的 指定消息槽地址, 调用对应的算子执行函数, 从而处理出队的所述指定消息; 所述系统堆桟为所述消息总线中所有算子共享的堆桟空间;各个算子所共享 的系统堆桟空间相互覆盖, 为重叠式, 即非层叠式; The entry mapping table searches the entry mapping table according to the target operator ID to obtain a function entry address corresponding to the target operator ID; and according to the function entry address and the specified message slot address of the specified message Calling the corresponding operator execution function to process the specified message of the team; The system stacking is a stacking space shared by all the operators in the message bus; the system stacking space shared by each operator overlaps each other, and is overlapped, that is, non-cascading;
并且, 所述消息总线内的算子仅具有就绪状态, 即使当所述消息总线内不存 在任何消息时, 所述消息总线内的算子仍处于就绪状态; 一旦当所述消息总线内 到达消息时, 且当该消息所对应的算子被调度时, 被调度到的算子立即获得处理 器。  And, the operator in the message bus only has a ready state, even if there is no message in the message bus, the operator in the message bus is still in the ready state; once the message arrives in the message bus When, and when the operator corresponding to the message is scheduled, the operator to be dispatched immediately obtains the processor.
优选的, 所述消息为定长消息或变长消息。  Preferably, the message is a fixed length message or a variable length message.
优选的,当所述并行环形分配器在所述线性内存块的最末端划割空白消息槽 时, 如果所述线性内存块最未端剩余的空闲空间小于所述消息占用空间值, 则直 接舍弃所述最未端剩余的空闲空间, 所述最未端剩余的空闲空间形成废弃槽。  Preferably, when the parallel ring distributor scribes a blank message slot at the end of the linear memory block, if the remaining free space of the least end of the linear memory block is smaller than the message space value, directly discarding The remaining free space in the most end, the remaining free space in the last end forms a discarding slot.
优选的,所述消息填充模块首先将所述消息及所述附加管理消息填充到所述 并行环形分配器分配的所述空白消息槽, 得到非空白消息槽; 然后所述并行入队 器对所述非空白消息槽进行非阻塞式并行入队操作具体为:  Preferably, the message filling module first fills the message and the additional management message to the blank message slot allocated by the parallel ring distributor to obtain a non-blank message slot; then the parallel enqueue pair The non-blocking parallel enqueue operation of the non-blank message slot is specifically as follows:
所述并行环形分配器配置有第一头指针和第一尾指针,当需要分配新的空白 消息槽时,直接在当前位置的第一尾指针后面划出与所述消息占用空间值相同的 空间, 得到所述新的空白消息槽, 然后再将所述第一尾指针非阻塞式并行移动到 所述新的空白消息槽的尾部;  The parallel ring distributor is configured with a first head pointer and a first tail pointer. When a new blank message slot needs to be allocated, the same space as the message occupied space value is directly drawn after the first tail pointer of the current position. Obtaining the new blank message slot, and then moving the first tail pointer non-blocking parallel to the tail of the new blank message slot;
所述并行入队器配置有第二头指针和第二尾指针;通过非阻塞式并行移动所 述第二尾指针实现对所述非空白消息槽进行非阻塞式并行入队操作;  The parallel enqueue is configured with a second head pointer and a second tail pointer; performing non-blocking parallel enqueue operation on the non-blank message slot by non-blocking parallel movement of the second tail pointer;
其中,所述并行环形分配器配置的第一头指针和第一尾指针不同于所述并行 入队器配置的第二头指针和第二尾指针。  Wherein the first head pointer and the first tail pointer of the parallel ring distributor configuration are different from the second head pointer and the second tail pointer of the parallel enqueue configuration.
优选的, 所述并行入队器首先对所述空白消息槽进行非阻塞式并行入队操 作,然后所述消息填充模块再向入队的所述空白消息槽填充所述消息及所述附加 管理消息具体为- 所述并行环形分配器与所述并行入队器共用相同的头指针和尾指针,当所述 并行环形分配器从所述线性内存块中分配出空白消息槽的同时,该空白消息槽也 被所述并行入队器执行了入队操作;然后所述消息填充模块再向入队的所述空白 消息槽填充所述消息及所述附加管理消息。  Preferably, the parallel enroller first performs a non-blocking parallel enqueue operation on the blank message slot, and then the message filling module fills the blank message slot of the enqueue with the message and the additional management. The message is specifically - the parallel ring distributor shares the same head pointer and tail pointer with the parallel enqueue, and when the parallel ring distributor allocates a blank message slot from the linear memory block, the blank The message slot is also enqueued by the parallel enqueue; the message padding module then populates the message and the additional management message with the blank message slot enqueued.
优选的, 在抢先环境下, 在所述并行环形分配器从所述线性内存块中分配出 空白消息槽之前, 预先使所述空白消息槽处于休眠状态, 其中, 处于休眠状态的 空白消息槽称为休眠消息槽;然后所述消息填充模块向所述休眠消息槽中填充所 述消息及所述附加管理消息, 当填充完成之后, 所述休眠消息槽被激活时, 即转 变为活跃状态, 其中, 处于活跃状态的消息槽称为活跃消息槽; 其中, 休眠消息 槽为不会被所述消息总线调度给算子执行的消息槽;活跃消息槽为属于所述消息 总线正常调度范围的消息槽。 Preferably, in a preemptive environment, before the parallel ring distributor allocates a blank message slot from the linear memory block, the blank message slot is pre-sleeped, wherein the sleep state is in a sleep state. The blank message slot is called a dormant message slot; then the message padding module fills the dormant message slot with the message and the additional management message, and when the padding message slot is activated, the padding message is changed to An active state, wherein the active message slot is called an active message slot; wherein, the dormant message slot is a message slot that is not scheduled to be executed by the message bus to the operator; the active message slot is scheduled to belong to the message bus. The range of message slots.
优选的, 采用变长消息时, 通过消息槽中写入的消息长度参数是否为 0区分 所述休眠消息槽和活跃消息槽; 当所述消息槽中写入的消息长度参数为 0时, 该 消息槽为所述休眠消息槽; 当所述消息槽中写入的消息长度参数不为 0时, 该消 息槽为所述活跃消息槽。  Preferably, when the variable length message is used, the dormant message slot and the active message slot are distinguished by whether the message length parameter written in the message slot is 0; when the message length parameter written in the message slot is 0, The message slot is the dormant message slot; when the message length parameter written in the message slot is not 0, the message slot is the active message slot.
优选的, 还包括: 监控管理中心; 所述监控管理中心用于对所述消息总线内 部的消息, 进行集中监视、 分析、 控制、 过滤和管理。  Preferably, the method further includes: a monitoring management center; the monitoring management center is configured to perform centralized monitoring, analysis, control, filtering, and management on messages within the message bus.
优选的, 还包括: 空间回收模块; 所述空间回收模块用于回收所述消息总线 内的出队后的消息本身以及所述消息槽。  Preferably, the method further includes: a space reclamation module; the space reclamation module is configured to recover the dequeued message itself and the message slot in the message bus.
优选的, 还包括: 节电装置; 所述节电装置用于: 当所述消息总线内不存在 消息时, 立即通知使用本消息总线的应用系统进行节能调度。  Preferably, the method further includes: a power saving device; the power saving device is configured to: immediately notify an application system using the message bus to perform energy saving scheduling when there is no message in the message bus.
本发明还提供一种应用上述的协同并发式消息总线的主动构件组装模型,所 述主动构件组装模型为集合 P= {第 1层主动构件、第 2层主动构件子集合…第 n 层主动构件子集合 }, 其中, n 2; 所述第 n层主动构件子集合中的各主动构件 基于第 n层虚拟消息总线进行构件组装,得到第 n-1层主动构件子集合中的单个 主动构件;所述第 n-1层主动构件子集合中的各主动构件基于第 n-1层虚拟消息 总线进行构件组装,得到第 n-2层主动构件子集合中的单个主动构件;以此类推, 直到所述第 3层主动构件子集合中的各主动构件基于第 3层虚拟消息总线进行构 件组装, 得到第 2层主动构件子集合中的单个主动构件; 所述第 2层主动构件子 集合中的各主动构件基于权利要求 1-10任一项所述的消息总线进行构件组装, 得到所述第 1层主动构件; The present invention also provides an active component assembly model applying the above-described collaborative concurrent message bus, the active component assembly model being a set P = {1st layer active component, 2nd layer active component subset... nth layer active component Sub-sets, where n 2 ; each active component in the n-th active component subset is assembled according to the n-th virtual message bus, and a single active component in the n-1th active component subset is obtained; Each active component in the n-1th active component subset is assembled based on the n-1th virtual message bus to obtain a single active component in the n-2 active component subset; and so on, until Each active component in the third layer active component subset is assembled based on a layer 3 virtual message bus to obtain a single active component in the second layer active component subset; the second layer active component subset Each active component is assembled according to the message bus according to any one of claims 1 to 10 to obtain the first layer active component;
其中, 所述集合 P中的各层各个所述主动构件符合相同的协议。  Each of the active components of each layer in the set P conforms to the same protocol.
优选的, 所述集合 P中第 1层主动构件包括: 所述消息总线、 接口算子 ID 映射表、 别名链接表以及一个以上的算子; 其中, 所述接口算子 ID映射表用于 存储接口算子 ID与入口函数的对应关系; 所述别名链接表用于存储引用算子 ID 与所述接口算子 ID的对应关系; 其中, 所述接口算子 ID为所述主动构件自身的 算子标识; 所述引用算子 ID为挂接在所述消息总线上的主动构件内部的算子标 识; Preferably, the layer 1 active component in the set P includes: the message bus, an interface operator ID mapping table, an alias link table, and one or more operators; wherein the interface operator ID mapping table is used for storing Corresponding relationship between the interface operator ID and the entry function; the alias link table is configured to store a correspondence between the reference operator ID and the interface operator ID; wherein the interface operator ID is the active component itself An operator identifier; the reference operator ID is an operator identifier that is attached to an active component on the message bus;
所述集合 P中第 2层主动构件子集合到第 n层主动构件子集合中的各个主动 构件分别包括: 所述虚拟消息总线、 所述接口算子 ID映射表、 所述别名链接表 以及一个以上的算子。  Each of the active components of the second-layer active component subset to the n-th active component subset of the set P includes: the virtual message bus, the interface operator ID mapping table, the alias link table, and a The above operator.
优选的,所述第 n层主动构件子集合中的各主动构件基于第 n层虚拟消息总 线进行构件组装, 得到第 n-1层主动构件子集合中的单个主动构件, 其中, n 3 具体为- 所述第 n层主动构件子集合中的各主动构件分别包括第 n层虚拟消息总线、 第 n层接口算子 ID映射表、 第 n层别名链接表以及一个以上的第 n层算子; 进 行构件组装后得到的第 n-1层主动构件子集合中的单个主动构件包括第 n-1层虚 拟消息总线、 第 n-1层接口算子 ID映射表、 第 n-1层别名链接表以及一个以上 的第 n-1层算子;  Preferably, each active component in the n-th active component subset is assembled according to the n-th virtual message bus, and a single active component in the n-1th active component subset is obtained, where n 3 is specifically - each active component in the nth active component subset includes an nth layer virtual message bus, an nth layer interface operator ID mapping table, an nth layer alias link table, and one or more nth layer operators; The single active component in the n-1th active component subset obtained after component assembly includes the n-1th layer virtual message bus, the n-1th interface operator ID mapping table, and the n-1th layer alias link table. And more than one n-1th layer operator;
在进行构件组装时, 将各个所述第 n层虚拟消息总线进行总线融合, 得到第 n-1层虚拟消息总线; 将各个所述第 n层接口算子 ID映射表进行表格融合, 得 到第 n-1层接口算子 ID映射表; 将各个所述第 n层别名链接表进行表格融合, 得到第 n-1层别名链接表;将各个所述第 n层算子进行融合,得到第 n-1层算子。  When component assembly is performed, each of the nth layer virtual message bus is bus-fused to obtain an n-1th layer virtual message bus; and each of the nth layer interface operator ID mapping tables is table-fused to obtain a nth a layer 1 interface operator ID mapping table; table fusion of each of the nth layer alias link tables to obtain an n-1th layer alias link table; and fusing each of the nth layer operators to obtain an nth- 1 layer operator.
优选的,所述第 2层主动构件子集合中的各主动构件基于所述的消息总线进 行构件组装, 得到所述第 1层主动构件具体为- 所述第 2层主动构件子集合中的各主动构件分别包括所述第 2层虚拟消息总 线、第 2层接口算子 ID映射表、第 2层别名链接表以及一个以上的第 2层算子; 进行构件组装后得到的第 1层主动构件包括所述消息总线、 第 1层接口算子 ID 映射表、 第 1层别名链接表以及一个以上的第 1层算子;  Preferably, each active component in the second layer active component subset is assembled according to the message bus, and the first layer active component is specifically - each of the second layer active component subsets The active component includes the layer 2 virtual message bus, the layer 2 interface operator ID mapping table, the layer 2 alias link table, and one or more layer 2 operators, respectively; and the first layer active component obtained after component assembly The message bus, a layer 1 interface operator ID mapping table, a layer 1 alias link table, and one or more layer 1 operators are included;
在进行构件组装时, 将各个所述第 2层虚拟消息总线进行总线融合, 得到所 述消息总线; 将各个所述第 2层接口算子 ID映射表进行表格融合, 得到第 1层 接口算子 ID映射表; 将各个所述第 2层别名链接表进行表格融合, 得到第 1层 别名链接表; 将各个所述第 2层算子进行融合, 得到第 1层算子。  When component assembly is performed, each of the second layer virtual message buses is bus-fused to obtain the message bus; each of the layer 2 interface operator ID mapping tables is table-fused to obtain a layer 1 interface operator. ID mapping table; table fusion of each of the second layer alias link tables to obtain a first layer alias link table; and fusing each of the second layer operators to obtain a first layer operator.
优选的,所述别名链接表存储的所述引用算子 ID与所述接口算子 ID的对应 关系为等值映射关系。  Preferably, the correspondence between the reference operator ID and the interface operator ID stored in the alias link table is an equivalence mapping relationship.
本发明还提供一种对上述得到的所述的主动构件组装模型进行构件拆分方 法, 包括以下步骤: The present invention also provides a component splitting method for the active component assembly model obtained as described above. The method includes the following steps:
预先设定构件拆分规则, 当所述主动构件组装模型满足所述构件拆分规则 时, 按所述构件拆分规则拆分所述主动构件组装模型。  The component splitting rule is preset, and when the active component assembly model satisfies the component splitting rule, the active component assembly model is split according to the component splitting rule.
优选的, 所述构件拆分规则为: 当所述消息总线的调度程序由两个以上内核 或处理器执行时,将所述消息总线分裂为与所述内核数量或所述处理器数量相同 的分布式的对等的子总线;所述主动构件组装模型中各层各个所述主动构件分别 挂接到对应的所述子总线上; 或者  Preferably, the component splitting rule is: when the scheduler of the message bus is executed by two or more cores or processors, splitting the message bus into the same number of the cores or the number of processors a distributed peer-to-peer sub-bus; each of the active components of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus; or
所述构件拆分规则为:动态统计所述主动构件组装模型中各个主动构件的负 荷, 根据预设的负载均衡原理, 动态地将所述消息总线分裂为分布式的对等的多 个子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对 应的所述子总线上; 或者  The component splitting rule is: dynamically counting the load of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset load balancing principle; Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus; or
所述构件拆分规则为:动态统计所述主动构件组装模型中各个主动构件的能 效比, 根据预设的节能原理, 动态地将所述消息总线分裂为分布式的对等的多个 子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对应 的所述子总线上; 或者  The component splitting rule is: dynamically counting energy efficiency ratios of the active components in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset energy-saving principle; Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus; or
所述构件拆分规则为:动态统计所述主动构件组装模型中各个主动构件的失 效率, 根据预设的可靠性原理, 动态地将所述消息总线分裂为分布式的对等的多 个子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对 应的所述子总线上。  The component splitting rule is: dynamically counting the failure rate of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset reliability principle Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
本发明的有益效果如下:  The beneficial effects of the present invention are as follows:
本发明提供的协同并发式消息总线、主动构件组装模型及构件拆分方法, 能 够有效克服现有 "并发"实现技术的弱点, 高效可靠地实现 "并发"技术、并行 编程, 具有普适、 廉价、 高效、 可靠、 节能、 复用、 透明分布、 微内核、 内在支 持对象技术等一系列优点。 附图说明  The collaborative concurrent message bus, the active component assembly model and the component splitting method provided by the invention can effectively overcome the weakness of the existing "concurrent" implementation technology, and realize the "concurrency" technology and parallel programming efficiently and reliably, and have universality and low cost. A series of advantages such as high efficiency, reliability, energy saving, reuse, transparent distribution, microkernel, and intrinsic support object technology. DRAWINGS
图 1为现有技术提供的 TinyOS 2. x基本任务调度器的结构示意图; 图 2为现有技术提供的拉模式下函数调用等效模型示意图;  1 is a schematic structural diagram of a TinyOS 2.x basic task scheduler provided by the prior art; FIG. 2 is a schematic diagram of an equivalent model of a function call in a pull mode provided by the prior art;
图 3为本发明提供的协同并发式消息总线的通用模型示意图;  3 is a schematic diagram of a general model of a collaborative concurrent message bus provided by the present invention;
图 4为本发明提供的协同并发式消息总线的一种具体应用模型示意图; 图 5为本发明提供的一种构件组装实例示意图。 具体实施方式 4 is a schematic diagram of a specific application model of a collaborative concurrent message bus provided by the present invention; FIG. 5 is a schematic diagram of an assembly example of a component provided by the present invention. detailed description
以下结合附图对本发明进行详细说明:  The present invention will be described in detail below with reference to the accompanying drawings:
如图 3所示, 本发明提供一种协同并发式消息总线, 本消息总线的并发通用 模型是: 并行入队、 协同出队, 即多入单出模型。 消息在进入消息队列池之前, 都属于非阻塞式并行操作; 进入消息队列池之后, 属于协同式串行操作。 具体包 括: 信息提取模块、并行环形分配器、线性内存块、消息填充模块、并行入队器、 消息队列池、排队顺序管理器、 入口映射表和系统堆桟。 以下对上述各部件详细 说明:  As shown in FIG. 3, the present invention provides a cooperative concurrent message bus. The concurrent common model of the message bus is: parallel enqueue, coordinated dequeue, that is, a multi-entry and single-out model. Messages are non-blocking parallel operations before entering the message queue pool; after entering the message queue pool, they are cooperative serial operations. These include: information extraction module, parallel ring distributor, linear memory block, message filling module, parallel enqueue, message queue pool, queue order manager, entry map, and system stack. The following detailed description of each of the above components:
(一) 信息获取模块  (1) Information acquisition module
信息获取模块用于从接收到的待处理的外部并行的消息中获取目标算子 ID 以及消息长度值; 其中, 所述目标算子 ID为处理所述消息的算子标识。 同时用 于获取附加管理消息的附加管理消息长度值,然后计算所述附加管理消息长度值 与获取到的所述消息长度值的和, 得到消息占用空间值; 其中, 所述附加管理消 息长度值 0。  The information obtaining module is configured to obtain the target operator ID and the message length value from the received external parallel message to be processed; wherein the target operator ID is an operator identifier for processing the message. And obtaining an additional management message length value of the additional management message, and then calculating a sum of the additional management message length value and the obtained message length value to obtain a message occupied space value; wherein the additional management message length value 0.
需要说明的是, 本发明中采用的算子一词为英文计算机术语 Actor的意译, 一般翻译为 "角色" 。个人觉得借用数学里的 "算子"这一概念, 能更精确地表 征 Actor的含义。 因此在本文中, 均采用 "算子"这一术语作为英文 Actor的中 文译词。  It should be noted that the term operator used in the present invention is a free translation of an English computer term Actor, which is generally translated as a "role". Personally, I feel that borrowing the concept of "operator" in mathematics can more accurately express the meaning of Actor. Therefore, in this paper, the term "operator" is used as the Chinese translation of English Actor.
从调度效率看, 算子是一个比任务、 进程、 线程更为轻量级的并发实体, 比 回调函数更重量级一些。 相当于纤程、 协程, 比纤程、 协程略微轻量级一点。 本 发明中, 消息总线内的算子仅具有就绪状态, 即使当所述消息总线内不存在任何 消息时, 所述消息总线内的算子仍处于就绪状态; 一旦当所述消息总线内到达消 息时, 且当该消息所对应的算子被调度时, 被调度到的算子立即获得处理器。  From the perspective of scheduling efficiency, an operator is a more lightweight concurrent entity than a task, process, or thread, and is more heavyweight than a callback function. Equivalent to fiber, coroutine, slightly lighter than fiber and coroutine. In the present invention, the operator in the message bus has only the ready state, even when there is no message in the message bus, the operator in the message bus is still in the ready state; once the message arrives in the message bus When, and when the operator corresponding to the message is scheduled, the operator to be dispatched immediately obtains the processor.
其中, 目标算子 ID可以简单地按顺序分发排列, 也可以隐含一些其它意义, 如: 优先级、 固定服务号、 分布式 ID号 等。 例如: 可以简单地将目标算 子 ID分为两部分: 外部总线节点号和消息总线内的算子号。 通过该种结构, 只 需简单替换掉引用的某目标算子 ID, 就能轻松放弃引用本地算子、 转而引用存 在于另外一个外部节点上的算子, 实现透明的分布式计算与转移。更复杂的划分 方法, 甚至可以借用类似于 Internet网的 IP地址划分概念, 实现更复杂的分布 式应用逻辑。 The target operator IDs may be simply arranged in order, or may imply some other meaning, such as: priority, fixed service number, distributed ID number, and the like. For example: You can simply split the target operator ID into two parts: the external bus node number and the operator number in the message bus. With this structure, simply replacing the referenced target operator ID, it is easy to abandon the reference to the local operator, and instead refer to the operator existing on another external node, to achieve transparent distributed computing and transfer. More complicated division In this way, even more complex distributed application logic can be realized by borrowing the concept of IP address division similar to the Internet.
在实用的消息总线中, 消息中的目标算子 ID, 一般会隐藏有其它有用的信 息(如外部节点号)。因此,需要把正确的本地目标算子 ID明确地转换提取出来。 消息内部包含的其它若干参数,也有可能需要进行统一的格式匹配与转换。因此, 需要进行参数提取与格式转换。 正常结果是, 得到一个正确的目标算子 ID, 以 及消息 (槽) 的首地址。  In the practical message bus, the target operator ID in the message is usually hidden with other useful information (such as the external node number). Therefore, it is necessary to explicitly convert the correct local target operator ID. Several other parameters contained within the message may also require uniform format matching and conversion. Therefore, parameter extraction and format conversion are required. The normal result is that you get a correct target operator ID and the first address of the message (slot).
(二) 并行环形分配器  (two) parallel ring distributor
并行环形分配器为非阻塞式并行的空间环形分配器,用于根据所述信息获取 模块获取到的所述消息占用空间值,按环形划分原则连续动态的划割所述线性内 存块, 非阻塞式并行地得到与消息占用空间值相同的空白消息槽。  The parallel ring distributor is a non-blocking parallel space ring allocator for continuously and dynamically scribing the linear memory block according to the ring division principle according to the message occupation space value acquired by the information acquisition module, and is non-blocking In parallel, a blank message slot with the same message footprint value is obtained.
当存在多个待入队消息时,则并行环形分配器动态的将线性内存块划分成多 个消息槽(Slot ), 每个消息槽正好容纳一条完整的消息, 当然, 根据实际需求, 消息槽中也可以容纳系统管理用的其它附加信息。这些消息槽被相邻连续地分配 与回收。 因此, 从逻辑上看, 线性内存块变成了环形的槽空间。 当所述并行环形 分配器在所述线性内存块的最末端划割空白消息槽时,如果所述线性内存块最未 端剩余的空闲空间小于所述消息占用空间值,则直接舍弃所述最未端剩余的空闲 空间, 所述最未端剩余的空闲空间形成废弃槽, 从而保证每个消息槽所使用的空 间是平面、 线性、 不绕回的, 使得算子与应用程序对槽空间的逻辑视图简洁、 干 净、 自然。  When there are multiple messages to be queued, the parallel ring distributor dynamically divides the linear memory block into multiple message slots (Slots), each message slot accommodating a complete message. Of course, according to actual needs, the message slot It can also accommodate other additional information for system management. These message slots are continuously allocated and reclaimed adjacent to each other. Therefore, logically, the linear memory block becomes a circular slot space. When the parallel ring distributor scribes a blank message slot at the end of the linear memory block, if the remaining free space of the least end of the linear memory block is smaller than the message occupied space value, directly discarding the most The remaining free space at the end, the remaining free space at the end of the end forms a discarding slot, thereby ensuring that the space used by each message slot is plane, linear, and not wrap-around, so that the operator and the application to the slot space The logical view is simple, clean, and natural.
该并行环形分配器是一个高效、简洁的非阻塞式并行的空间环形分配器, 相 对于阻塞式分配器, 消除了死锁、 优先级倒置、 中断不能加锁、 临界区不能并发 等问题; 用免费的纯软件方法, 实现无锁分配; 用廉价的硬件方法, 实现高效率 的单条汇编指令的无等待分配。 具体的, 可以利用中断屏蔽、 CAS/CAS2、 LL/SC 处理器原语 等, 用纯软件方法, 通过无锁(Lock-Free)算法进行分配; 也 可以利用硬件, 直接实现同样的功能, 得到无等待 (Wait-Free)算法的效果, 同 时获得高效率分配的效果: 一条汇编指令即可完成空间分配。用纯软件实现的无 锁算法留待后述。  The parallel ring distributor is an efficient and compact non-blocking parallel space ring distributor, which eliminates deadlock, priority inversion, interruption cannot be locked, and critical sections cannot be concurrent with respect to the blocking type distributor; Free software-only method for lock-free allocation; low-cost hardware method for efficient allocation of single assembly instructions without waiting. Specifically, the interrupt mask, CAS/CAS2, LL/SC processor primitives, etc. can be used to perform the allocation by a software-only method through a lock-free algorithm; or the hardware can be used to directly implement the same function. The effect of the Wait-Free algorithm, while achieving the effect of high efficiency allocation: a single assembly instruction can complete the space allocation. The lock-free algorithm implemented in pure software is left to be described later.
(三) 线性内存块  (3) Linear memory blocks
该线性内存块作为消息缓存区, 应该足够大。现代的常规应用程序中, 除了 固定长度的内存分配外, 常用的行为逻辑与指导准则为: 将剩余的内存 RAM空间 全部分配作为堆桟空间。与此相对应, 在使用本发明提供的消息总线的应用系统 中, 应该反过来首先固定应用系统的堆桟大小、然后将剩余的内存 RAM空间全部 分配作为消息缓存区。 这是因为, 大量并发的算子 Actor是组成本系统的主体, 因此存在大量不确定的消息, 需要大量不确定的消息缓存。 而与此同时, 在本应 用系统中, 每个算子所调用的函数层次不是特别多, 并且一般都只是很简单的直 接调用, 而所有算子的堆桟空间都是因为协同执行而相互重叠的, 因此能轻松估 计出所需要使用到的最大 RAM堆桟空间,因此可以作为固定长度的 RAM内存进行 分配。 This linear memory block acts as a message buffer and should be large enough. Modern routine application, except In addition to fixed-length memory allocation, common behavioral logic and guidelines are: All the remaining memory RAM space is allocated as heap space. Correspondingly, in an application system using the message bus provided by the present invention, the stack size of the application system should be fixed first, and then the remaining memory RAM space should be all allocated as a message buffer. This is because a large number of concurrent operator Actors are the main components of the system, so there are a large number of uncertain messages, requiring a large number of uncertain message buffers. At the same time, in this application system, the level of functions called by each operator is not particularly large, and generally it is only a very simple direct call, and the stacking space of all operators overlaps each other because of collaborative execution. Therefore, it is easy to estimate the maximum RAM stack space that needs to be used, so it can be allocated as a fixed-length RAM memory.
如果消息缓存区不够大, 导致应用系统在运行期间溢出, 则将无法再接收新 消息入队, 而导致系统故障或者崩溃。 则该错误的处理原则是: 由该应用系统自 行负责处理; 或者重新扩大消息缓存区, 或者修改应用系统的处理逻辑, 或者直 接让应用系统停机 等等。这与现代的常规应用程序对系统堆桟溢出的故障 处理方案完全类似。通过采用这样的逻辑与机制, 使得本消息总线卸下了一个本 来就应该由用户自行担保的责任: 无条件地保证应用系统不被大批量数据冲垮。 从而大大简化了本消息总线的设计逻辑与代码,获得最广泛的软硬件适应性与移 植性。  If the message buffer is not large enough, causing the application to overflow during runtime, it will no longer be able to receive new messages and cause system failure or crash. Then the error is handled by: the application system is responsible for processing; or re-expanding the message buffer, or modifying the processing logic of the application system, or directly stopping the application system, and the like. This is exactly the same as the modern routine application's troubleshooting solution for system heap overflows. By adopting such logic and mechanism, the message bus is unloaded with a responsibility that should be guaranteed by the user: Unconditionally guarantee that the application system is not washed by large amounts of data. This greatly simplifies the design logic and code of the message bus, and obtains the widest range of software and hardware adaptability and portability.
为了增加消息总线的普适性, 对于消息总线上传输的消息的内部结构, 本发 明只做出最少量的规定: 消息分为定长消息和变长消息; 对于定长消息的应用系 统, 一般用于相对特殊的应用环境, 如 ATM交换机等等类似场合。对于变长消息 应用系统, 应用最为广泛, 具有最普遍的使用价值。  In order to increase the universality of the message bus, the invention only makes a minimum specification for the internal structure of the message transmitted on the message bus: the message is divided into a fixed length message and a variable length message; for an application system of fixed length messages, generally Used in relatively specific application environments, such as ATM switches and the like. For variable-length messaging applications, it is the most widely used and has the most common use value.
对于定长消息和变长消息, 均必须包含目标算子 ID; 另外, 对于定长消息, 消息长度值由具体应用系统及其消息总线自行定义,不必明确地出现在消息结构 中; 对于变长消息, 消息长度值则必须明确地出现在消息结构中。 消息长度值与 目标算子 ID本身的长度, 与处理器字长密切相关, 由具体应用系统及其消息总 线自行定义, 一般推荐为 1、 2、 4、 8、 16等字节, 但并不强行规定采用哪种长 度。 单条消息的总长度、 其内部是否包含其它管理信息(如动态优先级) 等等, 也是由具体应用系统及其消息总线自行定义。  For fixed-length messages and variable-length messages, the target operator ID must be included; in addition, for fixed-length messages, the message length value is defined by the specific application system and its message bus, and does not have to explicitly appear in the message structure; Messages, message length values must be explicitly present in the message structure. The message length value and the length of the target operator ID itself are closely related to the processor word length, and are defined by the specific application system and its message bus. Generally, it is recommended to be 1, 2, 4, 8, or 16 bytes, but not It is mandatory to specify which length to use. The total length of a single message, whether it contains other management information (such as dynamic priority), etc., is also defined by the specific application system and its message bus.
(四) 消息填充模块  (4) Message filling module
所述消息填充模块用于将所述消息及所述附加管理消息填充到所述并行环 形分配器分配的所述空白消息槽, 得到非空白消息槽。 The message filling module is configured to fill the message and the additional management message to the parallel ring The blank message slot allocated by the shape allocator obtains a non-blank message slot.
在并行环形分配器为并行的任一消息 i进行空间分发、分配消息槽以后, 该 消息槽空间即被该消息私人占有。 因此, 可以对该消息槽任意处理。 此时, 即可 进行消息填充操作。此阶段即使具有非常长的时间延迟, 对系统其它部分也毫无 影响。  After the parallel ring distributor spatially distributes and allocates a message slot for any message i in parallel, the message slot space is privately occupied by the message. Therefore, the message slot can be arbitrarily processed. At this point, the message filling operation can be performed. Even if this phase has a very long time delay, it has no effect on the rest of the system.
具体的, 消息填充模块可以采用下列两种方案进行消息填充:  Specifically, the message filling module can use the following two schemes for message filling:
(一) 第一种方案: 先填充、 后入队:  (1) The first option: first fill, then enter the team:
具体的,消息填充模块首先将所述消息及所述附加管理消息填充到所述并行 环形分配器分配的所述空白消息槽, 得到非空白消息槽; 然后所述并行入队器对 所述非空白消息槽进行非阻塞式并行入队操作具体为:  Specifically, the message filling module first fills the message and the additional management message to the blank message slot allocated by the parallel ring distributor to obtain a non-blank message slot; then the parallel enroller pairs the non-blank message The non-blocking parallel enqueue operation of the blank message slot is specifically as follows:
所述并行环形分配器配置有第一头指针和第一尾指针,当需要分配新的空白 消息槽时,直接在当前位置的第一尾指针后面划出与所述消息占用空间值相同的 空间, 得到所述新的空白消息槽, 然后再将所述第一尾指针非阻塞式并行移动到 所述新的空白消息槽的尾部;  The parallel ring distributor is configured with a first head pointer and a first tail pointer. When a new blank message slot needs to be allocated, the same space as the message occupied space value is directly drawn after the first tail pointer of the current position. Obtaining the new blank message slot, and then moving the first tail pointer non-blocking parallel to the tail of the new blank message slot;
所述并行入队器配置有第二头指针和第二尾指针;通过非阻塞式并行移动所 述第二尾指针实现对所述非空白消息槽进行非阻塞式并行入队操作;  The parallel enqueue is configured with a second head pointer and a second tail pointer; performing non-blocking parallel enqueue operation on the non-blank message slot by non-blocking parallel movement of the second tail pointer;
其中,所述并行环形分配器配置的第一头指针和第一尾指针不同于所述并行 入队器配置的第二头指针和第二尾指针。  Wherein the first head pointer and the first tail pointer of the parallel ring distributor configuration are different from the second head pointer and the second tail pointer of the parallel enqueue configuration.
(二) 第二种方案: 先入队、 后填充:  (2) The second option: first enter the team, then fill:
并行入队器首先对所述空白消息槽进行非阻塞式并行入队操作,然后所述消 息填充模块再向入队的所述空白消息槽填充所述消息及所述附加管理消息具体 为:  The parallel enroller first performs a non-blocking parallel enqueue operation on the blank message slot, and then the message filling module fills the blank message slot of the enqueue with the message and the additional management message as follows:
所述并行环形分配器与所述并行入队器共用相同的头指针和尾指针,当所述 并行环形分配器从所述线性内存块中分配出空白消息槽的同时,该空白消息槽也 被所述并行入队器执行了入队操作;然后所述消息填充模块再向入队的所述空白 消息槽填充所述消息及所述附加管理消息。  The parallel ring distributor shares the same head pointer and tail pointer with the parallel enqueue, and when the parallel ring distributor allocates a blank message slot from the linear memory block, the blank message slot is also The parallel enroller performs an enqueue operation; then the message filling module populates the blank message slot enqueued with the message and the additional management message.
另外, 在抢先环境下, 在所述并行环形分配器从所述线性内存块中分配出空 白消息槽之前, 预先使所述空白消息槽处于休眠状态, 其中, 处于休眠状态的空 白消息槽称为休眠消息槽;然后所述消息填充模块向所述休眠消息槽中填充所述 消息及所述附加管理消息, 当填充完成之后, 所述休眠消息槽被激活时, 即转变 为活跃状态, 其中, 处于活跃状态的消息槽称为活跃消息槽; 其中, 休眠消息槽 为不会被所述消息总线调度给算子执行的消息槽;活跃消息槽为属于所述消息总 线正常调度范围的消息槽。 In addition, in the preemptive environment, before the parallel ring distributor allocates the blank message slot from the linear memory block, the blank message slot is pre-sleeped, wherein the blank message slot in the sleep state is called Sleeping the message slot; then the message filling module populates the dormant message slot with the message and the additional management message, and when the padding message is activated, the sleep message slot is activated An active state, wherein the active message slot is called an active message slot; wherein, the dormant message slot is a message slot that is not scheduled to be executed by the message bus to the operator; the active message slot is normal to the message bus The message slot of the dispatch scope.
一般采用在消息槽中增加管理标志的办法区分休眠消息槽与活跃消息槽。作 为一种简化方式,可以将管理标志隐藏在其它信息中,从而节省 RAM空间。例如: 采用变长消息时, 有用的消息长度肯定不为零; 因此, 可以约定, 通过消息槽中 写入的消息长度参数是否为 0区分所述休眠消息槽和活跃消息槽;当所述消息槽 中写入的消息长度参数为 0时, 该消息槽为所述休眠消息槽; 当所述消息槽中写 入的消息长度参数不为 0时, 该消息槽为所述活跃消息槽。这样, 只要把消息长 度参数瞬间写入到消息槽中, 即可激活该消息槽。  The dormant message slot and the active message slot are generally distinguished by adding a management flag in the message slot. As a simplification, you can hide the management space by hiding the management flags in other information. For example: When using a variable length message, the useful message length is certainly not zero; therefore, it can be agreed that the dormant message slot and the active message slot are distinguished by whether the message length parameter written in the message slot is 0; when the message When the message length parameter written in the slot is 0, the message slot is the dormant message slot; when the message length parameter written in the message slot is not 0, the message slot is the active message slot. In this way, the message slot can be activated by simply writing the message length parameter into the message slot.
(五) 并行入队器  (5) Parallel enrollment
并行入队器用于对所述空白消息槽或所述非空白消息槽进行非阻塞式并行 入队操作。  The parallel enroller is configured to perform a non-blocking parallel enqueue operation on the blank message slot or the non-blank message slot.
具体的, 并行入队器是消息并行转串行的关键部件, 需要非常小心翼翼编码 操作的相互抢占的并行行为, 过此而后, 转为非常轻松的协同的串行行为。 由于 本消息总线是一个多入单出模型, 因此并行入队器在具体实现时, 多数应用场合 下, 都能根据实际情况简化实现模型。  Specifically, the parallel enqueue is a key component of message parallel-to-serial, which requires very careful parallelism of the preemptive behavior of the encoding operations, and then turns into a very easy collaborative serial behavior. Since the message bus is a multi-input and single-out model, when the parallel enqueue is implemented, in most applications, the model can be simplified according to the actual situation.
并行入队器是一个高效、简洁的非阻塞式并行入队的部件, 相对于阻塞式入 队器, 消除了死锁、 优先级倒置、 中断不能加锁、 临界区不能并发等问题; 用免 费的纯软件方法, 实现无锁入队; 用廉价的硬件方法, 实现高效率的单条汇编指 令的无等待入队。具体的,可以利用中断屏蔽、 CAS/CAS2、LL/SC处理器原语 等, 用纯软件方法, 实现无锁 (Lock-Free)算法进行入队操作; 也可以利用硬件, 直接实现同样的功能, 得到无等待 (Wait-Free)算法的效果, 同时获得高效率入 队的效果: 一条汇编指令即可完成入队操作。链表的非阻塞式、特别是无锁入队 操作, 已有很多的公开论文陈述, 在此不再赘述。 并行入队器的具体实现, 与总 线内部的消息队列池的具体结构与实现, 密切相关。通常情况下, 是操作单个或 者多个含头尾指针的单链表, 对其完成尾部并行入队操作。为降低并行操作的复 杂性,也可以安排一个专门的单链表队列,仅用于并行转串行的入队操作;之后, 再对该并串队列进行后续管理操作。特殊情况下,入队可以有其它特别解决方案。 后文将描述一个特别的简洁模型。 (六) 消息队列池 Parallel enqueue is an efficient and concise non-blocking parallel enqueue component. Compared with blocking enqueue, it eliminates deadlock, priority inversion, interrupt can not be locked, and critical section can not be concurrent. The pure software method, the realization of lock-free team; with cheap hardware methods, to achieve efficient single-assembly instructions without waiting for the queue. Specifically, you can use the interrupt mask, CAS/CAS2, LL/SC processor primitives, etc., to implement the lock-free algorithm for the enqueue operation using pure software methods. You can also use the hardware to directly implement the same function. , get the effect of the Wait-Free algorithm, and get the effect of high efficiency enqueue: an assembly instruction can complete the enrollment operation. Non-blocking, especially lock-free operation of linked lists, there have been many public papers, and will not be repeated here. The specific implementation of the parallel enqueue is closely related to the specific structure and implementation of the message queue pool inside the bus. Usually, a single or multiple singly linked list with head and tail pointers is operated, and the tail parallel enqueue operation is completed. In order to reduce the complexity of parallel operations, a dedicated single-linked list queue can also be arranged for the parallel-to-serial enqueue operation; after that, the parallel-serial queue is subsequently managed. In special cases, there are other special solutions for entering the team. A special succinct model will be described later. (vi) Message queue pool
消息队列池用于缓存尚未处理的已入队消息。  The message queue pool is used to cache queued messages that have not yet been processed.
消息队列池, 是本消息总线的核心数据结构区, 用于缓存所有尚未处理的已 入队消息, 配合过滤、 管理、 调度、 挑选应该优先处理的消息。 由于这时已经完 全是协同操作, 因此, 能简单自然地设计各种调度管理算法。  The message queue pool is the core data structure area of the message bus. It is used to cache all the queued messages that have not been processed, and cooperate with filtering, management, scheduling, and picking up messages that should be processed first. Since it is completely coordinated at this time, various scheduling management algorithms can be designed simply and naturally.
消息队列池的具体实现方案, 与具体的应用系统密切相关。通常情况下, 是 一个含头尾指针的单链表,可以实现简单的调度算法, 如: 先进先出 FIFO (First The specific implementation of the message queue pool is closely related to the specific application system. Usually, it is a single-linked list with head and tail pointers, which can implement simple scheduling algorithms, such as: FIFO FIFO (First
In First Out)算法、 简单的优先级排序算法 等。 复杂情况下, 比如, 多 种简单的调度算法同时存在于一个系统, 这时需要使用多个单链表, 以实现相对 复杂的调度算法, 如: 时间优化的动态优先级算法、 最早截止任务优先In First Out) algorithm, simple prioritization algorithm, etc. In complex situations, for example, multiple simple scheduling algorithms exist in one system at the same time. In this case, multiple single-linked lists are needed to implement relatively complex scheduling algorithms, such as: time-optimized dynamic priority algorithm, earliest deadline task priority.
EDF (Earliest Deadline First)算法 等。 特殊情况下, 可能需要使用双链 表、 散列表等复杂的数据结构, 以完成系统特殊的功能与要求。 EDF (Earliest Deadline First) algorithm and so on. In special cases, it may be necessary to use complex data structures such as double-linked lists and hash tables to complete the special functions and requirements of the system.
本发明中, 对于消息队列池, 采用零 PCB, 从而简化了并发模型, 使得本消 息总线具备最广泛的适应性。 更为关键的, 能够有效节省 RAM空间。对于应用本 消息总线实现并发的应用系统而言, 由于构件组装, 一次拥有成千上万的算子 Actor是非常正常的事情。 因此, 零 PCB就使得算子数量与 RAM空间的占用毫无 关联。 无论存在多少算子, 其所占用的 RAM空间丝毫不变。 这样, 本消息总线就 能很轻易地应用于各种 RAM稀缺的场合, 如: WSN应用系统中。  In the present invention, for the message queue pool, zero PCB is used, thereby simplifying the concurrency model, and the communication bus has the widest adaptability. More critical, it can save RAM space. For applications that use this message bus for concurrency, it is quite normal to have thousands of operator Actors at a time due to component assembly. Therefore, zero PCB makes the number of operators unrelated to the occupation of RAM space. No matter how many operators exist, the RAM space occupied by them is unchanged. In this way, the message bus can be easily applied to various RAM scarce situations, such as: WSN application system.
零 PCB, 意味着算子不再能动态地表达其任务的多种状态, 因此约定: 总线 内的算子, 不再有等待状态, 而只存在就绪状态和运行状态。 即使消息总线内不 存在任何消息时, 消息总线内的算子也处于就绪状态。而当消息总线内到达消息 时, 消息总线内的算子排序后立即获得处理器, 从而转变为运行状态。 因此, 整 个应用系统是否处于等待状态, 取决于消息总线内部是否存在消息。这为系统节 能奠立了深刻的理论与技术支撑点。  Zero PCB, means that the operator can no longer dynamically express multiple states of its tasks, so the convention: The operators in the bus no longer have a wait state, but only the ready state and the running state. Even if there are no messages in the message bus, the operators in the message bus are in the ready state. When the message arrives in the message bus, the operators in the message bus get the processor immediately after sorting, and thus become the running state. Therefore, whether the entire application system is in a wait state depends on whether there is a message inside the message bus. This has laid a profound theoretical and technical support point for system energy saving.
零 PCB, 意味着一般的算子可以不用 RAM空间来动态地表达。 但是, 这不排 除某些特别用途的算子或队列, 可以占用很多 RAM空间, 也即, 采用非零 PCB来 表达。 比如: 在 EDF队列里, 记录每个实时算子的截止时间。  Zero PCB means that general operators can be dynamically expressed without RAM space. However, this does not exclude some special-purpose operators or queues, which can take up a lot of RAM space, that is, using a non-zero PCB. For example: In the EDF queue, record the deadline for each real-time operator.
因此, RAM零长度的任务控制块 PCB, 即零 PCB, 相对于 RAM内存中非零长 度的任务 PCB, 减少了调度执行时间, 形成了高效、简洁、统一的并发基础模型, 减少了 RAM空间的占用,使得本并发基础模型能普遍适用于任何现有的计算机体 系。 Therefore, the zero-length task control block PCB of the RAM, that is, the zero PCB, reduces the scheduling execution time relative to the non-zero-length task PCB in the RAM memory, and forms an efficient, concise, unified concurrent basic model, which reduces the RAM space. Occupancy, making this concurrent base model universally applicable to any existing computer body Department.
(七) 排队顺序管理器  (7) Queueing order manager
排队顺序管理器用于根据预设调度策略从所述消息队列池中选择需处理的 指定消息, 对所述指定消息进行协同的出队操作。  The queuing sequence manager is configured to select a specified message to be processed from the message queue pool according to a preset scheduling policy, and perform a coordinated dequeuing operation on the specified message.
具体的, 排队顺序管理器, 利用消息队列池、 各种调度算法等, 对所有尚未 处理的已入队消息进行调度管理。例如: 设置消息的优先顺序, 将最优先的消息 置于队首, 便于消息出队。 其中, 在选择队首时, 可以很简单地从队列的头部, 将消息提取标示出来。 如果有多个队列, 则需要先选择最优先的队列。 由于消息 格式一般比较复杂、不可预知, 因此也可以简单地提取消息槽的地址作为消息地 址。对于最简单的先进先出算法, 排队顺序管理器甚至可以做到不以明确独立的 形态出现, 而是隐含在其它相关机构与代码中。将排队顺序管理器放置于并行入 队器之后, 可以避免复杂、 繁琐、 危险的并行抢占操作。 由于此时已经完全是协 同操作, 因此, 能简单自然地设计各种调度管理算法。  Specifically, the queuing sequence manager utilizes a message queue pool, various scheduling algorithms, and the like to perform scheduling management on all unprocessed enqueue messages. For example: Set the priority of the message, put the highest priority message at the beginning of the team, and facilitate the message to leave the team. Among them, when selecting the head of the queue, it is very easy to extract the message from the head of the queue. If there are multiple queues, you need to select the highest priority queue first. Since the message format is generally complex and unpredictable, it is also possible to simply extract the address of the message slot as the message address. For the simplest FIFO algorithm, the Queueing Sequence Manager can even be implemented in a clear, independent form, but implicitly in other relevant organizations and code. By placing the queued sequence manager behind the parallel queue, you can avoid complex, cumbersome, and dangerous parallel preemption operations. Since it is completely cooperative operation at this time, various scheduling management algorithms can be designed simply and naturally.
(八) 入口映射表  (8) Entrance mapping table
入口映射表, 根据所述目标算子 ID查找所述入口映射表, 获得与所述目标 算子 ID对应的函数入口地址; 根据所述函数入口地址以及所述指定消息的指定 消息槽地址, 调用对应的算子执行函数, 从而处理出队的所述指定消息。  An entry mapping table, searching the entry mapping table according to the target operator ID, obtaining a function entry address corresponding to the target operator ID; calling according to the function entry address and the specified message slot address of the specified message The corresponding operator executes the function to process the specified message of the team.
入口映射表用于存储算子 ID与函数入口地址的映射关系, 根据目标算子 ID 查找入口映射表, 可以获得与目标算子 ID对应的函数入口地址, 以便下一步跳 到该入口处,执行该算子的函数。这实际上是一个汇编级别的间接地址跳转机制。 该入口映射表, 一般是一个按算子 ID顺序、 从小到大排列的地址表, 算子 ID本 身一般不明确地出现在该表内部。 为了压缩任务入口表的大小, 充分利用空间, 算子 ID—般采用连续的编码方式。  The entry mapping table is used to store the mapping relationship between the operator ID and the function entry address, and the entry mapping table is searched according to the target operator ID, and the function entry address corresponding to the target operator ID can be obtained, so that the next step is to jump to the entry and execute The function of this operator. This is actually an assembly level indirect address jump mechanism. The entry mapping table is generally an address table arranged in order of operator IDs, from small to large, and the operator ID itself does not explicitly appear inside the table. In order to compress the size of the task entry table and make full use of the space, the operator ID is generally encoded in a continuous manner.
为节省 RAM空间, 适应 RAM空间稀缺的应用系统, 可以将该入口映射表存放 在 ROM中。 该入口映射表也可以隐含附带或明确列出其它若干有用信息, 如: 算 子的静态优先级等。 由于此时是协同操作, 因此, 即使是在程序运行期间, 也能 轻易协同一致地修改该入口映射表, 实现系统代码的运行期间热升级。 这对于 24小时 *7天 /周、 连续运行的高可靠系统而言, 有非常重大的现实价值。 另外, 入口映射表存储算子 ID与函数入口地址的映射关系, 对于采用任务入口地址的 方案, 能跨越计算机标示并行算子, 直接支持完全透明的分布式并行计算。支持 运行期间的代码热升级。 In order to save RAM space and adapt to the application system where RAM space is scarce, the entry mapping table can be stored in the ROM. The entry mapping table may also implicitly or explicitly list other useful information, such as: static priority of the operator, and the like. Since it is a cooperative operation at this time, the entry mapping table can be easily and consistently modified even during the running of the program to implement hot upgrade during the running of the system code. This is of great practical value for a 24 hour*7 day/week, continuously operating, highly reliable system. In addition, the entry mapping table stores the mapping relationship between the operator ID and the function entry address. For the scheme using the task entry address, the parallel operator can be indicated across the computer to directly support the completely transparent distributed parallel computing. stand by Hot code upgrade during runtime.
(九) 系统堆桟与执行任务  (9) System stacking and execution tasks
系统堆桟为所述消息总线中所有算子共享的堆桟空间;各个算子所共享的系 统堆桟空间相互覆盖, 为重叠式, 即非层叠式。  The system stacks the stacking space shared by all the operators in the message bus; the system stacking space shared by each operator overlaps each other and is overlapped, that is, non-cascading.
根据前面得到的函数入口地址、 以及消息(槽)首地址, 直接调用该算子的 执行函数。 与 TinyOS 2. x相比, 最大的区别是, 本技术方案在执行时, 携带有 消息指针; 因此, 变成了主动消息模式, 能实现推模式的信息传送机制。 一个算 子完全退出以后, 其所占用的堆桟空间也完全清空。 由于系统内的所有算子都是 协同执行, 因此, 它们都共享相同的系统堆桟空间。 也即, 所有算子的堆桟空间 是重叠的, 相对于层叠式的任务堆桟, 本发明提供的重叠的协同系统堆桟, 大量 减少了 RAM堆桟空间的占用, 使系统更具普适性; 便于评估堆桟空间的最大使用 量, 便于 RAM空间分配管理工作。 在算子运行期间, 消息 (槽)是属于该算子完 全私有的。 因此, 在不妨碍总线运行的情况下, 算子能对该消息任意处理。 如: 重复或优先使用、 发送、 转发、 更改该消息 (槽), 以提高系统运行效率。  The execution function of the operator is directly called according to the function entry address obtained earlier and the first address of the message (slot). Compared with TinyOS 2. x, the biggest difference is that this technical solution carries a message pointer when it is executed; therefore, it becomes an active message mode, and the information transfer mechanism of the push mode can be realized. After an operator completely quits, the heap space occupied by it is completely emptied. Since all the operators in the system are coordinated, they all share the same system heap space. That is to say, the stacking space of all the operators is overlapped, and the overlapping collaborative system stacking provided by the invention substantially reduces the occupation of the RAM stacking space and makes the system more universal than the stacked task stacking. Sexuality; It is easy to evaluate the maximum usage of stacking space, which is convenient for RAM space allocation management. During the operator's operation, the message (slot) belongs to the operator that is completely private. Therefore, the operator can arbitrarily process the message without hindering the bus operation. For example: Repeat or prioritize, send, forward, change the message (slot) to improve system efficiency.
(十) 监控管理中心  (10) Monitoring Management Center
监控管理中心用于对所述消息总线内部的消息,进行集中监视、分析、控制、 过滤和管理。 比如: 统计消息总线内所有算子的实际运行时间; 清除发给某算子 的某类消息; 甚至强制终止运行某失控的算子 等等。一般主要用于系统调 试与测试阶段, 在系统正式运行期间可以不必存在。  The monitoring management center is used for centralized monitoring, analysis, control, filtering and management of messages inside the message bus. For example: statistics on the actual running time of all operators in the message bus; clearing certain types of messages sent to an operator; even forcibly terminating the running of an operator that is out of control, and so on. It is mainly used in the system debugging and testing phase, and does not have to exist during the official operation of the system.
(十一) 空间回收模块  (11) Space recovery module
空间回收模块用于回收所述消息总线内的出队后的消息本身以及所述消息 槽, 即: 用于消息本身的废弃回收、 以及消息槽空间的废弃回收。 消息本身的废 弃, 属于并行入队器的多入单出模式中的出队操作。在很简单的应用系统中, 可 以在队首选择的时候统一进行, 以便算子运行的时候, 可以很简单地消除废弃标 志, 重复利用该消息。 消息槽空间的回收: 正常情况下, 属于并行环形分配器的 多入单出模式中的空间回收操作, 也可由硬件实现。  The space reclamation module is configured to recover the dequeued message itself in the message bus and the message slot, that is, the discarding and recycling of the message itself, and the discarding and recycling of the message slot space. The abandonment of the message itself is a dequeue operation in the multi-entry and single-out mode of the parallel enqueue. In a very simple application system, it can be uniformly performed when the team leader selects, so that when the operator is running, the discarding flag can be easily eliminated and the message can be reused. Recycling of the message slot space: Under normal circumstances, the space reclamation operation in the multiple-input single-out mode belonging to the parallel ring distributor can also be implemented by hardware.
(十二) 节电装置  (12) Power saving device
节电装置的具体的实现方式与应用系统硬件密切相关。由于本消息总线能根 据内部是否存在消息, 从而即时知晓系统是否处于等待状态。 因此, 在总线内部 不存在消息时, 立即通知使用本消息总线的应用系统进行节能调度。 当有消息发 生时, 再通知硬件恢复正常运行状态。 The specific implementation of the power saving device is closely related to the application system hardware. Since the message bus can know whether the system is in a waiting state according to whether there is a message internally or not. Therefore, when there is no message inside the bus, the application system using the message bus is immediately notified to perform energy saving scheduling. When there is a message When it is born, the hardware is notified to resume normal operation.
在很多应用场合下 (如: 8051单片机), 处理器没有 CAS/CAS2指令、 也没 有 LL/SC等用于并行操作的高级同步原语。 因此, 只能用开关中断的方法模拟实 现类似原语。这会降低总线的调度效率。这时, 可以对通用模型做出一些简单的 适应性更改, 以适应具体的应用环境, 提高系统效率。 举例说明: 总线内部算子 产生的消息多、 而外部中断环境产生的消息少。 这时, 可以利用该特点, 设置 2 个总线消息缓存空间。 中断消息入队是竞争性的, 使用开关中断实现原语。算子 消息入队是协同性的, 则无需使用开关中断, 因此能提高调度效率。甚至能针对 中断优先的特点, 做出更高效率的技术修正, 使得二者能共用同一个消息缓存。  In many applications (eg, 8051 microcontrollers), the processor does not have CAS/CAS2 instructions, nor does it have advanced synchronization primitives for parallel operation such as LL/SC. Therefore, similar primitives can only be implemented by means of a switch interrupt. This will reduce the scheduling efficiency of the bus. At this time, some simple adaptive changes can be made to the general model to adapt to the specific application environment and improve system efficiency. For example: The bus internal operator generates more messages, while the external interrupt environment generates fewer messages. At this time, you can use this feature to set up 2 bus message buffer spaces. Interrupting messages into the queue is competitive, using switches to implement primitives. Operators Messages are coordinated, eliminating the need for switch interrupts, thus improving scheduling efficiency. Even more efficient technical corrections can be made for interrupt-priority features so that both can share the same message cache.
对于硬实时系统, 要求某些关键操作, 必须在确定内的时间界限内完成。本 通用协同模型, 可以在优先级调度的情况下, 稍加变更予以实现。对于响应速度 非常高速、严格的情形, 可以直接在硬件中断处理函数内部完成。对于响应时间 可以稍微推迟一步、能利用总线调度的情形, 可以安排在最高协同优先级下运行 算子。 入队操作也安排在最高优先级, 能保证入队时没有等待滞后。 同时, 拆分 所有超过规定时间的算子。 以使得在规定时间内, 总线对任一算子能及时执行完 毕。 进而, 能在规定时间内, 调度到最高优先级的算子, 完成硬实时响应。 由于 本模型有集中监控中心, 很容易监测各算子的运行时间。 因此, 很容易定位到那 些超过规定时间运行的算子, 帮助完成硬实时响应的设计工作。  For hard real-time systems, certain critical operations are required and must be completed within the time limits within the determination. This general collaborative model can be implemented with a slight change in the case of priority scheduling. For very fast, rigorous response times, it can be done directly inside the hardware interrupt handler. For cases where the response time can be slightly delayed and the bus can be scheduled, the operator can be scheduled to run at the highest synergy priority. The enrollment operation is also scheduled at the highest priority, ensuring that there is no waiting for lag when enrolling. At the same time, split all the operators over the specified time. So that the bus can be executed in time for any operator within the specified time. Further, the operator of the highest priority can be scheduled within a predetermined time to complete the hard real-time response. Since this model has a centralized monitoring center, it is easy to monitor the running time of each operator. Therefore, it is easy to locate operators that run beyond the specified time to help complete the design of hard real-time response.
本发明提供的消息总线, 存在一个简洁高效的具体特例。该特例的功能不是 特别齐全, 但执行性能特别高效, 能实现算子并发操作, 满足一般的并发应用环 境,或作为其它并发应用的基础。在借用硬件实现关键原子操作时,其执行效率, 可以与汇编级别的子程序调用, 具备相同或非常接近的性能。  The message bus provided by the present invention has a specific and simple and efficient special case. The special case is not particularly well-functioning, but its execution performance is particularly efficient, enabling operator concurrent operations to satisfy a typical concurrent application environment or as a basis for other concurrent applications. When borrowing hardware to implement key atomic operations, its execution efficiency can be the same or very close to that of assembly-level subroutine calls.
在该特例中, 并行环形分配器与并行入队器合二为一。采用休眠消息槽与消 息激活机制, 实现简单的 FIFO排序, 在入队的同时, 自然完成排队操作。 具体 工作步骤为- In this particular case, the parallel ring distributor and the parallel enqueue are combined into one. The dormant message slot and the message activation mechanism are used to implement simple FIFO ordering, and the queuing operation is naturally completed while enqueuing. The specific work steps are -
51、 休眠标识、 空间分配、 入队。 特殊硬件完成, 单条汇编指令可完成。 51, dormant identification, space allocation, enrollment. Special hardware is completed, a single assembly instruction can be completed.
52、 外部消息复制进入消息槽。  52. The external message is copied into the message slot.
53、 最简单的 FIFO排队。 隐含在 S1操作中, 不消耗时间。  53. The simplest FIFO queue. Implicit in the S1 operation, does not consume time.
54、 消息队首出队。 单条汇编指令可完成。 参数提取, 一般情况可省略。  54. The news team debuted. A single assembly instruction can be completed. Parameter extraction, general conditions can be omitted.
55、 算子 ID查表, 跳转执行。 汇编级的间接调用指令可完成。 S6、 空间回收。 特殊硬件完成, 单条汇编指令可完成。 55, operator ID lookup table, jump execution. Assembly-level indirect call instructions can be completed. S6, space recycling. Special hardware is completed, a single assembly instruction can be completed.
对比汇编级别的子程序调用过程, S1相当于改变堆桟指针, S2相当于参数 压桟, S5相当于间接 CALL汇编指令, S6相当于参数退桟。 S3不消耗时间。 因 此, 仅 S4是多出的执行时间, 是非常简单的操作, 单条汇编指令即可完成。 因 此, 总体执行时间, 仅多出 1条汇编指令时间。 在消息 (或参数)较多时, 所占 时间比重非常少。 因此, 可以做到非常接近的执行性能。 如果进一步优化操作, 采用更复杂的硬件, 可以做到相同的执行性能。  Compared with the assembly-level subroutine calling process, S1 is equivalent to changing the stack pointer, S2 is equivalent to parameter compression, S5 is equivalent to indirect CALL assembly instruction, and S6 is equivalent to parameter retirement. S3 does not consume time. Therefore, only S4 is an extra execution time, which is a very simple operation, and a single assembly instruction can be completed. Therefore, the total execution time is only one more assembly instruction time. When the number of messages (or parameters) is large, the proportion of time taken is very small. Therefore, very close execution performance can be achieved. If you optimize your operation and use more complex hardware, you can achieve the same performance.
下面对该特例进行详细说明:  The special case is described in detail below:
为叙述简单起见, 先约定两个术语: 让先环境、 抢先环境。  For the sake of simplicity, first define two terms: Let the environment first, and preempt the environment.
通常, 在低端嵌入式应用环境中, 普遍采用单核心单处理器的单片机, 不采 用操作系统。 应用软件采用结构化、 模块化、 顺序编程技术, 组装构成整个应用 系统, 直接运行在裸机状态下。外部环境事件发生时, 利用中断处理程序抢先抢 占主程序, 捕捉外部事件, 并把事件状态保存在某些事先约定好的特定位置。 同 时, 主程序使用一个很大的死循环, 轮回检查是否有外部事件发生。 若有发生, 则按照事先的约定, 检查提取外部事件的状态, 处理后输出。  Generally, in a low-end embedded application environment, a single-core single-processor microcontroller is commonly used, and no operating system is used. The application software uses structured, modular, sequential programming techniques to assemble the entire application system and run directly in bare metal. When an external environment event occurs, the interrupt handler is used to preempt the main program, capture external events, and save the event state at certain pre-agreed specific locations. At the same time, the main program uses a large endless loop to check if there are external events. If it happens, check the status of the external event according to the prior agreement, and output it after processing.
很多应用, 类似于上述应用场景, 主循环总是被外部中断所抢占, 但不会出 现主循环抢占外部中断的情况。 也即, 只要有外部中断代码在运行, 主循环肯定 暂停执行。 这种软件执行环境, 称之为让先执行环境, 简称为 "让先环境" 。 比 如: 单核单处理器时, LINUX执行实时优先调度政策, 所导致的实时线程运行环 境, 当其最低优先级的线程充当主循环时, 即构成让先环境。  For many applications, similar to the above application scenario, the main loop is always preempted by external interrupts, but the main loop does not preempt external interrupts. That is, as long as there is an external interrupt code running, the main loop will definitely suspend execution. This kind of software execution environment is called the first execution environment, which is simply referred to as "letting the environment first." For example, when a single-core single-processor is used, LINUX executes the real-time priority scheduling policy, resulting in a real-time thread running environment. When its lowest priority thread acts as the main loop, it constitutes the prior environment.
与之相反, 在多核处理器、 或单核多处理器、 或普通时间片式抢先调度时, 主线程与其它线程能相互抢占, 或同时并行交叉执行。这种软件执行环境, 称之 为抢先执行环境, 简称为 "抢先环境" 。  In contrast, in a multi-core processor, or a single-core multi-processor, or a normal time slice preemptive scheduling, the main thread and other threads can preempt each other, or concurrently cross-execution. This software execution environment is called the preemptive execution environment, referred to as the "preemptive environment".
在实现本消息总线时, 主循环作为调度程序, 完成消息出队、 调度、 协同运 行算子的功能; 其它外部中断,则相互抢占、把消息送入系统队列。抢先环境下, 调度程序与外部中断相互抢占、 交叉执行。 因此, 外部中断在填充消息槽、 但尚 未完全填充完毕时, 调度程序就有可能运行。此时, 调度程序就有机会接触到那 条半成品式的不完整消息。 因此, 需要采取一定的措施, 保证调度程序不会把那 条半成品消息,当成是正常的消息使用。在让先环境下,外部中断填充消息槽时, 调度程序没有机会被执行。调度程序要么看不见新消息, 要么看见的就是一条入 队后的完整消息。 利用这个特点, 在让先环境下, 就可以简化并行入队算法, 不 用给消息 (槽) 打上休眠标志。 When the message bus is implemented, the main loop acts as a scheduler, completing the functions of message dequeue, scheduling, and cooperative operation of the operator; other external interrupts preempt each other and send messages to the system queue. In the preemptive environment, the scheduler and the external interrupts preempt each other and cross-execute. Therefore, the dispatcher is likely to run when the external interrupt fills the message slot but has not been fully populated. At this point, the scheduler has access to the semi-finished incomplete message. Therefore, certain measures need to be taken to ensure that the scheduler does not use the semi-finished message as a normal message. In the preemptive environment, when the external interrupt fills the message slot, the scheduler has no chance to be executed. The scheduler either can't see the new message, or it sees an entry. Complete news after the team. With this feature, the parallel enqueue algorithm can be simplified in a pre-emptive environment without having to put a sleep flag on the message (slot).
本实施例可以用于抢先环境、 透明分布环境, 基于 x86 32bit多核系统。 本实施例最核心的技术要点在于, 将并行环形分配器与并行入队器合并操 作, 将环形空间的头尾指针, 同时当作是消息队列的头尾指针。 二个队列合用同 一付头尾指针。这样, 消息槽刚刚从线性空间中被分配出来、进入到环形槽空间 中的同时, 就意味着该消息槽已经进入了系统消息队列。  This embodiment can be used for preemptive environment and transparent distribution environment, based on x86 32bit multi-core system. The core technical point of this embodiment is that the parallel ring distributor and the parallel enqueue are combined to operate, and the head and tail pointers of the ring space are regarded as the head and tail pointers of the message queue at the same time. The two queues use the same head and tail pointer. In this way, the message slot has just been allocated from the linear space and into the circular slot space, which means that the message slot has entered the system message queue.
这时, 在抢先环境下, 为防止调度程序误用这个新消息槽(此时尚未填充消 息数据), 需要事先给该消息槽写上休眠标志。 该休眠标志隐含在该消息槽的长 度参数里。 当长度为 0时, 代表该消息槽在休眠, 尚未填充数据, 调度程序应该 忽略之。  At this time, in the preemptive environment, in order to prevent the scheduler from misusing the new message slot (the message data has not been filled at this time), the message slot needs to be written with a sleep flag in advance. The sleep flag is implicit in the length parameter of the message slot. When the length is 0, it means the message slot is sleeping, the data has not been filled, and the scheduler should ignore it.
消息格式为不定长二进制数据, 分为消息头、 消息体二部分。 消息体可以是 任意数据、 小于 65536-8字节的任意长度。 消息体为 0字节也是合法的, 这时, 整个消息就没有消息体, 只包含消息头部。 消息头有三部分: 2字节的消息长度 参数 size、 2字节 CAS2计数器 cas2cnt、 4字节算子 id。 共 8个字节, 正好在 32BIT x86 CPU的一次 CAS2操作范围内。  The message format is indefinitely long binary data, which is divided into two parts: the message header and the message body. The message body can be any data, any length less than 65536-8 bytes. It is also legal for the message body to be 0 bytes. In this case, the entire message has no message body and only the message header. The header has three parts: 2-byte message length Parameter size, 2 bytes CAS2 counter cas2cnt, 4-byte operator id. A total of 8 bytes, just within one CAS2 operation of the 32BIT x86 CPU.
在抢先环境下, 利用无锁算法, 预写休眠标志需要使用到 CAS2操作。 为防 止 CAS2无锁操作时的 ABA问题, Cas2cnt计数器是必须的。 具体原理可参看相 关论文, 此处不再赘述。 在让先环境下, 不需要使用休眠标志, 也不需要使用到 CAS2操作, 因此 cas2cnt没必要存在, 可以舍弃。 In a preemptive environment, using the lock-free algorithm, the pre-write sleep flag requires the use of a CAS2 operation. To prevent ABA problems when CAS2 has no lock operation, the Cas 2cnt counter is required. The specific principles can be found in related papers, and will not be described here. In the pre-emptive environment, there is no need to use the sleep flag, and there is no need to use the CAS2 operation. Therefore, cas2cnt does not need to exist and can be discarded.
本案例中, CAS操作用 x86的汇编指令 cmpxchg完成,一次可操作 4个字节; CAS2操作用汇编指令 cmpXChg8b完成, 一次可操作 8个字节。 在 x86架构下, 用汇编指令 lock完成内存总线锁定, 以完成多核时的 CAS/CAS2操作。 In this case, the CAS operation is completed with the x86 assembly instruction cmpxchg, which can operate 4 bytes at a time; the CAS2 operation is completed with the assembly instruction cmp XC hg8b, which can operate 8 bytes at a time. In the x86 architecture, the memory bus lock is completed with the assembly instruction lock to complete the CAS/CAS2 operation at the time of multi-core.
32BIT的算子 ID号可以极简单地划分为 2个部分: 节点号、 算子号。 节点 号为 0时, 随后的算子号, 被看作是本总线内的算子。 节点号不为 0时, 意味着 目标算子不在本总线内, 而是在其它外部节点: 随后的算子号, 因此被当成是该 外部节点内的算子。节点号与算子号各占多少个 BIT位, 可以在应用系统中, 事 先约定。 每个外部节点, 需要一个本地算子代为处理一些必要的事务, 如: 把该 消息转发到一条通向该外部节点的通信管道中去 等等。该本地算子, 称为 代理算子。 环形槽空间队列有头指针 head、 尾指针 tail , 兼作系统消息队列的头、 尾 指针。 当头、 尾指针相等时, 表示环形槽空间内没有消息 (槽), 为空队列。 不 考虑环形槽空间溢出的情形, 此种例外故障由用户应用程序自行处理。 因此, 尾 指针始终指向线性内存块的空闲区域。 The 32BIT operator ID number can be easily divided into two parts: node number, operator number. When the node number is 0, the subsequent operator number is treated as an operator in the bus. When the node number is not 0, it means that the target operator is not in the bus, but in other external nodes: the subsequent operator number, and therefore is regarded as an operator in the external node. How many BIT bits are occupied by the node number and the operator number, which can be agreed in advance in the application system. Each external node needs a local operator to handle some necessary transactions, such as: forwarding the message to a communication pipe to the external node, and so on. This local operator is called a proxy operator. The circular slot space queue has a head pointer head and a tail pointer tail, which double as the head and tail pointers of the system message queue. When the head and tail pointers are equal, it means that there is no message (slot) in the ring slot space, which is an empty queue. Regardless of the situation of the annular slot space overflow, such exception faults are handled by the user application itself. Therefore, the tail pointer always points to the free area of the linear memory block.
消息槽分配时, 直接在尾指针处, 按 8字节边界对齐后, 划出相应长度的空 闲空间, 然后移动尾指针: 这也意味着, 消息槽也同时进入了系统消息队列。 在 线性内存块的最末端分配时, 其所剩余的空闲空间, 可能无法容纳一条完整的消 息, 则把该末端空间分配成一个废弃的消息槽。 新消息在下个空闲位置(线性空 间的最开始端)连续分配。 由于消息槽边界始终是 8字节对齐, 与消息头部的长 度相等。 因此, 最末端的废弃消息槽, 最少也能容纳下消息的头部, 不至于在用 CAS2操作、 并发写入休眠标志时, 出现超边界读写的故障。  When the message slot is allocated, directly at the tail pointer, after the 8-byte boundary is aligned, the corresponding length of free space is drawn, and then the tail pointer is moved: This also means that the message slot also enters the system message queue. When the linear memory block is allocated at the very end, the remaining free space may not be able to accommodate a complete message, and the end space is allocated as an obsolete message slot. New messages are continuously allocated in the next free position (the beginning of the linear space). Since the message slot boundary is always 8-byte aligned, it is equal to the length of the message header. Therefore, the last discarded message slot can at least accommodate the header of the message, so that when the CAS2 is operated and the sleep flag is written concurrently, the fault of the super-boundary read/write occurs.
由于消息槽的长度刚好容纳一条消息, 因此, 由消息的长度能直接计算出消 息槽的长度。 而消息槽是连续分配的, 因此, 消息槽的长度实际上也隐含了下一 个消息槽的位置。因此, 不需要其它附加信息,所有的消息就可以组成一个 FIFO 的单链表。 从首指针开始, 可以按入队顺序, 遍历到所有的队列内消息。  Since the length of the message slot just accommodates a message, the length of the message slot can be directly calculated from the length of the message. The message slots are allocated consecutively, so the length of the message slot actually implies the location of the next message slot. Therefore, no additional information is required and all messages can form a single linked list of FIFOs. Starting from the first pointer, you can traverse all the messages in the queue in the order of enqueue.
消息从队列头指针处直接出队, 然后, 队列头指针 head指向下一个消息槽: 这也意味着, 前消息槽空间已被废弃回收, 进入了自由空闲的线性空间。 消息使 用完毕后, 在不出队的情况下可直接废弃。 废弃标志隐含在头部的算子 ID中。  The message is directly dequeued from the queue head pointer. Then, the queue head pointer head points to the next message slot: This also means that the previous message slot space has been discarded and discarded into a free-free linear space. After the message is used, it can be discarded without leaving the team. The obsolete flag is implicit in the operator ID of the header.
ID为 0, 意味着该消息已被废弃, 调度程序不再关注它。 ID不为 0, 意味着它是 有效消息, 需要调度执行。 An ID of 0 means the message has been discarded and the scheduler is no longer concerned about it. The ID is not 0, which means it is a valid message and needs to be scheduled for execution.
这样, 并行入队的消息, 只从队列尾部入队, 只修改队列的尾指针 tail ; 而出队的消息, 只从队列头部出队, 只修改队列的头指针 head。 因此, 不采用 其它临界资源保护措施, 也能自然轻松地完成并发竞争性的出入队操作, 提升执 行效率。  In this way, the messages entering the queue in parallel are only enqueued from the tail of the queue, and only the tail pointer tail of the queue is modified; and the message of the dequeue is only dequeued from the head of the queue, and only the head of the queue is modified. Therefore, without the use of other critical resource protection measures, it is also natural and easy to complete concurrent competitive entry and exit operations and improve execution efficiency.
参看图 4, 本案例最为核心的操作有三个:  Referring to Figure 4, there are three core operations in this case:
Al、 分配空槽入队; A2、 提交激活槽; A3、 调度执行。  Al, allocate empty slots to enter the queue; A2, submit the activation slot; A3, schedule execution.
需要发送消息的外部环境或内部算子, 根据消息长度, 调用 A1操作, 得到 休眠的私有消息槽。 然后, 把消息的其余部分复制到该消息槽。 最后, 根据消息 的目标算子 ID、 以及消息的长度参数, 调用 A2操作, 激活该消息。 等待总线调 度处理该消息。 本案例的总线 A3操作, 非常简单直观。 只是简单的处理一下休眠与废弃回 收问题即可。 其中, 代理算子这个概念, 放在调度程序内实现, 对于透明分布计 算有很大的好处。这样, 就可以在构件组装的链接配置文件中, 直接把构件内使 用到的 ID号, 链接到外部节点里。 而不用再另外编码生成本地算子, 再通过该 算子, 转发消息到外部节点。 The external environment or internal operator that needs to send the message, according to the length of the message, invokes the A1 operation to get the dormant private message slot. Then, copy the rest of the message to the message slot. Finally, according to the target operator ID of the message and the length parameter of the message, the A2 operation is invoked to activate the message. Wait for the bus to schedule processing of this message. The bus A3 operation in this case is very simple and intuitive. Just a simple deal with dormancy and waste recycling issues. Among them, the concept of the agent operator, implemented in the scheduler, has great benefits for transparent distribution calculation. In this way, the ID number used in the component can be directly linked to the external node in the link configuration file of the component assembly. Instead of using another encoding to generate a local operator, the operator forwards the message to the external node.
总线 A3操作时, 对于普通算子, 先标示废弃该消息, 再执行该消息对应的 目标算子。 理由在于, 这可以给该算子一个重复利用该消息的机会。 只要该算子 清除该废弃标志, 就可重复使用该消息, 提升系统执行效率。 比如: 在错误处理 算子中, 把消息的 ID修改为另外的算子, 就可以把消息快速优先地转发给后续 的错误处理算子。由于该条消息此时仍处于消息队列头部,因此能获得优先执行。  When the bus A3 is operating, for the ordinary operator, the message is discarded and the target operator corresponding to the message is executed. The reason is that this gives the operator a chance to reuse the message. As long as the operator clears the discard flag, the message can be reused to improve system execution efficiency. For example: In the error handling operator, by changing the ID of the message to another operator, the message can be quickly and preferentially forwarded to the subsequent error handling operator. Since the message is still at the head of the message queue at this time, priority execution can be obtained.
总线 A2操作, 在大于 0的长度参数 sz瞬间写入到休眠消息头部的 size域 时, 该休眠消息槽被激活 (消息槽休眠时, 其头部的 size域为 0)。 为提高执行 效率, 仅仅在消息队列刚刚为空时, 也即, 本条消息是消息队列内的第一条消息 时, 才发送信号, 唤醒睡眠中的调度程序。 唤醒信号也可以多次重复发送。  The bus A2 operation, when the length parameter sz greater than 0 is instantaneously written into the size field of the sleep message header, the sleep message slot is activated (the size field of the header is 0 when the message slot is sleeping). To improve execution efficiency, the signal is sent to wake up the sleep scheduler only when the message queue is just empty, that is, when the message is the first message in the message queue. The wake-up signal can also be sent multiple times.
总线 A1操作是无锁标示、 分配与入队操作, 采用了 CAS/CAS2操作。  The bus A1 operation is a lock-free designation, assignment and enqueue operation, and uses CAS/CAS2 operation.
( 1 )对尾指针 tai l及其所指向的消息槽头部做一个快照 snap。这时的 snap, 实际上可能是无用的垃圾数据, 也有可能是它人已处理好的有效头部: 可能是已 做好标志的头部、 或者是正在填充的消息、 或者干脆是已完全填好的消息头部。 然后反复与 tai l指针实时比较, 以确保所获得的快照、是从最新的队尾所获取。 成功之后的 snap, 不再可能是正在填充或填充完毕的头部。 因为, 那种情况下, tai l指针必然已被它人改变。  (1) Make a snapshot snap to the tail pointer tai l and the message slot head it points to. At this time, the snap may actually be useless garbage data, or it may be a valid header that it has processed: it may be the header of the flag, or the message being filled, or it may be completely filled. Good news head. It is then compared in real time with the tai l pointer to ensure that the snapshot obtained is taken from the latest tail. After the success of the snap, it is no longer possible to fill or fill the header. Because, in that case, the tai l pointer must have been changed by others.
( 2 ) 向快照 snap对应的内存写入相同的标志 M: 休眠且有效的消息, 其头 部 size域为 0, 且 id域不为 0。有时它人已抢先填充, 为防止破坏同一块内存, 采用 CAS2原子操作。 CAS2操作时, 其计数器 cas2cnt域(sent) , 在原来 snap 时获得的数值上加 1, 然后与标志 M共同写回去。 这样, 该 CAS2操作就保证了: 在写入标志 M之前、 并行竞争写入时, 有且仅有一次标志 M的成功写入; 在写入 标志 M之后, 仅有头部的 cas2cnt域能被修改。 因此在整体上保证了: 标志 M被 可靠地提前写入, 且不会破坏它人后续写入的其它有用的头部信息。  (2) Write the same flag to the memory corresponding to the snapshot snap M: Sleep and valid message, the header size field is 0, and the id field is not 0. Sometimes it is preemptively populated, in order to prevent damage to the same piece of memory, using CAS2 atomic operations. When CAS2 is operated, its counter cas2cnt field (sent) is incremented by 1 in the original snap and then written back together with the flag M. In this way, the CAS2 operation ensures that: before writing the flag M, when competing for parallel writing, there is only one write of the flag M successfully; after writing the flag M, only the cas2cnt field of the header can be modify. Therefore, it is ensured as a whole that the flag M is reliably written ahead of time without destroying other useful header information that is subsequently written by the person.
( 3 )修改队列尾指针 tai l , 以抢先入队。 由于环形空间需要回绕一整圈以 后, 才可能会以极其微小的概率回到原处。 因此, 新、 旧消息槽指针基本不可能 相等, 不存在 ABA问题。 仅采用 CAS操作, 就可完成竞争性的 tai l指针写入, 完成空间分配与入队操作。 (3) Modify the queue tail pointer tai l to preempt the queue. Since the annular space needs to wrap around a full circle, it is possible to return to its original position with a very small probability. Therefore, new and old message slot pointers are basically impossible Equal, there is no ABA problem. With only CAS operation, competitive tai l pointer writes can be completed, and space allocation and enqueue operations can be completed.
以上即为非阻塞入队的协同并发式消息总线的一个具体实施例。  The above is a specific embodiment of a non-blocking enqueue coordinated concurrent message bus.
本发明提供的非阻塞入队的协同并发式消息总线, 能够有效克服现有 "并 发"实现技术的弱点, 高效可靠地实现 "并发"技术、 并行编程, 具有普适、 廉 价、 高效、 可靠、 节能、 复用、 透明分布、 微内核、 内在支持对象技术等一系列 优点。 具体的, 包括以下优点:  The non-blocking and enrolled collaborative concurrent message bus provided by the invention can effectively overcome the weaknesses of the existing "concurrent" implementation technology, and realize the "concurrency" technology and parallel programming efficiently and reliably, and is universal, cheap, efficient, reliable, and Energy saving, multiplexing, transparent distribution, microkernel, and intrinsic support object technologies. Specifically, it includes the following advantages:
( 1 ) 普适性: 能广泛应用于各种计算机体系结构中, 如: 单处理器系统、 多向量系统、 大规模并行系统、 对称多处理系统、 集群系统、 向量机、 巨型机、 嵌入式系统等; 也能广泛应用于各类处理器架构或各种 CPU中, 如: X86架构、 RISC架构、 ARM处理器、 8051微处理器、 单片机等; 也能广泛应用于各类操作 系统、 各类软件系统中, 如: IBM 0S/400系统、 Windows系统、 Unix系统、 iOS 系统、 vxWorks系统、 ucOS I I系统、 顺序编程、 结构化编程、 模块化编程、 数 据库系统等。对于这些千变万化的软硬件环境, 均可使用统一的并发技术模型实 现。  (1) Universality: Can be widely used in various computer architectures, such as: single processor systems, multi-vector systems, massively parallel systems, symmetric multiprocessing systems, cluster systems, vector machines, supercomputers, embedded System, etc.; can also be widely used in various processor architectures or various CPUs, such as: X86 architecture, RISC architecture, ARM processor, 8051 microprocessor, microcontroller, etc.; can also be widely used in various operating systems, each Software-like systems, such as: IBM 0S/400 systems, Windows systems, Unix systems, iOS systems, vxWorks systems, ucOS II systems, sequential programming, structured programming, modular programming, database systems, and more. For these ever-changing hardware and software environments, a unified concurrency technology model can be implemented.
( 2 ) 廉价性: 可以利用现有的软硬件环境直接实现, 与现有的软硬件系统 与技术也完全相互兼容。为了获得更多优势, 也可以采用非常廉价统一的硬件设 施, 完成技术模型中的关键原子操作。  (2) Cheapness: It can be directly realized by using existing software and hardware environments, and is fully compatible with existing software and hardware systems and technologies. In order to gain more advantages, it is also possible to implement key atomic operations in the technical model using very inexpensive and uniform hardware facilities.
( 3 ) 高效性: 空间效率高: 其核心 C语言源代码不超过数百行。 时间效率 高: 并发效率优于现有普通线程技术, 可以超过一个数量级以上; 如果采用硬件 设施、 完成关键原子操作后, 与汇编级别的子程序调用指令相比, 并发效率可以 达到同等级别; 也即, 可以在数个或数十个机器指令周期内完成一次并发调度操 作。 开发效率高: 匹配特有的编程模型与组装复用技术, 与现有普通的模块化编 程、 对象化编程相比较, 开发效率可以超过一个数量级以上。  (3) High efficiency: High space efficiency: Its core C language source code does not exceed hundreds of lines. High time efficiency: Concurrency efficiency is better than existing common thread technology, which can exceed one order of magnitude; if hardware facilities are used and key atomic operations are completed, the concurrency efficiency can reach the same level compared with assembly level subroutine call instructions; That is, a concurrent scheduling operation can be completed in several or dozens of machine instruction cycles. High development efficiency: Matching the unique programming model and assembly multiplexing technology, compared with the existing common modular programming and object programming, the development efficiency can exceed one order of magnitude.
( 4) 高可靠性: 其核心代码非常少, 非常容易检查测试正确; 采用无锁或 无等待技术实现并发, 核心永不会死锁崩溃; 采用协同并发技术, 消除大量无谓 的临界条件竞争, 避免应用程序时序故障; 采用构件复用编程模型, 重复使用已 证明可靠的构件组装系统。  (4) High reliability: The core code is very small, it is very easy to check and test correctly; the use of lock-free or no-wait technology to achieve concurrency, the core will never deadlock collapse; using collaborative concurrency technology to eliminate a large number of unnecessary critical condition competition, Avoid application timing failures; use component reuse programming models to reuse proven component assembly systems.
( 5 ) 节能特性: 采用消息与事件驱动机制。 在没有负荷时, 系统能即时自 ( 6 )透明分布计算特征。 仅由 ID号代表系统内的并发算子 Actor, 并发算 子 Actor之间仅通过消息沟通, 与该算子存放于何处、在何处执行毫无关联。 因 此, 天然适应多核处理器 CMP (Chip Multi-Processor)结构、 对称多处理器 SMP (Symmetrical Multi-Processor)结构、 非对称多处理器 AMP (Asymmetrical Multi-Processor)结构、 非一致存储访问 NUMA (Non_Uniform Memory Access)结 构、 海量并行处理 MPP (Massive Paral lel Process)结构、 计算机集群、 分布式 计算 等等并行与分布式环境。 轻松进行负载平衡、计算转移等功能, 轻松 提升计算效能, 能在技术上实现全球统一计算环境。 (5) Energy-saving features: Adopt message and event-driven mechanism. When there is no load, the system can be instant (6) Transparent distribution calculation features. Only the ID number represents the concurrent operator Actor in the system, and the concurrent operator Actor communicates only through the message, and there is no correlation between where the operator is stored and where it is executed. Therefore, the natural multi-processor CMP (Chip Multi-Processor) structure, Symmetrical Multi-Processor (SMP) structure, Asymmetrical Multi-Processor (AMP) structure, non-uniform storage access NUMA (Non_Uniform) Memory Access) Structure, massive parallel processing MPP (Massive Paral Lel Process) structure, computer clustering, distributed computing, etc. Parallel and distributed environments. Easily perform functions such as load balancing and calculation transfer to easily improve computing performance and achieve a globally unified computing environment.
( 7 )微内核特征: 核心代码微小, 并通过高效的消息总线, 实现并发机制。 操作系统完全可以高效率地架构在它上面, 与单内核系统一争高下。  (7) Microkernel features: The core code is small, and the concurrency mechanism is implemented through an efficient message bus. The operating system can be fully architected on top of it, competing with single-core systems.
( 8 ) 支持面向对象技术: 能容纳超大规模的并发算子 Actor构件, 所有算 子均通过高效率的消息总线通讯,完美模拟与实现了对象技术中的主动对象的行 为与机制。  (8) Support for object-oriented technology: It can accommodate very large-scale concurrent operator Actor components. All operators communicate through high-efficiency message bus, which perfectly simulates and implements the behavior and mechanism of active objects in object technology.
应用上述协同并发式消息总线, 本发明还提供一种主动构件组装模型, 所述 主动构件组装模型为集合 P= {第 1层主动构件、 第 2层主动构件子集合…第 n 层主动构件子集合 }, 其中, n 2; 所述第 n层主动构件子集合中的各主动构件 基于第 n层虚拟消息总线进行构件组装,得到第 n-1层主动构件子集合中的单个 主动构件;所述第 n-1层主动构件子集合中的各主动构件基于第 n-1层虚拟消息 总线进行构件组装,得到第 n-2层主动构件子集合中的单个主动构件;以此类推, 直到所述第 3层主动构件子集合中的各主动构件基于第 3层虚拟消息总线进行构 件组装, 得到第 2层主动构件子集合中的单个主动构件; 所述第 2层主动构件子 集合中的各主动构件基于权利要求 1-10任一项所述的消息总线进行构件组装, 得到所述第 1层主动构件; Applying the above collaborative concurrent message bus, the present invention also provides an active component assembly model, wherein the active component assembly model is a set P = {Layer 1 active component, a second layer active component subset... an nth layer active component a set }, wherein n 2 ; each active component in the n-th active component subset is assembled according to an n-th virtual message bus, and a single active component in the n-1th active component subset is obtained; Each active component in the n-1th active component subset is assembled based on the n-1th virtual message bus to obtain a single active component in the n-2 active component subset; and so on, until Each active component in the third layer active component subset is assembled based on the layer 3 virtual message bus to obtain a single active component in the second layer active component subset; each of the second layer active component subsets The active component is assembled according to the message bus according to any one of claims 1 to 10, and the first layer active component is obtained;
其中, 集合 P中的各层各个所述主动构件符合相同的协议。本发明中, 将多 个小主动构件进行构件组装,最终得到了与各个小主动构件的构件协议相同的大 主动构件。大主动构件完全消除了对下级小主动构件的调用依赖性, 使得构件之 间仅具有数据上的松散联系。 能脱离具体应用环境, 完成独立的构件功能。使得 构件能够简洁、高效率地复用、重构、组合,使得整个构件系统具备高度复用性。  Each of the active components of each layer in the set P conforms to the same protocol. In the present invention, a plurality of small active members are assembled into members, and finally a large active member having the same component protocol as that of the respective small active members is obtained. The large active component completely eliminates the call dependency on the lower active component, so that there is only loose connection between the components. Can be separated from the specific application environment to complete independent component functions. The components can be reused, reconstructed and combined in a simple and efficient manner, so that the entire component system is highly reusable.
其中, 集合 P中第 1层主动构件包括: 所述消息总线、接口算子 ID映射表、 别名链接表以及一个以上的算子; 其中, 所述接口算子 ID映射表用于存储接口 算子 ID与入口函数的对应关系;所述别名链接表用于存储引用算子 ID与所述接 口算子 ID的对应关系;其中,所述接口算子 ID为所述主动构件自身的算子标识; 所述引用算子 ID为挂接在所述消息总线上的主动构件内部的算子标识; The layer 1 active component in the set P includes: the message bus, the interface operator ID mapping table, the alias link table, and one or more operators; wherein the interface operator ID mapping table is used to store the interface Corresponding relationship between the operator ID and the entry function; the alias link table is configured to store a correspondence between the reference operator ID and the interface operator ID; wherein the interface operator ID is an operator of the active component itself An identifier; the reference operator ID is an operator identifier that is attached to an active component on the message bus;
下面具体说明引用算子 ID、 别名链接表和接口算子 ID映射表:  The following refers to the reference operator ID, alias link table, and interface operator ID mapping table:
( 1 ) 引用算子 ID:  (1) Reference operator ID:
当构件单独以源码或中间库的形式存在时, 该构件内部所引用到的引用算 子 ID, 仅是待连接确认的符号名, 在多个相关的构件与配置文件一起编译连接 之后, 那些引用算子 ID就分配为正式的 ID值或变量。  When a component exists in the form of a source code or an intermediate library alone, the reference operator ID referenced inside the component is only the symbol name to be confirmed by the connection, and after the related components are compiled and connected with the configuration file, those references are used. The operator ID is assigned as a formal ID value or variable.
( 2) 别名链接表  (2) Alias link table
别名链接表用于存储引用算子 ID与所述接口算子 ID的对应关系。 优选的, 别名链接表存储的所述引用算子 ID与所述接口算子 ID的对应关系为等值映射关 系。 别名链接表, 操作上就是告知编译器, 某构件内所引用到的其它引用算子 ID, 应该与哪些构件的接口算子 ID链接在一起。 本质上就是, 确定并勾画构件 与构件之间应有的数据通讯连接, 以完成系统的预定功能。  The alias link table is used to store the correspondence between the reference operator ID and the interface operator ID. Preferably, the correspondence between the reference operator ID and the interface operator ID stored in the alias link table is an equivalence mapping relationship. The alias link table, in operation, tells the compiler that the other reference operator IDs referenced within a component should be linked with the interface operator IDs of which components. Essentially, the data communication connection between the component and the component is determined and delineated to complete the predetermined function of the system.
别名链接时, 仅把引用算子 ID与预定的接口算子 ID绑定在一起, 不关心算 子的入口函数及其参数与消息格式。二个函数的参数与消息的具体规格与形式是 否匹配, 由应用系统自行判定与决策, 从而给构件链接操作以最大的自由度。一 般可以在构件静态编译连接时, 由编译器进行检查; 也可以在系统动态运行时, 由算子自行检查确认。  When an alias is linked, only the reference operator ID is bound to the predetermined interface operator ID, and the operator's entry function and its parameters and message format are not concerned. The parameters of the two functions are matched with the specific specifications and forms of the message, and the application system determines and decides by itself, thereby giving the component link operation maximum freedom. It can generally be checked by the compiler when the component is statically compiled. It can also be checked and confirmed by the operator when the system is running dynamically.
别名链接的具体实现非常简单,仅仅是把引用 ID变量与已知 ID变量绑定为 同一个数值或变量,可以用编程语言里的别名操作或者赋值操作完成。举例说明, refld为引用算子 ID, calcld为已知的接口算子 ID。 用 C++语言实现为: alD— t ferefld = calcld ; 用 C i吾言实现为: alD— t refld = calcld。  The concrete implementation of the alias link is very simple. Just bind the reference ID variable and the known ID variable to the same value or variable, which can be done by alias operation or assignment operation in the programming language. For example, refld is the reference operator ID, and calcld is the known interface operator ID. In C++, the implementation is: alD—t ferefld = calcld; using C i to achieve: alD—t refld = calcld.
( 3) 接口算子 ID映射表  (3) Interface operator ID mapping table
接口算子 ID映射表用于存储接口算子 ID与入口函数的对应关系。  The interface operator ID mapping table is used to store the correspondence between the interface operator ID and the entry function.
构件内的消息入口函数可以与接口算子 ID分离。 也即, 构件的功能实现代 码部分, 可以不包含接口算子 ID的名称, 仅包含入口函数的代码。 二者的绑定 映射, 可以滞后一步, 在构件或系统组装时, 与别名链接一起完成。 多个接口算 子 ID, 可以映射指向为同一个入口函数。 这在实现静态引用多实例对象时, 极 具价值。 所述集合 P中第 2层主动构件子集合到第 n层主动构件子集合中的各个主动 构件分别包括: 所述虚拟消息总线、 所述接口算子 ID映射表、 所述别名链接表 以及一个以上的算子。 The message entry function within the component can be separated from the interface operator ID. That is, the function implementation code part of the component may not contain the name of the interface operator ID, but only the code of the entry function. The binding mapping of the two can be lagging behind, and is done with the alias link when the component or system is assembled. Multiple interface operator IDs can be mapped to the same entry function. This is extremely valuable when implementing statically referencing multi-instance objects. Each of the active components of the second-layer active component subset to the n-th active component subset of the set P includes: the virtual message bus, the interface operator ID mapping table, the alias link table, and a The above operator.
其中, 虚拟消息总线是一个逻辑上、 概念上的总线, 不用实际去关心编码, 不是一个单独明确出现的总线实体。构件总是插接到某根总线上, 通过调用总线 API函数, 构件以硬编码的形式要求挂接到总线上。 但构件单独以源码、 或中间 库的形式存在时, 该构件并没有与某根总线实际连接在一起, 并没有把总线的代 码包含在构件内。 只有当完成整个总线节点、 或整个系统的编译连接之后, 构件 才与某根总线的代码连接在一起, 成为总线的一个挂接部件。构件假设自己是在 一根总线上在操作, 但这根总线暂时还不存在, 因此称之为虚拟消息总线。 它不 在构件内部存在, 不影响构件的独立性。  Among them, the virtual message bus is a logical, conceptual bus, without actually concerned about coding, not a separate explicit bus entity. The component is always plugged into a bus, and by calling the bus API function, the component is hard-coded to attach to the bus. However, when the component exists in the form of source code or intermediate library alone, the component is not actually connected to a certain bus, and the code of the bus is not included in the component. Only after the completion of the compiled connection of the entire bus node, or the entire system, the component is connected to the code of a certain bus to become a hook component of the bus. The component assumes that it is operating on a bus, but this bus does not yet exist, so it is called a virtual message bus. It does not exist inside the component and does not affect the independence of the component.
第 n层主动构件子集合中的各主动构件基于第 n层虚拟消息总线进行构件组 装, 得到第 n-1层主动构件子集合中的单个主动构件, 其中, n 3具体为: 所述第 n层主动构件子集合中的各主动构件分别包括第 n层虚拟消息总线、 第 n层接口算子 ID映射表、 第 n层别名链接表以及一个以上的第 n层算子; 进 行构件组装后得到的第 n-1层主动构件子集合中的单个主动构件包括第 n-1层虚 拟消息总线、 第 n-1层接口算子 ID映射表、 第 n-1层别名链接表以及一个以上 的第 n-1层算子;  The active components in the n-th active component subset are assembled according to the n-th virtual message bus, and a single active component in the n-1th active component subset is obtained, where n 3 is specifically: the nth Each active component in the layer active component subset includes an nth layer virtual message bus, an nth layer interface operator ID mapping table, an nth layer alias link table, and one or more nth layer operators; The single active component in the n-1th active component subset includes an n-1th virtual message bus, an n-1th interface operator ID mapping table, an n-1th alias link table, and more than one N-1 layer operator;
在进行构件组装时, 将各个所述第 n层虚拟消息总线进行总线融合, 得到第 n-1层虚拟消息总线; 将各个所述第 n层接口算子 ID映射表进行表格融合, 得 到第 n-1层接口算子 ID映射表; 将各个所述第 n层别名链接表进行表格融合, 得到第 n-1层别名链接表;将各个所述第 n层算子进行融合,得到第 n-1层算子。  When component assembly is performed, each of the nth layer virtual message bus is bus-fused to obtain an n-1th layer virtual message bus; and each of the nth layer interface operator ID mapping tables is table-fused to obtain a nth a layer 1 interface operator ID mapping table; table fusion of each of the nth layer alias link tables to obtain an n-1th layer alias link table; and fusing each of the nth layer operators to obtain an nth- 1 layer operator.
第 2层主动构件子集合中的各主动构件基于所述的消息总线进行构件组装, 得到所述第 1层主动构件具体为- 所述第 2层主动构件子集合中的各主动构件分别包括所述第 2层虚拟消息总 线、第 2层接口算子 ID映射表、第 2层别名链接表以及一个以上的第 2层算子; 进行构件组装后得到的第 1层主动构件包括所述消息总线、 第 1层接口算子 ID 映射表、 第 1层别名链接表以及一个以上的第 1层算子;  Each active component in the second-layer active component subset is assembled based on the message bus, and the first-layer active component is specifically - each active component in the second-layer active component subset includes a a layer 2 virtual message bus, a layer 2 interface operator ID mapping table, a layer 2 alias link table, and one or more layer 2 operators; the first layer active component obtained after component assembly includes the message bus , a layer 1 interface operator ID mapping table, a layer 1 alias link table, and more than one layer 1 operator;
在进行构件组装时, 将各个所述第 2层虚拟消息总线进行总线融合, 得到所 述消息总线; 将各个所述第 2层接口算子 ID映射表进行表格融合, 得到第 1层 接口算子 ID映射表; 将各个所述第 2层别名链接表进行表格融合, 得到第 1层 别名链接表; 将各个所述第 2层算子进行融合, 得到第 1层算子。 When component assembly is performed, each of the second layer virtual message buses is bus-fused to obtain the message bus; each of the layer 2 interface operator ID mapping tables is table-fused to obtain a layer 1 An interface operator ID mapping table; table fusion of each of the second layer alias link tables to obtain a first layer alias link table; and fusing each of the second layer operators to obtain a first layer operator.
具体的, 构件组装时, 虚拟消息总线只是一个逻辑概念, 不用实际去关心编 码。 因此, 实际只需要完成接口算子 ID映射表与别名链接表即可, 这二者可以 放在同一个配置文件里。 因此, 构件组装操作, 就简化对应于完成一个简洁的配 置文件。 而实际的算子函数代码, 则可存放于一个算子函数库里。 该库的算子函 数之间, 没有任何的相互调用关系, 仅仅是简单的罗列关系, 大家并行存在于同 一个库而已。  Specifically, when components are assembled, the virtual message bus is just a logical concept, and there is no need to actually care about coding. Therefore, it is only necessary to complete the interface operator ID mapping table and the alias link table, which can be placed in the same configuration file. Therefore, the component assembly operation simplifies the correspondence to complete a compact configuration file. The actual operator function code can be stored in an operator function library. There is no mutual calling relationship between the operator functions of the library, just a simple list relationship, and everyone exists in the same library in parallel.
配置文件里的内容, 只是简单的罗列而已: 接口算子 ID与入口函数的对应 关、 引用算子 ID与接口算子的对应关系。 构件的引用、 拆分、 修改、 重利用等 等, 也都仅仅是改变其中的对应关系而已, 非常简单明了。 当需要完全包含另外 一个构件, 使它成为自己的一个部分时, 只要简单地把该构件的配置文件包含进 来即可, 不需更改它的函数代码部分。  The contents of the configuration file are simply listed: the correspondence between the interface operator ID and the entry function, and the correspondence between the reference operator ID and the interface operator. The reference, split, modification, reuse, etc. of the components are also just changing the corresponding relationship, which is very simple and clear. When you need to completely include another component and make it a part of itself, simply include the component's configuration file without changing its function code portion.
并发算子作为最基本的基础构件, 可以组装构成更大、 更高级的构件。在组 成更大的构件之后, 作为基础的算子之间, 仍然没有直接的函数调用关系, 仅有 数据通讯关系, 仍保持相互之间通过总线进行消息沟通的特点。通过一张局部的 别名链接表, 确定构件内部的各算子之间的数据连接与通讯关系。 由于本消息总 线的消息调度效率, 接近或与汇编级别的顺序 call调用相同, 因此, 大量存在 的算子极少或不会降低系统的运行效率。  Concurrent operators are the most basic building blocks that can be assembled to form larger, more advanced components. After the formation of larger components, there is still no direct function call relationship between the operators as the basis, only the data communication relationship, and still maintain the communication characteristics of each other through the bus. The data connection and communication relationship between the operators within the component is determined by a partial alias link table. Since the message scheduling efficiency of this message bus is close to or the same as the order-level call call at the assembly level, there are very few operators that exist or do not degrade the efficiency of the system.
如图 5所示, 为本发明提供的构件组装实例示意图, 从图中可以看出, 构件 3、 构件 4需要组成一个大的构件 Ca, 然后构件 Ca与构件 1、 构件 2需要组成更 大的构件 Cb。 构件 1、 构件 2、 构件 3、 构件 4之间的数据传送关系, 如图中左 半部分所示; 实际组成的构件装配运行结构, 如图中右半部分所示。  As shown in FIG. 5, a schematic diagram of the assembly of the components provided by the present invention is shown. As can be seen from the figure, the members 3 and 4 need to form a large member Ca, and then the components Ca and the members 1 and 2 need to be composed larger. Component Cb. The data transfer relationship between the component 1, the component 2, the component 3, and the component 4 is shown in the left half of the figure; the actual component assembly operation structure is shown in the right half of the figure.
构件 1、 构件 2、 构件 3、 构件 4实际的函数代码, 并行存放于另外的一个 算子函数库中, 不用关心。 构件 Ca的配置文件内容包含: 算子 ID3a、 ID3b与构 件 3内的入口函数的对应关系, 算子 ID4与构件 4内的入口函数的对应关系; 构 件 3引用 ID4、 构件 4引用 ID3b的对应关系; 对外公布的算子 ID3a、 构件 4引 用的算子。 构件 Cb的配置内容类似, 不再赘述。  Component 1, component 2, component 3, component 4 The actual function code, stored in another operator library in parallel, do not care. The configuration file of the component Ca includes: the correspondence between the operator ID3a, ID3b and the entry function in the member 3, the correspondence between the operator ID4 and the entry function in the member 4; the correspondence between the member 3 reference ID4 and the member 4 reference ID3b The operator ID3a and the operator referenced by component 4 are published. The configuration of component Cb is similar and will not be described again.
以上, 描述了构件组装的通用模型与具体实施案例, 通过上述构件组装通用 模型, 使得小型基础构件能轻易组装成大型构件, 同时, 大型构件也极容易分解 为小型基础构件。并发算子属于推模式的主动消息构件。应用本消息总线的构件, 对外呈现的接口为一个或多个算子, 每个算子绑定一个消息入口函数, 被一个算 子 ID所代表。 In the above, a general model and a concrete implementation example of component assembly are described. The general model is assembled by the above components, so that the small basic components can be easily assembled into large components, and at the same time, the large components are also easily decomposed. For small base components. The concurrent operator belongs to the active message component of the push mode. Applying the components of the message bus, the externally presented interface is one or more operators, and each operator is bound with a message entry function, which is represented by an operator ID.
对于上述主动构件组装模型,本发明还提供了一种对上述的主动构件组装模 型进行构件拆分方法, 包括以下步骤:  For the above-described active component assembly model, the present invention also provides a component splitting method for the above-described active component assembly model, comprising the following steps:
预先设定构件拆分规则, 当所述主动构件组装模型满足所述构件拆分规则 时, 按所述构件拆分规则拆分所述主动构件组装模型。  The component splitting rule is preset, and when the active component assembly model satisfies the component splitting rule, the active component assembly model is split according to the component splitting rule.
本发明提供下列四种构件拆分规则:  The present invention provides the following four component splitting rules:
( 1 ) 第一种构件拆分规则  (1) The first component splitting rule
构件拆分规则为:当所述消息总线的调度程序由两个以上内核或处理器执行 时,将所述消息总线分裂为与所述内核数量或所述处理器数量相同的分布式的对 等的子总线;所述主动构件组装模型中各层各个所述主动构件分别挂接到对应的 所述子总线上。  The component splitting rule is: when the scheduler of the message bus is executed by more than two cores or processors, splitting the message bus into distributed peers having the same number of cores or the number of processors a sub-bus; each of the active components of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
具体的, 由于总线是协同调度与执行的, 因此, 一根总线只适合于由一个处 理器的一个内核执行总线的调度程序,不能由多核或多处理器同时执行同一根总 线的调度程序。在多核或多处理器系统中, 如果一根总线的消息负荷非常大, 仅 由一个处理器的一个内核执行该总线的调度程序, 显得力不从心。那么, 可以根 据内核与处理器的数量, 把该总线分裂成 2根甚至多根子总线, 每个处理器内核 负责运行一根子总线。这样, 就能完成负荷的自动转移工作。 由于算子之间都是 消息通讯, 某个算子具体在哪根子总线上运行, 并不影响原来单根系统总线上算 子的数据通讯关系。 由于信息的局部性原理, 构件内部的算子之间的通讯, 相对 于构件外部的通讯, 一般应该频繁很多。 因此, 总线分裂的原则, 应该以构件为 单位进行划分。这样, 构件内部原来不存在的虚拟消息总线, 现在又重新实体化 为实际的子总线。 当然, 如果需要总线分裂, 那么原来在编译链接时, 很多可以 舍弃的构件信息, 就需要保持记录, 以保证能够重建与复现原来的构件结构与信 息。  Specifically, since the bus is co-scheduled and executed, a bus is only suitable for executing a bus scheduler by one core of one processor, and the same bus scheduler cannot be executed by multiple cores or multiple processors simultaneously. In a multi-core or multi-processor system, if the message load of one bus is very large, it is not enough to execute the scheduler of the bus by only one core of one processor. Then, according to the number of cores and processors, the bus can be split into two or even multiple sub-buses, and each processor core is responsible for running one sub-bus. In this way, the automatic transfer of the load can be completed. Since the operators are all message communication, which sub-bus is run on an individual sub-bus does not affect the data communication relationship of the operators on the original single-system bus. Due to the locality principle of information, the communication between the operators inside the component should be much more frequent than the communication outside the component. Therefore, the principle of bus splitting should be divided by components. In this way, the virtual message bus that did not exist inside the component is now re-materialized into the actual sub-bus. Of course, if bus splitting is required, then many of the component information that can be discarded when compiling the link needs to be kept in order to ensure that the original component structure and information can be reconstructed and reproduced.
( 2) 第二种构件拆分规则  (2) Second component splitting rules
所述构件拆分规则为:动态统计所述主动构件组装模型中各个主动构件的负 荷, 根据预设的负载均衡原理, 动态地将所述消息总线分裂为分布式的对等的多 个子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对 应的所述子总线上。 The component splitting rule is: dynamically counting the load of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset load balancing principle; Each of the active components or operators in each layer of the active component assembly model is respectively connected to the pair Should be on the sub-bus.
( 3 ) 第三种构件拆分规则  (3) The third component splitting rule
所述构件拆分规则为:动态统计所述主动构件组装模型中各个主动构件的能 效比, 根据预设的节能原理, 动态地将所述消息总线分裂为分布式的对等的多个 子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对应 的所述子总线上。  The component splitting rule is: dynamically counting energy efficiency ratios of the active components in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset energy-saving principle; Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
( 4) 第四种构件拆分规则  (4) The fourth component splitting rule
所述构件拆分规则为:动态统计所述主动构件组装模型中各个主动构件的失 效率, 根据预设的可靠性原理, 动态地将所述消息总线分裂为分布式的对等的多 个子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对 应的所述子总线上。  The component splitting rule is: dynamically counting the failure rate of each active component in the active component assembly model, and dynamically splitting the message bus into distributed peer-to-peer multiple sub-buses according to a preset reliability principle Each of the active components or operators of each layer in the active component assembly model is respectively hooked onto the corresponding sub-bus.
本发明提供的协同并发式消息总线、主动构件组装模型及构件拆分方法, 能 够有效克服现有 "并发"实现技术的弱点, 高效可靠地实现 "并发"技术、并行 编程, 具有普适、 廉价、 高效、 可靠、 节能、 复用、 透明分布、 微内核、 内在支 持对象技术等一系列优点。 以上所述仅是本发明的优选实施方式, 应当指出, 对于本技术领域的普通技 术人员来说, 在不脱离本发明原理的前提下, 还可以做出若干改进和润饰, 这些 改进和润饰也应视本发明的保护范围。  The collaborative concurrent message bus, the active component assembly model and the component splitting method provided by the invention can effectively overcome the weakness of the existing "concurrent" implementation technology, and realize the "concurrency" technology and parallel programming efficiently and reliably, and have universality and low cost. A series of advantages such as high efficiency, reliability, energy saving, reuse, transparent distribution, microkernel, and intrinsic support object technology. The above description is only a preferred embodiment of the present invention, and it should be noted that those skilled in the art can also make several improvements and retouchings without departing from the principles of the present invention. The scope of protection of the invention should be considered.

Claims

权利要求 Rights request
1、 一种协同并发式消息总线, 其特征在于, 包括: 信息获取模块、 并行环 形分配器、 线性内存块、 消息填充模块、 并行入队器、 消息队列池、 排队顺序管 理器、 入口映射表和系统堆桟; 1. A collaborative concurrent message bus, characterized by including: information acquisition module, parallel ring allocator, linear memory block, message filling module, parallel queue enqueuer, message queue pool, queuing order manager, entry mapping table and system stack;
其中, 所述信息获取模块用于从接收到的待处理的外部并行的消息中获取 目标算子 ID以及消息长度值; 其中, 所述目标算子 ID为处理所述消息的算子标 识; 同时用于获取附加管理消息的附加管理消息长度值, 然后计算所述附加管理 消息长度值与获取到的所述消息长度值的和, 得到消息占用空间值; 其中, 所述 附加管理消息长度值 Wherein, the information acquisition module is used to obtain the target operator ID and message length value from the received external parallel message to be processed; wherein the target operator ID is the operator identification for processing the message; and Used to obtain the additional management message length value of the additional management message, and then calculate the sum of the additional management message length value and the obtained message length value to obtain the message occupied space value; wherein, the additional management message length value
所述并行环形分配器为非阻塞式并行的空间环形分配器, 用于根据所述信 息获取模块获取到的所述消息占用空间值,按环形划分原则连续动态的划割所述 线性内存块, 非阻塞式并行地得到与消息占用空间值相同的空白消息槽; The parallel ring allocator is a non-blocking parallel space ring allocator, used to continuously and dynamically divide the linear memory block according to the ring division principle according to the message occupied space value obtained by the information acquisition module, Obtain an empty message slot with the same space value as the message occupied in a non-blocking manner in parallel;
所述消息填充模块用于将所述消息及所述附加管理消息填充到所述并行环 形分配器分配的所述空白消息槽, 得到非空白消息槽; The message filling module is used to fill the message and the additional management message into the blank message slot allocated by the parallel ring distributor to obtain a non-blank message slot;
所述并行入队器用于对所述空白消息槽或所述非空白消息槽进行非阻塞式 并行入队操作; The parallel enqueuing device is used to perform non-blocking parallel enqueuing operations on the blank message slot or the non-blank message slot;
所述消息队列池用于缓存尚未处理的已入队消息; The message queue pool is used to cache queued messages that have not yet been processed;
所述排队顺序管理器用于根据预设调度策略从所述消息队列池中选择需处 理的指定消息, 对所述指定消息进行协同的出队操作; The queuing order manager is used to select designated messages to be processed from the message queue pool according to the preset scheduling policy, and perform coordinated dequeuing operations on the designated messages;
所述入口映射表, 根据所述目标算子 ID查找所述入口映射表, 获得与所述 目标算子 ID对应的函数入口地址; 根据所述函数入口地址以及所述指定消息的 指定消息槽地址, 调用对应的算子执行函数, 从而处理出队的所述指定消息; 所述系统堆桟为所述消息总线中所有算子共享的堆桟空间; 各个算子所共 享的系统堆桟空间相互覆盖, 为重叠式, 即非层叠式; The entry mapping table searches the entry mapping table according to the target operator ID and obtains the function entry address corresponding to the target operator ID; according to the function entry address and the designated message slot address of the designated message , call the corresponding operator execution function to process the specified message dequeued; the system stack is the stack space shared by all operators in the message bus; the system stack space shared by each operator is mutually exclusive Covering is overlapping, that is, non-laminated;
并且, 所述消息总线内的算子仅具有就绪状态, 即使当所述消息总线内不 存在任何消息时, 所述消息总线内的算子仍处于就绪状态; 一旦当所述消息总线 内到达消息时, 且当该消息所对应的算子被调度时, 被调度到的算子立即获得处 理器。 Moreover, the operators in the message bus only have a ready state. Even when there is no message in the message bus, the operators in the message bus are still in a ready state; once a message arrives in the message bus , and when the operator corresponding to the message is scheduled, the scheduled operator immediately obtains the processor.
2、 根据权利要求 1所述的协同并发式消息总线, 其特征在于, 所述消息为 定长消息或变长消息。 2. The cooperative concurrent message bus according to claim 1, characterized in that the message is a fixed-length message or a variable-length message.
3、 根据权利要求 1所述的协同并发式消息总线, 其特征在于, 当所述并行 环形分配器在所述线性内存块的最末端划割空白消息槽时,如果所述线性内存块 最未端剩余的空闲空间小于所述消息占用空间值,则直接舍弃所述最未端剩余的 空闲空间, 所述最未端剩余的空闲空间形成废弃槽。 3. The cooperative concurrent message bus according to claim 1, wherein when the parallel ring allocator cuts a blank message slot at the end of the linear memory block, if the linear memory block is the last If the free space remaining at the end is less than the message occupied space value, the free space remaining at the end is directly discarded, and the free space remaining at the end forms a discard slot.
4、 根据权利要求 1所述的协同并发式消息总线, 其特征在于, 所述消息填 充模块首先将所述消息及所述附加管理消息填充到所述并行环形分配器分配的 所述空白消息槽, 得到非空白消息槽; 然后所述并行入队器对所述非空白消息槽 进行非阻塞式并行入队操作具体为: 4. The collaborative concurrent message bus according to claim 1, wherein the message filling module first fills the message and the additional management message into the empty message slot allocated by the parallel ring distributor , obtain a non-blank message slot; and then the parallel enqueueer performs a non-blocking parallel enqueuing operation on the non-blank message slot, specifically as follows:
所述并行环形分配器配置有第一头指针和第一尾指针, 当需要分配新的空 白消息槽时,直接在当前位置的第一尾指针后面划出与所述消息占用空间值相同 的空间, 得到所述新的空白消息槽, 然后再将所述第一尾指针非阻塞式并行移动 到所述新的空白消息槽的尾部; The parallel ring allocator is configured with a first head pointer and a first tail pointer. When a new empty message slot needs to be allocated, a space that is the same as the message occupied space is directly drawn behind the first tail pointer at the current position. , obtain the new blank message slot, and then move the first tail pointer to the end of the new blank message slot in a non-blocking manner in parallel;
所述并行入队器配置有第二头指针和第二尾指针; 通过非阻塞式并行移动 所述第二尾指针实现对所述非空白消息槽进行非阻塞式并行入队操作; The parallel queue enqueuer is configured with a second head pointer and a second tail pointer; through non-blocking parallel movement, the second tail pointer implements a non-blocking parallel queue enqueuing operation on the non-blank message slot;
其中, 所述并行环形分配器配置的第一头指针和第一尾指针不同于所述并 行入队器配置的第二头指针和第二尾指针。 Wherein, the first head pointer and the first tail pointer configured by the parallel ring allocator are different from the second head pointer and the second tail pointer configured by the parallel queue enqueuer.
5、 根据权利要求 1所述的协同并发式消息总线, 其特征在于, 所述并行入 队器首先对所述空白消息槽进行非阻塞式并行入队操作,然后所述消息填充模块 再向入队的所述空白消息槽填充所述消息及所述附加管理消息具体为: 5. The cooperative concurrent message bus according to claim 1, characterized in that, the parallel enqueueer first performs a non-blocking parallel enqueuing operation on the empty message slot, and then the message filling module then enters the queue. The empty message slot of the team is filled with the message and the additional management message specifically as follows:
所述并行环形分配器与所述并行入队器共用相同的头指针和尾指针, 当所 述并行环形分配器从所述线性内存块中分配出空白消息槽的同时,该空白消息槽 也被所述并行入队器执行了入队操作;然后所述消息填充模块再向入队的所述空 白消息槽填充所述消息及所述附加管理消息。 The parallel ring allocator and the parallel enqueueer share the same head pointer and tail pointer. When the parallel ring allocator allocates a blank message slot from the linear memory block, the blank message slot is also allocated. The parallel enqueueer performs the enqueuing operation; and then the message filling module fills the message and the additional management message into the empty message slot of the enqueue.
6、 根据权利要求 5所述的协同并发式消息总线, 其特征在于, 在抢先环境 下, 在所述并行环形分配器从所述线性内存块中分配出空白消息槽之前, 预先使 所述空白消息槽处于休眠状态, 其中, 处于休眠状态的空白消息槽称为休眠消息 槽;然后所述消息填充模块向所述休眠消息槽中填充所述消息及所述附加管理消 息, 当填充完成之后, 所述休眠消息槽被激活时, 即转变为活跃状态, 其中, 处 于活跃状态的消息槽称为活跃消息槽; 其中, 休眠消息槽为不会被所述消息总线 调度给算子执行的消息槽;活跃消息槽为属于所述消息总线正常调度范围的消息 槽。 6. The cooperative concurrent message bus according to claim 5, characterized in that, in a preemptive environment, before the parallel ring allocator allocates a blank message slot from the linear memory block, the blank message slot is pre-empted. The message slot is in a dormant state, where a blank message slot in a dormant state is called a dormant message slot; then the message filling module fills the dormant message slot with the message and the additional management message. After the filling is completed, when the dormant message slot is activated, it becomes an active state, where the message slot in the active state is called an active message slot; where the dormant message slot will not be scheduled by the message bus. Message slots for operator execution; active message slots are message slots that belong to the normal scheduling range of the message bus.
7、 根据权利要求 6所述的协同并发式消息总线, 其特征在于, 采用变长消 息时,通过消息槽中写入的消息长度参数是否为 0区分所述休眠消息槽和活跃消 息槽;当所述消息槽中写入的消息长度参数为 0时,该消息槽为所述休眠消息槽; 当所述消息槽中写入的消息长度参数不为 0时, 该消息槽为所述活跃消息槽。 7. The cooperative concurrent message bus according to claim 6, characterized in that when using variable length messages, the dormant message slot and the active message slot are distinguished by whether the message length parameter written in the message slot is 0; when When the message length parameter written in the message slot is 0, the message slot is the dormant message slot; when the message length parameter written in the message slot is not 0, the message slot is the active message groove.
8、 根据权利要求 1所述的协同并发式消息总线, 其特征在于, 还包括: 监 控管理中心;所述监控管理中心用于对所述消息总线内部的消息,进行集中监视、 分析、 控制、 过滤和管理。 8. The collaborative concurrent message bus according to claim 1, further comprising: a monitoring and management center; the monitoring and management center is used to conduct centralized monitoring, analysis, and control of messages within the message bus. Filter and manage.
9、 根据权利要求 1所述的协同并发式消息总线, 其特征在于, 还包括: 空 间回收模块;所述空间回收模块用于回收所述消息总线内的出队后的消息本身以 及所述消息槽。 9. The collaborative concurrent message bus according to claim 1, further comprising: a space recycling module; the space recycling module is used to recycle the dequeued messages themselves and the messages in the message bus groove.
10、 根据权利要求 1 所述的协同并发式消息总线, 其特征在于, 还包括: 节电装置; 所述节电装置用于: 当所述消息总线内不存在消息时, 立即通知使用 本消息总线的应用系统进行节能调度。 10. The collaborative concurrent message bus according to claim 1, further comprising: a power saving device; the power saving device is configured to: when there is no message in the message bus, immediately notify the use of this message The bus application system performs energy-saving scheduling.
11、 一种应用权利要求 1-10任一项所述的协同并发式消息总线的主动构件 组装模型, 其特征在于, 所述主动构件组装模型为集合 P= {第 1层主动构件、 第 2层主动构件子集合…第 n层主动构件子集合 }, 其中, n 2; 所述第 n层主 动构件子集合中的各主动构件基于第 n 层虚拟消息总线进行构件组装, 得到第 n-1层主动构件子集合中的单个主动构件; 所述第 n-1层主动构件子集合中的各 主动构件基于第 n-1层虚拟消息总线进行构件组装,得到第 n-2层主动构件子集 合中的单个主动构件; 以此类推, 直到所述第 3层主动构件子集合中的各主动构 件基于第 3层虚拟消息总线进行构件组装,得到第 2层主动构件子集合中的单个 主动构件; 所述第 2层主动构件子集合中的各主动构件基于权利要求 1-10任一 项所述的消息总线进行构件组装, 得到所述第 1层主动构件; 11. An active component assembly model applying the collaborative concurrent message bus according to any one of claims 1 to 10, characterized in that the active component assembly model is a set P = {first layer active component, second layer active component Layer active component sub-set...n-th layer active component sub-set}, where n 2 ; each active component in the n-th layer active component sub-set performs component assembly based on the n-th layer virtual message bus to obtain the n-1th A single active component in the layer active component subset; Each active component in the n-1th layer active component subset performs component assembly based on the n-1th layer virtual message bus to obtain the n-2th layer active component subset A single active component in; and so on, until each active component in the layer 3 active component subset is assembled based on the layer 3 virtual message bus, and a single active component in the layer 2 active component subset is obtained; Each active component in the second layer active component subset is assembled based on the message bus according to any one of claims 1 to 10 to obtain the first layer active component;
其中, 所述集合 P中的各层各个所述主动构件符合相同的协议。 Wherein, each active component of each layer in the set P complies with the same protocol.
12、 根据权利要求 11所述的主动构件组装模型, 其特征在于, 所述集合 P 中第 1层主动构件包括: 所述消息总线、 接口算子 ID映射表、 别名链接表以及 一个以上的算子; 其中, 所述接口算子 ID映射表用于存储接口算子 ID与入口函 数的对应关系;所述别名链接表用于存储引用算子 ID与所述接口算子 ID的对应 关系; 其中, 所述接口算子 ID为所述主动构件自身的算子标识; 所述引用算子 ID为挂接在所述消息总线上的主动构件内部的算子标识; 12. The active component assembly model according to claim 11, characterized in that, the set P The first layer active components include: the message bus, the interface operator ID mapping table, the alias link table and more than one operator; wherein, the interface operator ID mapping table is used to store the interface operator ID and entry function The corresponding relationship; the alias link table is used to store the corresponding relationship between the reference operator ID and the interface operator ID; wherein, the interface operator ID is the operator identification of the active component itself; the reference operator ID The sub-ID is the operator identification inside the active component mounted on the message bus;
所述集合 P中第 2层主动构件子集合到第 n层主动构件子集合中的各个主 动构件分别包括: 所述虚拟消息总线、 所述接口算子 ID映射表、 所述别名链接 表以及一个以上的算子。 Each active component in the second-layer active component sub-set to the n-th layer active component sub-set in the set P respectively includes: the virtual message bus, the interface operator ID mapping table, the alias link table and an The above operator.
13、 根据权利要求 12所述的主动构件组装模型, 其特征在于, 所述第 n层 主动构件子集合中的各主动构件基于第 n层虚拟消息总线进行构件组装,得到第 n-1层主动构件子集合中的单个主动构件, 其中, n 3具体为: 13. The active component assembly model according to claim 12, characterized in that each active component in the n-th layer active component subset is assembled based on the n-th layer virtual message bus to obtain the n-1th layer active component. A single active component in a sub-collection of components, where n 3 is specifically:
所述第 n层主动构件子集合中的各主动构件分别包括第 n层虚拟消息总线、 第 n层接口算子 ID映射表、 第 n层别名链接表以及一个以上的第 n层算子; 进 行构件组装后得到的第 n-1层主动构件子集合中的单个主动构件包括第 n-1层虚 拟消息总线、 第 n-1层接口算子 ID映射表、 第 n-1层别名链接表以及一个以上 的第 n-1层算子; Each active component in the nth layer active component subset includes an nth layer virtual message bus, an nth layer interface operator ID mapping table, an nth layer alias link table, and more than one nth layer operator; proceed A single active component in the n-1 layer active component subset obtained after component assembly includes the n-1 layer virtual message bus, the n-1 layer interface operator ID mapping table, the n-1 layer alias link table, and More than one n-1 level operator;
在进行构件组装时, 将各个所述第 n层虚拟消息总线进行总线融合, 得到 第 n-1层虚拟消息总线; 将各个所述第 n层接口算子 ID映射表进行表格融合, 得到第 n-1层接口算子 ID映射表;将各个所述第 n层别名链接表进行表格融合, 得到第 n-1层别名链接表;将各个所述第 n层算子进行融合,得到第 n-1层算子。 When assembling components, perform bus fusion on each of the n-th layer virtual message buses to obtain the n-1th layer virtual message bus; perform table fusion on each of the n-th layer interface operator ID mapping tables to obtain the n-th layer interface operator ID mapping table. -1 layer interface operator ID mapping table; perform table fusion on each of the n-th layer alias link tables to obtain the n-1 layer alias link table; fuse each of the n-th layer operators to obtain the n- Level 1 operator.
14、 根据权利要求 12所述的主动构件组装模型, 其特征在于, 所述第 2层 主动构件子集合中的各主动构件基于所述的消息总线进行构件组装,得到所述第 1层主动构件具体为: 14. The active component assembly model according to claim 12, characterized in that each active component in the second layer active component subset is assembled based on the message bus to obtain the first layer active component. Specifically:
所述第 2层主动构件子集合中的各主动构件分别包括所述第 2层虚拟消息 总线、 第 2层接口算子 ID映射表、 第 2层别名链接表以及一个以上的第 2层算 子; 进行构件组装后得到的第 1层主动构件包括所述消息总线、第 1层接口算子 ID映射表、 第 1层别名链接表以及一个以上的第 1层算子; Each active component in the subset of layer 2 active components includes the layer 2 virtual message bus, a layer 2 interface operator ID mapping table, a layer 2 alias link table, and more than one layer 2 operator. ; The first-layer active component obtained after component assembly includes the message bus, the first-layer interface operator ID mapping table, the first-layer alias link table, and more than one first-layer operator;
在进行构件组装时, 将各个所述第 2层虚拟消息总线进行总线融合, 得到 所述消息总线; 将各个所述第 2层接口算子 ID映射表进行表格融合, 得到第 1 层接口算子 ID映射表; 将各个所述第 2层别名链接表进行表格融合, 得到第 1 层别名链接表; 将各个所述第 2层算子进行融合, 得到第 1层算子。 When assembling components, perform bus fusion on each of the layer 2 virtual message buses to obtain the message bus; perform table fusion on each of the layer 2 interface operator ID mapping tables to obtain the first layer Layer interface operator ID mapping table; Table fusion of each of the layer 2 alias link tables to obtain a layer 1 alias link table; Fusion of each of the layer 2 operators to obtain a layer 1 operator.
15、 根据权利要求 12所述的主动构件组装模型, 其特征在于, 所述别名链 接表存储的所述引用算子 ID与所述接口算子 ID的对应关系为等值映射关系。 15. The active component assembly model according to claim 12, wherein the corresponding relationship between the reference operator ID and the interface operator ID stored in the alias link table is an equivalent mapping relationship.
16、一种对权利要求 11得到的所述的主动构件组装模型进行构件拆分方法, 其特征在于, 包括以下步骤: 16. A method for component disassembly of the active component assembly model obtained in claim 11, characterized in that it includes the following steps:
预先设定构件拆分规则, 当所述主动构件组装模型满足所述构件拆分规则 时, 按所述构件拆分规则拆分所述主动构件组装模型。 The component splitting rules are preset, and when the active component assembly model satisfies the component splitting rules, the active component assembly model is split according to the component splitting rules.
17、 根据权利要求 16所述的构件拆分方法, 其特征在于, 所述构件拆分规 则为: 当所述消息总线的调度程序由两个以上内核或处理器执行时, 将所述消息 总线分裂为与所述内核数量或所述处理器数量相同的分布式的对等的子总线;所 述主动构件组装模型中各层各个所述主动构件分别挂接到对应的所述子总线上; 或者 17. The component splitting method according to claim 16, characterized in that, the component splitting rule is: when the scheduler of the message bus is executed by more than two cores or processors, the message bus Split into distributed peer-to-peer sub-buses with the same number of cores or processors; each active component at each layer in the active component assembly model is respectively hooked to the corresponding sub-bus; or
所述构件拆分规则为: 动态统计所述主动构件组装模型中各个主动构件的 负荷, 根据预设的负载均衡原理, 动态地将所述消息总线分裂为分布式的对等的 多个子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到 对应的所述子总线上; 或者 The component splitting rules are: dynamically count the load of each active component in the active component assembly model, and dynamically split the message bus into multiple distributed peer-to-peer sub-buses according to the preset load balancing principle; Each active component or operator at each layer in the active component assembly model is respectively connected to the corresponding sub-bus; or
所述构件拆分规则为: 动态统计所述主动构件组装模型中各个主动构的能 效比, 根据预设的节能原理, 动态地将所述消息总线分裂为分布式的对等的多个 子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到对应 的所述子总线上; 或者 The component splitting rules are: dynamically count the energy efficiency ratio of each active component in the active component assembly model, and dynamically split the message bus into multiple distributed and equal sub-buses according to the preset energy-saving principle; Each active component or operator at each layer in the active component assembly model is respectively connected to the corresponding sub-bus; or
所述构件拆分规则为: 动态统计所述主动构件组装模型中各个主动构件的 失效率, 根据预设的可靠性原理, 动态地将所述消息总线分裂为分布式的对等的 多个子总线;所述主动构件组装模型中各层各个所述主动构件或算子分别挂接到 对应的所述子总线上。 The component splitting rules are: dynamically count the failure rate of each active component in the active component assembly model, and dynamically split the message bus into multiple distributed, peer-to-peer sub-buses according to the preset reliability principle. ; Each active component or operator at each layer in the active component assembly model is respectively connected to the corresponding sub-bus.
PCT/CN2013/001371 2013-01-18 2013-11-11 Cooperative concurrent message bus, driving member assembly model and member disassembly method WO2014110702A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310020046.5 2013-01-18
CN201310020046.5A CN103473031B (en) 2013-01-18 2013-01-18 Collaborative concurrent type frog messaging bus, driving member composition model and component method for splitting

Publications (1)

Publication Number Publication Date
WO2014110702A1 true WO2014110702A1 (en) 2014-07-24

Family

ID=49797908

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/001371 WO2014110702A1 (en) 2013-01-18 2013-11-11 Cooperative concurrent message bus, driving member assembly model and member disassembly method

Country Status (2)

Country Link
CN (1) CN103473031B (en)
WO (1) WO2014110702A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114706376A (en) * 2022-06-06 2022-07-05 南京宏泰半导体科技有限公司 Hardware control device and method based on software decoupling

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104168217B (en) * 2014-08-15 2018-01-09 新华三技术有限公司 A kind of First Input First Output dispatching method and device
CN105630530A (en) * 2014-11-15 2016-06-01 航天恒星科技有限公司 Multilevel boot method and system of digital signal processor
CN106598801A (en) * 2015-10-15 2017-04-26 中兴通讯股份有限公司 Coroutine monitoring method and apparatus
CN107577808B (en) * 2017-09-26 2020-03-17 武汉斗鱼网络科技有限公司 Method, device, server and medium for sorting multi-level list pages
CN109947468B (en) * 2017-12-20 2021-07-02 北京谊安医疗系统股份有限公司 Event delay method for realizing non-blocking and task-free switching
CN108804238B (en) * 2018-03-29 2022-03-04 中国工程物理研究院计算机应用研究所 Soft bus communication method based on remote procedure call
CN109491780B (en) * 2018-11-23 2022-04-12 鲍金龙 Multi-task scheduling method and device
CN110297661B (en) * 2019-05-21 2021-05-11 华东计算技术研究所(中国电子科技集团公司第三十二研究所) Parallel computing method, system and medium based on AMP framework DSP operating system
CN112015469B (en) * 2020-07-14 2023-11-14 北京淇瑀信息科技有限公司 System reconstruction method and device and electronic equipment
CN115185985B (en) * 2022-09-07 2022-12-20 北京镜舟科技有限公司 Data sorting method and device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6996681B1 (en) * 1999-04-26 2006-02-07 Bull, S.A. Modular interconnection architecture for an expandable multiprocessor machine, using a multilevel bus hierarchy and the same building block for all the levels
CN101105786A (en) * 2006-07-14 2008-01-16 中兴通讯股份有限公司 Double CPU communication method based on shared memory
US7870195B1 (en) * 2001-01-24 2011-01-11 Emc Corporation Inter-processor messaging
CN102567267A (en) * 2010-12-31 2012-07-11 北京大唐高鸿数据网络技术有限公司 Method for expanding time division multiplexing (TDM) bus
CN102880507A (en) * 2012-09-12 2013-01-16 科立讯通信股份有限公司 Method for applying and distributing chain structure message

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6996681B1 (en) * 1999-04-26 2006-02-07 Bull, S.A. Modular interconnection architecture for an expandable multiprocessor machine, using a multilevel bus hierarchy and the same building block for all the levels
US7870195B1 (en) * 2001-01-24 2011-01-11 Emc Corporation Inter-processor messaging
CN101105786A (en) * 2006-07-14 2008-01-16 中兴通讯股份有限公司 Double CPU communication method based on shared memory
CN102567267A (en) * 2010-12-31 2012-07-11 北京大唐高鸿数据网络技术有限公司 Method for expanding time division multiplexing (TDM) bus
CN102880507A (en) * 2012-09-12 2013-01-16 科立讯通信股份有限公司 Method for applying and distributing chain structure message

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114706376A (en) * 2022-06-06 2022-07-05 南京宏泰半导体科技有限公司 Hardware control device and method based on software decoupling
CN114706376B (en) * 2022-06-06 2022-08-26 南京宏泰半导体科技有限公司 Hardware control device and method based on software decoupling

Also Published As

Publication number Publication date
CN103473031A (en) 2013-12-25
CN103473031B (en) 2015-11-18

Similar Documents

Publication Publication Date Title
WO2014110702A1 (en) Cooperative concurrent message bus, driving member assembly model and member disassembly method
US10310820B2 (en) Programming model and interpreted runtime environment for high performance services with implicit concurrency control
TWI502511B (en) Resource management in a multicore architecture
Snir et al. The communication software and parallel environment of the IBM SP2
US7373640B1 (en) Technique for dynamically restricting thread concurrency without rewriting thread code
US9779042B2 (en) Resource management in a multicore architecture
EP1839146B1 (en) Mechanism to schedule threads on os-sequestered without operating system intervention
US8112559B2 (en) Increasing available FIFO space to prevent messaging queue deadlocks in a DMA environment
WO2014090008A1 (en) Task processing method and virtual machine
CN111694675B (en) Task scheduling method and device and storage medium
US8631086B2 (en) Preventing messaging queue deadlocks in a DMA environment
CN102193831A (en) Method for establishing hierarchical mapping/reduction parallel programming model
Schwan et al. “Topologies”—distributed objects on multicomputers
WO2014110701A1 (en) Independent active member and functional active member assembly module and member disassembly method
Sampson Process-oriented patterns for concurrent software engineering
Lufei et al. vStarCloud: An operating system architecture for Cloud computing
Frachtenberg et al. Storm: Scalable resource management for large-scale parallel computers
Sun et al. Gpsa: A graph processing system with actors
Ghosh et al. A Survey of Real-Time Operating Systems {Draft
Shi et al. DFlow: Efficient Dataflow-based Invocation Workflow Execution for Function-as-a-Service
Li et al. An Improved Real-time Scheduling Algorithm Based on Deadline Constraint
Vargas et al. Grand: Toward scalability in a grid environment
Gutiérrez et al. Modeling and schedulability analysis in the development of real-time distributed ada systems
CN114217915A (en) Lightweight multithreading mechanism based on master-slave model on heterogeneous many-core
CN116821041A (en) Efficient queue access for user space packet processing

Legal Events

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

Ref document number: 13871963

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 13871963

Country of ref document: EP

Kind code of ref document: A1