Related subject matter is found in U.S. patent application Ser. No. 10/353,216, filed Jan. 27, 2003, now U.S. Pat. No. 7,155,572, entitled “Method and Apparatus for Injecting Write a Cache,” invented by William Hughes and Patrick Conway and assigned to the hereof.
The present invention generally relates to data processing systems, and more particularly relates to non-uniform memory access (NUMA) data processing systems.
Some computer systems use multiple processors for higher performance. Early multi-processor systems had a shared main memory to which all processors had access by means of a common bus. However since the bandwidth of the shared bus became a major bottleneck in this multi-processor system, other architectures were developed. Among them is an architecture known as a non-uniform memory access (NUMA) architecture, in which each processor operates on a shared address space but memory is distributed among the processor nodes and memory access time depends on the location of the data in relation to the processor that needs it.
In multiprocessor systems some variables are shared by the nodes. For example in a banking database system many different processors may be able to access a customer's account data. However it is important that only one processor node is allowed to be the owner of the data at a time, and that all processor nodes that are allowed to change the customer's account data receive the right to access the data at some point. Thus NUMA multiprocessor systems put a “lock” around the variable when one user is granted ownership of it, and only release the lock when it is safe to pass ownership rights to another user.
If a given processor node attempts to read a variable which is already owned and hence locked by another node, it is not allowed the right to change the variable until, at least, the owner relinquishes it. There may also be other processors that desire to own the variable at the same time and that may be given priority over the given processor. Hence each processor that attempts to become the owner of a shared variable must wait for the lock to be released and then attempt to acquire the lock before another processor does. Typically these processors can be stuck executing a tight loop of instructions known as a “spinlock” to detect the lock release and these processors are said to be “spinning”.
Spinlocks can cause unbalanced performance in NUMA systems. Performance instability results from the fact that nodes which are physically close to the home node of a lock variable have a higher probability of acquiring a released lock variable than nodes that are far away. The net effect is that remote nodes are under-utilized because they spend more time spinning and less time working. The utilization of the processor nodes literally becomes a function of their proximity to lock variables. Proximity in turn varies based on where tasks are scheduled and where memory is allocated. System performance thus becomes erratic and generally unstable.
Accordingly, it is desirable to provide a method and apparatus for providing stability in NUMA systems. This and other desirable features and characteristics of the present invention will become apparent from the subsequent detailed description and the appended claims, taken in conjunction with the accompanying drawings and the foregoing technical field and background.
A data processor is provided that is adapted for use in a non uniform memory access (NUMA) data processing system having a local memory and a remote memory. The data processor includes a central processing unit and a communication link controller. The central processing unit executes a plurality of instructions including an atomic instruction on a lock variable, and generates an access request that includes a lock acquire attribute in response to executing the atomic instruction on the lock variable. The communication link controller is coupled to the central processing unit and has an output adapted to be coupled to the remote memory for selectively providing the access request with the lock acquire attribute to the remote memory if an address of the access request corresponds to the remote memory.
A method is also provided for use in a non-uniform memory access (NUMA) data processing system for guaranteeing fair access to a lock variable among a plurality of processor nodes. A first access request with a lock acquire attribute for the lock variable is received from a first processor node. A second access request with a lock acquire attribute for the lock variable is received from a second processor node within a predetermined length of time after receiving the first access request. A lock winner is determined as one of the first and second processor nodes that is next after a current owner of the lock variable in a predetermined order. Ownership of the lock variable is granted to the lock winner.
The present invention will hereinafter be described in conjunction with the following drawing figures, wherein like numerals denote like elements, and
The following detailed description is merely exemplary in nature and is not intended to limit the invention or the application and uses of the invention. Furthermore, there is no intention to be bound by any expressed or implied theory presented in the preceding technical field, background, brief summary or the following detailed description.
In
The non-uniform memory access time creates a bias in favor of nodes that are closest to the home node for a lock variable. Suppose for example node 3 owns a lock variable and node 2 is the home node for the data.
Since all the processors are attempting to obtain the lock, they quickly send a request packet known as “RdBlk” to test the updated state of the lock variable. This packet requests a copy of the data element by encoding RdBlk in the command (Cmd) field of the HyperTransport packet and specifying the address of the data element. The RdBlk packet also travels around NUMA system 10 in hops and these packets arrive at P2 at times based on their proximity. P2 then sends a read response packet with a shared copy of the lock variable. Since the semaphore bit now has the unlocked value of binary 0, each contending processor attempts to acquire the lock by sending a request packet which signals an intent to modify, known as a RdBlkM packet. Because in this example all other processors have been spinning waiting for release of the lock, when the lock is finally released P2 receives a large number of attempts to own the lock in a short period of time. This phenomenon is known as the “thundering herd”.
A simple system would grant ownership of the lock on a first come, first serve basis. Since many processors are attempting to obtain the lock, the processor that is physically closest to the lock variable has a bias in favor of getting the lock. In this example P2 would get ownership of the lock variable. Ownership is granted by sending a copy of the lock variable with the semaphore bit in the binary 0 state. P2 then stores the lock variable in its cache, and writes the semaphore bit to a binary 1 to indicate that the data element is owned. Any further polling of the lock variable by other nodes will result in P2 returning a copy with the semaphore bit in the 1 state. P5 is the farthest node from the home node and will never win the contention unless there are no other active contenders. This bias in favor of nodes physically close to the lock variable causes unbalanced system operation since P2 can access the lock variable frequently while P5 spends considerable time spinning and thus performing no useful work.
Processor node 102 includes generally a data processor in the form of a single-chip microprocessor 300, a dynamic random access memory (DRAM) 320, and an input/output (I/O) device 340. Microprocessor 300 includes generally a central processing unit (CPU) 302, a memory controller 304, a crossbar switch labeled “XBAR” 306, and three communication link controllers 308, 310, and 312 each labeled “HT” for HyperTransport, described more fully below. CPU 302 is a processor adapted to execute instructions of the so-called x86 instruction set. The x86 instruction set is based on the instruction set of the 8086 microprocessor first manufactured by Intel Corporation of Santa Clara, Calif. CPU 302 however includes many sophisticated features for high-performance execution of x86 programs including pipelining and superscalar design. CPU 302 also includes a level one data cache and a separate level one instruction cache, and a combined level two instruction and data cache.
Memory controller 304 is the mechanism for data transfer between microprocessor 300 and DRAM 320 which functions as a local memory, and between other system nodes and the local memory. Memory controller 304 offloads the task of initiating and terminating memory accesses from CPU 402. It includes internal queues to allow efficient use of the external bus to DRAM 320, and a directory mechanism for determining ownership and state of data in the local memory. In other embodiments DRAM 320 could be replaced by a lower-level memory system including one or more additional caches and main memory, by static RAM, by nonvolatile memory, etc.
XBAR 306 is a switching/multiplexing circuit designed to couple together the buses internal to microprocessor 300.
HT link controllers 308, 310, and 312 are coupled to devices external to microprocessor 300 over corresponding input and output channels. Each of HT link controllers 308, 310, and 312 complies with the physical interface specified in the HyperTransport I/O Link Specification. In node 102 HT link controllers 308 and 310 function as coherent links that communicate with nodes 101 and 104 of
I/O device 340 is an input/output device that, for example, implements the local area network communication protocol standardized by the Institute of Electrical and Electronics Engineers (IEEE) under the auspices of the IEEE 802.3 committee, commonly referred to as “Ethernet”. However other types of I/O functions are possible as well.
Other nodes in system 10 assume the same basic configuration as node 102. However, nodes 1, 3, 4, and 6 use all three available HT link controllers for coherent HyperTransport links between adjacent processor nodes. Remaining nodes 0, 2, 5, and 7 have an additional HT link controller available for use as a host bridge for connection to I/O devices using non-coherent HyperTransport links.
Microprocessor 300 implements two mechanisms to provide balanced spinlock support. First, CPU 302 provides a special RdBlkM packet with a lock acquire attribute in response to executing an atomic instruction. In the x86 instruction set, there are several atomic instructions: Bit Test and Set (BTS), Bit Test and Complement (BTC), Bit Test and Reset (BTR), Exchange and Add (XADD), Exchange Register/Memory with Register (XCHG), Compare and Exchange (CMPXCHG, CMPXCGH8B, and CMPXCHG16B). In addition there is a mechanism to assert an external control signal to signify a lock event by preceding an atomic instruction (or any of a number of instructions) by a LOCK prefix, opcode F0 hex, as described in the IA-32 Intel Architecture Software Developer's Manual, Volume 2 Instruction Set Reference, © 1997-2001 by the Intel Corporation (Order Number 245471), pages 2-1, 3-389 and 3-390.
In response to decoding and executing an atomic instruction, CPU 302 presents the RdBlkM packet with the lock acquire attribute to one of HT link controllers 308 and 310 that will be part of the path back to the home node of the data element. A normal RdBlkM packet (i.e., without a lock acquire attribute) is encoded by using a particular bit pattern in the Cmd field. The special RdBlkM packet with the lock acquire attribute uses the same Cmd field encoding but uses other bits to signify the lock acquire attribute. This new packet is better understood with reference to
The various fields associated with packet 400 will now be described. Cmd[5:0] is the command field which defines the packet type, and is equal to 000110 for the RdBlkM packet. SrcUnit[1:0] identifies the unit within the source node which generated the request. DstUnit[1:0] identifies the unit within the destination node to which this packet should be routed. Examples of units in this context are processors, memory controllers and bridges to non-coherent links. DstNode[2:0] identifies the node to which this packet should be routed. Depending on the packet, this field may identify either the source or target node for the transaction associated with this packet. SrcNode[2:0] identifies the original source node for the transaction. SrcTag[4:0] is a transaction tag which together with SrcNode and SrcUnit uniquely identifies the transaction associated with this packet. Each node can have up to 128 transactions in progress in the system. Addr[39:3] represents the 64-byte block address accessed by the request.
In the illustrated embodiment CPU 302 forms the RdBlkM with a lock acquire attribute by using the normal RdBlkM command encoding. However it uses one of the five available reserved bits, labeled “Rsv”, to signal the presence of the lock acquire attribute. Note that any of the Rsv bits can be used and either logic state can be used to signify the lock acquire attribute.
Returning now to
Step 502 represents the first attempt to obtain ownership of the lock variable, so node 2 grants ownership to the requesting node by sending a read response packet with the lock variable. In addition, however, memory controller 304 adds a new directory state, the L state, to indicate that the data element is a lock variable, and records the node that is the initial lock owner. This information is important for later detecting a lock release as will be described more fully below.
At step 504 memory controller 304 waits for the lock to be released. It has an entry in its directory for the data element containing the lock variable. Since the entry indicates that the data element containing the lock variable is in the L state, the next attempt to write the block will be a lock release. Thus it waits for a ChgToD packet to be received from the lock owner.
When the memory controller detects the lock has been released by the receipt of a ChgToD packet from the lock owner, it then places the line in the LM state, wherein the M bit indicates that the data as been modified. The memory controller 304 waits at step 506 for an attempt to acquire the lock, signaled by a RdBlkM packet with a lock acquire attribute to the same address. The source node of the RdBlkM packet becomes the first contender for the lock variable. However instead of granting the lock to the first contender to send a RdBlkM packet with a lock acquire attribute, memory controller 304 then waits, at step 508, for a predetermined length of time to see if other, more remote nodes in the system have been spinning waiting for the release of the lock. This predetermined length of time is equal to the delay in hops of the farthest node in the system for all the request and response packets associated with this protocol. After the expiration of this length of time, memory controller 304 then determines at step 510 the set of active contenders for the lock variable. Since memory controller 304 now knows the previous owner and the set of contenders, it is able to determine the lock winner in a fair manner. Memory controller 304 determines the lock winner as the next active contender after the last owner in round robin order. In the example of
Lock
LM
The line is modified in the owner's cache. Data in
Modified
memory is stale. The line contains a lock
variable.
Lock
LO
Line is shared but memory is stale. A line in LO
Owned
state at the owner must be written back on
replacement. The line contains a lock variable.
Lock
L
A line in L state contains a lock. The line may be
shared clean in a cache. The copy in memory
is current.
The general use of the directory states is as follows. The Invalid (I) state indicates the line is not cached in any cache in the system. A read request to a line in the I state results in an access to the lower level memory system. The Uncached (U) state indicates that the Modified line has been written back by a caching agent and is guaranteed to not be cached anywhere in the system. The Modified/Exclusive (ME) state indicates that the line has been read by a caching agent for read/write access. When the directory entry for a particular cache line is in the ME state, the caching agent may have the data in either the E state or the M state in its local cache. If the caching agent has the line in the E state, then it has read/write permission for its copy of the line, but it has not yet written to the line. If the caching agent has the line in the M state, then it has read-write permission for its cached copy of the line and it has already modified the data. When the caching agent has the line in the M state in its cache, then the data in memory is stale. The line is first installed in the caching agent in the E state and subsequently transitions to the M state when it is modified. Exactly one node in the system can have read/write access to the line. Any read request to a line in the ME state at the directory must first check to see where the most up-to-date copy in the system is. If the most recent data is in the processor cache, that processor must supply the line. If the processor has the cache line in the E state, then the line is invalidated (placed in the I state) in the processor cache and is supplied by the memory agent. When a line in ME state is read, the directory entry transitions to Owned (O) state to indicate that the data in memory is stale and also that there are sharers. Lock Modified (LM) state indicates that a line is Modified and additionally that the line contains a lock variable. Lock Owned (LO) state indicates that a line is Owned and additionally that the line contains a lock variable. The Lock (L) state indicates that the line contains a lock variable and that the copy in memory is current and may be cached clean.
In addition to using the new LM, LO and L directory states, memory controller 304 may implement other techniques for determining when the lock variable has been released. One such technique uses a release history buffer. The memory controller keeps the release history buffer for the last N stores without lock acquire attribute with the address and node that the store came from. The memory controller creates the entries in the release history buffer in response to RdBlkM and ChgToD requests. When a RdBlkM with a lock acquire attribute arrives, the memory controller examines the release history buffer for a recent store to the same address. If there was a recent release, then the memory controller waits for a programmed interval that is greater than the time it takes for a lock acquire request from the most distant node to arrive. After this interval, the memory controller examines all the lock acquire requests that have been received. It reorders the lock acquire requests to pass the lock in round robin order following the node stored in the history buffer. It then clears the store release entry in the history buffer. If there is no recent release present in the release history buffer, the memory controller 304 randomly orders the lock acquire requests and services them.
In the illustrated embodiment the ordered procedure for granting fair access to the lock variable was in round robin order. In other embodiments other ordered procedures for fair access are possible. Examples include reverse round robin order, an arbitrary order among all the nodes, historically balanced order, and random order. Note also that while the inter-node communication links were formed by coherent HyperTransport, other communication protocols may be used as well. The illustrated NUMA system included eight processors in a matrix but the spinlock support feature is useful for different topologies and is useful in NUMA systems having as few as two nodes. Note also that not all nodes in the system need to have processors associated with them.
While at least one exemplary embodiment has been presented in the foregoing detailed description, it should be appreciated that a vast number of variations exist. It should also be appreciated that the exemplary embodiment or exemplary embodiments are only examples, and are not intended to limit the scope, applicability, or configuration of the invention in any way. Rather, the foregoing detailed description will provide those skilled in the art with a convenient road map for implementing the exemplary embodiment or exemplary embodiments. It should be understood that various changes can be made in the function and arrangement of elements without departing from the scope of the invention as set forth in the appended claims and the legal equivalents thereof.
Number | Name | Date | Kind |
---|---|---|---|
4197580 | Chang et al. | Apr 1980 | A |
5375216 | Moyer et al. | Dec 1994 | A |
5535116 | Gupta et al. | Jul 1996 | A |
5553265 | Abato et al. | Sep 1996 | A |
5680576 | Laudon | Oct 1997 | A |
5727150 | Laudon et al. | Mar 1998 | A |
5829025 | Mittal | Oct 1998 | A |
5829028 | Lynch et al. | Oct 1998 | A |
5850534 | Kranick | Dec 1998 | A |
5996048 | Cherabuddi et al. | Nov 1999 | A |
6047316 | Barton et al. | Apr 2000 | A |
6101574 | Kumasawa et al. | Aug 2000 | A |
6212568 | Miller et al. | Apr 2001 | B1 |
6223258 | Palenca et al. | Apr 2001 | B1 |
6427188 | Lyon et al. | Jul 2002 | B1 |
6442666 | Stracovsky | Aug 2002 | B1 |
6480918 | McKenney et al. | Nov 2002 | B1 |
6490654 | Wickeraad et al. | Dec 2002 | B2 |
6502171 | Arimilli et al. | Dec 2002 | B1 |
6549961 | Kloth | Apr 2003 | B1 |
6654953 | Beaumont et al. | Nov 2003 | B1 |
6751684 | Owen et al. | Jun 2004 | B2 |
6792516 | Mastronarde et al. | Sep 2004 | B2 |
6823429 | Olnowich | Nov 2004 | B1 |
6829698 | Arimilli et al. | Dec 2004 | B2 |
6839816 | Borkenhagen et al. | Jan 2005 | B2 |
7062610 | Conway | Jun 2006 | B2 |
7155572 | Hughes et al. | Dec 2006 | B2 |
20020087796 | Fanning | Jul 2002 | A1 |
20030154350 | Edirisooriya et al. | Aug 2003 | A1 |
20030163649 | Kapur et al. | Aug 2003 | A1 |
20040019704 | Sano et al. | Jan 2004 | A1 |
20040034747 | Rowlands et al. | Feb 2004 | A1 |
20040128450 | Edirisooriya et al. | Jul 2004 | A1 |
Number | Date | Country |
---|---|---|
0 468 786 | Jan 1992 | EP |
0 681 241 | Nov 1995 | EP |
0 838 762 | Apr 1998 | EP |
WO 0038069 | Jun 2000 | WO |