]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blobdiff - ti/runtime/netapi/src/netapi_sched.c
Set qmQueMgmtProxyDataReg to NULL for k1, k2h
[keystone-rtos/netapi.git] / ti / runtime / netapi / src / netapi_sched.c
index cc5c657f8fc432f0fda7065a9f5018effbefec63..41988cb77571a224f3839cd1831949f88f558d76 100755 (executable)
@@ -8,9 +8,9 @@
  * DESCRIPTION:  netapi sample scheduler source file for user space transport
  *               library
  * 
- * REVISION HISTORY:  rev 0.0.1 
+ * REVISION HISTORY:
  *
- *  Copyright (c) Texas Instruments Incorporated 2010-2011
+ *  Copyright (c) Texas Instruments Incorporated 2013
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
 
  ****************************************/
 
-#include "netapi.h"
 #include "netapi_sched.h"
 
 #define NO_TIMER  //turn off timer related scheduling
-#define NO_GARBAGE  //turn off garbage collection
 
-void netapi_sched_get_stats(NETAPI_SCHED_HANDLE_T *s, 
-    unsigned long long * p_pkts, 
-    unsigned long long * p_cycles,
-    unsigned long long * p_cache_cycles)
+
+/********************************************************************
+ * FUNCTION PURPOSE:  API to get scheduling context statistics
+ ********************************************************************
+ * DESCRIPTION:  API to get scheduling context statistics
+ ********************************************************************/
+void netapi_schedGetStats(NETAPI_SCHED_HANDLE_T *s, 
+                          unsigned long long * p_pkts, 
+                          unsigned long long * p_cycles,
+                          unsigned long long * p_cache_cycles)
 {
-   *p_pkts= s->num_pkts;
-   *p_cycles= s->busy_cycles;
-   *p_cache_cycles= s->cache_cycles;
+   *p_pkts= s->stats.num_pkts;
+   *p_cycles= s->stats.busy_cycles;
+   *p_cache_cycles= s->stats.cache_cycles;
    return;
 }
 /****************************************/
 /************API************************/
 /**************************************/
 
-/* open a scheduling contex */
-NETAPI_SCHED_HANDLE_T * netapi_schedOpen(NETAPI_T n, NETAPI_SCHED_CONFIG_T * p_config, int *p_err)
+/********************************************************************
+ * FUNCTION PURPOSE:  API to open a scheduling context
+ ********************************************************************
+ * DESCRIPTION:  API to open a scheduling context
+ ********************************************************************/
+NETAPI_SCHED_HANDLE_T * netapi_schedOpen(NETAPI_T n, 
+                                         NETAPI_SCHED_CONFIG_T * p_config,
+                                         int *p_err)
 {
-  *p_err=0;
-   NETAPI_SCHED_HANDLE_T * ph = (NETAPI_SCHED_HANDLE_T *) netapi_get_scheduler(n);
-  if(!ph) {*p_err= NETAPI_ERR_NOMEM; return NULL;}
-  if(!p_config) {*p_err=  NETAPI_ERR_BAD_INPUT; return NULL;}
-  memcpy(&ph->config,p_config,sizeof(NETAPI_SCHED_CONFIG_T));
-  ph->start =   hplib_mUtilGetTimestamp();
-  ph->back = (void *) n;
-  if (ph->config.valid_flags & NETAPI_SCHED_DURATION)
-  {
-    if (ph->config.duration == NETAPI_SCHED_FOREVER) 
-       {
-       ph->shutdown_time=(uint64_t) -1; 
-       }
+    *p_err=0;
+     NETAPI_SCHED_HANDLE_T * ph = (NETAPI_SCHED_HANDLE_T *) netapi_get_scheduler(n);
+    if(!ph)
+    {
+        *p_err= NETAPI_ERR_NOMEM;
+        return NULL;
+    }
+    if(!p_config)
+    {
+        *p_err=  NETAPI_ERR_BAD_INPUT; 
+        return NULL;
+    }
+    memcpy(&ph->config,p_config,sizeof(NETAPI_SCHED_CONFIG_T));
+    ph->start =   hplib_mUtilGetTimestamp();
+    ph->back = (void *) n;
+    if (ph->config.valid_flags & NETAPI_SCHED_DURATION)
+    {
+        if (ph->config.duration == NETAPI_SCHED_FOREVER) 
+        {
+            ph->shutdown_time=(uint64_t) -1; 
+        }
+        else
+        {
+            ph->shutdown_time = ph->start + ph->config.duration;
+        }
+    }
     else
-       {
-       ph->shutdown_time = ph->start + ph->config.duration;
-       }
-  }
-  else ph->shutdown_time = (uint64_t) -1;
-  ph->state =NETAPI_SCHED_STATE_OPEN; 
-  return(ph);
-
+    {
+        ph->shutdown_time = (uint64_t) -1;
+    }
+    ph->state =NETAPI_SCHED_STATE_OPEN; 
+    return(ph);
 }
 
-/* re-configure a scheduling context */
-int netapi_schedControl(NETAPI_SCHED_HANDLE_T *s, NETAPI_SCHED_CONFIG_T *p_config, int *p_err)
+/********************************************************************
+ * FUNCTION PURPOSE:  API to re-configure a scheduling context, FUTURE, 
+ *                                  not implemented
+ ********************************************************************
+ * DESCRIPTION:  API to re-configure a scheduling context, FUTURE, 
+ *                                  not implemented
+ ********************************************************************/
+
+int netapi_schedControl(NETAPI_SCHED_HANDLE_T *s,
+                        NETAPI_SCHED_CONFIG_T *p_config,
+                        int *p_err)
 {
-  /* not implemented */
-
-  return 0;
+    /* NOT_IMPLEMENTED */
+    return 0;
 }
 
-
+/********************************************************************
+ * FUNCTION PURPOSE:  API for main entry point to scheduler
+ ********************************************************************
+ * DESCRIPTION:  API to get NETAPI scheduling context statistics
+ ********************************************************************/
 /* main entry point.  caller gives up control to scheduler */
-int netapi_schedWaitForEvents(NETAPI_SCHED_HANDLE_T *s, int *p_err)
+int netapi_schedRun(NETAPI_SCHED_HANDLE_T *s,
+                    int *p_err)
 {
-  int err;
-  *p_err=0;
-  unsigned long long t =  hplib_mUtilGetTimestamp();
-  int next_house;
-  volatile int pkts;
-  volatile unsigned long t1;
-  volatile unsigned long t2;
-  volatile unsigned long long cache_op_b2;
-  volatile unsigned long long n_c_ops;
-
-  next_house =  s->config.interval;
-  /* loop for duration or until shutdown */
-  for(;t< s->shutdown_time;)
-  {
-#ifndef NO_TIMER
-    t = hplib_mUtilGetTimestamp();
-#endif
-    next_house -=1;
-    //poll all  pktio channels we have open in RX mode 
-     //Osal_cache_op_measure_reset();
-     cache_op_b2= Osal_cache_op_measure(&n_c_ops);
-     t1=hplib_mUtilGetPmuCCNT();
-     pkts=pktio_pollAll((NETAPI_T) s->back, NULL, &err);
-     if (!pkts  && (s->config.yield == TRUE))
-     {
-        sched_yield();
-     }
-     t2=hplib_mUtilGetPmuCCNT();
-     if (pkts)
-     {
-        s->num_pkts+= (unsigned long long) pkts;
-        s->busy_cycles += (unsigned long long) (t2-t1);
-        cache_op_b2=  Osal_cache_op_measure(&n_c_ops)- cache_op_b2;
-        s->cache_cycles += (unsigned long long) cache_op_b2;
-     }
-
-#ifndef NO_GARBAGE
-    //poll pktlib garbage collections for registered heaps..
-    if (TRUE== s->config.pollGarbageQ)
+    int err;
+    *p_err=0;
+    unsigned long long t =  hplib_mUtilGetTimestamp();
+    int next_house;
+    volatile int pkts;
+    volatile unsigned long t1;
+    volatile unsigned long t2;
+    volatile unsigned long long cache_op_b2;
+    volatile unsigned long long n_c_ops;
+
+    next_house =  s->config.interval;
+    /* loop for duration or until shutdown */
+    for(;t< s->shutdown_time;)
     {
-        netapi_pollHeapGarbage((NETAPI_T) s->back);
-     }
-#endif    
-
 #ifndef NO_TIMER
-    //todo timers (local and global)
-    hplib_TimerPollAllGroups((NETAPI_T) s->back, HPLIB_TIMER_FITLER_ALL, 100000);
+        t = hplib_mUtilGetTimestamp();
 #endif
-    //poll NETCP/PA control channels 
-    if (TRUE== s->config.pollGarbageQ)
-    {
-        netapi_netcpPoll((NETAPI_T) s->back);
-    }
+        next_house -=1;
+
+         cache_op_b2= Osal_cache_op_measure(&n_c_ops);
+         t1=hplib_mUtilGetPmuCCNT();
+         /* poll all  pktio channels we have open in RX mode */
+         pkts=netapi_pktioPollAll((NETAPI_T) s->back, NULL, &err);
+         if (!pkts  && (s->config.yield == TRUE))
+         {
+            sched_yield();
+         }
+         t2=hplib_mUtilGetPmuCCNT();
+         if (pkts)
+         {
+            s->stats.num_pkts+= (unsigned long long) pkts;
+            s->stats.busy_cycles += (unsigned long long) (t2-t1);
+            cache_op_b2=  Osal_cache_op_measure(&n_c_ops)- cache_op_b2;
+            s->stats.cache_cycles += (unsigned long long) cache_op_b2;
+         }
+
+        /* poll pktlib garbage collections for registered heaps */
+        if (TRUE == s->config.pollGarbageQ)
+        {
+            netapi_pollHeapGarbage((NETAPI_T) s->back);
+        }
+
+
+        /*poll NETCP/PA control channels */
+        if (TRUE == s->config.pollCtrlQ)
+        {
+            netapi_netcpPoll((NETAPI_T) s->back);
+        }
 
-    //see if time to do a house keeping callback
-     if ((s->config.valid_flags & NETAPI_SCHED_CBV) && s->config.house_cb)
+        /* see if time to do a house keeping callback */
+        if ((s->config.valid_flags & NETAPI_SCHED_CBV) && s->config.house_cb)
         if (next_house<=0)
         {
-          s->config.house_cb(s);
-           next_house = s->config.interval;
+            s->config.house_cb(s);
+            next_house = s->config.interval;
+        }
+        /* see if we were closed and/or its time to close */
+        if (s->state!= NETAPI_SCHED_STATE_OPEN) 
+        {
+            s->state=NETAPI_SCHED_STATE_CLOSE;
+            break;
         }
-    //see if we were closed and/or its time to close
-    if (s->state!= NETAPI_SCHED_STATE_OPEN) 
-         { s->state=NETAPI_SCHED_STATE_CLOSE; break;}
-   
-  }
-  return 1;
-}
 
+    }
+    return 1;
+}
+/********************************************************************
+ * FUNCTION PURPOSE:  API to close a scheduling context
+ ********************************************************************
+ * DESCRIPTION:  API to close a scheduling context
+ ********************************************************************/
 /* shutdown scheduler context */
-int netapi_schedShutdown(NETAPI_SCHED_HANDLE_T * s, NETAPI_SCHED_SHUTDOWN_T * p_close, int * p_err)
+int netapi_schedClose(NETAPI_SCHED_HANDLE_T * s, 
+                      NETAPI_SCHED_SHUTDOWN_T * p_close,
+                      int * p_err)
 {
-  *p_err=0;
-  s->state=NETAPI_SCHED_STATE_CLOSE_IN_PROGRESS;  //say we are closing
-
+    *p_err=0;
+    if (p_close->shutdown_type == NETAPI_SCHED_SHUTDOWN_NOW)
+    {
+        s->state=NETAPI_SCHED_STATE_CLOSE_IN_PROGRESS;
+    }
   return 1;
 }