Updates for stats collection across processes
authorTinku Mannan <tmannan@ti.com>
Fri, 8 Aug 2014 16:36:35 +0000 (12:36 -0400)
committerTinku Mannan <tmannan@ti.com>
Fri, 8 Aug 2014 16:36:35 +0000 (12:36 -0400)
ti/runtime/netapi/demo/src/navl_external_posix.c
ti/runtime/netapi/demo/src/navl_wrapper.c
ti/runtime/netapi/demo/src/navl_wrapper.h
ti/runtime/netapi/demo/src/netapi_dpi_demo.c
ti/runtime/netapi/demo/src/netapi_dpi_demo.h

index 60ceec3ece44b8ea43680c92686a8551fabe710b..8ee00ab7e08413d22a58e6c9491dc439b399aab6 100755 (executable)
@@ -1,4 +1,3 @@
-#include <navl/navl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include "navl/navl.h"
+#include "navl_wrapper.h"
+extern navl_global_dpi_stats *pDpiStats;
 
 
-int malloc_inst=0;
-int malloc_bytes=0;
 void* our_malloc(size_t n)
 {
-    malloc_inst+=1;
-    malloc_bytes+= n;
+    pDpiStats->malloc_inst+=1;
+    pDpiStats->malloc_bytes+= n;
     return (malloc(n));
 }
 int null_log_message(const char *level, const char *func, const char *format, ... )
index e282b1229c302cf27458dc1ee342c4324e7a94d4..27f3be04586d724a4e348b7b1fd5171a12397536 100755 (executable)
@@ -9,55 +9,43 @@
 #include <assert.h>
 #include <stdarg.h>
 #include "ti/runtime/hplib/hplib.h"
+#include "ti/runtime/netapi/netapi_types.h"
 #include "navl_wrapper.h"
 /* timing */
 
 #define netapi_timing_start hplib_mUtilGetPmuCCNT
 
-extern int malloc_inst;
-
-
 navl_wrapper_cfg_info_t *pNavlCfg;
+navl_global_dpi_stats *pDpiStats;
 void* pShmBase;
 void *pShmEntry;
 
-int free_inst=0;
-extern int malloc_bytes;
-static unsigned long long malloc_cycles;
-static unsigned long long free_cycles;
-static int n_ops=0;
-static int n_class=0;
-static unsigned long min_time=100000000;
-static unsigned long max_time=0;
+//int free_inst=0;
+
 static unsigned long long timing=0LL;
-static unsigned long n_err=0;
+
 static char last_url[256];
 int class=0;
 void clear_pkt_stats();
 void navl_clear_stats(void)
 {
-    n_ops=0;
-    timing=0LL;
-    n_class=0;
-    min_time=100000000;
-    max_time=0;
-    n_err=0;
-    malloc_inst=0; free_inst=0; free_cycles=0LL; malloc_cycles=0LL;
+    memset(pDpiStats, 0, sizeof(navl_global_dpi_stats));
+    pDpiStats->min_time=100000000;
     clear_pkt_stats();
 }
 void navl_return_stats(int * Pn_ops, int * Pn_class, unsigned long * Pmin_time, unsigned long * Pmax_time, unsigned long long *Ptiming, int * Pmalloc_inst, int *Pmalloc_bytes, int * Pn_err, int *Pfree_inst, unsigned long *Pmalloc_cycles, unsigned long *Pfree_cycles)
 {
-    *Pn_ops=n_ops;
-    *Pn_class=n_class;
-    *Pmin_time=min_time;
-    *Pmax_time=max_time;
+    *Pn_ops=pDpiStats->n_ops;
+    *Pn_class=pDpiStats->n_class;
+    *Pmin_time=pDpiStats->min_time;
+    *Pmax_time=pDpiStats->max_time;
     *Ptiming=timing;
-    *Pmalloc_inst = malloc_inst;
-    *Pmalloc_bytes= malloc_bytes;
-    *Pn_err=n_err;
-    *Pfree_inst = free_inst; 
-    *Pmalloc_cycles= malloc_inst ? malloc_cycles/malloc_inst: 0;
-    *Pfree_cycles= free_inst? free_cycles/free_inst : 0;
+    *Pmalloc_inst = pDpiStats->malloc_inst;
+    *Pmalloc_bytes= pDpiStats->malloc_bytes;
+    *Pn_err=pDpiStats->n_err;
+    *Pfree_inst = pDpiStats->free_inst; 
+    *Pmalloc_cycles= pDpiStats->malloc_inst ? pDpiStats->malloc_cycles/pDpiStats->malloc_inst: 0;
+    *Pfree_cycles= pDpiStats->free_inst? pDpiStats->free_cycles/pDpiStats->free_inst : 0;
 }
 
 //#define MAX_BIN 10
@@ -72,85 +60,6 @@ void add2bin(long cycles, long p_bins[])
      p_bins[MAX_BIN-1] += 1; //max
 }
 
-#if 0
-/* for tracking packet stats */
-typedef struct
-{
-    uint64_t packets;
-    uint64_t bytes;
-    char name[12];
-    uint64_t cycles;
-    uint64_t cycles_nomem;
-    long cycles_nomem_max;
-    long cycles_nomem_min;
-    uint64_t class; //# packets classified
-    long bin_cycles[MAX_BIN];
-} navl_wrapper_pkt_stat_t;
-
-
-
-/* for tracking packets per thread/core basis */
-typedef struct 
-{
-    navl_wrapper_cfg_info_t     navl_cfg;
-    navl_wrapper_pkt_stat_t     stats_pkt[2];
-} navl_wrapper_shm_pkt_stats_t;
-
-
-
-
-/* for tracking memory stats */
-typedef struct
-{
-    int64_t curr;
-    int64_t peak;
-    int64_t fail;
-} navl_wrapper_stat_t;
-
-
-
-
-/* instance variables */
-typedef struct {
-/* handles */
-    navl_handle_t           navl;
-
-    /* configuration */
-    const char             *config_capfile;
-    const char             *config_plugins;
-    int                     config_num_proto;
-    int                     config_conn_id_attr;
-    int                     config_http_attr;
-    int                     config_num_memctx;
-    int                     config_num_memobj;
-
-    /* options */
-    int                     option_dpi;
-    int                     option_simple;
-    int                     option_track_memory;
-    int                     option_limit_memory;
-    int                     option_tunnel;
-    int                     option_realtime_mode;
-    int                     option_verbose;
-
-    /* diagnostics */
-    int                     error_navl;
-
-    /* statistics */
-#define NUM_MEM_CTX 50
-#define NUM_MEM_OBJ 50
-    navl_wrapper_stat_t    stats_mem[NUM_MEM_CTX][NUM_MEM_OBJ];
-    char                    ctx_name[NUM_MEM_CTX][64];
-    char                    obj_name[NUM_MEM_OBJ][64];
-    navl_wrapper_pkt_stat_t *stats_pkt[2];
-    uint64_t                stats_conns;
-
-    /* misc vars */
-    int                     running;
-    int64_t                 alloc_curr;
-    int64_t                 alloc_peak;
-} navl_mcb_t;
-#endif
 
 
 navl_mcb_t *g_reader = NULL;
@@ -192,7 +101,6 @@ do { \
 int navl_setup(void)
 {
     return (navl_wrapper_init(0, NULL));
-    //return 1;
 }
 
 
@@ -262,6 +170,7 @@ navl_wrapper_init(int argc, char *argv[])
     static navl_mcb_t reader;
 
     int ret;
+    int i;
 
     g_reader = &reader;
 
@@ -295,6 +204,41 @@ navl_wrapper_init(int argc, char *argv[])
 
     g_exename = "dpi_demo";
 
+
+    /* allocate segment for shared memory for packet stats */
+     /* allocate packet statistics */
+    pShmBase = hplib_shmOpen();
+    if (pShmBase)
+    {
+        pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_1);
+        pNavlCfg =  (navl_wrapper_cfg_info_t*)pShmEntry;
+        memset(pNavlCfg,
+               0,
+               sizeof(navl_wrapper_pkt_stat_t) * MAX_PROTOCOLS *NUM_FP_PROCS+ sizeof(navl_wrapper_cfg_info_t));
+        pNavlCfg =  (navl_wrapper_cfg_info_t*)pShmEntry;
+        pNavlCfg->num_protocols = g_reader->config_num_proto;
+        g_reader->stats_pkt[0] = pShmEntry + sizeof(navl_wrapper_cfg_info_t);
+
+        g_reader->stats_pkt[1] = pShmEntry + sizeof(navl_wrapper_cfg_info_t) +
+                (sizeof(navl_wrapper_pkt_stat_t)*MAX_PROTOCOLS); 
+
+        for(i=0;i< MAX_PROTOCOLS;i++)
+        {
+            g_reader->stats_pkt[0][i].cycles_min=10000000;
+            g_reader->stats_pkt[1][i].cycles_min=10000000;
+            g_reader->stats_pkt[0][i].cycles_max=0;
+            g_reader->stats_pkt[1][i].cycles_max=0;
+        }
+
+        pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_2);
+        pDpiStats = (navl_global_dpi_stats*) pShmEntry;
+    }
+    else
+    {
+        printf("navl_wrapper_init: hplib_shmOpen failure\n");
+        return NETAPI_ERR_NOMEM;
+    }
+
     /* EXTERNAL BINDINGS GO HERE */
     {
         /* Bind the platform specific functions. */
@@ -330,48 +274,9 @@ navl_wrapper_init(int argc, char *argv[])
 
     /* the number of protocols is the max + 1 */
     g_reader->config_num_proto = (ret + 1);
+    pNavlCfg->num_protocols = g_reader->config_num_proto;
 
-
-
-    /* allocate segment for shared memory for packet stats */
-     /* allocate packet statistics */
-    pShmBase = hplib_shmOpen();
-    if (pShmBase)
-    {
-        if (hplib_shmAddEntry(pShmBase,
-                          sizeof(navl_wrapper_pkt_stat_t)
-                         * g_reader->config_num_proto *NUM_FP_PROCS + sizeof(navl_wrapper_cfg_info_t),
-                         APP_ENTRY_1) != hplib_OK)
-        {
-            printf("navl_per_thread_init failure\n");
-            navl_wrapper_error();
-            return -1;
-        }
-        else
-        {
-            printf("navl_wrapper_init: num proto %d\n", g_reader->config_num_proto);
-            pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_1);
-            pNavlCfg =  (navl_wrapper_cfg_info_t*)pShmEntry;
-            memset(pNavlCfg,
-                   0,
-                   sizeof(navl_wrapper_pkt_stat_t) * g_reader->config_num_proto *NUM_FP_PROCS+ sizeof(navl_wrapper_cfg_info_t));
-            pNavlCfg =  (navl_wrapper_cfg_info_t*)pShmEntry;
-            pNavlCfg->num_protocols = g_reader->config_num_proto;
-            g_reader->stats_pkt[0] = pShmEntry + sizeof(navl_wrapper_cfg_info_t);
-
-        
-            g_reader->stats_pkt[1] = pShmEntry + sizeof(navl_wrapper_cfg_info_t) +
-                    (sizeof(navl_wrapper_pkt_stat_t)*g_reader->config_num_proto); 
-
-            printf("navl_wrapper_init:  address: 0x%x\n", pShmEntry);
-
-            printf("navl_wrapper_init: stats 0 address: 0x%x\n", &g_reader->stats_pkt[0]);
-
-            printf("navl_wrapper_init: stats 1 address: 0x%x\n", &g_reader->stats_pkt[1]);
-
-        }
-    }
-    return ;
+    return NETAPI_ERR_OK;
 }
 
 //per thread init. Call this in worker thread context
@@ -423,15 +328,7 @@ int navl_per_thread_init(uint32_t thread_num)
     g_reader->config_num_proto = (ret + 1);
 #endif
 
-#if 0
-    if ((g_reader->stats_pkt = 
-        (navl_wrapper_pkt_stat_t *)malloc(sizeof(*g_reader->stats_pkt)
-    * (g_reader->config_num_proto))) == NULL)
-    {
-        navl_wrapper_error();
-    }
-    memset(g_reader->stats_pkt, 0, sizeof(*g_reader->stats_pkt) * (g_reader->config_num_proto) * 2);
-#endif
+
     /* now fetch all the protocol name ahead of time do we don't have to lookup them up on each packet */
     for (ret = 0; ret != g_reader->config_num_proto; ret++)
         navl_proto_get_name(g_reader->navl, ret,
@@ -503,10 +400,11 @@ navl_classify_callback(navl_handle_t handle,
        (state==NAVL_STATE_TERMINATED) ||
        (state==NAVL_STATE_MONITORING))
     {
-        n_class+=1;
+        pDpiStats->n_class+=1;
         class =1;
     }
-        else class=0;
+    else
+        class=0;
 #if 0
     if (navl_proto_find_index(g_reader->navl, "HTTP") == packet->appidx)
     {
@@ -597,15 +495,16 @@ int navl_process_pkt(unsigned char *p_pkt, int len)
 {
     volatile unsigned long v1;
     volatile unsigned long v2;
-    unsigned long temp;
+    unsigned long temp=0;
     uint64_t last = 0;
     uint64_t next = 0;
     unsigned long long mf1;
     unsigned long long mf2;
-    mf1= malloc_cycles+free_cycles;
-    v1 = netapi_timing_start();
     int threadId =Osal_nwalGetProcId();
-
+    mf1= pDpiStats->malloc_cycles+pDpiStats->free_cycles;
+    
+    v1 = netapi_timing_start();
+    
 /* update the current packet */
     packet.sequence++;
     packet.size = len;
@@ -638,25 +537,30 @@ int navl_process_pkt(unsigned char *p_pkt, int len)
      * captured will be accumulated there */
     g_reader->stats_pkt[threadId -1][packet.appidx].packets++;
     g_reader->stats_pkt[threadId -1][packet.appidx].bytes += packet.size;
-    if(class)  g_reader->stats_pkt[threadId -1][packet.appidx].class++;
+    if(class)
+        g_reader->stats_pkt[threadId -1][packet.appidx].class++;
     //update timing
     v2 = netapi_timing_start();
     temp=v2-v1;
-    mf2= malloc_cycles+free_cycles;
+    mf2= pDpiStats->malloc_cycles + pDpiStats->free_cycles;
     timing+= (unsigned long long) temp;
     g_reader->stats_pkt[threadId -1][packet.appidx].cycles += (unsigned long long) temp;
     g_reader->stats_pkt[threadId -1][packet.appidx].cycles_nomem += ((unsigned long long) temp - (mf2-mf1));
 
-    if (g_reader->stats_pkt[threadId -1][packet.appidx].cycles_nomem_min > (temp - (unsigned long)(mf2-mf1)))
-        g_reader->stats_pkt[threadId -1][packet.appidx].cycles_nomem_min = (temp - (unsigned long)(mf2-mf1));
+    if (g_reader->stats_pkt[threadId -1][packet.appidx].cycles_min > temp)
+        g_reader->stats_pkt[threadId -1][packet.appidx].cycles_min = temp;
+
+    if (g_reader->stats_pkt[threadId -1][packet.appidx].cycles_max  < temp)
+    {
+        g_reader->stats_pkt[threadId -1][packet.appidx].cycles_max = temp;
 
-    if (g_reader->stats_pkt[threadId -1][packet.appidx].cycles_nomem_max < (temp - (unsigned long)(mf2-mf1)) )
-        g_reader->stats_pkt[threadId -1][packet.appidx].cycles_nomem_max = (temp - (unsigned long)(mf2-mf1));
+    }
+    
 
     add2bin((temp - (unsigned long)(mf2-mf1)),&g_reader->stats_pkt[threadId -1][packet.appidx].bin_cycles[0]); 
-    n_ops+=1;
-    if (temp>max_time) max_time=temp;
-    if (temp<min_time) min_time=temp;
+    pDpiStats->n_ops+=1;
+    if (temp > pDpiStats->max_time) pDpiStats->max_time = temp;
+    if (temp< pDpiStats->min_time) pDpiStats->min_time = temp;
     return 1;
 }
 
@@ -674,11 +578,10 @@ void navl_results(int threadId)
     uint64_t total_packets, total_bytes;
     void* pShmEntry;
 
-
     total_packets = 0;
     total_bytes = 0;
 
-    //if (g_reader->option_dpi)
+    if (g_reader->option_dpi)
     {
         printf("\n NAVL DPI stats for CORE ID %d\n", threadId);
         printf("\n AppProto    Packets  Class   Bytes        Cycles/Pkt      Cyclesnomem/Pkt  (min)  (max) ");
@@ -690,20 +593,20 @@ void navl_results(int threadId)
     //for (idx = 0; idx < g_reader->config_num_proto; idx++)
     for (idx = 0; idx < pNavlCfg->num_protocols; idx++)
     {
-        //if (g_reader->option_dpi)
+        if (g_reader->option_dpi)
         {
             if (g_reader->stats_pkt[threadId -1][idx].packets)
             {
                 /* We need to provide protocol definitions */  
-                printf(" %-12s%-12" PRIu64 " %" PRIu64 " %" PRIu64 "      %" PRIu64 "       %" PRIu64 "    %ld    %ld .. " , 
+                printf(" %-12s%-12" PRIu64 " %" PRIu64 " %" PRIu64 "      %" PRIu64 "       %" PRIu64 "    %ld    %ld    " , 
                         g_reader->stats_pkt[threadId -1][idx].name,
                         g_reader->stats_pkt[threadId -1][idx].packets, 
                         g_reader->stats_pkt[threadId -1][idx].class, 
                         g_reader->stats_pkt[threadId -1][idx].bytes,
                         g_reader->stats_pkt[threadId -1][idx].cycles/g_reader->stats_pkt[threadId -1][idx].packets, 
                         g_reader->stats_pkt[threadId -1][idx].cycles_nomem/g_reader->stats_pkt[threadId -1][idx].packets,
-                        g_reader->stats_pkt[threadId -1][idx].cycles_nomem_min,
-                        g_reader->stats_pkt[threadId -1][idx].cycles_nomem_max);
+                        g_reader->stats_pkt[threadId -1][idx].cycles_min,
+                        g_reader->stats_pkt[threadId -1][idx].cycles_max);
                 for(i=0;i<MAX_BIN;i++) printf("%ld ",g_reader->stats_pkt[threadId -1][idx].bin_cycles[i]);
                 printf("\n");
             }
@@ -725,14 +628,14 @@ void navl_results(int threadId)
     if (g_reader->option_track_memory)
         navl_wrapper_mem_stat_print();
 
-    if (g_reader->alloc_curr != 0)
-        printf("Bytes not freed: %" PRIi64 "\n", g_reader->alloc_curr);
+
+    if (pNavlCfg->alloc_curr != 0)
+        printf("Bytes not freed: %" PRIi64 "\n", pNavlCfg->alloc_curr);
 
     if (g_reader->alloc_peak != 0)
            printf("Peak allocated: %" PRIi64 "\n", g_reader->alloc_peak);
 
     printf("attr test: last http utl= %s\n",last_url);
-
 }
 
 static void 
@@ -768,6 +671,95 @@ navl_wrapper_mem_stat_print()
     printf("\n\n");
 }
 
+
+void navl_results2(int threadId)
+{
+    int idx;
+    int i;
+    uint64_t total_packets, total_bytes;
+    void* pShmEntry;
+    void* pShmBase;
+    void* pTemp;
+    navl_wrapper_cfg_info_t *pNavlCfg;
+    navl_wrapper_pkt_stat_t *pStats1;
+    navl_wrapper_pkt_stat_t *pStats2;
+    navl_mcb_t g_reader;
+
+    pShmBase = hplib_shmOpen();
+    if (pShmBase)
+    {
+        pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_1);
+        pNavlCfg =  (navl_wrapper_cfg_info_t*)pTemp;
+    
+        g_reader.stats_pkt[0] = pTemp + sizeof(navl_wrapper_cfg_info_t);
+    
+    
+        g_reader.stats_pkt[1] = pTemp + sizeof(navl_wrapper_cfg_info_t) +
+                (sizeof(navl_wrapper_pkt_stat_t)*pNavlCfg->num_protocols);
+    }
+    total_packets = 0;
+    total_bytes = 0;
+
+    //if (g_reader->option_dpi)
+    {
+        printf("\n NAVL DPI stats for CORE ID %d\n", threadId);
+        printf("\n AppProto    Packets  Class   Bytes        Cycles/Pkt      Cyclesnomem/Pkt  (min)  (max) ");
+        for(i=0;i<MAX_BIN;i++)
+            printf("<%s ",binStr[i]);
+        printf("\n ----------------------------------------------------------------------------------------------------------------------------------------------------\n");
+    }
+
+    //for (idx = 0; idx < g_reader->config_num_proto; idx++)
+    for (idx = 0; idx < pNavlCfg->num_protocols; idx++)
+    {
+        //if (g_reader->option_dpi)
+        {
+            if (g_reader.stats_pkt[threadId -1][idx].packets)
+            {
+                /* We need to provide protocol definitions */  
+                printf(" %-12s%-12" PRIu64 " %" PRIu64 " %" PRIu64 "      %" PRIu64 "       %" PRIu64 "    %ld    %ld    " , 
+                        g_reader.stats_pkt[threadId -1][idx].name,
+                        g_reader.stats_pkt[threadId -1][idx].packets, 
+                        g_reader.stats_pkt[threadId -1][idx].class, 
+                        g_reader.stats_pkt[threadId -1][idx].bytes,
+                        g_reader.stats_pkt[threadId -1][idx].cycles/g_reader.stats_pkt[threadId -1][idx].packets, 
+                        g_reader.stats_pkt[threadId -1][idx].cycles_nomem/g_reader.stats_pkt[threadId -1][idx].packets,
+                        g_reader.stats_pkt[threadId -1][idx].cycles_min,
+                        g_reader.stats_pkt[threadId -1][idx].cycles_max);
+                for(i=0;i<MAX_BIN;i++) printf("%ld ",g_reader.stats_pkt[threadId -1][idx].bin_cycles[i]);
+                printf("\n");
+            }
+        }
+
+        total_packets += g_reader.stats_pkt[threadId -1][idx].packets;
+        total_bytes += g_reader.stats_pkt[threadId -1][idx].bytes;
+    }
+
+    if (!total_packets)
+        printf("\n No packets captured.\n");
+    else
+        printf("\n %" PRIu64 " packets captured (%" PRIu64 " bytes)\n", total_packets, total_bytes);
+
+#if 0
+    if (g_reader.stats_conns)
+        printf(" %" PRIu64 " connections tracked\n", g_reader.stats_conns);
+
+    printf("\n");
+    //if (g_reader.option_track_memory)
+        navl_wrapper_mem_stat_print();
+
+    if (pNavlCfg->alloc_curr != 0)
+        printf("Bytes not freed: %" PRIi64 "\n", pNavlCfg->alloc_curr);
+
+    if (g_reader.alloc_peak != 0)
+           printf("Peak allocated: %" PRIi64 "\n", g_reader.alloc_peak);
+
+    printf("attr test: last http utl= %s\n",last_url);
+#endif
+}
+
+
+
 /* Private memory stamp type for tracking memory with navl_wrapper_malloc/free */
 typedef struct
 {
@@ -785,8 +777,8 @@ static void *navl_wrapper_malloc(size_t size)
     int ctx_tag, obj_tag;
     unsigned long t1;
     unsigned long t2;
-    malloc_inst+=1;
-    malloc_bytes+=size;
+    pDpiStats->malloc_inst+=1;
+    pDpiStats->malloc_bytes+=size;
     t1=netapi_timing_start();
 
     assert(size);
@@ -820,14 +812,14 @@ static void *navl_wrapper_malloc(size_t size)
     stat_mem = &g_reader->stats_mem[ctx_tag][obj_tag];
 
     /* check limits */
-    if (!g_reader->option_limit_memory || (g_reader->alloc_curr + size < g_reader->option_limit_memory))
+    if (!g_reader->option_limit_memory || (pNavlCfg->alloc_curr + size < g_reader->option_limit_memory))
     {
         memstamp_t *ptr = (memstamp_t *)malloc(size + sizeof(memstamp_t));
         if (ptr)
         {
             /* track peak values */
-            if ((g_reader->alloc_curr += size) > g_reader->alloc_peak)
-            g_reader->alloc_peak = g_reader->alloc_curr;
+            if ((pNavlCfg->alloc_curr += size) > g_reader->alloc_peak)
+            g_reader->alloc_peak = pNavlCfg->alloc_curr;
 
             if ((stat_mem->curr += size) > stat_mem->peak)
             stat_mem->peak = stat_mem->curr;
@@ -836,7 +828,7 @@ static void *navl_wrapper_malloc(size_t size)
             ptr->ctx_tag = ctx_tag;
             ptr->obj_tag = obj_tag;
             t2=netapi_timing_start();
-            malloc_cycles += (unsigned long long)  (t2-t1);
+            pDpiStats->malloc_cycles += (unsigned long long)  (t2-t1);
             return ptr->mem;
         }
     }
@@ -849,7 +841,7 @@ navl_wrapper_free(void *p)
 {
     unsigned long t1;
     unsigned long t2;
-    free_inst += 1;
+    pDpiStats->free_inst += 1;
     t1=netapi_timing_start();
     if (!p)
         return;
@@ -860,11 +852,11 @@ navl_wrapper_free(void *p)
     assert(p == ptr->mem);
 
     stat_mem->curr -= ptr->size;
-    g_reader->alloc_curr -= ptr->size;
+    pNavlCfg->alloc_curr -= ptr->size;
 
     free(ptr);
     t2=netapi_timing_start();
-    free_cycles += (unsigned long long)  (t2-t1);
+    pDpiStats->free_cycles += (unsigned long long)  (t2-t1);
 }
 
 static int
@@ -885,13 +877,16 @@ navl_wrapper_log_message(const char *level, const char *func, const char *format
 //clear stats
 void clear_pkt_stats()
 {
-    int ret;
-    int threadId =Osal_nwalGetProcId();
-     memset(g_reader->stats_pkt, 0, sizeof(*g_reader->stats_pkt) * (g_reader->config_num_proto)*2);
-    /* now fetch all the protocol name ahead of time do we don't have to lookup them up on each packet */
-    for (ret = 0; ret != g_reader->config_num_proto; ret++)
+    int ret, i;
+    memset(g_reader->stats_pkt[0], 0, (sizeof(navl_wrapper_pkt_stat_t)*MAX_PROTOCOLS));
+    memset(g_reader->stats_pkt[1], 0, (sizeof(navl_wrapper_pkt_stat_t)*MAX_PROTOCOLS));
+
+    for (i=0;i < NUM_FP_PROCS;i++)
     {
-        navl_proto_get_name(g_reader->navl, ret, g_reader->stats_pkt[threadId -1][ret].name, sizeof(g_reader->stats_pkt[threadId -1][ret].name));
-        g_reader->stats_pkt[threadId -1][ret].cycles_nomem_min=10000000;
+        /* now fetch all the protocol name ahead of time do we don't have to lookup them up on each packet */
+        for (ret = 0; ret != MAX_PROTOCOLS; ret++)
+        {
+            g_reader->stats_pkt[i][ret].cycles_min=10000000;
+        }
     }
 }
index 113d8befe44fc2e56af0af70b121457d1d61f4d6..9ba57b75b122bcd8906e31566290f57c931fde5e 100755 (executable)
@@ -68,14 +68,43 @@ extern "C" {
 
 #define NUM_FP_PROCS 2
 
+#define MAX_PROTOCOLS 1500
 
 #define MAX_BIN 10
 typedef struct 
 {
     uint32_t num_threads;
     uint32_t num_protocols;
+    uint32_t enable_dpi;
+    int64_t alloc_curr;
 } navl_wrapper_cfg_info_t;
 
+
+
+
+typedef struct
+{
+unsigned long n_ops;
+unsigned long n_class;
+unsigned long min_time;
+unsigned long max_time;
+unsigned long long tot;
+unsigned long m_op;
+unsigned long m_bytes;
+unsigned long n_err;
+unsigned long f_op;
+unsigned long m_cycles;
+unsigned long f_cycles;
+unsigned long long malloc_cycles;
+unsigned long long free_cycles;
+int malloc_inst;
+int malloc_bytes;
+int free_inst;
+} navl_global_dpi_stats;
+
+
+
+
 /* for tracking packet stats */
 typedef struct
 {
@@ -84,8 +113,8 @@ typedef struct
     char name[9];
     uint64_t cycles;
     uint64_t cycles_nomem;
-    long cycles_nomem_max;
-    long cycles_nomem_min;
+    unsigned long cycles_max;
+    unsigned long cycles_min;
     uint64_t class; //# packets classified
     long bin_cycles[MAX_BIN];
     uint32_t pad[3];
@@ -113,6 +142,8 @@ typedef struct
 
 
 
+#define NUM_MEM_CTX 50
+#define NUM_MEM_OBJ 50
 
 /* instance variables */
 typedef struct {
@@ -141,8 +172,8 @@ typedef struct {
     int                     error_navl;
 
     /* statistics */
-#define NUM_MEM_CTX 50
-#define NUM_MEM_OBJ 50
+//#define NUM_MEM_CTX 50
+//#define NUM_MEM_OBJ 50
     navl_wrapper_stat_t    stats_mem[NUM_MEM_CTX][NUM_MEM_OBJ];
     char                    ctx_name[NUM_MEM_CTX][64];
     char                    obj_name[NUM_MEM_OBJ][64];
index b074eb7ff98facf18d73febf677dd02d120acf1d..b9d1bc0c36fc9cd90f26e4b24d02d853d782aa74 100755 (executable)
 #include <ti/drv/cppi/device/k2e/src/cppi_device.c>\r
 \r
 extern Rm_ServiceHandle   *rmClientServiceHandle;\r
+extern NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;\r
 \r
 \r
 #define netapi_timing_start hplib_mUtilGetPmuCCNT\r
 \r
+navl_wrapper_cfg_info_t *pNavlCfg;\r
+navl_wrapper_pkt_stat_t *pStats1;\r
+navl_wrapper_pkt_stat_t *pStats2;\r
+navl_global_dpi_stats *pGlobDpiStats;\r
+void* pTemp;\r
 \r
-extern NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;\r
 \r
 STATS_T stats;\r
 paSysStats_t netcp_stats;\r
-struct dpi_stats dpis;\r
+//struct dpi_stats dpis;\r
 \r
 #define VDPI\r
 #ifdef VDPI\r
@@ -79,6 +84,12 @@ static int DPI=0;  //1 to enable
 static int DUMP_DPI_CONN=0;\r
 #endif\r
 \r
+\r
+void* pShmBase;\r
+void *pShmEntry;\r
+\r
+\r
+\r
 static int scnt=0;\r
 volatile static int QUIT=0;\r
 static int XMIT=0;\r
@@ -353,7 +364,6 @@ void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
     printf(">core rx stats:  %d %d %d\n",stats.core_rx[1],stats.core_rx[2],stats.core_rx[3]);\r
 \r
 \r
-    /* need to maintain number of fast path threads in some global context */\r
     for (j= 1;j < NUM_PROCS;j++)\r
     {\r
         tmp_npL[j]=0LL; tmp_cyclesL[j]=0LL; tmp_ccyclesL[j]=0LL;\r
@@ -384,28 +394,28 @@ void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
 \r
 #ifdef VDPI\r
     navl_return_stats(\r
-    &dpis.n_ops,\r
-    &dpis.n_class,\r
-    &dpis.min_time,\r
-    &dpis.max_time,\r
-    &dpis.tot,\r
-    &dpis.m_op,\r
-    &dpis.m_bytes,\r
-    &dpis.n_err,\r
-    &dpis.f_op,\r
-    &dpis.m_cycles,\r
-    &dpis.f_cycles);\r
+    &pGlobDpiStats->n_ops,\r
+    &pGlobDpiStats->n_class,\r
+    &pGlobDpiStats->min_time,\r
+    &pGlobDpiStats->max_time,\r
+    &pGlobDpiStats->tot,\r
+    &pGlobDpiStats->m_op,\r
+    &pGlobDpiStats->m_bytes,\r
+    &pGlobDpiStats->n_err,\r
+    &pGlobDpiStats->f_op,\r
+    &pGlobDpiStats->m_cycles,\r
+    &pGlobDpiStats->f_cycles);\r
 \r
     printf("dpi stats:  nops=%d nclass=%d min cycle=%d max  cycle=%d ave cycle=%lld #mallocs=%d #mbytes=%d n_err=%d fops=%d mCycles=%d fCycles=%d\n",\r
-    dpis.n_ops,\r
-    dpis.n_class,\r
-    dpis.min_time,\r
-    dpis.max_time,\r
-    dpis.n_ops? dpis.tot/dpis.n_ops : 0,\r
-    dpis.m_op,\r
-    dpis.m_bytes,\r
-    dpis.n_err,\r
-    dpis.f_op, dpis.m_cycles, dpis.f_cycles);\r
+    pGlobDpiStats->n_ops,\r
+    pGlobDpiStats->n_class,\r
+    pGlobDpiStats->min_time,\r
+    pGlobDpiStats->max_time,\r
+    pGlobDpiStats->n_ops? pGlobDpiStats->tot/pGlobDpiStats->n_ops : 0,\r
+    pGlobDpiStats->m_op,\r
+    pGlobDpiStats->m_bytes,\r
+    pGlobDpiStats->n_err,\r
+    pGlobDpiStats->f_op, pGlobDpiStats->m_cycles, pGlobDpiStats->f_cycles);\r
     navl_results(1);\r
     navl_results(2);\r
 #endif\r
@@ -578,9 +588,9 @@ ERR_fast_path_thread:
 }\r
 \r
 \r
-//******************************\r
-//  main program\r
-//*****************************\r
+/******************************\r
+* main program\r
+*****************************/\r
 int main(int argc, char **argv)\r
 {\r
     int err,i;\r
@@ -592,6 +602,8 @@ int main(int argc, char **argv)
     cpu_set_t cpu_set;\r
     int c;\r
     int statsQueryRequest = 0;\r
+    pthread_t *thrs;\r
+    int p;\r
 \r
 #if 0\r
     if (initRm())\r
@@ -618,98 +630,112 @@ int main(int argc, char **argv)
 \r
 #endif\r
 \r
-#if 1\r
-    if (statsQueryRequest)\r
+\r
+    if (!statsQueryRequest)\r
     {\r
-        navl_wrapper_cfg_info_t *pNavlCfg;\r
-        navl_wrapper_pkt_stat_t *pStats1;\r
-        navl_wrapper_pkt_stat_t *pStats2;\r
-        void* pTemp;\r
-        \r
-        void* pShmBase = hplib_shmOpen();\r
+        signal(SIGINT,netTest_utilMySig);\r
+        CPU_ZERO( &cpu_set);\r
+        CPU_SET( 0, &cpu_set);\r
+        hplib_utilSetupThread(HPLIB_THREADID, &cpu_set, hplib_spinLock_Type_LOL);\r
+    \r
+        /* create netapi */\r
+        our_netapi_default_cfg.rmHandle = rmClientServiceHandle;\r
+        netapi_handle = netapi_init(NETAPI_SYS_MASTER,\r
+                                    &our_netapi_default_cfg);\r
+        if (netapi_handle == NULL)\r
+        {\r
+            printf("main: netapi_init failure, exiting\n");\r
+            exit(1);\r
+        }\r
+        /* allocate segment for shared memory for packet stats */\r
+        /* allocate packet statistics */\r
+        pShmBase = hplib_shmOpen();\r
         if (pShmBase)\r
         {\r
-            pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_1);\r
-            pNavlCfg =  (navl_wrapper_cfg_info_t*)pTemp;\r
-\r
-            pStats1 = pTemp + sizeof(navl_wrapper_cfg_info_t);\r
-\r
-        \r
-            pStats2 = pTemp + sizeof(navl_wrapper_cfg_info_t) +\r
-                    (sizeof(navl_wrapper_pkt_stat_t)*pNavlCfg->num_protocols);\r
-\r
-            printf("main: pStats1: 0x%x pStats2: 0x%x\n", pStats1, pStats2);\r
+            if (hplib_shmAddEntry(pShmBase,\r
+                              sizeof(navl_wrapper_pkt_stat_t)\r
+                             * MAX_PROTOCOLS *NUM_FP_PROCS + sizeof(navl_wrapper_cfg_info_t),\r
+                             APP_ENTRY_1) != hplib_OK)\r
+            {\r
+                printf("main:  hplib_shmAddEntry failure\n");\r
+                return -1;\r
+            }\r
+            else\r
+            {\r
+                pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_1);\r
+                pNavlCfg =  (navl_wrapper_cfg_info_t*)pShmEntry;\r
+                memset(pNavlCfg,\r
+                       0,\r
+                       sizeof(navl_wrapper_pkt_stat_t) * MAX_PROTOCOLS *NUM_FP_PROCS+ sizeof(navl_wrapper_cfg_info_t));\r
+                pNavlCfg =  (navl_wrapper_cfg_info_t*)pShmEntry;\r
+                pNavlCfg->enable_dpi = 0; /* disable DPI by default */\r
+            }\r
+            if (hplib_shmAddEntry(pShmBase, sizeof(navl_global_dpi_stats), APP_ENTRY_2) != hplib_OK)\r
+            {\r
+                printf("main:  hplib_shmAddEntry failure\n");\r
+                return -1;\r
+            }\r
+            else\r
+            {\r
+                pShmEntry = hplib_shmGetEntry(pShmBase, APP_ENTRY_2);\r
+                pGlobDpiStats = (navl_global_dpi_stats*) pShmEntry;\r
+                memset(pGlobDpiStats, 0, sizeof(navl_global_dpi_stats));\r
+                pGlobDpiStats->min_time=100000000;\r
+            }\r
+        }\r
+        else\r
+        {\r
+            printf("main: hplib_shmOpen failure, exiting\n");\r
+            exit(1);\r
+        }\r
+            /* open the main heap */\r
+        OurHeap = Pktlib_findHeapByName("netapi");\r
+        if (!OurHeap)\r
+        {\r
+            printf("findheapbyname fail\n");\r
+            exit(1);\r
         }\r
-        sleep(10);\r
-        exit(1);\r
-    }\r
-#endif\r
-    printf("***net_test_dpi.. worker threads running on %d cores\n",NUM_FP_PROCS);\r
 \r
-    signal(SIGINT,netTest_utilMySig);\r
+        //if we want to relay network packets, we create a handle to the \r
+        //default netcp receive queue here\r
+        netcp_rx_chan= netapi_pktioOpen(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_bridge, &netcp_rx_cfg,  &err);\r
+        if (!netcp_rx_chan)\r
+        {\r
+            printf("pktio open RX failed err=%d\n",err);\r
+            exit(1);\r
+        }\r
 \r
-    CPU_ZERO( &cpu_set);\r
-    CPU_SET( 0, &cpu_set);\r
-    hplib_utilSetupThread(HPLIB_THREADID, &cpu_set, hplib_spinLock_Type_LOL);\r
-\r
-    /* create netapi */\r
-    our_netapi_default_cfg.rmHandle = rmClientServiceHandle;\r
-    netapi_handle = netapi_init(NETAPI_SYS_MASTER,\r
-                                &our_netapi_default_cfg);\r
-    if (netapi_handle == NULL)\r
-    {\r
-        printf("main: netapi_init failure, exiting\n");\r
-        exit(1);\r
-    }\r
-    netapi_netcpCfgExceptions(netapi_handle,\r
-                              NETCP_CFG_ALL_EXCEPTIONS,\r
-                              NETCP_CFG_ACTION_DISCARD,\r
-                              (NETCP_CFG_ROUTE_HANDLE_T)NULL);\r
-\r
-    /* open the main heap */\r
-    OurHeap = Pktlib_findHeapByName("netapi");\r
-    if (!OurHeap)\r
-    {\r
-        printf("findheapbyname fail\n");\r
-        exit(1);\r
-    }\r
+        netcp_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_TX, (PKTIO_CB) NULL, &netcp_tx_cfg,  &err);\r
+        if (!netcp_tx_chan)\r
+        {\r
+            printf("pktio open TX failed err=%d\n",err);\r
+            exit(1);\r
+        }\r
+        else  //install a fast path template into the NETCP TX channel\r
+        {\r
+            PKTIO_CONTROL_T control2;\r
+            control2.op = PKTIO_UPDATE_FAST_PATH;\r
+            PKTIO_CFG_T cfg2;\r
+            memset(&cfg2, 0, sizeof(PKTIO_CFG_T));\r
+            cfg2.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT;\r
+            cfg2.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;\r
+            netapi_pktioControl(netcp_tx_chan, NULL, &cfg2, &control2, &err);\r
+       }\r
 \r
-    //if we want to relay network packets, we create a handle to the \r
-    //default netcp receive queue here\r
-    netcp_rx_chan= netapi_pktioOpen(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_bridge, &netcp_rx_cfg,  &err);\r
-    if (!netcp_rx_chan)\r
-    {\r
-        printf("pktio open RX failed err=%d\n",err);\r
-        exit(1);\r
-    }\r
 \r
-    netcp_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_TX, (PKTIO_CB) NULL, &netcp_tx_cfg,  &err);\r
-    if (!netcp_tx_chan)\r
-    {\r
-        printf("pktio open TX failed err=%d\n",err);\r
-        exit(1);\r
-    }\r
-    else  //install a fast path template into the NETCP TX channel\r
-    {\r
-        PKTIO_CONTROL_T control2;\r
-        control2.op = PKTIO_UPDATE_FAST_PATH;\r
-        PKTIO_CFG_T cfg2;\r
-        memset(&cfg2, 0, sizeof(PKTIO_CFG_T));\r
-        cfg2.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT;\r
-        cfg2.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;\r
-        netapi_pktioControl(netcp_tx_chan, NULL, &cfg2, &control2, &err);\r
-   }\r
+        if (navl_setup() < 0)\r
+        {\r
+            printf("main: navl_setup failure, exiting\n");\r
+            exit(1);\r
+        }\r
 \r
-#ifdef VDPI\r
-    navl_setup();\r
-#endif\r
-    /*********************************************/\r
-    /*****************end NETAPI STARTUP**********/\r
-    /*********************************************/\r
+        /*********************************************/\r
+        /*****************end NETAPI STARTUP**********/\r
+        /*********************************************/\r
 \r
-    //now creaate a simple netcp rule\r
-    //to get a lot of packets\r
-    mac0 = netapi_netcpCfgCreateMacInterface(\r
+        //now creaate a simple netcp rule\r
+        //to get a lot of packets\r
+        mac0 = netapi_netcpCfgCreateMacInterface(\r
                       netapi_handle,\r
                       &all_mac[0],\r
                       NULL,\r
@@ -720,10 +746,10 @@ int main(int argc, char **argv)
                       0x0800,\r
                       1,\r
                       &err);\r
-    if (err) {printf("addmac0 failed %d\n",err); exit(1); }\r
-    else printf("addmac0 sucess\n");\r
+        if (err) {printf("addmac0 failed %d\n",err); exit(1); }\r
+        else printf("addmac0 sucess\n");\r
 \r
-    mac1 = netapi_netcpCfgCreateMacInterface(\r
+        mac1 = netapi_netcpCfgCreateMacInterface(\r
                       netapi_handle,\r
                       &all_mac[0],\r
                       NULL,\r
@@ -734,144 +760,133 @@ int main(int argc, char **argv)
                       0x0800,\r
                       1,\r
                       &err);\r
-    if (err) {printf("addmac1 failed %d\n",err); exit(1); }\r
-    else printf("addmac1 sucess\n");\r
+        if (err) {printf("addmac1 failed %d\n",err); exit(1); }\r
+        else printf("addmac1 sucess\n");\r
 \r
-#if 0\r
-    ip_rule0=netapi_netcpCfgAddIp(\r
-                      netapi_handle,\r
-                      0,\r
-                      nwal_IPV4,\r
-                      &all_ip,\r
-                      NULL,  //all IP\r
-                      NULL,\r
-                      (NETCP_CFG_ROUTE_HANDLE_T) NULL,\r
-                      (void*)NULL,\r
-                      &err\r
-        );\r
+        //calibrate idle\r
+        CALIB = calibrate_idle();\r
 \r
+        //**************************************\r
+        //Create a slow path thread\r
+        //***************************************\r
+        thrs = malloc( sizeof( pthread_t ) * NUM_PROCS );\r
+        if (thrs == NULL)\r
+        {\r
+            perror( "malloc" );\r
+            return -1;\r
+        }\r
+        printf( "dpi-demo: Starting slow_path_thread on core 0\n");\r
 \r
-    ip_rule1=netapi_netcpCfgAddIp(\r
-                      netapi_handle,\r
-                      1,\r
-                      nwal_IPV4,\r
-                      &all_ip,\r
-                      NULL,  //all IP\r
-                      NULL,\r
-                      (NETCP_CFG_ROUTE_HANDLE_T) NULL,\r
-                      (void*)NULL,\r
-                      &err\r
-        );\r
-#endif\r
-    if (err) {printf("addip0 failed %d\n",err); exit(1); }\r
+        if (pthread_create( &thrs[0], NULL, (void*)slow_path_thread,\r
+                          (void *)0 ))  //start at core 0\r
+        {\r
+            perror( "pthread_create" );\r
+            exit(1);\r
+        }\r
 \r
 \r
+        for (j= 1;j < NUM_PROCS;j++)\r
+        {\r
+            printf( "dpi-demo: Starting fast_path_thread on core 1\n");\r
+            if (pthread_create( &thrs[j], NULL, (void*)fast_path_thread,\r
+                          (void *)j ))  //start at core 1\r
+            {\r
+                perror( "pthread_create" );\r
+                exit(1);\r
+            }\r
+        }\r
+    }\r
+    else\r
+    {\r
+        \r
+        pShmBase = hplib_shmOpen();\r
+        if (pShmBase)\r
+        {\r
+            pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_1);\r
+            pNavlCfg =  (navl_wrapper_cfg_info_t*)pTemp;\r
 \r
+            pStats1 = pTemp + sizeof(navl_wrapper_cfg_info_t);\r
 \r
-    //calibrate idle\r
-    CALIB = calibrate_idle();\r
+        \r
+            pStats2 = pTemp + sizeof(navl_wrapper_cfg_info_t) +\r
+                    (sizeof(navl_wrapper_pkt_stat_t)*pNavlCfg->num_protocols);\r
 \r
-    //**************************************\r
-    //Create a slow path thread\r
-    //***************************************\r
-    {\r
-    pthread_t *thrs;\r
-    int p;\r
-    char c;\r
-    thrs = malloc( sizeof( pthread_t ) * NUM_PROCS );\r
-    if (thrs == NULL)\r
-    {\r
-        perror( "malloc" );\r
-        return -1;\r
-    }\r
-    printf( "dpi-demo: Starting slow_path_thread on core 0\n");\r
 \r
-    if (pthread_create( &thrs[0], NULL, (void*)slow_path_thread,\r
-                      (void *)0 ))  //start at core 0\r
-    {\r
-        perror( "pthread_create" );\r
-        exit(1);\r
+            pTemp = hplib_shmGetEntry(pShmBase, APP_ENTRY_2);\r
+            pGlobDpiStats = (struct dpi_stats*) pTemp;\r
+               navl_return_stats(\r
+            &pGlobDpiStats->n_ops,\r
+            &pGlobDpiStats->n_class,\r
+            &pGlobDpiStats->min_time,\r
+            &pGlobDpiStats->max_time,\r
+            &pGlobDpiStats->tot,\r
+            &pGlobDpiStats->m_op,\r
+            &pGlobDpiStats->m_bytes,\r
+            &pGlobDpiStats->n_err,\r
+            &pGlobDpiStats->f_op,\r
+            &pGlobDpiStats->m_cycles,\r
+            &pGlobDpiStats->f_cycles);\r
+\r
+            printf("dpi stats:  nops=%d nclass=%d min cycle=%d max cycle=%d ave cycle=%lld #mallocs=%d #mbytes=%d n_err=%d fops=%d mCycles=%d fCycles=%d\n",\r
+            pGlobDpiStats->n_ops,\r
+            pGlobDpiStats->n_class,\r
+            pGlobDpiStats->min_time,\r
+            pGlobDpiStats->max_time,\r
+            pGlobDpiStats->n_ops? pGlobDpiStats->tot/pGlobDpiStats->n_ops : 0,\r
+            pGlobDpiStats->m_op,\r
+            pGlobDpiStats->m_bytes,\r
+            pGlobDpiStats->n_err,\r
+            pGlobDpiStats->f_op, pGlobDpiStats->m_cycles, pGlobDpiStats->f_cycles);\r
+            navl_results2(1);\r
+            navl_results2(2);\r
+            \r
+            exit(1);\r
+        }\r
     }\r
 \r
 \r
-    for (j= 1;j < NUM_PROCS;j++)\r
-    {\r
-        printf( "dpi-demo: Starting fast_path_thread on core 1\n");\r
-        if (pthread_create( &thrs[j], NULL, (void*)fast_path_thread,\r
-                      (void *)j ))  //start at core 1\r
+        //this thread of execution (main) now just waits on user input\r
+        for(;;)\r
         {\r
-            perror( "pthread_create" );\r
-            exit(1);\r
+            printf(">");\r
+            c=getchar();\r
+            if (c=='C')\r
+            {\r
+                CAP=!CAP; \r
+                printf("CAPTURE= %d\n", CAP);\r
+            }\r
+            else if (c=='q') {QUIT=1;break;}\r
+            else if (c=='s')\r
+                our_stats_cb(netapi_handle, &netcp_stats);\r
+    #ifdef VDPI\r
+               else if (c=='c') \r
+                {navl_clear_stats();printf("> Clearing DPI stats\n");}\r
+               else if (c=='v') navl_set_verbose();\r
+               else if (c=='p') \r
+                 {DUMP_DPI_CONN = !DUMP_DPI_CONN;printf(">  **DPI CONN DUMP is %s ** \n", DUMP_DPI_CONN ?"enabled":"disabled");}\r
+               else if (c=='d')\r
+                 {\r
+                    pNavlCfg->enable_dpi = !pNavlCfg->enable_dpi;\r
+                    printf("enable_dpi flag: %d\n", pNavlCfg->enable_dpi);\r
+                    printf(">  **DPI is %s ** \n", pNavlCfg->enable_dpi?"enabled":"disabled");\r
+                 }\r
+    #endif\r
+            else if (c=='!') {system("sh");}\r
+    \r
+            else if ((c=='h')||(c=='?'))\r
+            {\r
+                printf("> 'q' to quit,  's' for stats,'d' to dump capture\n,> 'h' for help\n ");\r
+            }\r
+    #if 1\r
+            else if (c=='r')\r
+            {\r
+                netTest_utilDumpHeader(&last_header[0], 0,0,0);\r
+                netTest_utilDumpDescr(&last_desc[0], 0);\r
+            }\r
+    #endif\r
         }\r
 \r
-    }\r
-    //this thread of execution (main) now just waits on user input\r
-    for(;;)\r
-    {\r
-        printf(">");\r
-        c=getchar();\r
-        if (c=='C')\r
-        {\r
-            CAP=!CAP; \r
-            printf("CAPTURE= %d\n", CAP);\r
-        }\r
-        else if (c=='q') {QUIT=1;break;}\r
-        else if (c=='s')\r
-            our_stats_cb(netapi_handle, &netcp_stats);\r
-#ifdef VDPI\r
-           else if (c=='c') \r
-            {navl_clear_stats();printf("> Clearing DPI stats\n");}\r
-           else if (c=='v') navl_set_verbose();\r
-           else if (c=='p') \r
-             {DUMP_DPI_CONN = !DUMP_DPI_CONN;printf(">  **DPI CONN DUMP is %s ** \n", DUMP_DPI_CONN ?"enabled":"disabled");}\r
-           else if (c=='d') \r
-             {DPI = !DPI;printf(">  **DPI is %s ** \n", DPI?"enabled":"disabled");}\r
-#endif\r
-        else if (c=='!') {system("sh");}\r
-#if 0\r
-        else if (c=='t') {XMIT=!XMIT; printf("XMIT= %d\n", XMIT); }\r
-        else if (c=='p') {PKTGEN=!PKTGEN; printf("PKTGEN= %d @%d bytes\n",PKTGEN,pkt_len);}\r
-        else if (c=='S') {pkt_len+=64; if (pkt_len>1500) pkt_len=64; printf("pkt_len=%d\n",pkt_len);}\r
-        else if (c=='1')\r
-        {\r
-            RESET=1;\r
-        }\r
-        else if (c=='2')\r
-        {\r
-            RESET=(NUM_PROCS>=2) ?2:1;\r
-        }\r
-        else if (c=='3')\r
-        {\r
-            RESET=(NUM_PROCS>=3) ?3: 1;\r
-        }\r
-#endif\r
-        else if ((c=='h')||(c=='?'))\r
-        {\r
-            printf("> 'q' to quit,  's' for stats,'d' to dump capture\n,> 'h' for help\n ");\r
-        }\r
-#if 1\r
-        else if (c=='r')\r
-        {\r
-            netTest_utilDumpHeader(&last_header[0], 0,0,0);\r
-            netTest_utilDumpDescr(&last_desc[0], 0);\r
-        }\r
-        else if (c=='b')\r
-        {\r
-           int cc;\r
-            unsigned long long et= hplib_mUtilGetTimestamp();\r
-            for(cc=1;cc<NUM_PROCS+1;cc++)\r
-           printf(">NT_BENCH STATS core%d:    %d received   %d xmitted,  \n %lld idle cycles,  %lld duration ticks  idle=%lld\n pkt rate =%lld stall=%lld\n",\r
-                       cc,\r
-                       pkt_rx[cc],pkt_tx[cc],\r
-                       idle_cycles[cc],\r
-                       (et-start_time[cc]),\r
-                       (et>start_time[cc]) ? (idle_cycles[cc]*100)/(CALIB*(et-start_time[cc])): 0LL,\r
-                       (et>start_time[cc]) ? pkt_rx[cc]/(6LL*(et-start_time[cc])/1180000000LL): 0LL,\r
-                       pkt_stall[cc]\r
-                    );\r
-            }\r
-#endif\r
-    }\r
+\r
 \r
 #ifdef VDPI\r
             navl_done();\r
@@ -883,26 +898,23 @@ int main(int argc, char **argv)
                 pthread_join( thrs[i], NULL );\r
 \r
         free( thrs );\r
-    \r
-    }\r
 \r
-    /*************************************************\r
-     ************CLEAN UP****************************\r
-     ************************************************/\r
-    //get rid of rule, in the case that we are relaying packets\r
-    //also close our netcp rx channel\r
-    netapi_netcpCfgDelMac(netapi_handle,0,&err);\r
-    netapi_netcpCfgDelMac(netapi_handle,1,&err);\r
+        /*************************************************\r
+        ************CLEAN UP****************************\r
+        ************************************************/\r
+        //get rid of rule, in the case that we are relaying packets\r
+        //also close our netcp rx channel\r
+        netapi_netcpCfgDelMac(netapi_handle,0,&err);\r
+        netapi_netcpCfgDelMac(netapi_handle,1,&err);\r
     \r
-    netapi_pktioClose(netcp_rx_chan,&err);\r
-    netapi_pktioClose(netcp_tx_chan,&err);\r
+        netapi_pktioClose(netcp_rx_chan,&err);\r
+        netapi_pktioClose(netcp_tx_chan,&err);\r
 \r
 \r
-    //done\r
-    netapi_shutdown(netapi_handle);\r
+        //done\r
+        netapi_shutdown(netapi_handle);\r
 \r
 \r
-    //!finished!\r
 }\r
 #if 1\r
 static inline void send_it(Ti_Pkt *tip, int len, int out_port)\r
@@ -985,7 +997,7 @@ for(i=0;i<n_pkts;i++)
         {\r
 #ifdef VDPI\r
             {\r
-                if (DPI)\r
+                if (pNavlCfg->enable_dpi)\r
                     navl_process_pkt(p_pkt, len);\r
             }\r
 #endif\r
index efdc094e42628736022e02bbb37fddbd2d1eb988..98b7f82ca07646e62c1c09cdccfbc0d14339f33d 100755 (executable)
@@ -48,18 +48,5 @@ typedef struct head_t
        long udp[2];\r
 } HEAD_T;\r
 \r
-struct dpi_stats\r
-{\r
-unsigned long n_ops;\r
-unsigned long n_class;\r
-unsigned long min_time;\r
-unsigned long max_time;\r
-unsigned long long tot;\r
-unsigned long m_op;\r
-unsigned long m_bytes;\r
-unsigned long n_err;\r
-unsigned long f_op;\r
-unsigned long m_cycles;\r
-unsigned long f_cycles;\r
-};\r
+\r
 \r