Scheduling method based on threads
By splitting loop instances into event instances and scheduling them in groups based on critical section resources, the problem of automatic adjustment of thread parallelization scheduling in system modeling is solved, thereby improving parallel performance and efficiency.
Patent Information
- Application Number
- CN202410992535.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2026-01-23
AI Technical Summary
In existing technologies, the source code of system modeling needs to be modified to achieve parallel scheduling of threads, and the number of parallel threads cannot be automatically adjusted to adapt to different concurrent processes, resulting in low execution efficiency.
By obtaining the loop instance of the target thread, identifying the pause statements in the loop content and splitting them into event instances, querying critical section resources and performing group scheduling, parallel scheduling of threads can be achieved without modifying the source code.
It improves the parallel performance of threads and the efficiency of system utilization, reduces modeling time, and enables automatic adjustment of the number of parallel threads to adapt to different concurrent processes.
Smart Images

Figure CN121387451A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the field of communication, in particular to a thread-based scheduling method. BACKGROUND
[0002] SystemC is usually used for integrated circuit system modeling. With the increasing scale of integrated circuits, the running time of system modeling makes system modeling a bottleneck in the design process. Parallelization of systemC using multi-core servers and other facilities to improve simulation efficiency has become an increasingly important means.
[0003] Currently, there are many methods for parallel running of threads in computer system software, such as thread class, Portable Operating System Interface for UNIX (POSIX) thread library, Intel Threading Building Blocks (TBB), Open Multi-Processing (OpenMP), etc. Taking OpenMP as an example, OpenMP is an Application Programming Interface (API) for writing parallel threads, which can be used for parallel computing on shared memory architecture. Based on a multi-processor system, by adding special instructions in the source code to indicate parallel regions and adding synchronization and mutual exclusion instructions in the data critical section, the compiler can parallelize threads to achieve parallel scheduling of threads.
[0004] However, this method requires modification of the modeling source code and cannot automatically adjust the number of parallel threads to adapt to different concurrent processes. SUMMARY
[0005] Embodiments of the present application provide a thread-based scheduling method to at least solve the problem that the method of modifying source code to achieve parallel scheduling of threads in related technologies cannot automatically adjust the number of parallel threads to adapt to different concurrent processes.
[0006] According to an embodiment of the present application, a thread-based scheduling method is provided, comprising:
[0007] obtaining a loop instance of a target thread, and identifying running loop content in the loop instance and a pause statement in the loop content;
[0008] splitting the loop content according to the pause statement to generate at least one event instance for separate running;
[0009] query critical section resources accessed by the event instance, and group the event instance according to the queried critical section resources, and schedule the grouped event instance in parallel.
[0010] According to still another embodiment of the present application, a computer readable storage medium is also provided, which stores a computer program, wherein the computer program is configured to perform the steps of any of the above method embodiments when executed.
[0011] According to still another embodiment of the present application, an electronic device is also provided, which comprises a memory and a processor, the memory stores a computer program, and the processor is configured to execute the computer program to perform the steps of any of the above method embodiments.
[0012] According to still another embodiment of the present application, a computer program product is also provided, which comprises a computer program, and the computer program is executed by a processor to implement the steps of any of the above method embodiments.
[0013] In the embodiments of the present application, a loop instance of a target thread is acquired, and running loop content in the loop instance and a pause statement in the loop content are identified; the loop content is split according to the pause statement, and at least one event instance for separate running is generated; critical section resources accessed by the event instance are queried, and the event instance is grouped according to the queried critical section resources, and the grouped event instance is scheduled in parallel. Thus, the parallelization of the thread is realized, and the thread code does not need to be modified, thereby solving the problem that the related art cannot automatically adjust the number of parallel threads to adapt to different concurrent processes in the manner of modifying the source code to realize the parallelization and scheduling of the thread, fully improving the parallel performance of the thread and the system utilization efficiency, and greatly reducing the modeling time. BRIEF DESCRIPTION OF DRAWINGS
[0014] Figure 1 is a hardware structure block diagram of a computer terminal of a thread-based scheduling method according to an embodiment of the present application;
[0015] Figure 2 is a system architecture diagram of a thread-based scheduling method according to an embodiment of the present application;
[0016] Figure 3 is a flowchart of a thread-based scheduling method according to an embodiment of the present application;
[0017] Figure 4 is a flowchart of splitting loop content in a loop instance according to an embodiment of the present application;
[0018] Figure 5 is a flowchart of assigning a scheduling queue to an event instance according to an embodiment of the present application;
[0019] Figure 6 is a flowchart of a scheduling queue for assigning a corresponding critical section resource to an event instance according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] Hereinafter, embodiments of the present application will be described in detail with reference to the accompanying drawings and in conjunction with embodiments.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and in the above-described drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence.
[0022] A systemC modeling model usually has a global clock, and all modeling thread loop instances SC_THREAD need to be synchronized under the synchronization of the global clock, and are scheduled to run to achieve clock-accurate modeling results. In addition, multiple modeling thread loop instances SC_THREAD often access critical section resources or models and resources with mutual exclusion requirements, such as global variables, ports, or FIFOs, at the same scheduling time; the internal scheduling algorithm of systemC executes all modeling thread SC_THREAD in a single-threaded manner, one after another, and cannot fully utilize the resources of a multi-core server, affecting the running speed.
[0023] Moreover, the execution content of the modeling thread is located inside the while loop statement of SC_THREAD, and the modeling runs continuously without exiting during the running period, and when the current period is executed, the current stack needs to be saved in order to continue running at the last execution position in the next time slice, and the parallel operation of the stack will destroy the stack content, so the SC_THREAD of the modeling thread cannot be directly implemented in whole parallelization.
[0024] The current method for implementing modeling thread parallelization usually modifies the modeling source code, and implements thread parallelization through manual modification or compiler instructions, however, this method not only cannot automatically adjust the number of parallel threads to adapt to different concurrent processes and fine-grained critical data access, but also uses synchronization and mutual exclusion instructions in large-grained critical section resource usage, which makes the critical section resource be accessed in series, reducing the execution efficiency.
[0025] Based on the aforementioned technical problems, this application proposes a thread-based scheduling method. The technical concept involves splitting the loop content of the loop instance SC_THREAD of the modeling thread into one or more event instances SC_METHOD. Then, based on the critical data accessed by each SC_METHOD, the SC_METHODs are grouped and scheduled in parallel, achieving thread parallelization based on the SystemC kernel. Furthermore, the code of the modeling thread does not need to be modified. This solves the problem in related technologies where the number of parallel threads cannot be automatically adjusted to adapt to different concurrent processes and fine-grained critical data access. It not only improves the parallel performance and system utilization efficiency of SystemC modeling but also significantly reduces modeling time.
[0026] The methods and embodiments provided in this application can be executed on a mobile terminal, a computer terminal, or a similar computing device. Taking running on a computer terminal as an example, Figure 1 This is a hardware structure block diagram of a computer terminal using a thread-based scheduling method according to an embodiment of this application. Figure 1 As shown, a computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0027] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the thread-based scheduling method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thus implementing the aforementioned method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0028] The transmission device 106 is configured to receive or send data via a network. The network can include a wireless network provided by a communication provider of the computer terminal. In an example, the transmission device 106 includes a network adapter (NIC) that can be connected to other network devices through a base station to communicate with the Internet. In an example, the transmission device 106 can be a radio frequency (RF) module configured to communicate with the Internet in a wireless manner.
[0029] Figure 2 is a system architecture diagram of a thread-based scheduling method according to an embodiment of the present application. The embodiment of the present application can run on the system architecture as shown in Figure 2 , and as shown in Figure 2 , the system architecture includes a conversion and splitting module, a critical section resource scanning module, a scheduling configuration module, and a parallel scheduling execution module.
[0030] The conversion and splitting module can be configured to split the loop instances (such as sc_thread1 and sc_thread2) and convert them into event instances (such as sc_method1 and sc_method2) that can be run independently.
[0031] The critical section resource scanning module can be configured to scan the critical section resources accessed by each event instance to query the critical section resources corresponding to each event instance.
[0032] The scheduling configuration module can be configured to group the event instances according to the queried critical section resources, and allocate the grouped event instances to corresponding scheduling queues.
[0033] The parallel scheduling execution module can be configured to run the event instances in the scheduling queues in parallel.
[0034] In the embodiment, a thread-based scheduling method running on the computer terminal is provided, Figure 3 is a flowchart of a thread-based scheduling method according to an embodiment of the present application. As shown in Figure 3 , the flowchart includes the following steps:
[0035] In step S301, the loop instances of a target thread are obtained, and the running loop content in the loop instances and the pause statements in the loop content are identified.
[0036] In an embodiment of the present application, the loop instance SC_THREAD of the thread can be continuously running and can save breakpoint recovery. The loop instance can be the content executed by the thread at each time point, which can include loop content (e.g., periodic data processing, etc.) and non-loop content (e.g., state update, etc.) executed by the thread at consecutive time points. The execution of the thread can control the execution time of the thread by calling the pause function wait() in the loop instance, the next trigger function next_trigger(), etc.
[0037] As an example, the loop content can be code with a loop structure and running in the loop instance. The loop content can be serially run in a loop period. The loop content can include single execution content, which can include at least one pause statement WAIT.
[0038] For example, the content in the loop instance SC_THREAD of the target thread can be scanned to identify the loop content in the SC_THREAD, to extract the single execution content of the loop content, and to identify the pause statement WAIT in the single execution content.
[0039] In step S302, the loop content is split according to the pause statement to generate at least one event instance for separate running.
[0040] In an embodiment of the present application, the loop content in the SC_THREAD can be split to eliminate the loop structure and the pause statement WAIT in the loop content.
[0041] As an example, the loop content in the loop instance SC_THREAD of the thread can be split to obtain at least one event instance SC_METHOD that can be executed separately. The scheduling of the event instance can be triggered by an event, and when an event is notified, the corresponding SC_METHOD is executed. The event instance is run by the event and does not involve time change.
[0042] For example, in an embodiment of the present application, the loop instance SC_THREAD of the thread that needs to be continuously running and save breakpoint recovery can be replaced by the event instance SC_METHOD that can exit the current time slice to realize the parallelization of the thread.
[0043] As an example, the loop content can run with multiple pause statements WAIT, and the running content between adjacent two pause statements WAIT in the loop content can be extracted in sequence. For each running content, a corresponding event instance is generated.
[0044] For example, the execution content between the current WAIT and the next WAIT can be taken as the execution content of an event instance SC_METHOD, and the loop content of the loop instance SC_THREAD can be split into one or more event instances SC_METHOD.
[0045] In an exemplary embodiment, the loop content includes a plurality of pause statements, and the splitting of the loop content according to the pause statements generates at least one event instance for separate running, including:
[0046] obtaining a syntax tree corresponding to the loop content; the syntax tree includes a pause node corresponding to each pause statement of the plurality of pause statements;
[0047] splitting the syntax tree according to the pause nodes to generate at least one sub-syntax tree and the event instance corresponding to each sub-syntax tree; wherein the sub-syntax tree is used to generate the event instance for separate running.
[0048] As an example, a pause statement WAIT is generally used in the loop content WHILE in SC_THREAD to wait for a time or an event. The loop content can include a plurality of pause statements, and the loop content can correspond to a tree-shaped syntax tree, which can include a pause node corresponding to each pause statement of the plurality of pause statements. The syntax tree can be split into at least one sub-syntax tree based on the pause nodes.
[0049] As an example, a syntax tree corresponding to the loop content can be obtained, and the syntax tree of the loop content can be split based on the pause nodes to generate at least one sub-syntax tree and the event instance corresponding to each sub-syntax tree; wherein the sub-syntax tree can be used to generate the event instance for separate running.
[0050] In an exemplary embodiment, the splitting of the syntax tree according to the pause nodes generates at least one sub-syntax tree and the event instance corresponding to each sub-syntax tree, including:
[0051] extracting, in sequence, running content corresponding to adjacent two pause nodes in the syntax tree;
[0052] for each running content, generating a sub-syntax tree and the event instance corresponding to the sub-syntax tree.
[0053] As an example, the syntax tree corresponding to the loop content can include a plurality of pause nodes, the running content corresponding to adjacent two pause nodes in the syntax tree can be extracted in sequence, and for each running content, a sub-syntax tree and the event instance corresponding to the sub-syntax tree can be generated.
[0054] For example,Figure 4 is a flowchart of splitting the loop content in a loop instance according to an embodiment of the present application, which can include the following steps as shown in Figure 4
[0055] 1) scanning the wait nodes in the syntax tree of the loop content;
[0056] As an example, the source node of the syntax tree of the loop content can be a loop node, which can include a loop statement block node, and the loop statement block node can include a wait node.
[0057] 2) determining whether the number of current wait nodes is greater than 1;
[0058] 3) if no, i.e. the number of wait nodes is equal to 1, deleting the loop node and the wait node and generating a loop statement block node at the position of the loop node;
[0059] 4) generating the source code of the SC_METHOD instance according to the content corresponding to the loop statement block node;
[0060] 5) if yes, i.e. in the case that the number of wait nodes is greater than 1, creating a sub-syntax tree of the syntax tree based on the wait nodes;
[0061] 6) adding the content between the current wait node and the next wait statement node to the sub-syntax tree, and generating the SC_METHOD instance based on the sub-syntax tree;
[0062] 7) deleting the content corresponding to the current wait node and the next wait node in the syntax tree;
[0063] 8) scanning the next wait node;
[0064] 9) determining whether the wait node in the current syntax tree is the last one;
[0065] 10) if yes, returning to steps 3)-4); if no, returning to steps 5)-9) until the wait node in the current syntax tree is the last one.
[0066] In an exemplary embodiment, it further includes:
[0067] obtaining the sensitive list of the loop instance;
[0068] generating the sensitive list of each event instance according to the pause statement and the sensitive list of the loop instance;
[0069] The sensitive list of the loop instance includes at least one event, each of the pause statements corresponds to at least one event, the sensitive list of each of the event instances includes at least one event corresponding to the pause statement, and the event in the sensitive list of the event instance is used to drive the event instance to access the critical section resource.
[0070] As an example, the sensitive list of the loop instance can include at least one event, and the event in the sensitive list of the loop instance can drive the loop instance to run according to the time sequence relationship of each event.
[0071] Embodiments of the present application can generate a corresponding sensitive list of the event instance according to the sensitive list of the loop instance and the pause statement in the loop instance. For example, the execution content of the two WAIT statements can be extracted to generate an event instance SC_METHOD and a corresponding sensitive list, and the time sequence relationship of the event can be controlled by a clock or a sensitive list.
[0072] The sensitive list of the event instance can include at least one event corresponding to each pause statement, and the event in the sensitive list of the event instance can be used to drive the corresponding event instance to run, for example, to drive the corresponding event instance to access the critical section resource.
[0073] In step S303, the critical section resource accessed by the event instance is queried, and the event instance is grouped according to the queried critical section resource, and the grouped event instance is scheduled in parallel.
[0074] As an example, the critical section resource can refer to a shared resource that needs to be accessed by multiple threads or processes in a multi-threaded or concurrent execution environment.
[0075] Embodiments of the present application can query the critical section resource accessed by the event instance, group the event instance according to the queried critical section resource, and schedule the grouped event instance in parallel.
[0076] In an exemplary embodiment, the querying of the critical section resource accessed by the event instance includes:
[0077] According to the event in the sensitive list of the event instance, the critical section resource accessed by the event driven event instance is queried.
[0078] As an example, the sensitive list of the event instance is used to query the critical section resource accessed by the event instance corresponding to the event in the sensitive list of the event instance.
[0079] In an exemplary embodiment, the grouping of the event instance according to the queried critical section resource includes:
[0080] According to the critical section resource accessed by the event instance queried, determine the event instance accessing the same critical section resource, and configure the same queue identifier;
[0081] The event instances with the same queue identifier are assigned to the same instance group.
[0082] Exemplarily, the critical section resource can refer to a shared resource accessed by multiple event instances, including a region and data requiring mutual exclusion access, for ensuring that only one event instance can access at any moment.
[0083] As an example, the critical section resource accessed by the SC_METHOD instance can be identified, and each SC_METHOD instance can be grouped according to the critical section resource accessed by each SC_METHOD instance, so that the SC_METHOD instances accessing a certain critical section resource can be ensured to be in the same group.
[0084] As an example, the SC_METHOD instances accessing the same critical section and mutual exclusion data can be configured with the same queue identifier, and the SC_METHOD instances with the same queue identifier can be assigned to the same instance group.
[0085] For example, if multiple SC_METHOD instances involve accessing the same critical section and mutual exclusion data, the same queue identifier GROUP ID can be configured for each of the multiple SC_METHOD instances, and the multiple SC_METHOD instances with the same GROUP ID can be assigned to the same instance group.
[0086] As an example, the event instances in the same instance group can be assigned to the scheduling queue of the corresponding critical section resource, and the scheduling queue can be set with the same queue identifier as the event instances assigned to the scheduling queue.
[0087] In an exemplary embodiment, the parallel scheduling of the grouped event instances includes:
[0088] For the instance group, the event instances in the same instance group are assigned to the scheduling queue of the corresponding critical section resource;
[0089] The event instances in different scheduling queues are scheduled in parallel.
[0090] As an example, the SC_METHOD instances to be run can be grouped according to the GROUP ID identifiers, the SC_METHOD instances with the same GROUP ID identifier are assigned to the same instance group, and the SC_METHOD instances in the same instance group are assigned to the scheduling queue of the corresponding critical region resource, so as to perform parallel scheduling on the event instances in different scheduling queues, thereby realizing parallel running of multiple SC_METHOD instances or grouped SC_METHOD instances.
[0091] For example, Figure 5 is a flowchart of assigning a scheduling queue to an event instance according to an embodiment of the present application, which can specifically include the following steps: Figure 5 as shown, which can specifically include the following steps:
[0092] S500, start;
[0093] S501, scan the scheduling queue to be run;
[0094] S502, determine whether there is an SC_METHOD instance in the scheduling queue to be run;
[0095] S503, if yes, run the scheduling queue and execute the SC_METHOD instances in different scheduling queues in parallel;
[0096] S504, if no, obtain the SC_METHOD instance;
[0097] S505, group the SC_METHOD instances according to the GROUP ID identifiers and put them into the corresponding scheduling queue, and execute the steps S502-S503.
[0098] The access to the critical region resource in the prior art cannot be parallelized, and is usually forced to be executed in series, such as through the serial instruction openMP # pragma omp critical, which seriously affects the running performance. The embodiment of the present application can group the SC_METHOD instances accessing the same critical region resource and store them in the same scheduling queue, thereby avoiding the use of serial instructions and facilitating parallel execution.
[0099] As an example, the embodiment of the present application can realize parallel running of the SC_METHOD instances in different scheduling queues according to various existing parallel running technologies, such as the instruction # pragma omp parallel for of openMP. The parallel running technology is prior art, and the embodiment of the present application will not be described in detail here.
[0100] In an exemplary embodiment, the method of assigning the event instances in the same instance group to the scheduling queues of the corresponding critical section resources comprises:
[0101] determining the belonging relationship of the critical section resources to the scheduling queues and the assignment relationship of the event instances to the scheduling queues;
[0102] assigning the event instances in the same instance group to the scheduling queues of the corresponding critical section resources according to the belonging relationship and the assignment relationship.
[0103] Exemplarily, it can be determined whether the critical section resources accessed by the event instances have corresponding scheduling queues and whether the event instances are assigned to corresponding scheduling queues.
[0104] As an example, before assigning the event instances in the same instance group to the scheduling queues of the corresponding critical section resources, a corresponding relationship table of the event instances and the accessed critical section resources can be established.
[0105] For example, the critical section resources critical accessed by each event instance SC_METHOD can be scanned, and each event instance SC_METHOD accessed critical section resource critical can be identified and recorded, to generate a corresponding relationship table of the event instances and the critical section resources.
[0106] For example, the critical section resources critical accessed by each event instance SC_METHOD can be scanned, and each event instance SC_METHOD accessed critical section resource critical can be identified and recorded, to generate a corresponding relationship table of the event instances and the critical section resources.
[0107] Table 1
[0108] method1 method2 method3 method4 method5 ... critical1 Y Y critical2 Y Y critical3 Y Y Y ... ...
[0109] In Table 1, “Y” indicates that the event instance method accesses the critical section resource critical, and the critical section resource critical corresponding to each event instance method in Table 1 is blank, indicating that the event instance method does not access the critical section resource critical.
[0110] According to the critical section resources corresponding to the event instances recorded in Table 1, it can be queried whether each critical resource of the event instance has a corresponding scheduling queue.
[0111] As an example, the scheduling queue Thread Queue allocation state of the event instance method can be queried according to the event instance recorded in Table 1, and the allocation relationship between the event instance method and the scheduling queue Thread Queue can be determined according to the queried allocation state of the event instance method and the scheduling queue Thread Queue, and then it can be determined whether the event instance has been allocated the corresponding scheduling queue.
[0112] As an example, the event instances in the same instance group can be allocated to the scheduling queue of the corresponding critical section resource according to the belonging relationship of the critical section resource and the scheduling queue and the allocation relationship of the event instance and the scheduling queue.
[0113] As an example, allocating the event instances in the same instance group to the scheduling queue of the corresponding critical section resource can include various cases, such as the critical section resource not owning the scheduling queue and the event instance not being allocated the scheduling queue, the critical section resource not owning the scheduling queue and the event instance being allocated the scheduling queue, the critical section resource owning the scheduling queue and the event instance not being allocated the scheduling queue, the critical section resource owning the scheduling queue and the event instance being allocated the scheduling queue but the owned scheduling queue being different from the allocated scheduling queue, and the like.
[0114] The following describes allocating the event instance to the scheduling queue of the corresponding critical section resource according to the above several cases:
[0115] In an exemplary embodiment, the event instances in the same instance group are allocated to the scheduling queue of the corresponding critical section resource according to the belonging relationship and the allocation relationship, including:
[0116] According to the belonging relationship of the critical section resource not owning the scheduling queue and the allocation relationship of the event instance not being allocated the scheduling queue, a new scheduling queue of the critical section resource is created, and the event instances in the same instance group are allocated to the new scheduling queue.
[0117] As an example, if the critical section resource accessed by the event instance does not own the scheduling queue and the event instance has not been allocated the scheduling queue (i.e., the SC_METHOD instance has not joined the scheduling queue), a scheduling queue of the critical section resource corresponding to the SC_METHOD instance can be created, the scheduling queue is set as the owner of the critical section resource corresponding to the SC_METHOD instance, and the SC_METHOD instance is added to the corresponding scheduling queue.
[0118] For example, according to Table 1, taking method1 critical1 as an example:
[0119] 1) From Table 1, the critical resource accessed by method1 is critical1. If it is queried that critical1 does not own the corresponding scheduling queue, a new scheduling queue Thread Queue1 for the critical resource critical1 can be created, and the owner of the critical resource critical1 can be set as the scheduling queue Thread Queue1.
[0120] A critical resource table in which the critical resource and the scheduling queue belong to each other can be established, as shown in Table 2 below:
[0121] Table 2
[0122] Critical Section Resource Owner critical1 Thread Queue1 critical2 NULL critical3 NULL
[0123] 2) If it is queried that method1 is not assigned a scheduling queue, method1 can be assigned to the owner Thread Queue1 queue of critical1.
[0124] A scheduling table of the scheduling queue Thread Queue1 and method1 can be established, as shown in Table 3 below:
[0125] Table 3
[0126] Thread Queue1 method1
[0127] Thus, the scheduling allocation of the event instance is realized in the case that the critical resource accessed by the event instance does not own the scheduling queue, and the event instance has not been assigned a scheduling queue.
[0128] In an exemplary embodiment, the method further comprises:
[0129] According to the belonging relationship that the critical resource does not own the scheduling queue, and the assignment relationship that the event instance has been assigned a scheduling queue, the belonging relationship is set as that the critical resource owns the scheduling queue to which the event instance has been assigned.
[0130] As an example, if the critical resource does not own the scheduling queue, and the event instance has been assigned a scheduling queue (i.e., the SC_METHOD instance has joined the scheduling queue), the scheduling queue of the SC_METHOD can be set as the owner of the critical resource.
[0131] For example, according to Table 1, taking method1 critical3 as an example:
[0132] 1) The critical resource accessed by method 1 is critical 3. If it is inquired that method 1 has assigned a scheduling queue Thread Queue 1 (as shown in Table 3 above), the owner of the critical resource critical 3 can be set as the scheduling queue Thread Queue 1.
[0133] A critical resource table in which the critical resource and the scheduling queue belong to each other can be established, as shown in Table 4 below:
[0134] Table 4
[0135] Critical Section Resource Owner critical1 Thread Queue1 critical2 NULL critical3 Thread Queue1
[0136] Thus, the setting of the owner of the critical resource in the case that the critical resource does not have a scheduling queue and the event instance has assigned a scheduling queue is realized.
[0137] In an exemplary embodiment, the assignment of the event instance in the same instance group to the scheduling queue of the corresponding critical resource according to the belonging relationship and the assignment relationship comprises:
[0138] According to the belonging relationship that the critical resource has a scheduling queue and the assignment relationship that the event instance does not have a scheduling queue, the event instance in the same instance group is assigned to the scheduling queue owned by the critical resource.
[0139] As an example, if the critical resource has a scheduling queue and the event instance does not have a scheduling queue (i.e., the SC_METHOD instance has not joined the scheduling queue), the SC_METHOD instance can be joined in the scheduling queue of the owner of the critical resource.
[0140] For example, according to Table 1, take method 2 critical 1 as an example:
[0141] 1) According to Table 1, the critical resource accessed by method 2 is critical 1. If it is inquired that critical 1 has owned the corresponding scheduling queue Thread Queue 1 (as shown in Table 4 above), it can be further inquired whether method 2 has assigned the corresponding scheduling queue.
[0142] 2) If method 2 has not assigned the corresponding scheduling queue, method 2 can be assigned to the scheduling queue Thread Queue 1 of the owner of critical 1, as shown in Table 5 below:
[0143] Table 5
[0144] Thread Queue1 method1 method2
[0145] Thus, the critical region resource owning scheduling queue is realized, and the scheduling allocation of the event instance is allocated in the case that the event instance is not allocated a scheduling queue.
[0146] In an exemplary embodiment, further comprising:
[0147] According to the relationship of the critical region resource owning scheduling queue, the allocation relationship of the event instance having allocated a scheduling queue, in the case that the scheduling queue of the critical region resource is different from the scheduling queue allocated to the event instance, the scheduling queue allocated to the event instance is deleted, and the event instance in the deleted scheduling queue is re-allocated to the scheduling queue of the critical region resource.
[0148] As an example, if the critical region resource owns a scheduling queue, the event instance has allocated a scheduling queue (i.e., the SC_METHOD instance has joined the scheduling queue), and the scheduling queue of the critical region resource is different from the scheduling queue allocated to the event instance, the scheduling queue allocated to the event instance can be deleted, and the event instance in the deleted scheduling queue is re-allocated to the scheduling queue of the critical region resource.
[0149] In an exemplary embodiment, further comprising:
[0150] The critical region resource corresponding to the deleted scheduling queue is obtained.
[0151] The scheduling queue of the critical region resource corresponding to the deleted scheduling queue is set to the scheduling queue of the critical region resource owning the scheduling queue.
[0152] As an example, after deleting the scheduling queue allocated to the event instance, the critical region resource owned by the deleted scheduling queue can be queried, and the owner of the critical region resource of the deleted scheduling queue queried can be set to the scheduling queue of the critical region resource owning the scheduling queue.
[0153] For example, according to Table 1, taking method3 critical3 as an example:
[0154] 1) As can be seen from Table 1, the critical region resource accessed by method3 is critical3, and the owner of critical3 is the scheduling queue Thread Queue1 as shown in Table 4, and whether method3 has allocated a corresponding scheduling queue can be further queried;
[0155] 2) If it is queried that method3 has allocated a scheduling queue, and the scheduling queue is Thread Queue2 as shown in Table 6 below:
[0156] Table 6
[0157] Thread Queue1 method1 method2 Thread Queue2 ....method_other method3
[0158] That is, the scheduling queue (Thread Queue1) owned by the critical region resource critical3 is different from the scheduling queue (Thread Queue2) allocated to the event instance;
[0159] 3) The scheduling queue Thread Queue2 allocated to method3 can be deleted, and method3 and method_other in the scheduling queue Thread Queue2 can be allocated to the scheduling queue Thread Queue1 owned by the critical region resource critical3, as shown in the following Table 7:
[0160] Table 7
[0161] Thread Queue1 method1 method2 ...method_other method3
[0162] 4) The critical region resource owned by the deleted scheduling queue Thread Queue2 is inquired, as shown in the following Table 8:
[0163] Table 8
[0164] Critical Section Resource Owner critical1 Thread Queue1 critical2 Thread Queue2 critical3 Thread Queue1 ... ...
[0165] It can be seen that the critical region resource owned by Thread Queue2 is critical2, and the scheduling queue owned by critical2 can be further reset;
[0166] 5) The owner of critical2 is set to the scheduling queue Thread Queue1 of critical3 owning the scheduling queue, as shown in the following Table 9:
[0167] Table 9
[0168]
[0169]
[0170] Thus, the scheduling allocation of the event instance and the setting of the owner of the critical region resource in the case that the critical region resource owns the scheduling queue, the event instance has been allocated the scheduling queue, and the scheduling queue owned by the critical region resource is different from the scheduling queue allocated to the event instance are realized.
[0171] As an example, if the critical region resource owns the scheduling queue, the event instance has been allocated the scheduling queue, and the scheduling queue owned by the critical region resource is the same as the scheduling queue to which the event instance has been allocated, no processing can be performed.
[0172] The embodiment of the application achieves parallelization of the systemC kernel by splitting the loop content in the modeling thread SC_THREAD into one or more SC_METHOD instances, and scheduling and grouping the SC_METHOD instances according to the critical section resources, without modifying the thread code, thereby solving the problem in the related art that the parallelization scheduling of the thread cannot automatically adjust the number of parallel threads to adapt to different concurrent processes, and fully improving the parallel performance of the thread and the system utilization efficiency, and greatly reducing the modeling time.
[0173] The process of assigning the scheduling queue of the corresponding critical section resource to the event instance is further described below through an example:
[0174] For example, Figure 6 is a flowchart of assigning the scheduling queue of the corresponding critical section resource to the event instance according to the embodiment of the application, as shown in Figure 6 , the process can include the following steps:
[0175] (1) start;
[0176] (2) determine whether all event instances method have been scheduled and assigned;
[0177] (3) if not, the next method can be obtained, and it is determined whether there is a critical section resource accessed by the method to be scanned;
[0178] (4) if yes, the next critical section resource can be obtained, and it is determined whether the critical section resource has a scheduling queue;
[0179] (5) if the critical section resource does not have a scheduling queue, and the event instance has not joined the scheduling queue, a scheduling queue can be created, the created scheduling queue is set as the scheduling queue of the critical section resource, and the event instance is added to the scheduling queue of the critical section resource;
[0180] (6) if the critical section resource does not have a scheduling queue, and the event instance has joined the scheduling queue, the scheduling queue of the event instance is set as the scheduling queue of the critical section resource;
[0181] (7) if the critical section resource has a scheduling queue, and the event instance has not joined the scheduling queue, the event instance can be directly added to the scheduling queue owned by the critical section resource;
[0182] (8) if the critical section resource has a scheduling queue, and the event instance has joined the scheduling queue, it is determined whether the scheduling queue joined by the event instance is the same as the scheduling queue owned by the critical section resource;
[0183] (9) If the same, no processing can be performed; if different, all event instances in the scheduling queue of the event instance can be transferred to the scheduling queue of the critical section resource owned by the critical section resource, and the owner of the critical section resource corresponding to the scheduling queue is set to the scheduling queue of the critical section resource owned by the critical section resource;
[0184] (10) It is judged whether all event instances method have been scheduled and allocated, and if yes, the method ends.
[0185] The event instance allocation manner of the example can realize parallel running of event instances in the scheduling queue without changing the modeling code using the systemC interface, thereby greatly improving the speed of systemC modeling.
[0186] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as a ROM / RAM, a magnetic disk, or an optical disk), and includes a plurality of instructions for causing a terminal device (which can be a mobile phone, a computer, a server, or a network device) to execute the methods described in the various embodiments of the present application.
[0187] The embodiments of the present application also provide a computer readable storage medium, which stores a computer program, and the computer program is configured to execute the steps in any of the above method embodiments when running.
[0188] In an example embodiment, the above computer readable storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.
[0189] The embodiments of the present application also provide an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor is configured to execute the computer program to perform the steps in any of the above method embodiments.
[0190] In an example embodiment, the above electronic device can also include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0191] The specific examples in the present embodiment can refer to the examples described in the above embodiments and exemplary embodiments, which will not be repeated here.
[0192] Embodiments of the present application also provide a computer program product comprising a computer program which, when executed by a processor, implements the steps of any of the above method embodiments.
[0193] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present application can be realized by general computing devices, which can be concentrated on a single computing device or distributed on a network composed of multiple computing devices, which can be realized by program codes executable by computing devices, so that they can be stored in storage devices and executed by computing devices, and in some cases, the steps shown or described can be executed in different order, or they can be made into individual integrated circuit modules, or multiple modules or steps can be made into a single integrated circuit module. Thus, the present application is not limited to any specific combination of hardware and software.
[0194] The above only describes exemplary embodiments of the present application and is not intended to limit the present application. Those skilled in the art can make various modifications and changes to the present application. Any modification, equivalent replacement, improvement, etc. within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A thread-based scheduling method, characterized in that, include: Obtain the loop instance of the target thread, and identify the running loop content and the pause statement in the loop content; The loop content is split according to the pause statement to generate at least one event instance for individual execution; The critical section resources accessed by the event instance are queried, and the event instances are grouped according to the queried critical section resources. The grouped event instances are then scheduled in parallel.
2. The method according to claim 1, characterized in that, The loop content includes multiple pause statements. The step of splitting the loop content according to the pause statements to generate at least one event instance for individual execution includes: Obtain the syntax tree corresponding to the loop content; the syntax tree includes a pause node corresponding to each of the multiple pause statements; The syntax tree is split according to the pause node to generate at least one sub-syntax tree and the event instance corresponding to each sub-syntax tree; wherein the sub-syntax tree is used to generate the event instance that runs independently.
3. The method according to claim 2, characterized in that, The step of splitting the syntax tree according to the pause node to generate at least one sub-syntax tree and the event instance corresponding to each sub-syntax tree includes: Extract the running content corresponding to two adjacent pause nodes in the syntax tree in sequence; For each instance of the execution content, a sub-syntax tree and the corresponding event instance are generated.
4. The method according to claim 1, characterized in that, Also includes: Obtain the sensitivity list of the loop instance; Based on the pause statement and the sensitivity list of the loop instance, generate a sensitivity list for each event instance; The sensitive list of the loop instance includes at least one event, each pause statement corresponds to at least one event, the sensitive list of each event instance includes at least one event corresponding to the pause statement, and the events in the sensitive list of the event instance are used to drive the event instance to access the critical section resource.
5. The method according to claim 4, characterized in that, The query for the critical section resources accessed by the event instance includes: Based on the events in the sensitivity list of the event instance, query the critical section resources accessed by the event instance driven by the event.
6. The method according to claim 1, characterized in that, The step of grouping the event instances based on the retrieved critical section resources includes: Based on the critical section resources accessed by the queried event instances, determine the event instances that access the same critical section resource and configure the same queue identifier. Event instances with the same queue identifier are assigned to the same instance group.
7. The method according to claim 6, characterized in that, The parallel scheduling of the grouped event instances includes: For the instance group, the event instances in the same instance group are assigned to the scheduling queue of the corresponding critical section resource; The event instances in different scheduling queues are scheduled in parallel.
8. The method according to claim 7, characterized in that, The step of allocating event instances within the same instance group to the scheduling queue of the corresponding critical section resource includes: Determine the relationship between the critical section resource and the scheduling queue, as well as the allocation relationship between the event instance and the scheduling queue; Based on the affiliation relationship and the allocation relationship, the event instances in the same instance group are allocated to the scheduling queue of the corresponding critical section resource.
9. The method according to claim 8, characterized in that, The step of allocating event instances within the same instance group to the scheduling queue corresponding to the critical section resource based on the affiliation relationship and the allocation relationship includes: Based on the relationship between the critical section resource not having a scheduling queue and the allocation relationship between the event instance not being assigned a scheduling queue, a new scheduling queue is created for the critical section resource, and the event instances in the same instance group are assigned to the new scheduling queue.
10. The method according to claim 9, characterized in that, Also includes: Based on the relationship between the critical section resource not owning a scheduling queue and the allocation relationship between the event instance and the scheduling queue, the relationship is set to the critical section resource owning the scheduling queue allocated to the event instance.
11. The method according to claim 8, characterized in that, The step of allocating event instances within the same instance group to the scheduling queue corresponding to the critical section resource based on the affiliation relationship and the allocation relationship includes: Based on the relationship between the critical section resource owning the scheduling queue and the allocation relationship between the event instance and the unassigned scheduling queue, the event instances in the same instance group are assigned to the scheduling queue owned by the critical section resource.
12. The method according to claim 8, characterized in that, Also includes: Based on the ownership relationship of the critical section resource with the scheduling queue and the allocation relationship of the scheduling queue to which the event instance has been assigned, if the scheduling queue owned by the critical section resource is different from the scheduling queue assigned to the event instance, the scheduling queue to which the event instance has been assigned is deleted, and the event instance in the assigned scheduling queue is reassigned to the scheduling queue owned by the critical section resource.
13. The method according to claim 12, characterized in that, Also includes: Retrieve the critical section resources corresponding to the deleted scheduling queue; Set the scheduling queue of the critical section resource corresponding to the deleted scheduling queue to be the scheduling queue of the critical section resource that owns the scheduling queue.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of claims 1 to 13.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method described in any one of claims 1 to 13.
16. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method described in any one of claims 1 to 13.