Hi Subrata/CAI,

Pls find attached patch for ht_enabled and ht_affinity.
I am not having a 16-CPU machine at my end to test ht_interrupt test code.


Regards,
Rohit

On Mon, Jun 1, 2009 at 8:31 PM, CAI Qian<[email protected]> wrote:
> From: CAI Qian <[email protected]>
> Subject: Re: [LTP] Fw: Regarding ht_enable test case failure
> Date: Sun, 31 May 2009 16:58:27 +0800 (CST)
>
>> OK. The compilation error was probably due to my incomplete build last
>> time. Sorry about that.
>>
>> smt_smp_interrupt.sh is no working for 2 CPU system.
>>
>> # cat /proc/interrupts
>>            CPU0       CPU1
>>   0:    1821938    1845925    IO-APIC-edge  timer
>>   1:          2          1    IO-APIC-edge  i8042
>>   4:        176        259    IO-APIC-edge  serial
>>   6:          2          3    IO-APIC-edge  floppy
>>   8:          2          1    IO-APIC-edge  rtc
>>   9:          0          0   IO-APIC-level  acpi
>>  12:          4          1    IO-APIC-edge  i8042
>>  82:      52431       2322   IO-APIC-level  uhci_hcd:usb3, ahci
>>  90:          0          0   IO-APIC-level  uhci_hcd:usb4
>>  98:          0          0   IO-APIC-level  uhci_hcd:usb5
>> 106:         53         52   IO-APIC-level  HDA Intel
>> 114:        242      25683         PCI-MSI  eth0
>> 201:          0          0   IO-APIC-level  ehci_hcd:usb1, uhci_hcd:usb2
>> NMI:          0          0
>> LOC:    3667704    3667763
>> ERR:          0
>> MIS:          0
>>
>> # ./smt_smp_interrupt.sh
>> smt_smp_interrupt    0  INFO  :  Begin: SMT/SMP Interrupt
>> smt_smp_interrupt    0  INFO  :  smp_affinity is 00000002
>> smt_smp_interrupt    1  CONF  :  /proc/irq/114/smp_affinity:Not set
>> smt_smp_interrupt    0  INFO  :  End: SMT/SMP Interrupt
>>
>> I am not having a 16-CPU machine at the moment, so I'll test on it later
>> when had a chance.
>>
>
> I have finally had a chance to test it on the 16-CPU machine, but
> smt_smp_interrupt.sh test failed,
>
> # ./smt_smp_interrupt.sh
> smt_smp_interrupt    0  INFO  :  Begin: SMT/SMP Interrupt
> cat: /proc/irq/154: Is a directory
> cat: 162: No such file or directory
> cat: 170: No such file or directory
> cat: 178: No such file or directory
> cat: 186: No such file or directory
> cat: 194: No such file or directory
> cat: 202/smp_affinity: No such file or directory
> smt_smp_interrupt    0  INFO  :  smp_affinity is
> ./smt_smp_interrupt.sh: line 86: [: 31: unary operator expected
> smt_smp_interrupt    0  INFO  :  Begin: HyperThreading Interrupt
> smt_smp_interrupt    1  CONF  :  HT is not enabled or not supported.
> smt_smp_interrupt    0  INFO  :  End: HyperThreading Interrupt
> smt_smp_interrupt    0  INFO  :  End: SMT/SMP Interrupt
>
>
> This probably due to multiple eth0 entries in /proc/interrupts.
>
> # cat /proc/interrupts
>           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       
> CPU6       CPU7       CPU8       CPU9       CPU10      CPU11      CPU12      
> CPU13      CPU14
>  CPU15
>  0:   29973184          0      82092          0          0          0         
>  0          0          0          0          0          0          0          
> 0          0
>    0    IO-APIC-edge  timer
>  4:          0          0          0         10        388          0        
> 219          0          0          0          0          0          0         
>  0          0
>    0    IO-APIC-edge  serial
>  8:          0          0          3          0          0          0         
>  0          0          0          0          0          0          0          
> 0          0
>    0    IO-APIC-edge  rtc
>  9:          0          0          0          0          0          0         
>  0          0          0          0          0          0          0          
> 0          0
>    0   IO-APIC-level  acpi
>  82:          0          0          0          0          0          0        
>   0          0          0          0          0          0          0         
>  0          0
>    0   IO-APIC-level  ehci_hcd:usb1
>  90:          0          0          0          0          0          0        
>   0          0          0          0          0          0         49         
>  0          0
>    0   IO-APIC-level  ehci_hcd:usb2, uhci_hcd:usb5, uhci_hcd:usb7
>  98:          0          0          0          0          0          0        
>   0          0          0          0          0          0          0         
>  0          0
>    0   IO-APIC-level  uhci_hcd:usb3
> 106:          0          0          0          0          0          0        
>   0          0          0          0          0          0          0         
>  0          0
>    0   IO-APIC-level  uhci_hcd:usb4
> 114:          0          0         43          0          0          0        
>   0          0          0          0          0          0          0         
>  0          0
>    0   IO-APIC-level  uhci_hcd:usb6
> 154:         91          0          0          0          0          0        
>   0          0          0          0          0          0      45761         
>  0     117042
>  1105       PCI-MSI-X  eth0
> 162:         28          0          0          0        230          0        
> 451          0          0          0        562          0        298         
>  0        159
>    0       PCI-MSI-X  eth0
> 170:         24          0          0          0        458          0        
> 460          0          0          1       1497          0        193         
>  0        467
>    0       PCI-MSI-X  eth0
> 177:          0         22          0         27      38596       1422       
> 4017          0       4063          0          0          0       2367        
>   0          0
>    0   IO-APIC-level  ioc0
> 178:         22          0          0          0       8039          0       
> 1054          0          0          0          0         16       1850        
>  20       9302
>    0       PCI-MSI-X  eth0
> 186:         38          0          0          0        530          0       
> 1100          0          0          0         40          0        163        
>   0        176
>    0       PCI-MSI-X  eth0
> 194:         23          0          0          0       3163          0       
> 3521          0          0         16          0         20       6674        
>   0        448
>    0       PCI-MSI-X  eth0
> 202:         49          0          0          0        637          0       
> 1305          0          0          6        120          0        733        
>   4       1087
>    0       PCI-MSI-X  eth0
> NMI:          0          0          0          0          0          0        
>   0          0          0          0          0          0          0         
>  0          0
>    0
> LOC:   30053985   30053999   30054001   30053998   30053997   30053995   
> 30053993   30053991   30053716   30053990   30053974   30053914   30053953   
> 30053870   30053986   30053818
> ERR:          0
> MIS:          0
>
> Other tests look good though.
>
> CAI Qian
>
Signed-off-by: rohit verma ([email protected])
===============================================================================
diff -ruNB ltp-full-20090531/runtest/hyperthreading 
ltp-full-20090531_o/runtest/hyperthreading
--- ltp-full-20090531/runtest/hyperthreading    2003-03-29 03:38:02.000000000 
+0530
+++ ltp-full-20090531_o/runtest/hyperthreading  2009-06-22 12:19:22.000000000 
+0530
@@ -1,5 +1,5 @@
 #DESCRIPTION:Hyperthreading stress tests
-ht_enabled ht_enabled
-ht_affinity ht_affinity
+smt_smp_enabled smt_smp_enabled.sh
+smt_smp_affinity smt_smp_affinity.sh
 ht_interrupt ht_interrupt
 
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/HTaffinity.c
 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/HTaffinity.c
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/HTaffinity.c
    2009-03-05 14:24:33.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/HTaffinity.c
  2009-06-22 12:17:03.000000000 +0530
@@ -21,7 +21,7 @@
 #include <string.h>
 #include "test.h"
 
-char *TCID = "ht_affinity";
+char *TCID = "smt_smp_affinity";
 int TST_TOTAL = 3;
 
 
/************************************************************************************
@@ -161,7 +161,7 @@
 
 int HT_GetAffinity()
 {
-       unsigned long mask,mask1,mask2;
+       unsigned long mask, mask1;
        pid_t pid;
 
        mask=0x1;
@@ -173,20 +173,18 @@
 
        sleep(1);
 
-       mask1=get_porc_affinity(pid);
-       sched_getaffinity(pid, sizeof(unsigned int), &mask2);
+       sched_getaffinity(pid, sizeof(unsigned int), &mask1);
 
-       if(mask==0x1 && mask==mask1 && mask==mask2)
+       if (mask == 0x1 && mask == mask1)
        {
                mask=0x2;
                sched_setaffinity(pid, sizeof(unsigned long), &mask);
 
                sleep(1);
 
-               mask1=get_porc_affinity(pid);
-               sched_getaffinity(pid, sizeof(unsigned int), &mask2);
+               sched_getaffinity(pid, sizeof(unsigned int), &mask1);
 
-               if(mask==0x2 && mask==mask1 && mask==mask2)
+               if (mask == 0x2 && mask == mask1)
                        return 1;
                else
                        return 0;
@@ -195,7 +193,6 @@
                return 0;
 }
 
-// return 0 means Pass, return 1 means Fail
 int HT_InheritAffinity()
 {
        unsigned long mask;
@@ -217,7 +214,7 @@
                exit(0);
        }
 
-       mask=get_porc_affinity(pid);
+       sched_getaffinity(pid, sizeof(unsigned int), &mask);
 
        if(mask==0x2)
                return 1;
@@ -228,7 +225,6 @@
 // return 0 means Pass, return 1 means Fail
 int main(int argc, char *argv[])
 {
-       tst_resm(TINFO, "Begin: HyperThreading Affinity");
 
 #ifndef __i386__
        tst_brkm(TCONF, NULL, "This test suite can only excute on i386 
architecture.");
@@ -261,7 +257,5 @@
        }
 #endif
 
-       tst_resm(TINFO, "End: HyperThreading Affinity");
-
        return 0;
 }
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.c 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.c
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.c   
    2009-03-05 14:24:33.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.c 
    2009-06-22 12:17:03.000000000 +0530
@@ -10,57 +10,14 @@
 #define PROC_PATH      "/proc"
 #define BUFF_SIZE      8192
 #define PROCESSOR_STR  "processor"
-#define PACKAGE_STR    "cpu_package"
-#define HT_FLAG "ht"
-#define FLAG_STR "flags"
 
 #define MAX_CPU_NUM 128
 
 char buffer[BUFF_SIZE];
 
-int is_cmdline_para(const char *para)
-{
-       FILE *fp;
-
-       if((fp=fopen("/proc/cmdline","r"))!=NULL && para!=NULL)
-       {
-               while(fgets(buffer, BUFF_SIZE-1, fp) != NULL)
-               {
-                       if(strstr(buffer, para) != NULL)
-                       {
-                               fclose(fp);
-                               return 1;
-                       }
-               }
-               fclose(fp);
-       }
-
-       return 0;
-}
-
-int is_ht_kernel()
-{
-       FILE *fp;
-
-       if((fp=fopen("/proc/cpuinfo","r"))!=NULL)
-       {
-               while(fgets(buffer, BUFF_SIZE-1, fp) != NULL)
-               {
-                       if(strncmp(buffer, PACKAGE_STR, strlen(PACKAGE_STR)) == 
0)
-                       {
-                               fclose(fp);
-                               return 1;
-                       }
-               }
-               fclose(fp);
-       }
-
-       return 0;
-}
-
 inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx)
 {
-#ifndef _i386__
+#ifndef __i386__
        return;
 #else
        __asm__("cpuid"
@@ -83,116 +40,25 @@
        smp_num_siblings = (ebx&0xff0000) >> 16;
        ht = (edx&0x10000000) >> 28;
 
-       if(ht==1 && smp_num_siblings==2){
-//             printf("The processor in this system supports HT\n");
+       if (ht == 1 && smp_num_siblings >= 2) {
+               /*printf("The processor in this system supports HT\n");*/
                return 1;
-       }else{
-//             printf("The processor in this system does not support HT\n");
+       } else {
+       /*printf("The processor in this system does not support
+       * HT\n");*/
                return 0;
        }
 }
 
-
-int is_ht_enabled()
-{
-    int cpu_map[MAX_CPU_NUM];
-    /*A bit-map shows whether a 'logic' processor has ht flag */
-    int ht_cpu[MAX_CPU_NUM];
-    int logic_cpu_num = 0;
-    int package = -1;
-    int cpu_id = -1;
-    char* ht_flag = NULL;
-    int i = 0;
-    int j = 0;
-    int k = 0;
-
-    FILE *fp;
-    char *proc_cpuinfo = (char*)alloca (strlen (PROC_PATH) + 
sizeof("/cpuinfo"));
-    strcat (strcpy (proc_cpuinfo, PROC_PATH), "/cpuinfo");
-
-    if ((fp = fopen(proc_cpuinfo, "r")) != NULL) {
-        while (fgets(buffer, BUFF_SIZE-1, fp) != NULL) {
-            if (strncmp (buffer, PROCESSOR_STR, strlen(PROCESSOR_STR)) == 0) {
-                sscanf(buffer, PROCESSOR_STR "\t: %d", &cpu_id);
-                ht_cpu[cpu_id] =0;
-                while (fgets(buffer, BUFF_SIZE-1, fp) != NULL) {
-                    if (strncmp(buffer, PACKAGE_STR, strlen(PACKAGE_STR)) == 
0) {
-                        sscanf(buffer, PACKAGE_STR "\t: %d", &package);
-                        cpu_map[cpu_id] = package;
-                        printf("cpu_map[%d]=%d\n",cpu_id,package);
-                    }
-                    if (strncmp(buffer, FLAG_STR, strlen(FLAG_STR)) == 0) {
-                        ht_flag = buffer;
-                        while(*ht_flag != '\0'){
-                            /*printf("ht_flag=%s",ht_flag);*/
-                            if(strncmp(ht_flag,HT_FLAG,strlen(HT_FLAG))==0){
-                                ht_cpu[cpu_id] = 1;
-                                break;
-                            }
-                            ht_flag++;
-                        }
-                        printf("ht_cpu[%d]=%d\n",cpu_id,ht_cpu[cpu_id]);
-                        logic_cpu_num += 1;
-                        break;
-                    }
-                }
-            }
-        }
-    }else
-        return 0;
-
-    fclose(fp);
-
-    for(i =0; i < logic_cpu_num; i++){
-        if(ht_cpu[i] == 1){
-            for(j = i + 1; j < logic_cpu_num; j++){
-                if(cpu_map[i]==cpu_map[j]){
-                    for(k = j +1; k < logic_cpu_num; k++){
-                        if(cpu_map[j]==cpu_map[k]){
-                        /* Not proper HT support, with 3 logic processor in 1 
cpu package*/
-                            return 0;
-                        }
-                    }
-                    if(ht_cpu[j] ==1){
-                        return 1;
-                    }else
-                        return 0;
-                }
-            }
-            /* in this case, processor[i] has ht flag, but is not ht enabled*/
-            if(j == logic_cpu_num){
-                return 0;
-            }
-        }
-    }
-    if(i == logic_cpu_num){
-            return 0;
-    }
-    return 0;
-}
-
-// return 0 means Pass,
-// return 1 means ht is not enabled,
-// return 2 means CPU is not support ht,
-// return 3 mean kernel is not support ht.
+/* return 0 means Pass,
+ return 1 means ht is not enabled,*/
 int check_ht_capability()
 {
        int result;
-
-       if(is_ht_kernel())
-       {
-               if(is_ht_cpu())
-               {
-                       if(is_ht_enabled())
-                               result = 0; //HT is enabled by default in this 
system.
-                       else
-                               result = 1; //HT is not enabled by default in 
this system.
-               }
-               else
-                       result = 2; //This processor does not support HT.
-       }
+       if (is_ht_cpu())
+               result = 0; /*HT is enabled by default in this system.*/
        else
-               result = 3; //HT feature is not included in this Linux Kernel.
+               result = 1; /*HT is not enabled by default in this system.*/
 
        return result;
 }
@@ -212,14 +78,14 @@
        FILE *pfile;
        int count;
 
-        if((pfile=fopen(CPUINFO_PATH, "r"))==NULL)
+       pfile = fopen(CPUINFO_PATH, "r");
+       if (pfile == NULL)
                return 0;
 
        count=0;
 
-       while(fgets(buf, 255, pfile)!=NULL)
-       {
-               if(strncmp(buf, CPU_NAME, strlen(CPU_NAME))==0)
+       while (fgets(buf, 255, pfile) != NULL) {
+               if (strncmp(buf, CPU_NAME, strlen(CPU_NAME)) == 0)
                        count++;
        }
 
@@ -239,10 +105,12 @@
 
         sprintf(buf, "%s%d/%s%c", PROCFS_PATH, pid, STAT_NAME, 0);
 
-       if((pfile=fopen(buf, "r"))==NULL)
+       pfile = fopen(buf, "r");
+       if (pfile == NULL)
                return -1;
 
-       if(fscanf(pfile, "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d 
%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
+       if (fscanf(pfile, "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d\
+        %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
                 &da, str, &ch, &da, &da, &da, &da, &da, &da, &da,\
                 &da, &da, &da, &da, &da, &da, &da, &da, &da, &da,\
                 &da, &da, &da, &da, &da, &da, &da, &da, &da, &da,\
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.h 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.h
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.h   
    2003-01-15 23:18:55.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/HTutils.h 
    2009-06-22 12:17:03.000000000 +0530
@@ -8,8 +8,6 @@
 
 // return 0 means Pass,
 // return 1 means ht is not enabled,
-// return 2 means CPU is not support ht,
-// return 3 mean kernel is not support ht.
 int check_ht_capability();
 
 extern char buf[];
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile    
    2009-02-26 11:59:48.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile  
    2009-06-22 12:17:03.000000000 +0530
@@ -12,6 +12,8 @@
        ${CC} -o ht_affinity HTaffinity.c HTutils.c $(CFLAGS) $(LOADLIBES)
 
 install:
+       @chmod 755 smt_smp_affinity.sh
+       @ln -f smt_smp_affinity.sh ../../../../bin/
        @set -e; for i in $(TARGETS) ; do ln -f $$i ../../../../bin/$$i ; done
 
 clean:
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/smt_smp_affinity.sh
 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/smt_smp_affinity.sh
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_affinity/smt_smp_affinity.sh
     1970-01-01 05:30:00.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_affinity/smt_smp_affinity.sh
   2009-06-22 12:47:49.000000000 +0530
@@ -0,0 +1,87 @@
+#!/bin/sh
+################################################################################
+##                                                                            
##
+## This program is free software;  you can redistribute it and#or modify      
##
+## it under the terms of the GNU General Public License as published by       
##
+## the Free Software Foundation; either version 2 of the License, or          
##
+## (at your option) any later version.                                        
##
+##                                                                            
##
+## This program is distributed in the hope that it will be useful, but        
##
+## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
##
+## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   
##
+## for more details.                                                          
##
+##                                                                            
##
+## You should have received a copy of the GNU General Public License          
##
+## along with this program;  if not, write to the Free Software               
##
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    
##
+##                                                                            
##
+################################################################################
+#
+# File:          smt_smp_affinity.sh
+#
+# Description: This program tests the following:
+#              Set affinity through system call sched_setaffinity
+#              get affinity through system call sched_getaffinity
+#              Inheritance of Affinity
+#
+# Author:      Rohit Verma, [email protected]
+#
+# History:     May 21 2009 - Created. - Rohit Verma
+
+export TST_TOTAL=1
+export TCID=smt_smp_affinity
+export TST_COUNT=1
+TFAILCNT=0
+RC=0
+
+# check for HT/SMP System
+tst_resm TINFO "Begin: SMT/SMP Affinity"
+
+if [ -f ./ht_enabled ];then
+       ./ht_enabled
+       ret_value=$?
+
+       if [ $ret_value -ne 0 ];then
+               tst_resm TCONF "SMT/SMP is not supported"
+               tst_resm TINFO "End: SMT/SMP Affinity"
+               TFAILCNT=$(( $TFAILCNT+1 ))
+               exit $TFAILCNT
+       fi
+else
+       tst_resm TBROK "ht_enabled:File not found"
+       tst_resm TINFO "End: SMT/SMP Affinity"
+       TFAILCNT=$(( $TFAILCNT+1 ))
+       exit $TFAILCNT
+fi
+
+no_of_processor=`cat /proc/cpuinfo | grep -c processor`
+no_of_cpu=`ls /sys/devices/system/cpu/ | grep -c cpu[0-9]`
+
+if [ $no_of_processor -lt $no_of_cpu ];then
+
+       tst_resm TCONF "cpuX:offline"
+       tst_resm TINFO "End: SMT/SMP Affinity"
+       TFAILCNT=$(( $TFAILCNT+1 ))
+       exit $TFAILCNT
+
+else
+        cpu_cores=`cat /proc/cpuinfo | grep "cpu cores" | cut -f 2 -d ':'\
+                        | sed 's/ //' | uniq`
+
+       if [ $cpu_cores -ge 1 ];then
+               if [ -f ./ht_affinity ];then
+                       ./ht_affinity
+               else
+                       tst_resm TBROK "ht_affinity:File not found"
+                       tst_resm TINFO "End: SMT/SMP Affinity"
+                       TFAILCNT=$(( $TFAILCNT+1 ))
+                       exit $TFAILCNT
+               fi
+       else
+               tst_resm TINFO "TBD"
+       fi
+fi
+
+tst_resm TINFO "End: SMT/SMP Affinity"
+
+exit
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/HTenabled.c 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/HTenabled.c
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/HTenabled.c  
    2009-03-05 14:24:33.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/HTenabled.c
    2009-06-22 12:17:03.000000000 +0530
@@ -16,62 +16,16 @@
 #include "test.h"
 #include "HTutils.h"
 
-char *TCID = "ht_enable";
+char *TCID = "smt_smp_enabled";
 int TST_TOTAL = 1;
 
 int main(int argc, char *argv[])
 {
-       tst_resm(TINFO, "Begin: HyperThreading Enabled");
-
+       int ret_val = 1;
 #ifndef __i386__
        tst_brkm(TCONF, NULL, "This test suite can only excute on i386 
architecture.");
 #else
-       if(is_cmdline_para("noht"))
-          {
-               tst_resm(TINFO, "The kernel boot paramter 'noht' is set.");
-               switch(check_ht_capability())
-               {
-               case 0:
-                       tst_resm(TFAIL, "HT is enabled.");
-                       break;
-               case 1:
-                       tst_resm(TPASS, "HT is dinabled.");
-                       break;
-               case 2:
-                       tst_brkm(TCONF, NULL, "This processor does not support 
HT.");
-                       break;
-               case 3:
-                       tst_resm(TFAIL, "HT feature is not included in this 
Linux Kernel.");
-                       break;
-               default:
-                       tst_resm(TFAIL, "Unknown reason.");
-               }
-       }
-       else
-       {
-               tst_resm(TINFO, "The kernel boot paramter 'noht' is not set.");
-               switch(check_ht_capability())
-               {
-               case 0:
-                       tst_resm(TPASS, "HT is enabled.");
-                       break;
-               case 1:
-                       tst_resm(TFAIL, "HT is not enabled.");
-                       break;
-               case 2:
-                       tst_brkm(TCONF, NULL, "This processor does not support 
HT.");
-                       break;
-               case 3:
-                       tst_resm(TFAIL, "HT feature is not included in this 
Linux Kernel.");
-                       break;
-               default:
-                       tst_resm(TFAIL, "Unknown reason.");
-               }
-       }
+               ret_val = check_ht_capability();
 #endif
-
-       tst_resm(TINFO, "End: HyperThreading Enabled");
-
-       return 0;
+       return ret_val;
 }
-
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.c 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.c
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.c    
    2009-03-05 14:24:33.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.c  
    2009-06-22 12:17:03.000000000 +0530
@@ -18,46 +18,6 @@
 
 char buffer[BUFF_SIZE];
 
-int is_cmdline_para(const char *para)
-{
-       FILE *fp;
-
-       if((fp=fopen("/proc/cmdline","r"))!=NULL && para!=NULL)
-       {
-               while(fgets(buffer, BUFF_SIZE-1, fp) != NULL)
-               {
-                       if(strstr(buffer, para) != NULL)
-                       {
-                               fclose(fp);
-                               return 1;
-                       }
-               }
-               fclose(fp);
-       }
-
-       return 0;
-}
-
-int is_ht_kernel()
-{
-       FILE *fp;
-
-       if((fp=fopen("/proc/cpuinfo","r"))!=NULL)
-       {
-               while(fgets(buffer, BUFF_SIZE-1, fp) != NULL)
-               {
-                       if(strncmp(buffer, PACKAGE_STR, strlen(PACKAGE_STR)) == 
0)
-                       {
-                               fclose(fp);
-                               return 1;
-                       }
-               }
-               fclose(fp);
-       }
-
-       return 0;
-}
-
 inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx)
 {
 #ifndef __i386__
@@ -83,117 +43,28 @@
        smp_num_siblings = (ebx&0xff0000) >> 16;
        ht = (edx&0x10000000) >> 28;
 
-       if(ht==1 && smp_num_siblings==2){
-//             printf("The processor in this system supports HT\n");
+       if (ht == 1 && smp_num_siblings >= 2) {
+               /*printf("The processor in this system supports HT\n");*/
                return 1;
-       }else{
-//             printf("The processor in this system does not support HT\n");
+       } else {
+               /*printf("The processor in this system does not support
+               * HT\n");*/
                return 0;
        }
 }
 
-
-int is_ht_enabled()
-{
-    int cpu_map[MAX_CPU_NUM];
-    /*A bit-map shows whether a 'logic' processor has ht flag */
-    int ht_cpu[MAX_CPU_NUM];
-    int logic_cpu_num = 0;
-    int package = -1;
-    int cpu_id = -1;
-    char* ht_flag = NULL;
-    int i = 0;
-    int j = 0;
-    int k = 0;
-
-    FILE *fp;
-    char *proc_cpuinfo = (char*)alloca (strlen (PROC_PATH) + 
sizeof("/cpuinfo"));
-    strcat (strcpy (proc_cpuinfo, PROC_PATH), "/cpuinfo");
-
-    if ((fp = fopen(proc_cpuinfo, "r")) != NULL) {
-        while (fgets(buffer, BUFF_SIZE-1, fp) != NULL) {
-            if (strncmp (buffer, PROCESSOR_STR, strlen(PROCESSOR_STR)) == 0) {
-                sscanf(buffer, PROCESSOR_STR "\t: %d", &cpu_id);
-                ht_cpu[cpu_id] =0;
-                while (fgets(buffer, BUFF_SIZE-1, fp) != NULL) {
-                    if (strncmp(buffer, PACKAGE_STR, strlen(PACKAGE_STR)) == 
0) {
-                        sscanf(buffer, PACKAGE_STR "\t: %d", &package);
-                        cpu_map[cpu_id] = package;
-                        printf("cpu_map[%d]=%d\n",cpu_id,package);
-                    }
-                    if (strncmp(buffer, FLAG_STR, strlen(FLAG_STR)) == 0) {
-                        ht_flag = buffer;
-                        while(*ht_flag != '\0'){
-                            /*printf("ht_flag=%s",ht_flag);*/
-                            if(strncmp(ht_flag,HT_FLAG,strlen(HT_FLAG))==0){
-                                ht_cpu[cpu_id] = 1;
-                                break;
-                            }
-                            ht_flag++;
-                        }
-                        printf("ht_cpu[%d]=%d\n",cpu_id,ht_cpu[cpu_id]);
-                        logic_cpu_num += 1;
-                        break;
-                    }
-                }
-            }
-        }
-    }else
-        return 0;
-
-    fclose(fp);
-
-    for(i =0; i < logic_cpu_num; i++){
-        if(ht_cpu[i] == 1){
-            for(j = i + 1; j < logic_cpu_num; j++){
-                if(cpu_map[i]==cpu_map[j]){
-                    for(k = j +1; k < logic_cpu_num; k++){
-                        if(cpu_map[j]==cpu_map[k]){
-                        /* Not proper HT support, with 3 logic processor in 1 
cpu package*/
-                            return 0;
-                        }
-                    }
-                    if(ht_cpu[j] ==1){
-                        return 1;
-                    }else
-                        return 0;
-                }
-            }
-            /* in this case, processor[i] has ht flag, but is not ht enabled*/
-            if(j == logic_cpu_num){
-                return 0;
-            }
-        }
-    }
-    if(i == logic_cpu_num){
-            return 0;
-    }
-    return 0;
-}
-
-// return 0 means Pass,
-// return 1 means ht is not enabled,
-// return 2 means CPU is not support ht,
-// return 3 mean kernel is not support ht.
+/*return 0 means Pass,
+return 1 means ht is not enabled*/
 int check_ht_capability()
 {
        int result;
-
-       if(is_ht_kernel())
-       {
-               if(is_ht_cpu())
-               {
-                       if(is_ht_enabled())
-                               result = 0; //HT is enabled by default in this 
system.
-                       else
-                               result = 1; //HT is not enabled by default in 
this system.
-               }
-               else
-                       result = 2; //This processor does not support HT.
+       if (is_ht_cpu()) {
+               result = 0;
+               /*HT is enabled by default in this system.*/
+       } else {
+               result = 1;
+               /*HT is not enabled by default in this system.*/
        }
-       else
-               result = 3; //HT feature is not included in this Linux Kernel.
-
        return result;
 }
 
@@ -212,14 +83,14 @@
        FILE *pfile;
        int count;
 
-        if((pfile=fopen(CPUINFO_PATH, "r"))==NULL)
+       pfile = fopen(CPUINFO_PATH, "r");
+       if (pfile == NULL)
                return 0;
 
        count=0;
 
-       while(fgets(buf, 255, pfile)!=NULL)
-       {
-               if(strncmp(buf, CPU_NAME, strlen(CPU_NAME))==0)
+       while (fgets(buf, 255, pfile) !=  NULL) {
+               if (strncmp(buf, CPU_NAME, strlen(CPU_NAME)) == 0)
                        count++;
        }
 
@@ -242,7 +113,8 @@
        if((pfile=fopen(buf, "r"))==NULL)
                return -1;
 
-       if(fscanf(pfile, "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d 
%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
+       if (fscanf(pfile, "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d\
+        %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
                 &da, str, &ch, &da, &da, &da, &da, &da, &da, &da,\
                 &da, &da, &da, &da, &da, &da, &da, &da, &da, &da,\
                 &da, &da, &da, &da, &da, &da, &da, &da, &da, &da,\
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.h 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.h
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.h    
    2003-01-15 23:18:55.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/HTutils.h  
    2009-06-22 12:17:03.000000000 +0530
@@ -8,8 +8,6 @@
 
 // return 0 means Pass,
 // return 1 means ht is not enabled,
-// return 2 means CPU is not support ht,
-// return 3 mean kernel is not support ht.
 int check_ht_capability();
 
 extern char buf[];
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile
--- ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile 
2009-02-26 11:59:48.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile   
    2009-06-22 12:17:03.000000000 +0530
@@ -10,6 +10,8 @@
        ${CC} -o ht_enabled HTenabled.c HTutils.c $(CFLAGS) $(LOADLIBES)
 
 install:
+       @chmod 755 smt_smp_enabled.sh
+       @ln -f smt_smp_enabled.sh ../../../../bin/
        @set -e; for i in $(TARGETS) ; do ln -f $$i ../../../../bin/$$i ; done
 
 clean:
diff -ruNB 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/smt_smp_enabled.sh
 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/smt_smp_enabled.sh
--- 
ltp-full-20090531/testcases/kernel/sched/hyperthreading/ht_enabled/smt_smp_enabled.sh
       1970-01-01 05:30:00.000000000 +0530
+++ 
ltp-full-20090531_o/testcases/kernel/sched/hyperthreading/ht_enabled/smt_smp_enabled.sh
     2009-06-22 12:48:48.000000000 +0530
@@ -0,0 +1,78 @@
+#!/bin/sh
+################################################################################
+##                                                                            
##
+## This program is free software;  you can redistribute it and#or modify      
##
+## it under the terms of the GNU General Public License as published by       
##
+## the Free Software Foundation; either version 2 of the License, or          
##
+## (at your option) any later version.                                        
##
+##                                                                            
##
+## This program is distributed in the hope that it will be useful, but        
##
+## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
##
+## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   
##
+## for more details.                                                          
##
+##                                                                            
##
+## You should have received a copy of the GNU General Public License          
##
+## along with this program;  if not, write to the Free Software               
##
+## Foundation, Inc., 59 Tiemple Place, Suite 330, Boston, MA 02111-1307 USA   
##
+##                                                                            
##
+################################################################################
+#
+# File:          smt_smp_enabled.sh
+#
+# Description: This program tests whether HT/SMP is supported or not.
+#
+# Author:      Rohit Verma, [email protected]
+#
+# History:     May 21 2009 - Created. - Rohit Verma
+
+export TST_TOTAL=1
+export TCID=smt_smp_enabled
+export TST_COUNT=1
+TFAILCNT=0
+RC=0
+
+
+# check for SMT/SMP System
+tst_resm TINFO "Begin: SMT/SMP Enabled"
+if [ -f ./ht_enabled ];then
+       ./ht_enabled
+       ret_value=$?
+
+       if [ $ret_value -ne 0 ];then
+               tst_resm TCONF "SMT/SMP is not supported"
+               tst_resm TINFO "End: SMT/SMP Enabled"
+               TFAILCNT=$(( $TFAILCNT+1 ))
+               exit $TFAILCNT
+       fi
+else
+       tst_resm TBROK "ht_enabled:File not found"
+       tst_resm TINFO "End: SMT/SMP Enabled"
+       TFAILCNT=$(( $TFAILCNT+1 ))
+       exit $TFAILCNT
+fi
+
+no_of_processor=`cat /proc/cpuinfo | grep -c processor`
+no_of_cpu=`ls /sys/devices/system/cpu/ | grep -c cpu[0-9]`
+
+if [ $no_of_processor -lt $no_of_cpu ];then
+       test_op="Enable:/sys/devices/system/cpu/cpuX/online"
+       tst_resm TCONF "$test_op"
+       tst_resm TINFO "End: SMT/SMP Enabled"
+       TFAILCNT=$(( $TFAILCNT+1 ))
+       exit $TFAILCNT
+else
+cpu_cores=`cat /proc/cpuinfo | grep "cpu cores" | cut -f 2 -d ':'\
+                        | sed 's/ //' | uniq`
+
+       if [ $cpu_cores == 1 ];then
+               tst_resm TPASS "SMT is enable"
+       elif [ $cpu_cores -ge 2 ];then
+               tst_resm TPASS "SMP System"
+       else
+               tst_resm TCONF "TBD"
+       fi
+fi
+
+tst_resm TINFO "End: SMT/SMP Enabled"
+
+exit
------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to