code 128 c# Processor Affinity in C#.NET

Maker Code-128 in C#.NET Processor Affinity

Processor Affinity
Code 128A Maker In Visual C#
Using Barcode maker for VS .NET Control to generate, create Code128 image in Visual Studio .NET applications.
www.OnBarcode.com
Code 128 Code Set A Recognizer In C#.NET
Using Barcode decoder for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Processor affinity is a means of controlling the scheduling of a process so that a certain process s threads will execute on a set of processors.
Generate Barcode In Visual C#.NET
Using Barcode generator for Visual Studio .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
EAN / UCC - 13 Printer In Visual C#
Using Barcode maker for VS .NET Control to generate, create EAN / UCC - 13 image in .NET framework applications.
www.OnBarcode.com
A process can also tell the scheduler that it should run only on certain processors. This keeps the process on the processors where it is allowed to execute. This is called processor affinity. It is possible to change a process s processor affinity using the System.Diagnostics.Process class. Using the static/shared method on the Process class called GetCurrentProcess retrieves a reference to the current process. We can then change the ProcessorAffinity property to indicate the desired Figure 5.13 Bitmask affinity. ProcessorAffinity is a pointer to a 32-bit value example integer. It contains a bitmask on which processors a process can execute. The low-order bit corresponds to the first processor in the machine, CPU 0. The high-order bit matches the last processor that can be installed in the machine, which under 32-bit Windows is 32. In figure 5.13 we can infer that the machine has at least three processors and that the process can execute on CPU 1 and CPU 2 but not on CPU 0. DIGGING DEEPER INTO THREAD CONTROL 89
Encode PDF-417 2d Barcode In Visual C#
Using Barcode generation for .NET framework Control to generate, create PDF417 image in VS .NET applications.
www.OnBarcode.com
Encode UPC-A In Visual C#
Using Barcode creator for .NET Control to generate, create UPC A image in .NET applications.
www.OnBarcode.com
The integer value returned by ProcessorAffinity would be 6: ( 0*23) + ( 1*22) + (1*21) + (0*20 )=6 Figure 5.14 shows the impact of changing the processes processor affinity.
1D Barcode Creation In Visual C#
Using Barcode generator for Visual Studio .NET Control to generate, create 1D image in VS .NET applications.
www.OnBarcode.com
Creating USPS Confirm Service Barcode In C#
Using Barcode drawer for .NET Control to generate, create USPS Confirm Service Barcode image in VS .NET applications.
www.OnBarcode.com
Figure 5.14 Processor affinity
Code128 Maker In None
Using Barcode maker for Font Control to generate, create Code 128B image in Font applications.
www.OnBarcode.com
Code 128 Code Set A Encoder In None
Using Barcode drawer for Software Control to generate, create Code 128 image in Software applications.
www.OnBarcode.com
Since Thread T1 has an affinity of 6 it will not be scheduled on CPU 0 or CPU 3. It will only be scheduled on CPU 1 or CPU 2. When a process first loads, it can determine what processors it can execute on by examining the contents of ProcessorAffinity. It is important to remember that even though you might set the processor affinity, it is possible that it will change during the life of the process. One way this can happen is by using Task Monitor. If you rightclick on a process, on a machine with more than one processor, you can select Set Affinity. This will display the dialog box in figure 5.15. By selecting what processor the current process can execute on, you can essentially override any settings that might have been specified by the program. Remember this
UCC - 12 Printer In Objective-C
Using Barcode generator for iPhone Control to generate, create Universal Product Code version A image in iPhone applications.
www.OnBarcode.com
Paint 2D In Visual Basic .NET
Using Barcode drawer for .NET framework Control to generate, create 2D image in Visual Studio .NET applications.
www.OnBarcode.com
ProcessorAffinity
Creating QR Code ISO/IEC18004 In Objective-C
Using Barcode creation for iPad Control to generate, create Denso QR Bar Code image in iPad applications.
www.OnBarcode.com
Paint Quick Response Code In None
Using Barcode generation for Software Control to generate, create QR Code ISO/IEC18004 image in Software applications.
www.OnBarcode.com
dialog box
Code 39 Extended Printer In Objective-C
Using Barcode encoder for iPhone Control to generate, create Code-39 image in iPhone applications.
www.OnBarcode.com
Draw EAN-13 Supplement 5 In Objective-C
Using Barcode encoder for iPad Control to generate, create EAN / UCC - 13 image in iPad applications.
www.OnBarcode.com
CHA PTE R 5
Generating Code-128 In Java
Using Barcode maker for Java Control to generate, create Code 128 Code Set B image in Java applications.
www.OnBarcode.com
Create Barcode In None
Using Barcode creation for Software Control to generate, create Barcode image in Software applications.
www.OnBarcode.com
CONTROLLING THREADS
Making Barcode In Objective-C
Using Barcode creation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Code 128 Code Set B Generator In VS .NET
Using Barcode encoder for .NET Control to generate, create ANSI/AIM Code 128 image in VS .NET applications.
www.OnBarcode.com
when developing. Do not count on multiple processors. Even in situations where there are multiple processors the scheduler may choose to execute each thread of a process on the same processor. Under symmetric multiprocessing, the process has very little control of how it is scheduled. In general, it is better to let the operating system take care of it for you.
USING TASK MANAGER TO SET PROCESSOR AFFINITY
1 2 3 4 5
Open Task Manager. Right-click on the process that you wish to change the processor affinity of. Select Set Affinity from the context menu that pops up. Update the check boxes. Click OK.
One use of this type of capability would be to restrict a misbehaving multithreaded application to execute on a single processor. This may remove concurrency issues. Since each thread in the process would execute on the same processor, true concurrency would not be reached. This may reduce timing issues. This approach is not a replacement to proper design and implementation, but under extreme circumstances it is a valid short-term fix. 5.7.3 Specifying an ideal processor Suppose that you wanted the web site monitor to utilize a certain processor. One way you could accomplish this is to set the process s processor affinity as we discussed in the last section. A less restrictive approach is to set the thread s ideal processor.
Ideal Processor
An ideal processor is one that a thread would prefer to be scheduled on. The scheduler may or may not honor that preference.
This allows us to give the scheduler a hint as to what processor we think that the thread should execute on. The scheduler may or may not listen to our hint because we don t know as much about the load on the system as it does. It may be that some other process also thinks it should execute on the same processor we think we should execute on. The motivation of setting an ideal processor is to take advantage of the CPU s cache. Since it has been working with the data our thread uses, the data is already in the CPU s cache. Loading the CPU s cache is a relatively expensive operation. Processors have caches because it is much faster to retrieve data from a cache than it is from main memory. Caching is also done at multiple levels. If the data the processor needs isn t in the first-level cache it looks in the second. If the data isn t in the second-level cache, it looks in main memory. Not all systems have a second-level cache. For those systems with only a first-level cache, if the data needed isn t in that cache it is loaded there from main memory. Processor cache sizes have grown to where relatively large first-level caches are not unusual. When a processor references data, it is generally loaded into the cache (listing 5.5).
Copyright © OnBarcode.com . All rights reserved.