Whamcloud - gitweb
b_2074
[fs/lustre-release.git] / lnet / utils / portals.c
index 3325892..fb031ae 100644 (file)
 #include <stdarg.h>
 #include <asm/byteorder.h>
 
+#ifdef __CYGWIN__
+
+#include <netinet/in.h>
+
+#warning assuming little endian
+
+#define __cpu_to_le64(x) ((__u64)(x))
+#define __le64_to_cpu(x) ((__u64)(x))
+#define __cpu_to_le32(x) ((__u32)(x))
+#define __le32_to_cpu(x) ((__u32)(x))
+#define __cpu_to_le16(x) ((__u16)(x))
+#define __le16_to_cpu(x) ((__u16)(x))
+
+#endif /* __CYGWIN__ */
 #include <portals/api-support.h>
 #include <portals/ptlctl.h>
 #include <portals/list.h>
@@ -63,7 +78,6 @@ typedef struct
 static name2num_t nalnames[] = {
         {"any",         0},
         {"tcp",                SOCKNAL},
-        {"toe",                TOENAL},
         {"elan",       QSWNAL},
         {"gm",         GMNAL},
         {"ib",         IBNAL},
@@ -95,6 +109,9 @@ pcfg_ioctl(struct portals_cfg *pcfg)
                 PORTAL_IOC_INIT (data);
                 data.ioc_pbuf1   = (char*)pcfg;
                 data.ioc_plen1   = sizeof(*pcfg);
+                /* XXX liblustre hack XXX */
+                data.ioc_nal_cmd = pcfg->pcfg_command;
+                data.ioc_nid = pcfg->pcfg_nid;
 
                 rc = l_ioctl (PORTALS_DEV_ID, IOC_PORTAL_NAL_CMD, &data);
         }
@@ -651,7 +668,7 @@ int jt_ptl_connect(int argc, char **argv)
                 return 0;
         }
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, TOENAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, 0))
                 return -1;
         
         rc = ptl_parse_ipaddr (&ipaddr, argv[1]);
@@ -797,7 +814,7 @@ int jt_ptl_disconnect(int argc, char **argv)
                 return 0;
         }
 
-        if (!g_nal_is_compatible (NULL, SOCKNAL, TOENAL, 0))
+        if (!g_nal_is_compatible (NULL, SOCKNAL, 0))
                 return 0;
 
         if (argc >= 2 &&
@@ -838,7 +855,7 @@ int jt_ptl_push_connection (int argc, char **argv)
                 return 0;
         }
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, TOENAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, 0))
                 return -1;
         
         if (argc > 1 &&
@@ -1371,7 +1388,8 @@ lwt_control(int enable, int clear)
 }
 
 static int
-lwt_snapshot(int *ncpu, int *totalsize, lwt_event_t *events, int size)
+lwt_snapshot(cycles_t *now, int *ncpu, int *totalsize, 
+             lwt_event_t *events, int size)
 {
         struct portal_ioctl_data data;
         int                      rc;
@@ -1390,6 +1408,9 @@ lwt_snapshot(int *ncpu, int *totalsize, lwt_event_t *events, int size)
         LASSERT (data.ioc_count != 0);
         LASSERT (data.ioc_misc != 0);
         
+        if (now != NULL)
+                *now = data.ioc_nid;
+
         if (ncpu != NULL)
                 *ncpu = data.ioc_count;
 
@@ -1499,14 +1520,13 @@ get_cycles_per_usec ()
 int
 jt_ptl_lwt(int argc, char **argv)
 {
-#define MAX_CPUS 8
         int             ncpus;
         int             totalspace;
         int             nevents_per_cpu;
         lwt_event_t    *events;
-        lwt_event_t    *cpu_event[MAX_CPUS + 1];
-        lwt_event_t    *next_event[MAX_CPUS];
-        lwt_event_t    *first_event[MAX_CPUS];
+        lwt_event_t    *cpu_event[LWT_MAX_CPUS + 1];
+        lwt_event_t    *next_event[LWT_MAX_CPUS];
+        lwt_event_t    *first_event[LWT_MAX_CPUS];
         int             cpu;
         lwt_event_t    *e;
         int             rc;
@@ -1514,6 +1534,9 @@ jt_ptl_lwt(int argc, char **argv)
         double          mhz;
         cycles_t        t0;
         cycles_t        tlast;
+        cycles_t        tnow;
+        struct timeval  tvnow;
+        int             printed_date = 0;
         FILE           *f = stdout;
 
         if (argc < 2 ||
@@ -1541,11 +1564,12 @@ jt_ptl_lwt(int argc, char **argv)
                 return (0);
         }
                 
-        if (lwt_snapshot(&ncpus, &totalspace, NULL, 0) != 0)
+        if (lwt_snapshot(NULL, &ncpus, &totalspace, NULL, 0) != 0)
                 return (-1);
 
-        if (ncpus > MAX_CPUS) {
-                fprintf(stderr, "Too many cpus: %d (%d)\n", ncpus, MAX_CPUS);
+        if (ncpus > LWT_MAX_CPUS) {
+                fprintf(stderr, "Too many cpus: %d (%d)\n", 
+                        ncpus, LWT_MAX_CPUS);
                 return (-1);
         }
 
@@ -1560,11 +1584,14 @@ jt_ptl_lwt(int argc, char **argv)
                 return (-1);
         }
 
-        if (lwt_snapshot(NULL, NULL, events, totalspace)) {
+        if (lwt_snapshot(&tnow, NULL, NULL, events, totalspace)) {
                 free(events);
                 return (-1);
         }
 
+        /* we want this time to be sampled at snapshot time */
+        gettimeofday(&tvnow, NULL);
+
         if (argc > 2) {
                 f = fopen (argv[2], "w");
                 if (f == NULL) {
@@ -1645,6 +1672,17 @@ jt_ptl_lwt(int argc, char **argv)
                 
                 if (t0 <= next_event[cpu]->lwte_when) {
                         /* on or after the first event */
+                        if (!printed_date) {
+                                cycles_t du = (tnow - t0) / mhz;
+                                time_t   then = tvnow.tv_sec - du/1000000;
+                                
+                                if (du % 1000000 > tvnow.tv_usec)
+                                        then--;
+
+                                fprintf(f, "%s", ctime(&then));
+                                printed_date = 1;
+                        }
+                        
                         rc = lwt_print(f, t0, tlast, mhz, cpu, next_event[cpu]);
                         if (rc != 0)
                                 break;
@@ -1666,5 +1704,48 @@ jt_ptl_lwt(int argc, char **argv)
 
         free(events);
         return (0);
-#undef MAX_CPUS
 }
+
+int jt_ptl_memhog(int argc, char **argv)
+{
+        static int                gfp = 0;        /* sticky! */
+
+        struct portal_ioctl_data  data;
+        int                       rc;
+        int                       count;
+        char                     *end;
+        
+        if (argc < 2)  {
+                fprintf(stderr, "usage: %s <npages> [<GFP flags>]\n", argv[0]);
+                return 0;
+        }
+
+        count = strtol(argv[1], &end, 0);
+        if (count < 0 || *end != 0) {
+                fprintf(stderr, "Can't parse page count '%s'\n", argv[1]);
+                return -1;
+        }
+
+        if (argc >= 3) {
+                rc = strtol(argv[2], &end, 0);
+                if (*end != 0) {
+                        fprintf(stderr, "Can't parse gfp flags '%s'\n", argv[2]);
+                        return -1;
+                }
+                gfp = rc;
+        }
+        
+        PORTAL_IOC_INIT(data);
+        data.ioc_count = count;
+        data.ioc_flags = gfp;
+        rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_MEMHOG, &data);
+
+        if (rc != 0) {
+                fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno));
+                return -1;
+        }
+        
+        printf("memhog %d OK\n", count);
+        return 0;
+}
+