]> git.openfabrics.org - ~ardavis/dapl.git/commitdiff
Use inet_ntoa instead of open coding it. IP addresses were being
authorArlin Davis <arlin.r.davis@intel.com>
Tue, 16 Oct 2007 21:09:56 +0000 (14:09 -0700)
committerArlin Davis <arlin.r.davis@intel.com>
Tue, 16 Oct 2007 21:09:56 +0000 (14:09 -0700)
reversed on PowerPC.

On PowerPC the timebase ticks at a different frequency to the CPU.
dapltest currently assumes a 1:1 relationship, and gives bogus values
when scaling timebase to real time.

To fix this, look at the timebase field in /proc/cpuinfo instead. To
keep things consistent with x86, scale that value to MHz.

Signed-off-by: Anton Blanchard <anton@samba.org>
test/dapltest/cmd/dapl_netaddr.c
test/dapltest/mdep/linux/dapl_mdep_user.c
test/dapltest/test/dapl_test_util.c
test/dtest/dtest.c

index 92a6886f33489bee2342ad23e9391060a594cf9c..0b16303beccb4b51c940299696adbd38825a6cb9 100644 (file)
@@ -132,13 +132,9 @@ DT_NetAddrLookupHostAddress (DAT_IA_ADDRESS_PTR    to_netaddr,
     }
 
     /* Pull out IP address and print it as a sanity check */
-    rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
     DT_Mdep_printf ("Server Name: %s \n", hostname);
-    DT_Mdep_printf ("Server Net Address: %d.%d.%d.%d\n",
-                   (rval >>  0) & 0xff,
-                   (rval >>  8) & 0xff,
-                   (rval >> 16) & 0xff,
-                   (rval >> 24) & 0xff);
+    DT_Mdep_printf ("Server Net Address: %s\n",
+                   inet_ntoa(((struct sockaddr_in *)target->ai_addr)->sin_addr));
 
     *to_netaddr = * ((DAT_IA_ADDRESS_PTR) target->ai_addr);
 
index 491ead1e2dbebe0daaaa2c439b8b68e8646287e8..015e53ca2d60f6994941158a1c400267a4cfbdf2 100644 (file)
@@ -185,16 +185,18 @@ double
 DT_Mdep_GetCpuMhz (
     void )
 {
-#define DT_CPU_MHZ_BUFFER_SIZE         128
+#define DT_TSC_BUFFER_SIZE     128
 #if defined (__PPC__) || defined (__PPC64__)
-#define DT_CPU_MHZ_MHZ          "clock"
+#define DT_TSC_RATE            "timebase"
+#define DT_TSC_BASE            1000000.0
 #else
-#define DT_CPU_MHZ_MHZ                 "cpu MHz"
+#define DT_TSC_RATE            "cpu MHz"
+#define DT_TSC_BASE            1.0
 #endif
-#define DT_CPU_MHZ_DELIMITER   ":"
+#define DT_TSC_DELIMITER       ":"
 
     FILE *fp;
-    char buffer[DT_CPU_MHZ_BUFFER_SIZE];
+    char buffer[DT_TSC_BUFFER_SIZE];
     char *mhz_str;
 
     fp = fopen ("/proc/cpuinfo", "r");
@@ -206,16 +208,16 @@ DT_Mdep_GetCpuMhz (
 
     for (;;)
     {
-       if ( NULL == fgets (buffer, DT_CPU_MHZ_BUFFER_SIZE, fp) )
+       if ( NULL == fgets (buffer, DT_TSC_BUFFER_SIZE, fp) )
        {
            printf ("cpu MHZ not found\n");
            exit (1);
        }
 
-       if ( !strncmp (buffer, DT_CPU_MHZ_MHZ, strlen (DT_CPU_MHZ_MHZ) ) )
+       if ( !strncmp (buffer, DT_TSC_RATE, strlen (DT_TSC_RATE) ) )
        {
-           (void) strtok (buffer, DT_CPU_MHZ_DELIMITER);
-           mhz_str = strtok (NULL, DT_CPU_MHZ_DELIMITER);
+           (void) strtok (buffer, DT_TSC_DELIMITER);
+           mhz_str = strtok (NULL, DT_TSC_DELIMITER);
 
            break;
        }
@@ -227,7 +229,7 @@ DT_Mdep_GetCpuMhz (
        exit (1);
     }
 
-    return strtod (mhz_str, NULL);
+    return strtod (mhz_str, NULL) / DT_TSC_BASE;
 }
 
 
index f4554e74a5c944b130e6814a37dcd3f18d6104cc..fb345e80ab1f4324c32bd85fb80dfc77f54ca529 100644 (file)
@@ -142,16 +142,10 @@ DT_query (   Per_Test_Data_t *pt_ptr,
        else if (ip6_addr->sin6_family == AF_INET )
 
        {
-           int rval;
-
            ip_addr = (struct sockaddr_in *)pt_ptr->ia_attr.ia_address_ptr;
-           rval = (int) ip_addr->sin_addr.s_addr;
 
-           DT_Tdep_PT_Printf (phead, "\tLocal IP address %d.%d.%d.%d\n",
-                         (rval >>  0) & 0xff,
-                         (rval >>  8) & 0xff,
-                         (rval >> 16) & 0xff,
-                         (rval >> 24) & 0xff);
+           DT_Tdep_PT_Printf (phead, "\tLocal IP address %s\n",
+                         inet_ntoa(ip_addr->sin_addr));
        }
 
        DT_Tdep_PT_Printf (phead, "***** ***** ***** ***** ***** *****\n");
index 27387ce9bfba2d20a6d30026a2c82abc0708e4c6..52afdbf3a211d76d6c216a6bcdc06185b148fc12 100644 (file)
@@ -716,20 +716,15 @@ connect_ep( char *hostname, int conn_id )
     }
     else {  /* CLIENT */
        struct addrinfo *target;
-       int             rval;
 
        if (getaddrinfo (hostname, NULL, NULL, &target) != 0) {
            printf("\n remote name resolution failed!\n");
            exit ( 1 );
        }
 
-       rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
        printf ("%d Server Name: %s \n", getpid(), hostname);
-       printf ("%d Server Net Address: %d.%d.%d.%d\n", getpid(),
-           (rval >>  0) & 0xff,
-           (rval >>  8) & 0xff,
-           (rval >> 16) & 0xff,
-           (rval >> 24) & 0xff);
+       printf ("%d Server Net Address: %s\n", getpid(),
+           inet_ntoa(((struct sockaddr_in *)target->ai_addr)->sin_addr));
 
        remote_addr = *((DAT_IA_ADDRESS_PTR)target->ai_addr);