CN102479107A - Method for scheduling program - Google Patents

Method for scheduling program Download PDF

Info

Publication number
CN102479107A
CN102479107A CN2010105594332A CN201010559433A CN102479107A CN 102479107 A CN102479107 A CN 102479107A CN 2010105594332 A CN2010105594332 A CN 2010105594332A CN 201010559433 A CN201010559433 A CN 201010559433A CN 102479107 A CN102479107 A CN 102479107A
Authority
CN
China
Prior art keywords
message
task
function
formation
mission
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2010105594332A
Other languages
Chinese (zh)
Inventor
汪旭光
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
TIANJIN ZHONGXING SOFTWARE Co Ltd
Original Assignee
TIANJIN ZHONGXING SOFTWARE Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by TIANJIN ZHONGXING SOFTWARE Co Ltd filed Critical TIANJIN ZHONGXING SOFTWARE Co Ltd
Priority to CN2010105594332A priority Critical patent/CN102479107A/en
Publication of CN102479107A publication Critical patent/CN102479107A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Executing Machine-Instructions (AREA)

Abstract

The invention discloses a method and a device for scheduling a processor program. The method comprises the following steps of: setting at least one task function for realizing a preset function in the processor program, and allocating a task ID (identifier) to each task function; setting a message queue, wherein each message in the message queue comprises a task ID and a data transmission pointer; and extracting the messages in the message queue, searching the corresponding task functions according to the task IDs in the messages, transmitting the data transmission pointer in the messages to the task functions, and scheduling the task functions to execute operation. By utilizing the method and the device, the designability and execution efficiency of the program are improved.

Description

A kind of method of program scheduler
Technical field
The present invention relates to field of software development, relate in particular to program scheduler method and the devices in the exploitation of low and middle-end processor program such as 8,16.
Background technology
Processor generally has high-end and branch low side.High-end processor, for example high-end single-chip microcomputer, the system resource of high-end single-chip microcomputer is abundant, and general the transplanting has operating system.The low side processor, low and middle-end single-chip microcomputers such as for example 8,16, the system resource of low and middle-end single-chip microcomputer is limited, if the graft procedure system because operating system takies a large amount of system resource, makes single-chip microcomputer carry out inefficiency, even can not move.
With the low and middle-end single-chip microcomputer is example, and existing way is, a master routine is set in SCM program, and the main function of an infinite loop is set in the master routine, and this main function is realized all functions of single-chip microcomputer.
Take the defective of this mode to be, the main function of an infinite loop is accomplished all functions of SCM program, makes the structural variation of calling program; Especially the function of working as single-chip microcomputer is more; When program is big, almost there is nothing structural, and; When the programmer wanted maintenance or revises SCM program, very difficulty also can become.Simultaneously, it is also very low that the single-chip microcomputer of this mode is carried out efficient, because the main function adopts top-down execution mechanism; The shortcoming of this mechanism is; Where the subfunction of not knowing to realize specific function can only begin from the first statement of main function to carry out, up to the subfunction that is triggered to expectation; Just carry out subfunction, realize particular functionality.If realize the afterbody of the subfunction of specific function at the main function, this will be a thing that ten minutes is consuming time.
Therefore, in the prior art, the defective that the low and middle-end SCM program exists is: complex structure, it is low to carry out efficient.
Summary of the invention
The technical problem underlying that the present invention will solve is, a kind of dispatching method and device of processor program is provided, and adopts this method and apparatus can improve the structural of processor program, and it is high to carry out efficient.For solving the problems of the technologies described above, the present invention provides a kind of SCM program dispatching method, comprising:
The mission function that at least one is used to realize predetermined function is set in processor program, and is each mission function configuration task ID;
Message queue is set, and each the bar message in the said message queue comprises a task ID and transmits data pointer;
Extract the message in the message queue, search corresponding mission function, and pass to mission function to the transmission data pointer in the message, the scheduler task executable operations according to the task ID in the message.
In a preferred embodiment of the present invention, processor is a single-chip microcomputer.
In a preferred embodiment of the present invention, message also comprises message id, search corresponding mission function according to the task ID in the message after, the message id in the message with transmit data pointer and pass to mission function, scheduler task function executable operations.
In another embodiment of the present invention, message queue comprises interrupt message formation and task message formation, and the priority of interrupt message formation is higher than the task message formation; The message of extracting in the message queue specifically comprises: judge whether the interrupt message formation has message, if any, then from interrupting message queue cancellation breath; As not, judge then whether the task message formation has message, if any; Then cancellation breath from the task message formation as not, then calls Hook Function.
Further, message queue is a circle queue, when extracting the message in the message queue, presses the principle of FIFO and extracts the message in the message team.
The invention also discloses a kind of processor program dispatching device, comprising:
The mission function module is used at processor program the mission function that at least one is used to realize predetermined function being set, and is each mission function configuration task ID;
The message queue module is used to be provided with message queue, and each the bar message in the message queue comprises a task ID and transmits data pointer;
Sending module is used for extracting the message of message queue, searches corresponding mission function according to the task ID in the message, and passes to mission function to the transmission data pointer in the message, scheduler task function executable operations.
In a kind of preferred embodiment of the present invention, processor is a processor of single chip computer,
In a kind of preferred embodiment of the present invention, message also comprises message id, said search corresponding mission function according to the task ID in the message after, the message id in the message with transmit data pointer and pass to mission function, scheduler task function executable operations.
In another embodiment of the present invention, message queue comprises interrupt message formation and task message formation, and the priority of interrupt message formation is higher than the task message formation; Message in the said extraction message queue specifically comprises: judge whether said interrupt message formation has message, if any, then from said interrupt message formation cancellation breath; As not, judge then whether said task message formation has message, if any; Then cancellation breath from said task message formation as not, then calls Hook Function.
The invention has the beneficial effects as follows:
Processor comprises at least one mission function, has improved the structural of program, makes calling program be more conducive to programmer's maintenance or modification, can not influence other mission function to the modification of particular task function.Simultaneously; To comprise the trigger mechanism that task ID and the message that transmits data pointer are carried out as the triggering mission function; Improved execution efficient; That is: through the corresponding mission function of task ID (task number) index, transmit the operation that data pointer finishes the work function for the mode of mission function, improved the execution efficient of single-chip microcomputer through transmitting.
In a kind of preferred mode; Message comprises message number, and when the mission function transmission transmits data pointer, pass-along message ID (message number) gives mission function; Operation by the more accurate index mission function of message id will be carried out further improves executing efficiency.Just message id, mission function ID and transmission data pointer all will take certain space, and the composition that message rationally is set according to actual conditions can reach best effect.
Description of drawings
Fig. 1 is the SCM program dispatching method process flow diagram of an embodiment of the present invention;
Fig. 2 is the task chart of an embodiment of the present invention;
Fig. 3 is the message queue structural drawing of an embodiment of the present invention;
Fig. 4 is provided with the message queue process flow diagram for an embodiment of the present invention;
Fig. 5 is the scheduler task function process flow diagram of an embodiment of the present invention;
Fig. 6 is the SCM program dispatching device structural representation of an embodiment of the present invention.
Embodiment
Combine accompanying drawing that the present invention is done further explain through embodiment below.
Processor comprises high-end processor and low and middle-end processor, is example with the single-chip microcomputer, and high-end has, 64 single-chip microcomputers, low and middle-end single-chip microcomputers such as 8,16 are arranged.For high-end processor; The general transplanting has operating system, and travelling speed is than very fast, and the low and middle-end processor is because system resource is limited; Be not suitable for the graft procedure system, so the dispatching method of processor program seems even more important for improving the processor travelling speed.With 8,16 single-chip microcomputers are example below, explain the present invention is that the processor program dispatching method is how to improve executing efficiency.It is understandable that; Though the present invention relatively is fit to not have the low and middle-end processor of graft procedure system, if low and middle-end single-chip microcomputers such as especially 8,16 are high-end processor; Such as the program scheduler method that high-end single-chip microcomputer adopts the present invention to conceive, equally belong to the scope of the present invention's protection.Below, be example with low and middle-end single-chip microcomputers such as 8,16, specify inventive concept of the present invention:
In the prior art; The low and middle-end single-chip microcomputer generally is employed in the mode that an infinite loop is set in the main function and realizes user function; This mode makes the program structure property variation of single-chip microcomputer, and when the function that especially will realize as the user was a lot, program can be very complicated; This moment, the main function did not almost have structurally, and this safeguards to the programmer or revises user program and brought very big puzzlement.Simultaneously, the operating mechanism of main function adds factors such as program structure property difference, and it is low to cause single-chip microcomputer of the prior art to carry out efficient, can not realize the function of expecting fast.
Based on this, the present invention at first is divided into the mission function that is used to realize predetermined function one by one with SCM program, improves the structural of SCM program with this, has increased the convenience of programmer or user's modification program.Drive mission function with message event then and carry out intended function, thereby improved executing efficiency.In this process, each task sharing system stack helps conserve system resources.
Embodiment 1:
As shown in Figure 1, the embodiment of the invention provides a kind of SCM program dispatching method, comprising:
11, at least one mission function is set in SCM program, mission function is used to realize intended function, and is each mission function configuration task ID.
12, message queue is set, each bar message comprises task ID and transmits data pointer in the message queue;
13, the message in the extraction message queue, the mission function corresponding according to the task ID index, and to its transmission transmission data pointer, scheduler task function executable operations.
In the step 11, the number of mission function is decided according to actual conditions in the SCM program, and the function of mission function also confirms in advance that by user or programmer each mission function can only be realized a function, also can realize a plurality of functions.Each mission function is by corresponding with it task ID index,
Ask like Fig. 2; In one embodiment; Dispose the task list that is specifically designed to the index mission function, this table comprises task ID and mission function handle, and task ID and mission function handle are corresponding one by one; The mission function handle is exactly corresponding function pointer with regard to the task function, just mission function entry reference.In this table, task ID and mission function handle can be filled in by the user, and the form of expression of this table in code can be the form of two-dimensional array.Certainly, also can be provided with flexibly according to actual conditions.
In the step 12, each the bar message in the message queue comprises task ID and transmits data pointer.The corresponding mission function handle of task ID; Be the mission function pointer, be used for the index mission function, transmit and attach the parameter of transmitting when data pointer is used for sending message between task; If there are data to need to transmit; Can the pointer of data to be passed be filled into this, if there are not data to need to transmit, this transmits data pointer is empty.
As shown in Figure 3, in one embodiment, message queue is a circle queue, and this message queue can be represented the interrupt message formation, also can represent the task message formation, and the shape of interrupt message formation and task message formation is identical with structure.Each bar message in this message queue also comprises message id (being message number) except that comprising described task ID and transmitting the data pointer.This message id number is user oneself definition, and what each ID representes is specified according to service needed by the user.Such as; In the single-chip microcomputer operational process; Find the corresponding mission function of this task according to the task ID in the message, call this function then and message id and transmission data pointer are passed to this mission function as function parameter, message id is used to indicate mission function specifically to realize what function.That is to say that mission function possibly have a plurality of functions, message id then points out mission function to realize one of them or several function, specifically realize several, by consumer premise justice.Just; In the program process; With one of task ID index (mission function) on a large scale, with one on the accurate rope of message id (certain function in the mission function) among a small circle, thus structural and operational efficiency that can more effective raising program; Especially under the more situation of program function, more effective.In the actual conditions; Message id and task ID generally take a byte, transmit data pointer and in 8 single-chip microcomputers, take 1 bit byte, in 16 single-chip microcomputers, take 2 words; But this is not unique mode, and specifically taking byte number can rationally confirm according to actual conditions.
In the diagram, SIZE representes the message number that this message queue can be deposited, such as, SIZE=11 representes that this message queue can be deposited 11 message, and IN representes the address that message deposits in, and when OUT represented the cancellation breath, first need cancel the address of breath.Be original state when OUT=IN, this moment, message queue was empty; When IN+1=OUT, message queue is full.Message is deposited according to the mode of FIFO in this formation.
As shown in Figure 4, to have represented the message queue process flow diagram is set in a kind of embodiment, in this embodiment, message queue is a circle queue.Diagram is provided with the message queue flow process and promptly can representes to be provided with interrupt message formation flow process, also can represent to be provided with task message formation flow process.This flow process specifically comprises:
1) judges that, at first IN adds 1 and whether equals OUT,, represent that current message pool piled message, do not have unnecessary space to deposit new information if equal.At this moment, then return queue full to sending messaging program; If be not equal to, then descend the step;
2), add message data (message number, task number and transmission data pointer) to address that IN points to.
3), IN adds 1, and judges whether the IN that adds after 1 equates with SIZE.After promptly judgement deposits message in, whether arrived the afterbody of circle queue, if, then IN is changed to 0, come back to the circle queue head, expression needs begin to deposit in message from the circle queue head; If IN and SIZE are unequal, then return OK, expression can continue to add place, address pointed, 1 back at IN and deposit message.
In the step 13, when extracting in the message queue message, judge whether message queue has message earlier, if any; Then extract message, carry out scheduled operation, as denying according to the message trigger mission function; Then call and carry out the HOOK function, i.e. Hook Function, Hook Function is the call back function that needs execution specified conditions under.Among the present invention, carrying out Hook Function is not have message in the message queue with condition, and the operation that this Hook Function will be carried out is fully by user's realization, carry out what operation can, also can carry out blank operation.But Hook Function was unfit to do multioperation, otherwise can cause system real time to reduce, such as; In one embodiment; After not having message in the judgement message queue, directly carry out blank operation (also can realize), can not have any impact like this system with Hook Function.
As shown in Figure 5, represented scheduler task function process flow diagram in a kind of embodiment.In this embodiment, message queue comprises interrupt message formation and task message formation, and the priority of interrupt message formation is higher than the task message formation, when promptly extracting message; Earlier judge whether the interrupt message formation has message, if any, then cancellation ceases from interrupt message queue; As not, judge then whether message is arranged in the task message formation, if any; Then cancellation breath from the task message formation as not, then calls the HOOK function.Message comprises message number, task number and transmission data pointer in this embodiment, certainly, also can not comprise message number, specifically decides according to actual conditions.
This flow process detailed process comprises:
1), judge whether the interrupt message formation has message, judge promptly whether the IN of interrupt message formation equals OUT,, forward step 2 to if equate); If it is unequal; Promptly representing has message in the interrupt message formation; Then cancellation ceases from interrupt message queue, promptly writes down the value of * OUT, just writes down the information (message id, task ID and transmission data pointer) that OUT points to the address; Can take the mode that message is stacked to preserve, forward step 3) then to;
2), judge whether message is arranged in the task message formation, judge promptly whether the IN in the task message equals OUT, if equate, the formation of expression task message does not have message yet, then calls and carries out the HOOK function.As unequal, in the formation of expression task message message is arranged, then cancellation ceases from the task message formation, and promptly logger task message * OUTR value goes to step 4) then;
3), judge whether OUT equals SIZE in the interrupt message formation, if equate, show that OUT has pointed to the circle queue afterbody, forward step 5) to after OUT is put 0.If unequal, directly forward step 5) to;
4), judge whether OUT equals SIZE in the task message formation, if equate, show that OUT has pointed to the circle queue afterbody, forward step 5) to after OUT is put 0.If unequal, directly forward step 6) to;
5), the mission function corresponding according to the task I D index in the message of preserving, with message number with transmit data pointer and pass to mission function as function parameter, mission function according to message number with transmit the data pointer executable operations;
6), the mission function corresponding according to the task ID index in the message of preserving, with message number with transmit data pointer and pass to mission function as function parameter, mission function according to message number with transmit the data pointer executable operations;
7), return beginning.
Embodiment 2:
As shown in Figure 6, a kind of SCM program dispatching device comprises:
Mission function module 2 is used at said SCM program the mission function that at least one is used to realize predetermined function being set, and is each mission function configuration task ID;
Message queue module 1 is used to be provided with message queue, and each the bar message in the said message queue comprises a said task ID and transmits data pointer;
Sending module 3 is used for extracting the message of message queue, searches corresponding mission function according to the task ID in the message, and passes to mission function to the transmission data pointer in the message, and the scheduler task function is executed the task according to the data pointer that transmits.
In a kind of mode of priority of present embodiment; Each message in the message queue module comprises message I D; Search the mission function of correspondence according to the task ID in the message after, pass to mission function to message id in the message and transmission data pointer, scheduler task function executable operations.
In another embodiment of present embodiment, message module comprises interrupt message formation and task message formation, and the priority of interrupt message formation is higher than the task message formation; The message of extracting in the message queue specifically comprises: judge whether the interrupt message formation has message, if any, then from interrupting message queue cancellation breath; As not, judge then whether the task message formation has message, if any; Then cancellation breath from the task message formation as not, then calls Hook Function.
Can also message queue be made as circle queue, message is arranged in the message queue by the principle of FIFO.
SCM program dispatching method and device in the embodiment of the invention, through being one or more mission functions with procedure division, each mission function function of realization or a plurality of function or a series of relevant function are decided according to actual conditions.Because program is made up of the mission function module, has increased the structural of program, be beneficial to programmer or user to the specific part update routine, such as, to a certain mission function.Simultaneously, adopt message (comprising message number, task number and transmission data pointer), improved program implementation speed as the mechanism that triggers mission function.Because the task number in the message is corresponding one by one with the mission function pointer in task list, and the corresponding mission function of mission function pointed, thereby can index the mission function that needs apace through task ID.Then with message number with transmit the form of data pointer and pass to mission function with function parameter; The function that message number can indicate mission function to realize fast; Generally, mission function is the set of a plurality of power functions, certainly also not the Exclusion Tasks function only realize the situation of a function.Transmit the data that data pointer pointing system or other task need pass to mission function, according to transmitting data pointer, mission function can the calling system internal memory in corresponding transmission data, thereby realize intended function.Simultaneously, transferred data deposit in the Installed System Memory, through transmitting the data pointer index, are equivalent to, and each task can be shared the transmission data according to transmitting data pointer, thereby has practiced thrift internal memory, and the low and middle-end single-chip microcomputer limited for system resource is even more important.Method and device through message trigger SCM program execution predetermined function have improved executing efficiency.
Above content is to combine concrete embodiment to the further explain that the present invention did, and can not assert that practical implementation of the present invention is confined to these explanations.For the those of ordinary skill of technical field under the present invention, under the prerequisite that does not break away from the present invention's design, can also make some simple deduction or replace, all should be regarded as belonging to protection scope of the present invention.

Claims (6)

1. a processor program dispatching method is characterized in that, comprising:
The mission function that at least one is used to realize predetermined function is set in said processor program, and is each mission function configuration task ID;
Message queue is set, and each the bar message in the said message queue comprises a said task I D and transmits data pointer;
Extract the message in the message queue, search corresponding mission function, and pass to mission function to the transmission data pointer in the message, scheduler task function executable operations according to the task ID in the message.
2. processor program dispatching method as claimed in claim 1 is characterized in that, said processor is a processor of single chip computer.
3. according to claim 1 or claim 2 processor program dispatching method; It is characterized in that; Said message also comprises message id; Said search corresponding mission function according to the task I D in the message after, the message id in the message with transmit data pointer and pass to mission function, scheduler task function executable operations.
4. processor program dispatching method as claimed in claim 3 is characterized in that, said message queue comprises interrupt message formation and task message formation; The priority of interrupt message formation is higher than the task message formation, and the message in the said extraction message queue specifically comprises: judge whether said interrupt message formation has message, if any; Then,, judge then whether said task message formation has message as not from said interrupt message formation cancellation breath; If any; Then cancellation breath from said task message formation as not, then calls Hook Function.
5. processor program dispatching method as claimed in claim 4 is characterized in that, said message queue is a circle queue, when extracting the message in the message queue, extracts the message in the said message team by the principle of FIFO.
6. according to claim 1 or claim 2 processor program dispatching method; It is characterized in that; Also comprise the task list that is provided for the index mission function; Said task list comprises task ID and mission function pointer one to one, and the mission function that said mission function pointed is corresponding is through the correspondence of task list realization task ID and mission function.
CN2010105594332A 2010-11-23 2010-11-23 Method for scheduling program Pending CN102479107A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2010105594332A CN102479107A (en) 2010-11-23 2010-11-23 Method for scheduling program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2010105594332A CN102479107A (en) 2010-11-23 2010-11-23 Method for scheduling program

Publications (1)

Publication Number Publication Date
CN102479107A true CN102479107A (en) 2012-05-30

Family

ID=46091760

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2010105594332A Pending CN102479107A (en) 2010-11-23 2010-11-23 Method for scheduling program

Country Status (1)

Country Link
CN (1) CN102479107A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110442439A (en) * 2019-08-05 2019-11-12 北京百佑科技有限公司 Task process processing method, device and computer equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110442439A (en) * 2019-08-05 2019-11-12 北京百佑科技有限公司 Task process processing method, device and computer equipment
CN110442439B (en) * 2019-08-05 2022-04-01 北京百佑科技有限公司 Task process processing method and device and computer equipment

Similar Documents

Publication Publication Date Title
CN101950260A (en) Processor program dispatching method and device
CN107526624B (en) Intelligent contract execution engine based on Java virtual machine
CN100585563C (en) Method for servicing task of timer
CN102110022B (en) Sensor network embedded operation system based on priority scheduling
CN101859260B (en) Timer management device and management method for operating system
CN109684060B (en) Mixed scheduling method for multiple types of time-critical tasks
CN105045658B (en) A method of realizing that dynamic task scheduling is distributed using multinuclear DSP embedded
CN104156264B (en) A kind of base band signal process tasks in parallel real-time scheduling method based on many GPU
CN102118261A (en) Method and device for data acquisition, and network management equipment
CN103473129B (en) Multi-task queue scheduling system with scalable number of threads and implementation method thereof
CN101510163B (en) Processing method and system for planning task
CN106101021B (en) A kind of real-time execution dispatching method of Ethernet system functional block
CN105187327A (en) Distributed message queue middleware
CN103823706B (en) A kind of plant model analog simulation real-time scheduling method based on RTLinux
CN101667147A (en) Multitasking controllable automatic snapshot method
CN103092682A (en) Asynchronous network application program processing method
CN101751289A (en) Mixed scheduling method of embedded real-time operating system
CN106506389A (en) Network request asynchronous processing method and device
CN109670199A (en) A kind of efficient power network topology analysis method and device
CN100593146C (en) Method for preventing industrial automation system from snowslip
CN101452399A (en) Task secondary scheduling module and method
CN101968749B (en) Method for receiving message passing interface (MPI) information under circumstance of over-allocation of virtual machine
CN102831046A (en) Method and device for collecting software performance in communication system
CN100383743C (en) Real-time task scheduling method in Java operating system
CN102479107A (en) Method for scheduling program

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20120530