Wiki-en veut du vieux:)?
Bienvenu dans le Forum (et for Femmes:)!) des 'wikinenveut'Smile!
On y discute de tout les sujets, concernant l'exclusion, le droit des pères, l'écriture et l'art en général, mais surtout et sinon de Linux et des Logiciels Libres et des NTIC, par et pour les gens de R.2000:)!
Everybody welcomes at Home:)!
Rechercher
 
 

Résultats par :
 


Rechercher Recherche avancée

Shopactif


Navigation
 Portail
 Index
 Membres
 Profil
 FAQ
 Rechercher
Partenaires
Forum gratuit


Tchat Blablaland



Comment voir si l'hyperthreading est actif ?

Voir le sujet précédent Voir le sujet suivant Aller en bas

Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 5:47

Quand l'hyperthreading est actif sous Linux, le noyau voit deux CPUs logiques au lieu d'un (visible dans /etc/cpuinfo). Comment distinguer alors les CPUs physique et logique ?

Très simplement, en regardant le physical id du CPU !
Dans votre /proc/cpuinfo, vous observez ceci
processor 0
physical id : 0

processor 1
physical id : 0

processor 2
physical id : 3

processor 3
physical id : 3
Cela signifie que vous avez deux CPUs physiques mais quatre logiques! L'hyperthreading est actif
Sinon, vous auriez :
processor 0
physical id : 0

processor 1
physical id : 3

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 5:51

Pour ma babasse MSI M670 real AMD64, sous Ubuntu 10.10, j'ai avec nano /proc/cpuinfo :


processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 76
model name : Mobile AMD Sempron(tm) Processor 3400+
stepping : 2
cpu MHz : 1808.430
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat$
bogomips : 3616.86
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:14



--


ma problématique du jour, je cherche à detecter si mon processeur fonctionne en tant qu'HyperThreading;
Ou plus généralement, combien de processeurs physiques existent sur une architecture donnée.

Bon, pour vous evitez de partir dans des voies qui ne seraient pas les bonnes voici le topo :

- Dmesg et le nombre de processeur : dmesg n'affiche que les processeurs dit "virtuel" donc si l'hyperthreading est activité, on en verra deux, alors que physiquement il n'en existe qu'un.

- Le processeur ID : je cherche une solution sans cette "option kernel".
ma problématique étant de découvrir combien il existe de procs physiques sans avoir à redémarrer la machine (qui pourrait être en prod ou bien à 1000 km de ma position)

- Cat /proc/irq/*/smp_affinity | uniq : ne marche pas, si un HT et un bi-proc il n'existe qu'une seule adresse physique visibile, donc la solution est ailleurs (de toute facon, la vérité est ailleurs Wink

- Voir le "cpu_sibling_map" : le CPU Sibling Map indique le nombre de processeur virtuel. avec de l'HT on voit deux processeurs sur un seul.

- Dans /proc/cpuinfo, y'a le flags avec "ht" : le flags est positionné, mais est-ce que le processeur le supporte-il ? et est-il actif en ce moment ? ;-)

- Et dmidecode ? : affiche aussi deux processeurs sur un HT

Voila un peu près, j'en oublie car j'ai fait pas mal de test par-ci, par-là ; l'objectif est de découvrir le nombre de processeurs physique et sans avoir à rédemarrer la machine ni la démonter évidement. (pour ma part, je regarderai bien le /proc/kcore:)!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:15

http://linuxfr.org/~prae/10281.html ..Wink ou tout y est, dont le tread d'au-dessus et plein de réponses de 'spécialistes'Smile!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:18

Pour Windows:(?

//-------------------------------------------------------------------------------------------------
//
// Copyright © 2001, Intel Corporation . Other brands and names may be claimed as the property of others.
//
//
// CPU Counting Utility
// Date : 10/30/2001
// Version: 1.4
//
//
//
// File Name: CPUCount.cpp
//
// Note: 1) LogicalNum = Number of logical processors per PHYSICAL PROCESSOR. If you want to count
// the total number of logical processors, multiply this number with the total number of
// physical processors (PhysicalNum)
//
// 2) To detect whether hyper-threading is enabled or not is to see how many logical ID exist
// per single physical ID in APIC
//
// 3) For systems that don't support hyper-threading like AMD or PIII and below. the variable
// LogicalNum will be set to 1 (which means number of logical processors equals to number of
// physical processors.)
//
// 4) Hyper-threading cannot be detected when application cannot access all processors in
// the system. The number of physical processors will be set to 255. Make sure to enable ALL
// physical processors at startup of windows, and applications calling this function, CPUCount,
// are NOT restricted to run on any particular logical or physical processors(can run on ALL
// processors.)
//
// 5) Windows currently can handle up to 32 processors.
//
//
//-------------------------------------------------------------------------------------------------


#define HT_BIT 0x10000000 // EDX[28] Bit 28 is set if HT is supported
#define FAMILY_ID 0x0F00 // EAX[11:8] Bit 8-11 contains family processor ID.
#define PENTIUM4_ID 0x0F00
#define EXT_FAMILY_ID 0x0F00000 // EAX[23:20] Bit 20-23 contains extended family processor ID
#define NUM_LOGICAL_BITS 0x00FF0000 // EBX[23:16] Bit 16-23 in ebx contains the number of logical
// processors per physical processor when execute cpuid with
// eax set to 1

#define INITIAL_APIC_ID_BITS 0xFF000000 // EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
// initial APIC ID for the processor this code is running on.
// Default value = 0xff if HT is not supported


// Status Flag
#define HT_NOT_CAPABLE 0
#define HT_ENABLED 1
#define HT_DISABLED 2
#define HT_SUPPORTED_NOT_ENABLED 3
#define HT_CANNOT_DETECT 4

unsigned int HTSupported(void);
unsigned char LogicalProcPerPhysicalProc(void);
unsigned char GetAPIC_ID(void);
unsigned char CPUCount(unsigned char *,
unsigned char *);


#include <windows.h>
#include <stdio.h>




void main(void)
{

unsigned char LogicalNum = 0, // Number of logical CPU per ONE PHYSICAL CPU
PhysicalNum = 0, // Total number of physical processor

HTStatusFlag = 0;


printf("CPU Counting Utility\n");
printf("Version 1.4\n");
printf("Copyright (C) 2001 Intel Corporation. All Rights Reserved\n\n");

HTStatusFlag = CPUCount(&LogicalNum, &PhysicalNum);

switch(HTStatusFlag)
{
case HT_NOT_CAPABLE:
printf("Hyper-threading technology not capable\n");
break;

case HT_DISABLED:
printf("Hyper-threading technology disabled\n");
break;

case HT_ENABLED:
printf("Hyper-threading technology enabled\n");
break;

case HT_SUPPORTED_NOT_ENABLED:
printf("Hyper-threading technology capable but not enabled\n");
break;

case HT_CANNOT_DETECT:
printf("Hyper-threading technology cannot be detected\n");
break;


}

printf("Number of logical processors per physical processor: %d\n", LogicalNum);

if (PhysicalNum != (unsigned char)-1)
printf("Number of physical processors: %d\n", PhysicalNum);
else
{
printf("Can't determine number of physical processors\n");
printf("Make sure to enable ALL processors\n");
}

printf("\n\nPress Enter To Continue\n");
getchar();
}



unsigned int HTSupported(void)
{


unsigned int Regedx = 0,
Regeax = 0,
VendorId[3] = {0, 0, 0};

__try // Verify cpuid instruction is supported
{
__asm
{
xor eax, eax // call cpuid with eax = 0
cpuid // Get vendor id string
mov VendorId, ebx
mov VendorId + 4, edx
mov VendorId + 8, ecx

mov eax, 1 // call cpuid with eax = 1
cpuid
mov Regeax, eax // eax contains family processor type
mov Regedx, edx // edx has info about the availability of hyper-Threading

}
}

__except (EXCEPTION_EXECUTE_HANDLER)
{
return(0); // cpuid is unavailable
}

if (((Regeax & FAMILY_ID) == PENTIUM4_ID) ||
(Regeax & EXT_FAMILY_ID))
if (VendorId[0] == 'uneG')
if (VendorId[1] == 'Ieni')
if (VendorId[2] == 'letn')
return(Regedx & HT_BIT); // Genuine Intel with hyper-Threading technology

return 0; // Not genuine Intel processor

}


unsigned char LogicalProcPerPhysicalProc(void)
{

unsigned int Regebx = 0;
if (!HTSupported()) return (unsigned char) 1; // HT not supported
// Logical processor = 1
__asm
{
mov eax, 1
cpuid
mov Regebx, ebx
}

return (unsigned char) ((Regebx & NUM_LOGICAL_BITS) >> 16);

}


unsigned char GetAPIC_ID(void)
{

unsigned int Regebx = 0;
if (!HTSupported()) return (unsigned char) -1; // HT not supported
// Logical processor = 1
__asm
{
mov eax, 1
cpuid
mov Regebx, ebx
}

return (unsigned char) ((Regebx & INITIAL_APIC_ID_BITS) >> 24);

}


unsigned char CPUCount(unsigned char *LogicalNum,
unsigned char *PhysicalNum)
{
unsigned char StatusFlag = 0;
SYSTEM_INFO info;


*PhysicalNum = 0;
*LogicalNum = 0;
info.dwNumberOfProcessors = 0;
GetSystemInfo (&info);

// Number of physical processors in a non-Intel system
// or in a 32-bit Intel system with Hyper-Threading technology disabled
*PhysicalNum = (unsigned char) info.dwNumberOfProcessors;

if (HTSupported())
{
unsigned char HT_Enabled = 0;

*LogicalNum= LogicalProcPerPhysicalProc();

if (*LogicalNum >= 1) // >1 Doesn't mean HT is enabled in the BIOS
//
{
HANDLE hCurrentProcessHandle;
DWORD dwProcessAffinity;
DWORD dwSystemAffinity;
DWORD dwAffinityMask;

// Calculate the appropriate shifts and mask based on the
// number of logical processors.

unsigned char i = 1,
PHY_ID_MASK = 0xFF,
PHY_ID_SHIFT = 0;

while (i < *LogicalNum)
{
i *= 2;
PHY_ID_MASK <<= 1;
PHY_ID_SHIFT++;

}

hCurrentProcessHandle = GetCurrentProcess();
GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity,
&dwSystemAffinity);

// Check if available process affinity mask is equal to the
// available system affinity mask
if (dwProcessAffinity != dwSystemAffinity)
{
StatusFlag = HT_CANNOT_DETECT;
*PhysicalNum = (unsigned char)-1;
return StatusFlag;
}
dwAffinityMask = 1;
while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity)
{
// Check if this CPU is available
if (dwAffinityMask & dwProcessAffinity)
{
if (SetProcessAffinityMask(hCurrentProcessHandle,
dwAffinityMask))
{
unsigned char APIC_ID,
LOG_ID,
PHY_ID;

Sleep(0); // Give OS time to switch CPU

APIC_ID = GetAPIC_ID();
LOG_ID = APIC_ID & ~PHY_ID_MASK;
PHY_ID = APIC_ID >> PHY_ID_SHIFT;

if (LOG_ID != 0) HT_Enabled = 1;

}

}

dwAffinityMask = dwAffinityMask << 1;

}

// Reset the processor affinity
SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity);


if (*LogicalNum == 1) // Normal P4 : HT is disabled in hardware
StatusFlag = HT_DISABLED;

else
if (HT_Enabled)
{
// Total physical processors in a Hyper-Threading enabled system.
*PhysicalNum /= (*LogicalNum);
StatusFlag = HT_ENABLED;
}
else StatusFlag = HT_SUPPORTED_NOT_ENABLED;

}

}
else
{
// Processors do not have Hyper-Threading technology
StatusFlag = HT_NOT_CAPABLE;
*LogicalNum = 1;

}
return StatusFlag;
}

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:19

D'après :

http://gcc.gnu.org/ml/gcc-help/2002-07/msg00239/Cpucount.cpp

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:28

Autre réponse au :

http://fluid-particles.googlecode.com/svn/trunk/CoreDetection/CpuTopology.cpp

-

Attention il s'agit de portage de processeurs..., un peu pour des spécialistes.., voir carrément pour des super spécialistes en systèmes et de plus compétents en Windows et en nunux:)!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:33

En général, Linux est destiné à des serveurs (60% des serveurs sont sous de U*nix, nux et autre BSD par exemple:)! et c'est très heureux, parce qu'eux fonctionnent avec des 'sources' Libres, modifiables si vous le voulez/pouvez et constamment améliorées par des spécialistes du genre de ceux cités ici:)!

http://cache-www.intel.com/cd/00/00/27/66/276611_276611.txt

--


Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:36

La meilleure réponse trouvée est celle-ci :

http://software.intel.com/en-us/articles/methods-to-utilize-intels-hyper-threading-technology-with-linux/

pour les processeurs Intel, il est vrai..; donc venant de M$ et/mais appliquée à Linux apparemment graĉe à un programme en fichier txt!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:42

Le but est toujours :


Le moyen, pour un proc Intel :

'By exploiting Intel's Hyper-Threading Technology, programmers can produce significant performance improvements to applications.

This article explains what Hyper-Threading Technology (HT Technology) is, how it works and the benefits obtained by using it. It then goes on to show examples of code that utilizes Hyper-Threading Technology in C++, C and/or FORTRAN. In addition, code to detect the support of Hyper-Threading Technology will be provided.

--

toujorus dela page :

http://software.intel.com/en-us/articles/methods-to-utilize-intels-hyper-threading-technology-with-linux/

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:44

http://linux.developpez.com/faq/?page=Config#ups est pas mal aussi Smile!

--

Some explanations too:)!

--


The Concept of Hyper-Threading
Hyper-Threading Technology has been in development by Intel for more than 4 years. Hyper-Threading is a more efficient way to use processing power of a CPU. Processor components are always idle at some point in the code execution. In the past improving processor performance consisted primarily of increasing the clock speed, enlarging the cache, reducing the size of the chip or simply developing MPU systems and adding more processors. Intel has developed Hyper-Threading Technology to allow application performance gains without the need of hardware changes or adding more processors. Hyper-Threading, also referred to as simultaneous multithreading (SMT), allows different threads to run simultaneously on different execution units within one physical processor. Hyper-Threading extends multi-threading using an architecture state where one physical processor can look like two (or more) logical processors to the operating system and applications. Two processor states on the chip create a logical dual processor configuration. Each logical processor maintains a complete set of the architecture state instructions and shares access to the functional units of the CPU. The architecture state consists of registers including the general-purpose registers, the control registers, the advanced programmable interrupt controller (APIC) registers as well as some machine state registers. A Hyper-Threading enabled processor can manage data as if it were two logical processors by handling data instructions in parallel rather than serially.

The architecture state consists of registers including the general-purpose registers, the control registers, the advanced programmable interrupt controller registers as well as some machine state registers. Logical processors share most resources on the physical processor: caches, execution units, branch predictors, control logic and buses. Developers who thread applications are positioned to take advantage of Hyper-Threading Technology. Threaded applications can immediately pick up all the performance benefits of Hyper-Threading based multiprocessing whenever they are running on an Intel Hyper-Thread enabled processors. Intel C++/Fortran compiler support Hyper-Threading using the OpenMP directive and pragmas guided parallelization. As an example, OpenMP parallel sections of code where section-1 calls an integer-intensive routine and where section-2 calls a floating-point intensive routine can use Hyper-Threading by scheduling section-1 and section-2 onto two different logical processors achieving higher performance by more fully utilizing processor resources. The OpenMP standard API supports a multi-platform, shared-memory, parallel programming in C++, C and Fortran95 on al l Intel architectures and operating systems such as Windows NT, Linux, and UNIX. Simply stated Hyper-Threading Technology (HT Technology) is a more efficient way to use processing power, now coders have to be educated to take advantage of HT Technology.


--

Still from page :

http://software.intel.com/en-us/articles/methods-to-utilize-intels-hyper-threading-technology-with-linux/

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:45

Wouah, Intel serai devenu Linux compliant alors:)!

--


Programming Hyper-Threaded Technology
Determining Logical Processors

When Hyper-Threading Technology is used, applications must inquire to the operating system as to the number of logical processors on the system as well as the number of physical processors. This is not only important for determining how the code should run, but for licensed software where the number of physical processors determines the cost of the application.

The first step to determining the HT Technology capacity of the CPU is to see if the processor supports the cpuid instruction and is a genuine Intel® Pentium® 4 processor or later. The code then retrieves the model specific feature information using the cpuid instruction and setting the eax register to one. It does not matter which processor you execute the CPUID instruction on, all physical processors present must support the same number of logical processors. After executing the CPUID instruction, if bit 28 in edx is set then the physical processor supports Hyper-Threading Technology. This does not mean the processor supports more than one logical processor, that the BIOS has enabled the feature, or that the operating system is utilizing the extra logical processors. Additional steps are required to determine the number of logical processors supported by the physical processor as well as querying the operating system to determine the logical to physical processor mapping.

Sample Code 1.0: Determine Hyper-Threading support.

#define HT_BIT 0x10000000 // Bit 28 indicates Hyper-Threading
Technology support
#define FAMILY_ID 0x0f00 // Bits 11 through 8 is family
processor id
#define EXT_FAMILY_ID 0x0f00000 // Bits 23 through 20 is
extended family processor id
#define PENTIUM4_ID 0x0f00 // Pentium 4 family processor
id
// Returns non-zero if Hyper-Threading Technology supported
zero if not.
// Hyper-Threading Technology still may not be enabled due to
BIOS or OS settings.
unsigned int Is_HT_Supported(void)
{
unsigned int reg_eax = 0;
unsigned int reg_edx = 0;
unsigned int vendor_id[3] = {0, 0, 0};
__try { // verify cpuid instruction is supported
__asm {
xor eax, eax // call cpuid with eax = 0 (faster than mov ax,
1)
cpuid // to get vendor id string
mov vendor_id, ebx
mov vendor_id + 4, edx
mov vendor_id + 8, ecx
mov eax, 1 // call cpuid with eax = 1
cupid // to get the CPU family information
mov reg_eax, eax // eax contains cpu family type info
mov reg_edx, edx // edx has Hyper-Threading info
}
}
__except (EXCEPTION_EXECUTE_HANDLER ) {

return 0; // The CPUID call is not supported
}
// Is this a Pentium 4 or later processor?
if (((reg_eax & FAMILY_ID) == PENTIUM4_ID) ||
(reg_eax & EXT_FAMILY_ID))
if (vendor_id[0] == 'uneG')
if (vendor_id[1] == 'Ieni')
if (vendor_id[2] == 'letn')
return (reg_edx & HT_BIT); // Intel Processor
Hyper-Threading
return 0; // The processor is not Intel.
}



If the physical processor supports Hyper-Threading Technology, bits 16-23 in register ebx, using the cpuid instruction with eax equal to one, identifies the number of logical processors the physical processor supports. Note that although a processor supports Hyper-Threading Technology and has more than one logical processor, Hyper-Threading Technology may not be enabled by the BIOS or that the operating system is utilizing the extra logical processors. If Hyper-Threading Technology is not supported, the default number of logical processors per physical processor is one. In the next step, each processor recognized by the operating system must be queried to provide the logical to physical processor mapping.


--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:50

Le but est seul et uniquement de farie avancer la connaissance et de faire réaliser aussi la complexité de l'informatique..., la vrai : la système:)!

Selon moi tous ceux qui parleent d'informatique, dont moi presque aussi, n'y connaissent absolument rien de rien:(! Lol?

--


Sample Code 2.0: Determining the number of logical processors per physical processor.

// Register EBX bits 23 through 16 indicate the number of
logical processors per package
#define NUM_LOGICAL_BITS 0x00FF0000
// Return the number of logical processors per physical
processors.
unsigned char LogicalProc_PerCPU(void)
{
unsigned int reg_ebx = 0;
if ( Is_HT_Supported()) {
__asm {
mov eax, 1 // call cpuid with eax = 1 to get the CPU family
information
cpuid
mov reg_ebx, ebx // get number of logical processors
}
return (unsigned char) ((reg_ebx &
NUM_LOGICAL_BITS) >> 16);
}
else {
return (unsigned char) 1;
}
}



The above code is shown in two separate calls to cpuid for the sake of clarity and can be combined.

Each logical processor has a unique Advanced Programmable Interface Controller (APIC) ID. The APIC ID is initially assigned by the hardware at system reset and can be later reprogrammed by the BIOS or the operating system. On a processor that supports HT Technology, the CPUID instruction also provides the initial APIC ID for a logical processor prior to any changes by the BIOS or operating system. In order to retrieve the APIC ID for each of the logical processors recognized by the operating system, the code must be run on the specific processors. Setting the processor affinity for the executing code using operating specific system calls will do this.

Sample Code 3.0: Retrieving the Processor APIC ID.

#define INITIAL_APIC_ID_BITS 0xFF000000 // EBX bits 31:24 has
the unique APIC ID
// Returns the 8-bit unique Initial APIC ID for the processor
this
// code is running on. The default value returned is 0xFF
if
// Hyper-Threading Technology is not supported.
unsigned char Get_APIC_ID (void)
{
unsigned int reg_ebx = 0;
if (!Is_HT_Supported()) {
return (unsigned char) -1;
}
else {
__asm {
mov eax, 1 // call cpuid with eax = 1 for family
information
cpuid
mov reg_ebx, ebx // Has APIC ID info
}
return (unsigned char) ((reg_ebx &
INITIAL_APIC_ID_BITS) >> 24);
}
}



The Initial APIC ID is composed of the physical processor's ID and the logical processor's ID within the physical processor. The least significant bits of the APIC ID are used to identify the logical processors within a single physical processor. The number of logical processors per physical processor package determines the number of least significant bits needed. As an example, one least significant bit is needed to represent the logical IDs for two logical processors but two least significant bits are needed to represent the logical IDs for both 3 and 4 logical processors. The remaining most significant bits identify the physical processor ID. As a result, initial APIC IDs are not necessarily consecutive values starting from zero. In general, the APIC ID is given by the following formula:

((Physical Package ID << (1 +
((int)(log(2)(max(Logical_Per_Package-1, 1)))) || Logical
ID)



In addition to non-consecutive initial APIC IDs, operating system processors IDs can be non-consecutive in value. It is also possible for the operating system to limit the processors a process may utilize. Therefore, even if Hyper-Threading Technology is enabled, the application may not be able to run on both logical processors sharing the same physical processor.

To know which logical processor IDs are sharing the same physical processor for the purposes of load balancing and licensing strategy for your application the Sample Code 4.0 below can be used as a guide. It prints out a table containing the operating system's processor affinity ID, APIC ID, the physical processor ID, and the logical processor ID within the physical processor. If there are two logical processor IDs sharing the same physical processor ID, then Hyper-Threading Technology is enabled.

Sample Code 4.0: Associating logical to physical processors.

#include <stdio.h>
// Include the previous routines here.
void main (void) {
// Check to see if Hyper-Threading Technology is
available
if (Is_HT_Supported()) { // See code sample 1.
unsigned char HT_Enabled = 0;
unsigned char Logical_Per_CPU;
printf ("Hyper-Threading Technology is available.");
Logical_Per_CPU = LogicalProc_PerCPU(); // See code sample
2.
printf ("Logical Processors Per CPU: %d",
Logical_Per_CPU);
// Logical processors > 1
// does not mean that Hyper-Threading Technology is
enabled.
if (Logical_Per_CPU > 1) {
HANDLE hCurrentProcessHandle;
DWORD dwProcessAffinity;
DWORD dwSystemAffinity;
DWORD dwAffinityMask;
// Physical processor ID and Logical processor IDs are
derived
// from the APIC ID. Calculate the shift and mask values
knowing the number of
// logical processors per physical processor.
unsigned char i = 1;
unsigned char PHY_ID_MASK = 0xFF;
unsigned char PHY_ID_SHIFT = 0;
while (i < Logical_Per_CPU){
i *= 2;
PHY_ID_MASK <<= 1;
PHY_ID_SHIFT++;
}
// The OS may limit the processors that this process may run
on.
hCurrentProcessHandle = GetCurrentProcess();
GetProcessAffinityMask(hCurrentProcessHandle,
&dwProcessAffinity,
&dwSystemAffinity);
// If our available process affinity mask does not equal
the
// available system affinity mask, then we may not be able
to
// determine if Hyper-Threading Technology is enabled.
if (dwProcessAffinity != dwSystemAffinity) {
printf ("This process can not utilize all
processors.");
}
dwAffinityMask = 1;
while (dwAffinityMask != 0
&& dwAffinityMask <=
dwProcessAffinity) {
// Check to make sure we can utilize this processor
first.
if (dwAffinityMask & dwProcessAffinity)
{
if (SetProcessAffinityMask(hCurrentProcessHandle,
dwAffinityMask)) {
unsigned char APIC_ID;
unsigned char LOG_ID;
unsigned char PHY_ID;
Sleep(0); // This process may not be running on the cpu
that
// the affinity is now set to. Sleep gives the OS
// a chance to switch to the desired cpu.
// Get the logical and physical ID of the CPU
APIC_ID = Get_APIC_ID(); // See code sample 3.
LOG_ID = APIC_ID & ~PHY_ID_MASK;
PHY_ID = APIC_ID >> PHY_ID_SHIFT;
// Print out table of processor IDs
printf ("OS Affinity ID: 0x%.8x, APIC ID: %d PHY ID: %d, LOG
ID: %d",
dwAffinityMask, APIC_ID, PHY_ID, LOG_ID);
if (LOG_ID != 0)
HT_Enabled = 1;
}
else {
// This should not happen. A check was made to ensure we
// can utilize this processor before trying to set affinity
mask.
printf ("Set Affinity Mask Error Code: %d",
GetLastError());
}
}
dwAffinityMask = dwAffinityMask << 1;
}
// Reset the processor affinity if this code is used in an
application.
SetProcessAffinityMask(hCurrentProcessHandle,
dwProcessAffinity);
if (HT_Enabled) {
printf ("Processors with Hyper-Threading enabled were
detected.");
}
else {
printf ("Processors with Hyper-Threading enabled were not
detected.");
}
}
else {
printf ("Processors with Hyper-Threading are not
enabled.");
}
}
else {
printf ("Hyper-Threading Processors are not
detected.");
}
}



OpenMP
The open multiprocessing or OpenMP* standard API provides library routines, environment variables directives and pragmas that are the standard for coding parallelism. OpenMP supports multi-platform, shared-memory, parallel programming in C++/C/Fortran95 on all Intel architectures and popular operating systems. OpenMP is a de facto rather than official standard that has wide support and is advisable to adopt in HT Technology and standard threaded multiprocessing. OpenMP is the industry standard for portable multithreaded application development, and is effective at fine grain (loop level) and large grain (function level) threading.

Program Design
Developers should observe carefully the following guidelines in terms of their affects on hyper-threading:

1. Threads should not compete for the same resources. This causes logical processors to stall while waiting for the same event. Avoid this problem by having threads do very different things. If threads must perform the same work, make them operate on different data and different events and/or assign the task to a different physical processor, if possible.

2. Where two threads perform different tasks, developers should use processor affinity to assign these threads to the same physical processor. Linux is moving towards processor affinity*.

3. When iterating while waiting for a resource to free or an event to occur prevent context switches while a thread is waiting. This is done with a pause instruction placed into the loop. On older processors pause is a no-op and does nothing. However, with HT Technology enabled processors it helps the processor reduce loop-exit overhead and free resources for the second thread.

4. Many of the standard practices of multiprocessor-oriented programming apply to hyper-threading. These include:

The use of thread pools (in which a pool of threads is reused) rather than repeatedly creating new threads
minimizing thread synchronization
minimizing thread use where there is no or little advantage.


5. The Intel Xeon processor, due to its unusually deep execution pipeline, benefits if programs make code jumps consistent with Intel's branch-prediction algorithm. This algorithm, which is heavily used in out-of-order execution, assumes that backwards jumps are always taken (as they would be in a loop) and that forward jumps are never taken. As a result, when testing a value, the most frequent path should either fall through or branch backwards, while the least-probable decision should jump forward.

Linux* Issues with Hyper-Threaded Technology
For Linux to make use of HT Technology an SMP kernel must be installed. This is confirmed by the output of uname -a, which shows the kernel version ending in SMP. The output of cat /proc/cpuinfo (see below) will show the number of CPU's and their properties. HT Technology is shown by the presence of the ht flag. If the computer BIOS supports SMP (or an analogous option is activated in BIOS), the machine can be used as an SMP system with Linux. When the SMP kernel is installed, it will seem as if double the physical processors are available. At present the errata kernels 2.4.9-21 and 2.4.9-31 have HT Technology support, but you have to pass "acpismp=force" on the kernel command line to enable it.

> $cat /proc/cpuinfo
> processor : 0
> vendor_id : GenuineIntel
> cpu family : 15
> model : 1
> model name : Intel(R) Pentium(R) 4 CPU 1.70GHz
> stepping : 2
> cpu MHz : 1694.907
> cache size : 256 KB
> fdiv_bug : no
> hlt_bug : no
> f00f_bug : no
> coma_bug : no
> fpu : yes
> fpu_exception : yes
> cpuid level : 2
> wp : yes
> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr
pge
> mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss
ht tm
> bogomips : 3381.65
>



The Linux 2.4 kernel will not be developed to take an active advantage of HT Technology and patches may be required to fix some possible problems. Rusty Russell (a Linux developer) mentions: "The hyperthreading issue... is likely to throw a new set of complications into the mix. A processor which does hyperthreading looks like two independent CPUs, but it [processes] should not be scheduled [by the scheduler] as such - it is better to divide process across real (hardware) processors first."

Work is underway in the Linux community to add HT Technology patches to the 2.4 release of the Linux kernel. HT Technology changes to Linux are being exploited by Carrier Grade Linux Change Project under the ODSL (see below). HT Technology offers performance enhancement potentials that are a prime requirement of the carrier grade environment. Active utilization of HT Technology will likely appear in the standard 2.5 Linux kernel, although it has not yet been placed into the development queue due to prerequisite work being done.

Linux HT Technology Capable Compilers

The Intel Linux C++ Compiler 6.0 has increased levels of Linux and industry standards support that provide improved compatibility with GNU C, broader support of Linux distributions, support for the C++ ABI object model and GNU inline ASM for IA32. - The Intel C++ Compiler supports OpenMP API version 1.0 and performs code transformation for shared memory parallel p rogramming. The Intel compiler supports multi-threaded application development and debugging, with support for OpenMP 1.0 for C and new support for OpenMP 1.0 for C++. This makes it fully capable of designing HT Technology enabled applications on HT Technology enabled hardware.

Conclusion
The release of Intel Hyper-Threading processors is being met with great enthusiasm and effort by the Linux development community. Carrier Grade Linux efforts are under way to exploit HT Technology to achieve greater availability and response time in the demanding carrier grade environment. Additionally, HT Technology is a great step in encouraging the improvement of software performance through better programming techniques to take advantage of new hardware technology without having to, yet again, reinvent the world.

It is likely that Intel will continue to develop the HT Technology of several logical processors running on each physical processor. With HT Technology, Intel will drag software development into a standard methodology of using threaded code, an effort that will benefit everyone.

Further Reading
Media Applications on Hyper-Threading Technology [ PDF 75KB ]
Hyper Threading In-Depth By Viktor Kartunov
Hyper-Threading white paper
Carrier Grade Change Project - Hyper-Threading support with processor affinity: Information*


About the Author
Thomas Wolfgang Burger is the owner of Thomas Wolfgang Burger Consulting. He has been a consultant, instructor, analyst and applications developer since 1978.





Comments (0)
Trackbacks (0)

Leave a comment
To obtain technical support, please go to Software Support.
Name (required)*

Email (required; will not be displayed on this page)*

Your URL (optional)


Comment*


Login
Login ID:
Password:
Remember Me?


New Registration?
Forgot Login ID?
Forgot Password?
Author
TW Burger
Total Points:
564
Registered User

Tags for this Page
Hyper-Threading Technology

--

http://software.intel.com/en-us/articles/methods-to-utilize-intels-hyper-threading-technology-with-linux/

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:58

Vu la qualité de l'article de ce spacialiste un tread sur le but de l'hypertreading est nécessaire, comme avec celui-ci... toujours pour 'Untel'Smile! arf?

http://developer.intel.com/technology/platform-technology/hyper-threading/index.htm

On y explique (enfin?), l'utilité de l'HT:)!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 6:59

Enabling better graphics
With Intel HT Technology multimedia enthusiasts can create, edit, and encode graphically intensive files while running background applications such as virus protection software without compromising system performance.

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 7:00

Improving business efficiency
With Intel HT Technology, multi-threaded software applications can execute threads in parallel within each processor core. When Intel HT Technology and Intel® Turbo Boost Technology are combined in processors based on Intel® Microarchitecture, codenamed Nehalem, intelligent server processors deliver better performance by adapting to the workload and automatically disabling inactive cores and increasing processor frequency on remaining cores to get the tasks done quicker.

With Intel HT Technology, businesses can:

Improve business productivity by doing more simultaneously without slowing down
Provide faster response times for Internet and e-commerce applications, enhancing customer experiences
Increase the number of transactions that can be processed simultaneously
Utilize existing 32-bit applications technologies while maintaining 64-bit future readiness

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 7:05

Je 'cut'n pass', comme l'article est assez ancien, il sert de base de départ afin de diffuser la connaissance..., mais j'y cite les sources evidement ; ne serais-ce que parce que ça concerne l'Intel ; assez peut Libre pourtant, mais qui là paradoxalement fais un effort pour les proc 16 et 32 bits...Sad!

Le 64 n'est qu'esquissé et pas encore à l'ordre du jour ; c'est dire:(!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 7:06

Parce que sinon le monde du Libre, c'est plutôt ça:(!

--

http://www.linuxfoundation.org/collaborate/workgroups/cgl

et à propos d'HT, c'est un peu hors sujet:(!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 7:11

Comment faire du Buzz, le Linus plonge avec des requins...Sad!

http://www.linux.com/news/featured-blogs/185-jennifer-cloer/377421-video-full-footage-of-linux-torvalds-shark-tank-dive

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 7:25

Notez que suivant votre niveau.., il y a de la demande au moins aux USA et au Canada:)!

http://jobs.linux.com/search?search_string=&search=1&go=Find+Jobs&job_group_ids[]=12704&location_string=&country_code=&distance=50&posted_time=&sort_by=date

--

Un pote à moi, Brésilien a obtenu un poste il y a quelques années en Tanzanie avec l'ONU, mais le temps de faire venir sa famille.., il a fuis sous la menace de ces connards de fascistes et racistes de nazis noirs...Sad!

Il y a 'perdu' deux ans là-bas ou presque, et n'a du sa 'survie' et celles de sa femme et de leur enfant qu'au fait qu'ils étaient assez colorés, ou presque:(!

Bref essayez de faire le bien et il ya toujours des 'connards' pour tout casser:(!!!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Milux le Ven 5 Nov - 7:41

Tu me diras que c'est tout à fait à l'image de ce qui se fait tous les jours dans le monde de l'informatique ; car entre désinformation.... :

- Genre, les abrutits des médias, qui n'y connaissant évidement absolument rien en informatique parlent chaque jour de 'hackers'.... quand il s'aggit de 'crakers' ; vous savez ces 'connards' de dévoyés, qui s'attaquent (ou cherchent au moins...Sad!)... aux systèmes:(! - et qui sont évidement en fait nos 'bêtes noire' ; que l'on traquent et raison pour lesquelles on 'hacke' 'mutuellement' nos systèmes... :

- un hacke, c'est en ligne, tester mutuellement nos systèmes avec des programme Libres d'ailleurs et ce afin de déterminer quels en sont les failles, à corriger, patcher et donc à en améliorer la sécurité...Smile!

- meilleures pensées à mon mentor de l'époque - salut le Fred:)!- entre autre auteur d'un programme (simple selon lui Smile! ) et destiné à relever les IP des machines sniffeuses.. comme par exemple sur sa machine...SmileWink!

- je ne parle pas ici de petits ordinateurs.., mais de serveurs (d'ou mon début de tread sur l'HT d'ailleurs:)!.., bref un monde dont les lilipitiens de l'informatique et micro-céphales de la connaissance.., s'imaginent (peut-être?)... faire partie ; ce de façon inversement proportionnelle avec la prétention qu'ils dégagent, par rapport à la réalité de la vérité objective évidement:)!

--

Milux

Messages : 2794
Date d'inscription : 30/08/2010

Revenir en haut Aller en bas

Re: Comment voir si l'hyperthreading est actif ?

Message  Contenu sponsorisé


Contenu sponsorisé


Revenir en haut Aller en bas

Voir le sujet précédent Voir le sujet suivant Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum