Executing an instruction of currently active thread before context switch upon receiving inactive context ID to be activated

Information

  • Patent Grant
  • 9519507
  • Patent Number
    9,519,507
  • Date Filed
    Friday, May 1, 2015
    9 years ago
  • Date Issued
    Tuesday, December 13, 2016
    7 years ago
Abstract
Systems and methods for managing context switches among threads in a processing system. A processor may perform a context switch between threads using separate context registers. A context switch allows a processor to switch from processing a thread that is waiting for data to one that is ready for additional processing. The processor includes control registers with entries which may indicate that an associated context is waiting for data from an external source.
Description
BACKGROUND OF THE INVENTION

This invention relates generally to the field of network communication processors, and more specifically to the field of system device instructions and context switching.


Network communication systems demand real-time performance. The performance of conventional processors in network communication systems is degraded by long latency accesses, especially to shared resources. For example, in order to look up data in a table lookup unit, a processor must send an operation with data to the table lookup unit (TLU) commanding the TLU to look up data in a table. After performing the lookup operation, the TLU stores the resulting data internally. The processor sends a load command requesting that the TLU load the result on the bus and return the data to the processor. This procedure requires two bus transactions initiated by the processor. Therefore, it would be desirable to have a single transaction both command the device to perform an operation and provide the result to the processor.


Another latency problem is that some conventional processors will await receipt of the result of the look up before processing other instructions. One way of dealing with this problem is to perform instructions in a different thread while a first thread awaits data. This is called a context switch. Context switches performed in software, store all data in the processor registers in memory and then use the processor registers for a new context. This requirement to store and restore data using a single set of registers wastes processor cycles. Therefore, it would be desirable to have a context switch performed that does not waste processor cycles.


SUMMARY OF THE INVENTION

Systems and methods consistent with the present invention allow for performing a single transaction that supplies data to a device and commands the device to perform an action and return the result to a processor.


In addition, systems and methods consistent with the present invention further allow for performing a context switch with no stall cycles by using an independent set of registers for each context.


A processing system consistent with the present invention includes a processor configured to formulate an instruction and data for sending to a device. The formulated instruction requests that the device perform a command and return data to the processor. A bus controller is configured to generate a system bus operation to send the formulated instruction and data along with a thread identifier to the device.


A processor consistent with the present invention executes instructions in threads. The processor includes a context register file having a separate set of general registers for a plurality of contexts, where the threads are each assigned a separate context, and context control registers having a separate set of control registers for the plurality of contexts.


Another processing system consistent with the present invention includes a processor configured to formulate an instruction and data, from a thread associated with a first context, for sending to a device, the instruction requesting the device to perform a command and return data to the processor, and perform a context switch to switch from processing the first context to a second context. A bus controller is configured to generate a system bus operation to send the formulated instruction and data along with a thread identifier to the device.


A method consistent with the present invention processes a single instruction that both requests a system device operation and requests the system device return data, the method comprising the steps of fetching an instruction from memory, forming a descriptor, constructing a system bus address, initiating a system bus operation to request a device to perform an operation and return data to a processor identified in a thread identifier, and retrieving return data from a system bus based on the thread identifier provided with the returned data.


Another method consistent with the present invention switches between contexts using a processor having a context register file having a separate set of general registers for a plurality of contexts, each set of registers being associated with a thread, and context control registers having a separate set of control registers for the plurality of contexts, the method comprising the steps of receiving a context switch instruction, receiving an identifier of a next context to activate from the scheduler, performing a next instruction in a current context, and pointing a processor program counter to the context program counter in the context control register associated with the next context.





BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate one embodiment of the invention and, together with the description, serve to explain the objects, advantages, and principles of the invention. In the drawings:



FIG. 1 is a block diagram of a processing system consistent with methods and systems of the present invention;



FIG. 2a shows a context register file consistent with methods and systems of the present invention;



FIG. 2b shows a context control file consistent with methods and systems of the present invention;



FIG. 3 shows an instruction format consistent with methods and systems of the present invention;



FIG. 4 is a flowchart showing the steps for processing a write descriptor load word instruction consistent with methods and systems of the present invention;



FIG. 5 is a flowchart showing the steps of a method for processing a write descriptor load word with a context switch consistent with methods and systems of the present invention; and



FIG. 6 is a flowchart showing the steps of a method for completing the load word for the instruction in FIG. 5.





DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

Reference will now be made in detail to embodiments consistent with this invention that are illustrated in the accompanying drawings. The same reference numbers in different drawings generally refer to the same or like parts.


Processing systems for network communications require several bus and processor cycles to perform a write to a system device and a read from the system device. Systems and methods consistent with the present invention provide a single instruction that directs a device to read and load data when the device is ready. In accordance with a preferred embodiment, the single instruction includes a thread identifier so that the device can send the data back to the requesting thread at the processor.


In addition, systems and methods consistent with the present invention provide for a context switch that prevents the introduction of stall cycles by using a different set of registers for a plurality of threads. In this manner, processing can switch quickly from one set of registers used by one thread to a different set of registers used by another thread. As used herein, the term thread describes a set of program instructions or a software program that relies on a context register set to perform a particular task.



FIG. 1 shows an exemplary processing system that may be used in systems and methods consistent with the present invention. Processor 100 is preferably a RISC type processor that may include, among other elements, those in Lexra's LX4180 processor. In this example, processor 100 connects to instruction memory 120, which may be, for example, a cache, RAM or DRAM.


Processor 100 includes a context register file 200 and context control registers 210. As used herein, a context is an independent set of general registers in context register file 200 and control registers in context control register 210 that are used in executing a thread. As stated, a thread may be software that relies on the contents of the context registers to perform a particular task. The term context may also generally be used to refer to a thread currently using the context's registers. Processor 100 further includes a processor program counter (PPC) 110 that points to the program counter of an active context stored in a context program counter within the context control registers 210.


Processor 100 couples to scheduler 130. Scheduler 130 determines the context that should execute in the event of a context switch. This context switch optimizes the processor and bus cycles. If, for example, a current active context is awaiting data, a context switch may be performed so that another context is processed while the current context awaits the data, thereby reducing the waste of valuable processing time. In accordance with the disclosed embodiment, the current context will not be reactivated until the scheduler selects it after another context switch occurs.


Processor 100 sends commands over system bus 150 to system device 160 via bus controller 140. Bus controller 140 and system bus 150 may be similar to those used with conventional RISC processors. In systems and methods consistent with the present invention, however, bus controller 140 adds a global thread identifier (GTID) to every outgoing transaction. The GTID indicates the processor number and context number of the originating thread. System device 160 may be, for example, a table look-up unit. And, although FIG. 1 shows only one system device, one of ordinary skill in the art will recognize that multiple devices may be in communication with system bus 150.


Bus controller 140 generates command data (CMD) for each instruction, indicating whether the instruction is, for example, a read, a write, a split read, a write-twin-word split read. In this embodiment, a word consists of 32 bits and a twin word has 64 bits. Among its other tasks, bus controller 140 outputs a device address to system bus 150 along with the CMD, the GTID, and any data to be sent to the device. The device address identifies the device that will receive the command and the GTID is used by the device in returning data to a requesting processor. Again one of ordinary skill will recognize that processor 100 may include additional parts, many of which are common and whose description is unnecessary to understand the systems and methods consistent with the present invention.



FIG. 2a shows an exemplary context register file 200 having 8 contexts, context 7 through context 0. In this figure, each context has 32 physical general registers, but the number of contexts and the number of registers may vary depending on the complexity of the particular system, the amount of data communication on the system bus, the number of system devices present, etc.



FIG. 2b shows an exemplary context control file 210 having 3 control registers for each of the 8 contexts shown in FIG. 2a. Context control file 210 includes a context program counter (CXPC) 212 for keeping track of the next instruction to be executed in the context and a context status register (CXSTATUS) 214 having a wait load bit, which, when set, indicates that the context is awaiting data from an external device. CXSTATUS 214 may include additional status information such as an indication that the context requires external events or data to complete its task. A write address register 216, also within context control file 210, is configured to store the address of a general purpose register in an inactive context that may be awaiting data from an external device.



FIG. 3 is an exemplary representation of an instruction 300 stored in instruction memory 120. Instruction 300 includes an opcode field 310 and sub-opcode field 360 that indicate the particular operation requested. The requested operations may be commands such as read, write, and write-split read. In this example, a write-split read is an instruction that writes to a system device and directs the device to return read data when available. Instruction 300 also includes rS 320, rT 330, and rD 340; fields referring to the general purpose registers in FIG. 2a. The identified registers hold data used by the instruction or the registers that will ultimately be receiving the instruction results. In a write-split read instruction, for example, rS 320 and rT 330 identify the registers holding data that will be written to system device 160 at system device address 350. rD 340 is the identifier of the destination register, indicating the location in which the result of the load instruction should be stored. The identity of register rD may be stored in the write address register 216 so that when load data is returned, processor 100 reads the context control file 210 to determine the particular register in which to write the result.



FIG. 4 shows the steps of a method 400 for processing a write-split read instruction consistent with the methods and systems of the present invention. First, processor 100 fetches instruction 300 from instruction memory 120 based on a value in PPC 110 (step 410). Processor 100 then forms a 64 bit descriptor by concatenating bits [63:32] of register S 320 and bits [31:0] of register T 330 (step 420). Processor 100 constructs a system bus address using device address 350 provided in the instruction (step 430). The actual device address is less than 32 bits, so the remaining system bus address bits are set to zero or some constant predefined value.


Following the construction of the system bus address, processor 100 initiates a system bus operation to write the descriptor to the device, having the device perform some function, and requests that the device provide a read word response back to the processor identified with a GTID (step 440). Bus controller 140 sends out instruction 300 to the device address including data, the command, and a GTID. System device 160 saves the descriptor in a memory, performs an operation using information in the descriptor, and returns the result of the operation as read data directed to the processor identified in the GTID (step 450). Bus controller 140 then receives a read word or twin word response from the system device (step 460). Finally, processor 100 writes the received data to rD register 340 (step 470) thus, completing the operation.



FIG. 5 show the steps of a method 500 for processing a write descriptor load word (WDLW) instruction in accordance with systems and methods of the present invention. Referring to FIG. 5, processor 100 initially fetches instruction 300 from instruction memory 120 based on the value in PPC 110 (step 510). Using this value, processor 100 forms a 64-bit descriptor by concatenating bits [63:32] of register S 320 and bits [31:0] of register T 330 (step 520). Processor 100 next sets the wait load bit in context status register 210 of the active context (step 530). Processor 100 then constructs a system bus address using device address 350 provided in the instruction (step 540). The device address is less than 32 bits, so the remaining system bus address bits are set to zero or some constant predefined value.


Once the system bus address is constructed, processor 100 initiates a system bus operation to write the descriptor to the device and requests that the device provide a read word response (step 550). Processor 100 stores the register identified in rD 340 in write address register 216 in the active context's control file 210 indicating the register that will receive any returned data from system device 160 (step 560).


Steps 565-590 describe the steps used to perform a context switch in systems and methods consistent with the present invention. Processor 100 first receives an identifier of the next context to be activated from scheduler 130 (step 565). Processor 100 then performs the following instruction in the active context (step 570). By performing the next step in this instruction before moving on to the next context, the processor is able to execute an instruction, and is performing useful work instead of stalling for a cycle while the context switch is performed. Processor 100 then stores program counter (PC) of the next instruction in this active context in the CXPC 212 of the active context (step 580). Processor next points PPC to CXPC 212 of the new context designated by scheduler 130 (step 590).



FIG. 6 shows the remaining steps 600 for completing the load word portion of the WDLW instruction described in the method of FIG. 5. After system device 160 receives the command, data, and the GTID from system bus 150, it writes the descriptor to a memory. System device 160 then performs any requested function and loads the resulting data onto system bus 150 along with the GTID (step 610). Upon receiving the read word response from system bus 150 (step 620), bus controller 140 forwards it to processor 100. Processor 100 writes this read word to the register indicated in the write address register 216 by obtaining the identity of the originating context from the GTID (step 630). Processor 100 next clears the originating context's wait load flag in CXSTATUS register 214, indicating that the context is available for execution (step 640). Finally, scheduler 130 monitors the wait load flags of all of the contexts and will select this context when appropriate (step 650).


There are many variations that may be made consistent with the present invention. For example, in another embodiment, system device 160 returns a twin word in response to a write twin word read twin word instruction (WDLT). Further, while the implementations above specifically mention word or twin word data reads and writes, systems and methods consistent with the present invention may be used with other sized data reads and writes. In addition, there may be multiple processors sharing the system bus and accessing the system bus devices.


The foregoing description is presented for purposes of illustration and description. It is not exhaustive and does not limit the invention to the precise form disclosed. Modifications and variations are possible in light of the above teachings or may be acquired from practicing the invention. The scope of the invention is defined by the claims and their equivalents.

Claims
  • 1. A method for context switching in an electronic processor, comprising: receiving, at the electronic processor from a scheduler, an identity of a first context, the first context currently inactive;performing, at the electronic processor after the receiving the identity of the first context, a first instruction of a thread associated with a second context, the second context currently active;storing, at the electronic processor at a context program counter register of the second context, a program counter of the first instruction; andpointing, at the electronic processor, a processor program counter to a context program counter register of the first context.
  • 2. The method of claim 1, further comprising: setting, at the electronic processor, a bit of a context status register of the second context, the bit indicating that the second context is awaiting data from an external device.
  • 3. The method of claim 2, wherein the setting is performed before the receiving.
  • 4. The method of claim 2, further comprising clearing the bit of the context status register of the second context after the second context has received the data from the external device.
  • 5. The method of claim 2, further comprising storing an identity of a register, the identity of the register stored at a field of a second instruction of the thread, the register configured to store the data from the external device.
  • 6. The method of claim 5, wherein the second instruction is performed before the first instruction.
  • 7. A system for context switching, comprising: a memory configured to store an identity of a first context, the first context currently inactive; andan electronic processor having a context program counter register of the first context, a context program counter register of a second context, and a processor program counter, the electronic processor configured to perform, after the identity of the first context is stored in the memory, a first instruction of a thread associated with the second context, the second context currently active, the electronic processor configured to store, at the context program counter register of the second context, a program counter of the first instruction, and the electronic processor configured to point the processor program counter to the context program counter register of the first context.
  • 8. The system of claim 7, wherein the electronic processor has a context status register of the second context, the electronic processor further configured to set a bit of the context status register of the second context, the bit indicating that the second context is awaiting data from an external device.
  • 9. The system of claim 8, wherein the electronic processor is configured to set the bit of the context status register of the second context before the identity of the first context is stored in the memory.
  • 10. The system of claim 8, wherein the electronic processor is configured to clear the bit of the context status register of the second context after the second context has received the data from the external device.
  • 11. The system of claim 8, wherein the electronic processor has a write address register of the second context, the electronic processor further configured to store, in the write address register of the second context, an identity of a register, the identity of the register stored in a field of a second instruction of the thread, the register configured to store the data from the external device.
  • 12. The system of claim 11, wherein the electronic processor is configured to perform the second instruction before the first instruction.
CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a division of U.S. application Ser. No. 12/429,655 filed Apr. 24, 2009, which in turn is a continuation of U.S. application Ser. No. 11/552,640, filed Oct. 25, 2006, now U.S. Pat. No. 7,529,915 issued May 5, 2009, which is a divisional of U.S. application Ser. No. 09/591,510, filed Jun. 12, 2000, now U.S. Pat. No. 7,162,615 issued Jan. 9, 2007, each of which is fully incorporated herein by reference.

US Referenced Citations (48)
Number Name Date Kind
5008812 Bhandarkar et al. Apr 1991 A
5197138 Hobbs et al. Mar 1993 A
5345588 Greenwood et al. Sep 1994 A
5353418 Nikhil et al. Oct 1994 A
5361334 Cawley Nov 1994 A
5386563 Thomas Jan 1995 A
5390332 Golson Feb 1995 A
5421014 Bucher May 1995 A
5488716 Schneider et al. Jan 1996 A
5493687 Garg et al. Feb 1996 A
5506987 Abramson et al. Apr 1996 A
5524250 Chesson et al. Jun 1996 A
5535397 Durante et al. Jul 1996 A
5649229 Matsuzaki et al. Jul 1997 A
5649230 Lentz Jul 1997 A
5696956 Razdan et al. Dec 1997 A
5701493 Jaggar Dec 1997 A
5758112 Yeager et al. May 1998 A
5761506 Angle et al. Jun 1998 A
5764885 Sites et al. Jun 1998 A
5802272 Site et al. Sep 1998 A
5860003 Eidler et al. Jan 1999 A
5900025 Sollars May 1999 A
5926646 Pickett et al. Jul 1999 A
5933627 Parady Aug 1999 A
6026475 Woodman Feb 2000 A
6182183 Wingard et al. Jan 2001 B1
6205468 Diepstraten Mar 2001 B1
6216220 Hwang Apr 2001 B1
6223208 Kiefer et al. Apr 2001 B1
6269425 Mounes-Toussi et al. Jul 2001 B1
6292888 Nemirovsky et al. Sep 2001 B1
6378065 Arnold et al. Apr 2002 B1
6389449 Nemirovsky et al. May 2002 B1
6442585 Dean et al. Aug 2002 B1
6477562 Nemirovsky et al. Nov 2002 B2
6535905 Kalafatis et al. Mar 2003 B1
6567839 Borkenhagen et al. May 2003 B1
6789100 Nemirovsky et al. Sep 2004 B2
7020879 Nemirovsky et al. Mar 2006 B1
7058064 Nemirovsky et al. Jun 2006 B2
7082519 Kelsey et al. Jul 2006 B2
7120783 Fotland et al. Oct 2006 B2
7162615 Gelinas et al. Jan 2007 B1
7529915 Gelinas et al. May 2009 B2
9047093 Gelinas et al. Jun 2015 B2
20010043610 Nemirovsky et al. Nov 2001 A1
20020038416 Fotland et al. Mar 2002 A1
Non-Patent Literature Citations (7)
Entry
File history for U.S. Appl. No. 09/591,510, filed Jun. 12, 2000. Inventors: Robert Gelinas et al.
File history for U.S. Appl. No. 11/552,640, filed Oct. 26, 2006. Inventors: Robert Gelinas et al.
File history for U.S. Appl. No. 12/429,655, filed Apr. 24, 2009. Inventors: Robert Gelinas et al.
Class-IC Data Sheet; MOSAID Semiconductors; 1999, 2 pages.
Hehr, Ron; UTCAM-ENGINE™ Accelerates Large Table Look-up Applications; 1999; 28 pages; UTMC Microelectronic Systems; Colorado Spring, CO.
Rabaey et al.; “Challenges and Opportunities in Broadband and Wireless Communication Designs”; Proc. of the 2000 IEEE/ACM International Conference on CAD, Nov. 2000, pp. 76-82, San Jose, CA.
Product Brief; C-5 Digital Communications Processor; 1999-2000; 8 pages; C-Port Corporation, North Andover, MA 01845.
Related Publications (1)
Number Date Country
20150234676 A1 Aug 2015 US
Divisions (2)
Number Date Country
Parent 12429655 Apr 2009 US
Child 14701871 US
Parent 09591510 Jun 2000 US
Child 11552640 US
Continuations (1)
Number Date Country
Parent 11552640 Oct 2006 US
Child 12429655 US