The present invention relates to computer systems, and more particularly to such systems executing multiple threads.
Computer systems including multiprocessor (MP) and single processor systems may include a plurality of “threads,” each of which executes program instructions independently from other threads. Use of multiple processors allows various tasks or functions, and even multiple applications, to be handled more efficiently and with greater speed. Utilizing multiple threads or processors means that two or more processors or threads can share the same data stored within the system. However, care must be taken to maintain memory ordering when sharing data.
For data consistency purposes, if multiple threads or processors desire to read, modify, and write to a single memory location, the multiple agents should not be allowed to perform operations on the data simultaneously. Further complicating the use of multiple processors is that data is often is stored in a cache associated with a processor. Because such caches are typically localized to a specific processor, multiple caches in a multiprocessor computer system can contain different copies of a given data item. Any agent accessing this data should receive a valid or updated (i.e., latest) data value, and data being written from the cache back into memory must be the current data so that cache coherency is maintained.
Memory instruction processing acts in accordance with a target instruction set architecture (ISA) memory order model. For reference, Intel Corporation's two main ISAs: Intel® architecture (I-32 or x86) and Intel's ITANIUM® processor family (IPF) have very different memory order models. In IA-32, load (i.e., read) and store (i.e., write) operations must be visible in program order, while in the IPF architecture, they do not in general. Further, while executing multiple threads in a chip multiprocessor (CMP) or other MP system, ordered memory instructions are used in synchronization and communication between different threads.
Multithreaded (MT) software uses different mechanisms to interact and coordinate between different threads. Two common forms of MP synchronization are barriers and semaphore spin-locks. A barrier mechanism helps a program synchronize different threads at predefined points in the program. Typically, each thread either increments or decrements a memory variable in an atomic fashion when it reaches such a point. Every thread then waits for the memory variable to reach a predetermined barrier level. Synchronization is achieved once all threads have completed the updates. When the barrier is reached, all threads can then proceed.
A semaphore spin-lock mechanism is used to guarantee mutual exclusion across multiple threads while accessing a shared memory variable or structure (i.e., a shared element). In order to provide a unique and consistent view of the shared element, it is guarded by a lock variable. Every thread needing access to the shared element must acquire the guarding lock (i.e., locking) via an atomic semaphore operation. When a lock is acquired, the remaining threads can only acquire the lock after it is released (i.e., unlocking) by the original requester. Only the thread that acquired the lock performs operations/updates on the shared element (software convention), thus mutual exclusion is ensured. Locking is performed by designating a particular value to represent a locked state, and a different value to represent an unlocked state. Each thread seeking to access the shared element acquires the lock by updating the lock variable atomically to the lock value (after possibly checking that the lock has not already been acquired).
Most ISA's provide specific semaphore instructions to achieve MP synchronization between multiple threads or processors. Among these, an atomic-add is a popular instruction for a barrier synchronization mechanism. However, known barrier synchronization methods and semaphore spin-locks cause inefficiencies. Barrier mechanisms typically require significant traffic, such as inter-processor cache traffic, as the lock variable moves to different cores of the multiprocessor. Similarly, spin-lock mechanisms require significant traffic between different processor cores. Still further, an atomic-add instruction requires that the shared variable be brought deep into processor cores to perform the add operation, again requiring significant traffic, as well as utilizing processor resources. Accordingly, a need exists for improved manners of synchronization between multiple threads.
In various embodiments, a shared memory variable (“shared variable”) may be used to maintain synchronization between multiple threads. The shared variable may have multiple portions, with each portion being independently associated with one of the threads. In such manner, the shared variable may represent the synchronization status of each of the threads independently.
In some embodiments, the shared variable may be updated using a set mechanism, rather than an arithmetic operation, such as an increment or decrement operation. In such manner, the status of various threads may be updated without causing the shared variable to be cached or otherwise brought into a processor core. That is, set/reset operations may be performed in a remote or last level cache. Furthermore, these operations may be performed without expensive adders or other circuitry that would need to be located near an execution core.
In one embodiment, an instruction referred to herein as a fetchset instruction may be a low-cost instruction to improve MT synchronization, particularly in cases of low thread count. The fetchset instruction as executed by a given thread performs a read on a shared variable and sets or stores a predetermined value into a portion of the shared variable corresponding to the thread. For example, in an embodiment in which eight or fewer threads are executing, the shared variable may be eight bytes. Each byte of the shared variable may correspond to one of the threads. In one embodiment, the predetermined value to be set may be all “ones”. For example, fetchset1 stores FFhex (i.e., 11111111) at the specified memory address of a given portion. Such an instruction may be low cost, since setting (i.e., overwriting) memory state is less expensive than performing read-add-update operations.
While discussed above as devoting a byte per thread, in other embodiments a different arrangement may exist. For example in one embodiment, a single bit may be used to represent a thread. Further, while described above as setting the predetermined value to ones, in other embodiments any other desired value may be used.
Referring now to
Still referring to
While not shown in
Referring now to
Alternately, if the thread does reach a barrier, control passes to block 130 where a fetchset operation is performed on a first memory variable. The first memory variable may be stored in a cache accessible by the multiple threads. Such a fetchset operation may include the steps described above with respect to
If the current thread is the last to reach the barrier, the second memory variable may be updated (block 160). For example, the second memory variable may have its contents updated from zero to one. Control then passes to block 170, where the synchronization is completed, as all threads of the program have reached the barrier, and the contents of the first and second memory variables are set. Accordingly, method 100 concludes (oval 180).
Because of the low cost of implementing a fetchset instruction and as it may be defined on byte granularity, setting of the variable may be exported to a shared last level cache (LLC) of a CMP or other processor. In such manner, a cache line including the variable can be prevented from being copied into a core (near the execution pipeline) on every barrier update. Thus, inter-processor cache traffic in moving the lock variable across different cores may be avoided. Software may be used to ensure that the cache line remains pinned in the LLC by avoiding false sharing on the cache block and avoiding any other reads or updates to the memory variable (that would source a copy of the cache line into one of the core caches).
Other embodiments may be used to provide fine-grain locking using a single variable. For example, a 16-byte fetchset instruction may represent 16 fine-grain locks. In such an embodiment, a data structure containing 16 data elements can be locked using one shared variable. Each element of the data structure is allocated a byte within the lock variable. Then, only that portion of the structure may be locked using a fetchset instruction. In such manner, non-blocking access to the same structure is permitted, as long as the particular element to be accessed is not locked. If the original value returned by a fetchset operation to a first thread is clear in the particular byte location, then the first thread may successfully lock that element. If however the byte position was already set, the entry was previously locked by a different thread. Accordingly, the locking operation would need to be retried later by the first thread.
Referring now to
After reading the shared variable, it may be determined whether the portion of the variable corresponding to the data element is locked (diamond 230). For example, in one embodiment it may be determined whether that portion is set (i.e., has a value of ones). If the portion indicates that the data element is locked, the thread is not allowed to access the data element, and may accordingly retry the fetchset operation later (block 240). In such manner, if a different thread has concluded an operation on the data element, the next time the thread accesses the shared variable, the specific portion may be in a reset state.
If instead at diamond 230 it is determined that the portion of the shared variable is not locked, that portion may be locked (block 250). Then the current thread may update the data element that corresponds to that portion of the data structure (block 260). For example, the thread may update the data element and write the updated value back to its memory location. Then, the thread may unlock that portion of the shared variable (block 270) so that other threads may obtain a lock on the given data element. Accordingly, method 200 ends (oval 280).
In various embodiments, because a fetchset or other such instruction supports a predefined update payload (i.e., the predefined value), the payload may be synthesized at the particular cache executing the instruction. As a result, the update to the shared variable is protected against payload corruption through soft errors as the instruction flows through the machine.
Furthermore, because the synchronization status of each thread is isolated, it provides a robust barrier synchronization mechanism. Any thread that fails to report to the barrier does not have its byte location set in the shared variable. In such manner, any errant thread resulting in a software failure (either due to software or hardware error) may be isolated and identified based on the status of the shared variable. Software may then selectively perform recovery on the particular thread.
A 16 byte variant of the fetchset instruction (i.e., a fetchset.double) may be defined to operate on a 16 byte granularity, and thus provide synchronization among 16 threads.
In some embodiments, a hierarchical barrier mechanism may be used to establish synchronization in software with large thread counts. In such embodiments, a fetchset-based mechanism may serve as an effective barrier mechanism at a lower level of the hierarchy to establish synchronization within a CMP processor or within a local cluster of a clustered system.
Referring now to Table 1 below, shown is an instruction syntax for a fetchset instruction in accordance with an embodiment of the present invention. As shown in Table 1, the instruction syntax is within the scope of the IPF ISA.
As shown in Table 1, the instruction syntax indicates: whether an 8 byte or 16 byte read operation is to be performed; the payload to be written into the specified location; the size; and the type of semaphore, for example, whether it is an acquire or release operation.
Referring now to Table 2 below, shown is a pseudocode example of establishing a barrier synchronization using a fetchset instruction in accordance with an embodiment of the present invention. Again, this pseudocode is in the IPF context, although the scope of the present invention is not so limited.
Generally, the code of Table 2 performs the following activities. First, the code initializes the location in the cache where the shared variable is to be stored and further initializes the shared variable to zero. Then, independent threads are executed. Upon completion of a thread, a fetchset instruction is performed by each thread to read the value of the shared variable and compare it to a predetermined value. If the shared variable equals that value, it means that the current thread is the last thread, and synchronization is completed. If not, the current thread updates its portion of the shared variable, and enters a spin loop until the last thread completes its execution to thus complete synchronization.
Referring now to
It is to be understood that in other embodiments additional processors may be coupled to coherent memory 330. Furthermore in certain embodiments, coherent memory 330 may be implemented in parts and spread out such that a subset of processors within system 300 communicate to some portions of coherent memory 330 and other processors communicate to other portions of coherent memory 330.
As shown in
Coherent memory 330 may also be coupled (via a hub link) to an input/output (I/O) hub 335 that is coupled to an I/O expansion bus 355 and a peripheral bus 350. In various embodiments, I/O expansion bus 355 may be coupled to various I/O devices such as a keyboard and mouse, among other devices. Peripheral bus 350 may be coupled to various components such as peripheral device 370 which may be a memory device such as a flash memory, add-in card, or the like. Although the description makes reference to specific components of system 300, numerous modifications of the illustrated embodiments may be possible.
In some embodiments, a multiprocessor system may be a point-to-point bus system, such as in a common system interface (CSI) system. Referring now to
As shown in
First processor 470 and second processor 480 may be coupled to a chipset 490 via P-P interfaces 452 and 454, respectively. As shown in
In turn, chipset 490 may be coupled to a first bus 416 via an interface 496. In one embodiment, first bus 416 may be a Peripheral Component Interconnect (PCI) bus, as defined by the PCI Local Bus Specification, Production Version, Revision 2.1, dated June 1995 or a bus such as the PCI Express bus or another third generation I/O interconnect bus, although the scope of the present invention is not so limited.
As shown in
Embodiments may be implemented in a computer program that may be stored on a storage medium having instructions to program a computer system to perform the embodiments. The storage medium may include, but is not limited to, any type of disk including floppy disks, optical disks, compact disk read-only memories (CD-ROMs), compact disk rewritables (CD-RWs), and magneto-optical disks, semiconductor devices such as read-only memories (ROMs), random access memories (RAMs) such as dynamic and static RAMs, erasable programmable read-only memories (EPROMs), electrically erasable programmable read-only memories (EEPROMs), flash memories, magnetic or optical cards, or any type of media suitable for storing electronic instructions. Other embodiments may be implemented as software modules executed by a programmable control device.
While the present invention has been described with respect to a limited number of embodiments, those skilled in the art will appreciate numerous modifications and variations therefrom. It is intended that the appended claims cover all such modifications and variations as fall within the true spirit and scope of this present invention.
This application is a continuation of U.S. patent application Ser. No. 11/026,207, filed Dec. 29, 2004, now U.S. Pat. No. 7,937,709, the content of which is hereby incorporated by reference.
Number | Name | Date | Kind |
---|---|---|---|
4926375 | Mercer et al. | May 1990 | A |
5430850 | Papadopoulos et al. | Jul 1995 | A |
5448732 | Matsumoto | Sep 1995 | A |
5535393 | Reeve et al. | Jul 1996 | A |
5611070 | Heidelberger et al. | Mar 1997 | A |
5745778 | Alfieri | Apr 1998 | A |
5822764 | Hardage et al. | Oct 1998 | A |
5872963 | Bitar et al. | Feb 1999 | A |
5893097 | Hayata et al. | Apr 1999 | A |
5926835 | Guidot et al. | Jul 1999 | A |
5991845 | Bohannon et al. | Nov 1999 | A |
6009426 | Jouenne et al. | Dec 1999 | A |
6058460 | Nakhimovsky | May 2000 | A |
6134594 | Helland et al. | Oct 2000 | A |
6167423 | Chopra et al. | Dec 2000 | A |
6243788 | Franke et al. | Jun 2001 | B1 |
6289410 | Cummins | Sep 2001 | B1 |
6370625 | Carmean et al. | Apr 2002 | B1 |
6463527 | Vishkin | Oct 2002 | B1 |
6535905 | Kalafatis et al. | Mar 2003 | B1 |
6539501 | Edwards | Mar 2003 | B1 |
6542991 | Joy et al. | Apr 2003 | B1 |
6671707 | Hudson et al. | Dec 2003 | B1 |
6708256 | Zahir | Mar 2004 | B2 |
6795845 | Kalafatis et al. | Sep 2004 | B2 |
6795901 | Florek et al. | Sep 2004 | B1 |
7191294 | Nakamura et al. | Mar 2007 | B2 |
7360217 | Melvin et al. | Apr 2008 | B2 |
7380086 | Archambault et al. | May 2008 | B2 |
7512950 | Marejka | Mar 2009 | B1 |
20020010836 | Barroso et al. | Jan 2002 | A1 |
20020032831 | Saulsbury et al. | Mar 2002 | A1 |
20020046324 | Barroso et al. | Apr 2002 | A1 |
20020060685 | Handley et al. | May 2002 | A1 |
20020078122 | Joy et al. | Jun 2002 | A1 |
20020091909 | Nakanishi | Jul 2002 | A1 |
20020095453 | Steensgaard | Jul 2002 | A1 |
20020124205 | Grey et al. | Sep 2002 | A1 |
20020138717 | Joy et al. | Sep 2002 | A1 |
20020147760 | Torii | Oct 2002 | A1 |
20030005262 | Kottapalli et al. | Jan 2003 | A1 |
20030014602 | Shibayama et al. | Jan 2003 | A1 |
20030018691 | Bono | Jan 2003 | A1 |
20030061394 | Buch | Mar 2003 | A1 |
20030088608 | McDonald | May 2003 | A1 |
20030088610 | Kohn et al. | May 2003 | A1 |
20030115476 | McKee | Jun 2003 | A1 |
20030135711 | Shoemaker et al. | Jul 2003 | A1 |
20030191927 | Joy et al. | Oct 2003 | A1 |
20030225816 | Morrow et al. | Dec 2003 | A1 |
20030229740 | Maly et al. | Dec 2003 | A1 |
20040078795 | Alverson et al. | Apr 2004 | A1 |
20040187118 | Blainey et al. | Sep 2004 | A1 |
20050050374 | Nakamura et al. | Mar 2005 | A1 |
20050216659 | Ogawa et al. | Sep 2005 | A1 |
20060080398 | Hoover et al. | Apr 2006 | A1 |
Entry |
---|
The Patent Office of the State Intellectual Property Office of the People's Republic of China, Notice on Office Action dated Aug. 10, 2007, with English language translation. |
The Patent Office of the State Intellectual Property Office of the People's Republic of China, Second Office Action dated Aug. 22, 2008, with English language translation. |
The Patent Office of the State Intellectual Property Office of the People's Republic of China, Third Office Action dated May 8, 2009, in a related application. |
E.I. Compendex No. 1991030082385 High Speed Synchronization of Processors Using Fuzzy Barriers, Gupta, Rajiv, Univ of Pittsburgh, United States International Journal of Parallel Programming (Int J Parallel Program) 1990 19/1 (53-73) Publication Date Dec. 1, 1990. |
Gale Group PROMT(R) (c) 2009, Gale/Cenage; Supplier No. 93792719 Mastering Concurrency: Correctly Implementing Concurrency in Computer Software is Vital for Accurate Computational Modeling, and for the Saftey and Reliability of Embedded Control Systems, (IT). Moores, Jim. Nuclear Engineering Intterational, v 47, n 579, p. 39(1), Oct. 2002. |
Number | Date | Country | |
---|---|---|---|
20110173634 A1 | Jul 2011 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 11026207 | Dec 2004 | US |
Child | 13069684 | US |