The invention relates to semaphore management subsystems and more particularly to generic semaphore management subsystems and method for locking multiple semaphores.
Within a network processor several data frames are processed at the same time. Each data frame is processed by one processor/thread. Each processor/thread operates independently from all the other processors/threads. Thus, as the software (picocode) processes a data frame, the software has no knowledge of other frames which have been, are being, or will be processed. As data frames are processed, a thread may need access to a shared resource. This shared resource is shared among all threads. To allow a thread access to the resource without interference from other threads, semaphores are used.
A semaphore is a mechanism which allows a processor/thread to use a resource without interference from another processor/thread. A semaphore is used to ensure one and only one processor/thread has “ownership” of a given resource at any given time.
A network processor is a multi-processor environment with resources which can be accessed by all processors/threads. Thus, semaphores are an intricate part of network processors. As discussed above, network processors process data frames which belong to one or more data flows. To increase performance and eliminate the need to use general system resources, semaphore management in hardware is implemented.
When writing software, it is often desirable to access more than one resource within the scope of a software function. If updates to these resources are necessary, it is desirable to lock these resources. As software functions get more complex, it becomes necessary to lock multiple resources. As a specific example, consider tree management on a Network Processor. In this algorithm, picocode may need to lock the root of the tree chain that it is working on. In addition, picocode may also need to lock the leaf address which may be updated from multiple places. Implementing this algorithm requires the locking of two semaphores simultaneously.
Another example is when common software functions are used. Common software routines are software routines that can be accessed from any thread. Some common routines cannot be run on multiple threads at the same time, for example, common software routines used in queue management. Picocode may need to access the Free Queue, and also a general purpose queue at the same time and this would be done with two separate routines protected by two different semaphores to prevent the routines from running on multiple threads. One can see that the ability to lock multiple semaphores at once can provide a significant performance increase. Some common code routines require multiple semaphores to be locked at the same time in order to maximize execution performance. Having multiple semaphores per thread allows all the threads to execute these common code routines. If only one semaphore is available, one thread would have to be dedicated to running the common code routines that require multiple semaphores. Multiple semaphores provide finer granularity in locking resources and provide the ability for different combinations of locked down resources. With a single semaphore, groups of resources would have to be pre-defined for locking down together. With multiple semaphores, the software has more freedom in the ability to pick and choose the combinations of resources to be locked down, providing a very flexible and powerful solution.
Described is a semaphore system that enables one entity to lock multiple semaphores simultaneously. The semaphore system includes a storage structure in which N (N can be any value greater than 0) storage locations are assigned to each thread of a multiprocessing complex. A one-bit indicator is provided for each storage location. The setting of the indicator indicates the state of the semaphore associated with the location. For example, if the bit is set to a logical “I”, the semaphore is locked and unlocked if the bit is set to logical “0”. The address (i.e. the semaphore value) of the semaphore can be recorded in each location.
A software lock command is generated to lock one of N semaphores assigned to each thread of a multiprocessing unit. For example, assume N=2. To lock both semaphores, one lock command is issued with sem_num=0 and a second lock command is issued with sem_num=1. Of course a single command with appropriate parameters (two semaphore values) could be issued to lock both semaphores. A software unlock (Semaphore_Unlock) command is structured such that it can unlock anywhere from one locked semaphore to N locked semaphores.
This invention is described in conjunction with the Semaphore Management System For Use With Multi-Thread Processor Systems (hereinafter the SMS system) described in USPTO published application 2003/0005195 A1, published Jan. 2, 2003 and incorporated herein by reference. To the extent possible similar components will use the same reference numerals used therein. While the invention is described in conjunction with the SUS system, it will be apparent to those skilled in the art that it is adaptable for use with a variety of semaphore management systems such as the Ordered Semaphore Management Subsystem described in USPTO published application 2003/0002440 A1, published Jan. 2, 2003 and USPTO application for Flow Look Ahead in an Ordered Semaphore Management System filed herewith.
In
Each of the processors 13-1-13-n include a semaphore coprocessor 13p which interfaces a hardware semaphore manager subsystem 16 constructed according to the invention. The semaphore subsystem 16 is implemented in hardware and interfaces with, for example, the Dyatic Protocol Processor Unit (DPPU) of the using processing system. Each DPPU contains four threads which can each process one data frame. Each DPPU has one Semaphore Co-Processor associated with it. The threads in a given DPPU interface to the one Semaphore Co-Processor within the DPPU. The multiple Semaphore Co-Processors all communicate with the central Semaphore Manager subsystem. The Semaphore Manager subsystem 16 contains all of the tables and control logic to lock, unlock, and arbitrate for semaphores.
In
A semaphore can be locked when a software thread issues a single command “Semaphore Lock” (Sem_Lock) with three parameters. The first parameter is the “Semaphore Value” (Sem_Val). This is, for example, a 32 bit value which the thread wishes to lock. The second parameter is the “Timeout Enable” (Timeout_Enable) bit. When the Timeout Enable bit is set and the requested semaphore is already locked by a different thread, the Semaphore Lock command will terminate without locking the semaphore. The third parameter is the Semaphore Number (Sem_Num). This parameter indicates which of the two or more assigned addresses in storage 21 the requested semaphore value is to be stored at, or unlocked in the case of an unlock command. As pointed out above, two semaphores can be locked at the same time by issuing two semaphore lock commands. A single command with appropriate parameters (two or more Sem_Val's and associated Sem_Num's) could be implemented.
In the preferred embodiment, each thread has more than one assigned register in the semaphore value storage and is thus identified as the source of the semaphore value requested. Alternatively, a content addressable memory system could be used in which case the requested semaphore value can be placed in any available register along with the thread number/ID and the Sem_Num to distinguish between multiple semaphore requests from the same thread.
In the preferred embodiment each thread was allocated two storage locations and could concurrently lock two different semaphores. The relative addresses of the allocated storage locations are determined by multiplying the thread number or ID (0 thru n) by two and adding the Sem_Num value (0 or 1). If more than two Sem_Num's are used the relative addresses for each thread can be determined by multiplying the thread number (0 thru n) by the maximum number m of Sem_Num's and adding the specific Sem_Num (0 thru (m−1)) provided with the semaphore lock request.
If block 102 is negative the process proceeds to block 110, a fair round-robin function which selects one Semaphore Lock Command to service. This function selects one thread of all threads which could all issue a Semaphore Lock command at the same time. Block 120 is a test to see if a Semaphore Lock command from a given thread won the round-robin selection. If the Semaphore Lock command did not win the round-robin selection, it is returned to block 110 (the round-robin function) until it does win.
If the Semaphore Lock command does win the round-robin selection, the logic flow continues to block 130. At block 130, the Semaphore Value (Sem_Val) parameter received with the Semaphore lock command is checked to determine if this 32 bit value (Sem_Val) is already locked. This is accomplished by comparing the Sem_Val to the contents of the Semaphore_Value registers in
If the Sem_Val is locked, block 150 checks if the Sem_Val is already locked by thread N, the same thread which is requesting to lock it again. If thread N is attempting to lock the Sem_Val for which it has already locked, block 160 will generate an error signal to the software program on thread N at block 160 and signals the Semaphore Lock command is complete at block 190.
If the Sem_Val is locked (go to block 150) and it is not locked by thread N, the thread requesting the Sem_Val to be locked, control is passed to block 170. At block 170, the Timeout_Enable parameter is checked. If the Timeout_Enable parameter is not set (logic ‘0’b), this Sem_Lock command is returned to the round-robin selection algorithm, block 110. This allows the Sem_Val command to eventually lock the Sem_Val once it becomes unlocked. If the Timeout_Enable parameter is set (logic ‘1’b) at block 170, block 180 will signal the software program that the Sem_Val was not able to be locked for thread N. The Semaphore Lock command is complete at block 190.
The foregoing is illustrative of the present invention and is not to be construed as limiting the invention. While several embodiments of this invention have been described in detail, those skilled in this art will readily appreciate that many modifications are possible without materially departing from the novel teachings and advantages of this invention. Accordingly, all such modifications are intended to be included within the scope of this invention as defined by the claims. In the claims, means-plus-function clauses are intended to cover the structures described herein as performing the recited function and structural functional equivalents thereof. Therefore, it is to be understood that the foregoing is illustrative of the present invention and is not to be construed as limited to the specific embodiments disclosed, and that modifications to the disclosed embodiments, as well as other embodiments, are intended to be included within the scope of the claims appended hereto.
This application claims the benefit of the filing date of provisional application Ser. No. 60/325,076, filed Sep. 26, 2001 for METHOD FOR LOCKING MULTIPLE SEMAPHORES IN HARDWARE.
Number | Name | Date | Kind |
---|---|---|---|
4805106 | Pfeifer | Feb 1989 | A |
4907228 | Bruckert et al. | Mar 1990 | A |
5142632 | Tychon et al. | Aug 1992 | A |
5159686 | Chastain et al. | Oct 1992 | A |
5233701 | Nakata | Aug 1993 | A |
5261106 | Lentz et al. | Nov 1993 | A |
5276886 | Dror | Jan 1994 | A |
5339443 | Lockwood | Aug 1994 | A |
5485593 | Baker | Jan 1996 | A |
5548780 | Krein | Aug 1996 | A |
5613139 | Brady | Mar 1997 | A |
5664092 | Waites | Sep 1997 | A |
5675829 | Oskouy et al. | Oct 1997 | A |
5696939 | Iacobovici et al. | Dec 1997 | A |
5734909 | Bennett | Mar 1998 | A |
5842018 | Atkinson et al. | Nov 1998 | A |
5852731 | Wang et al. | Dec 1998 | A |
5862180 | Heinz | Jan 1999 | A |
5864653 | Tavallaei et al. | Jan 1999 | A |
5893157 | Greenspan et al. | Apr 1999 | A |
5901308 | Cohn et al. | May 1999 | A |
5931923 | Roberts | Aug 1999 | A |
6018785 | Wenniger | Jan 2000 | A |
6026427 | Nishihara et al. | Feb 2000 | A |
6029190 | Oliver | Feb 2000 | A |
6070254 | Pratt et al. | May 2000 | A |
6079013 | Webb et al. | Jun 2000 | A |
6105085 | Farley | Aug 2000 | A |
6119246 | McLaughlin et al. | Sep 2000 | A |
6122713 | Huang et al. | Sep 2000 | A |
6125401 | Huras et al. | Sep 2000 | A |
6128706 | Bryg et al. | Oct 2000 | A |
6131094 | Gord | Oct 2000 | A |
6134579 | Tavallaei et al. | Oct 2000 | A |
6134619 | Futral et al. | Oct 2000 | A |
6154847 | Schofield et al. | Nov 2000 | A |
6161169 | Cheng | Dec 2000 | A |
6173313 | Klots et al. | Jan 2001 | B1 |
6182108 | Williams et al. | Jan 2001 | B1 |
6199094 | Presler-Marshall | Mar 2001 | B1 |
6725457 | Priem et al. | Apr 2004 | B1 |
6748470 | Goldick | Jun 2004 | B1 |
7036125 | Basso et al. | Apr 2006 | B1 |
7062583 | Kolinummi et al. | Jun 2006 | B1 |
7089555 | Calvignac et al. | Aug 2006 | B1 |
7100161 | Latour | Aug 2006 | B1 |
20020138544 | Long | Sep 2002 | A1 |
20030002440 | Calvignac et al. | Jan 2003 | A1 |
20030005195 | Davis et al. | Jan 2003 | A1 |
20030060898 | Jenkins et al. | Mar 2003 | A1 |
20030115476 | McKee | Jun 2003 | A1 |
20030145035 | de Bonet | Jul 2003 | A1 |
Number | Date | Country |
---|---|---|
0953903 | Nov 1999 | EP |
1033654 | Sep 2000 | EP |
4361340 | Dec 1992 | JP |
8329019 | Dec 1996 | JP |
9044376 | Feb 1997 | JP |
1 1039176 | Feb 1999 | JP |
9231123 | Feb 1999 | JP |
11272480 | Oct 1999 | JP |
2001005694 | Jan 2001 | JP |
2001022720 | Jan 2001 | JP |
WO9603697 | Feb 1996 | WO |
Number | Date | Country | |
---|---|---|---|
20030061259 A1 | Mar 2003 | US |
Number | Date | Country | |
---|---|---|---|
60325076 | Sep 2001 | US |