commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r7019 - in gnuradio/branches/developers/eb/gcell/src:


From: eb
Subject: [Commit-gnuradio] r7019 - in gnuradio/branches/developers/eb/gcell/src: include lib
Date: Sat, 24 Nov 2007 02:29:12 -0700 (MST)

Author: eb
Date: 2007-11-24 02:29:11 -0700 (Sat, 24 Nov 2007)
New Revision: 7019

Added:
   gnuradio/branches/developers/eb/gcell/src/include/gc_mbox.h
Modified:
   gnuradio/branches/developers/eb/gcell/src/include/gc_jd_queue.h
   gnuradio/branches/developers/eb/gcell/src/lib/gc_client_thread_info.h
   gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager.h
   gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.cc
   gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.h
Log:
work-in-progress on cell job manager

Modified: gnuradio/branches/developers/eb/gcell/src/include/gc_jd_queue.h
===================================================================
--- gnuradio/branches/developers/eb/gcell/src/include/gc_jd_queue.h     
2007-11-24 06:48:59 UTC (rev 7018)
+++ gnuradio/branches/developers/eb/gcell/src/include/gc_jd_queue.h     
2007-11-24 09:29:11 UTC (rev 7019)
@@ -38,14 +38,14 @@
  * to avoid inadvertently losing reservations created with
  * the load-and-reserve instructions.
  *
- * FIXME make it lock free ;)  For now, use a mutex.
+ * FIXME make it lock free ;)  For now, use a spin lock.
  */
 
 typedef struct gc_jd_queue
 {
-  gc_eaddr_t           head;
-  gc_eaddr_t           tail;
-  volatile uint32_t    mutex;          // libsync mutex (spin lock)
+  gc_eaddr_t   head;
+  gc_eaddr_t   tail;
+  uint32_t     mutex;          // libsync mutex (spin lock)
 
   // pad out to a full cache line
   uint8_t      _pad[128 - 2*sizeof(gc_eaddr_t) - sizeof(uint32_t)];    

Added: gnuradio/branches/developers/eb/gcell/src/include/gc_mbox.h
===================================================================
--- gnuradio/branches/developers/eb/gcell/src/include/gc_mbox.h                 
        (rev 0)
+++ gnuradio/branches/developers/eb/gcell/src/include/gc_mbox.h 2007-11-24 
09:29:11 UTC (rev 7019)
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio 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 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_GC_MBOX_H
+#define INCLUDED_GC_MBOX_H
+
+/*
+ * The PPE and SPE exchange a few 32-bit messages via mailboxes.
+ * All have a 4 bit opcode in the high bits.
+ *
+ *      3                   2                   1
+ *    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |  op   |                        arg                            |
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ */
+
+#define MK_MBOX_MSG(cmd, args) ((((cmd) & 0xf) << 28) | ((args) & 0x0fffffff))
+#define MBOX_MSG_OP(msg)  (((msg) >> 28) & 0xf)
+#define        MBOX_MSG_ARG(msg) ((msg) & 0x0fffffff)
+
+// PPE to SPE (sent via SPE Read Inbound Mailbox)
+
+#define OP_EXIT                0x0     // exit now
+#define        OP_PING         0x1     // send PING_REPLY with arg
+#define OP_PING_REPLY  0x2     // 
+
+// SPE to PPE (sent via SPE Write Outbound Interrupt Mailbox)
+
+#define OP_JOB_DONE    0x3     // arg is job_id from gc_job_desc_private
+
+
+#endif /* INCLUDED_GC_MBOX_H */


Property changes on: gnuradio/branches/developers/eb/gcell/src/include/gc_mbox.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: gnuradio/branches/developers/eb/gcell/src/lib/gc_client_thread_info.h
===================================================================
--- gnuradio/branches/developers/eb/gcell/src/lib/gc_client_thread_info.h       
2007-11-24 06:48:59 UTC (rev 7018)
+++ gnuradio/branches/developers/eb/gcell/src/lib/gc_client_thread_info.h       
2007-11-24 09:29:11 UTC (rev 7019)
@@ -27,7 +27,6 @@
 enum gc_ct_state_t {
   CT_RUNNING,
   CT_WAITING_JOB,
-  CT_WAITING_SHUTDOWN
 };
 
 /*

Modified: gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager.h
===================================================================
--- gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager.h      
2007-11-24 06:48:59 UTC (rev 7018)
+++ gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager.h      
2007-11-24 09:29:11 UTC (rev 7019)
@@ -78,8 +78,8 @@
   virtual int nspes() const = 0;
 
   /*!
-   * \brief Return a pointer to a properly aligned job descriptor.
-   * Throws if none are available.
+   * \brief Return a pointer to a properly aligned job descriptor,
+   * or zero if none are available.
    */
   virtual gc_job_desc *alloc_job_desc() = 0;
 

Modified: gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.cc
===================================================================
--- gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.cc        
2007-11-24 06:48:59 UTC (rev 7018)
+++ gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.cc        
2007-11-24 09:29:11 UTC (rev 7019)
@@ -23,6 +23,7 @@
 #include "config.h"
 #endif
 #include "gc_job_manager_impl.h"
+#include "gc_mbox.h"
 
 #include <stdio.h>
 #include <stdexcept>
@@ -73,7 +74,8 @@
 }
 
 gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options)
-  : d_eh_thread(0), d_eh_state(EHS_INIT), d_shutdown_requested(false),
+  : d_eh_cond(&d_eh_mutex), d_eh_thread(0), d_eh_state(EHS_INIT),
+    d_shutdown_requested(false),
     d_nclients(0), d_client_thread(0), d_job_busy(0)
 {
   if (options != 0)
@@ -246,7 +248,18 @@
 bool
 gc_job_manager_impl::shutdown()
 {
-  return false;                        // FIXME
+  omni_mutex_lock      l(d_eh_mutex);
+
+  d_shutdown_requested = true;         // set flag for event handler thread
+
+  // should only happens during early QA code
+  if (d_eh_state == EHS_INIT)
+    return false;
+
+  while (d_eh_state != EHS_DEAD)       // wait for it to finish
+    d_eh_cond.wait();
+
+  return true;
 }
 
 int
@@ -282,6 +295,14 @@
   return false;                        // FIXME
 }
 
+extern "C" static void *
+start_event_handler(void *arg)
+{
+  gc_job_manager_impl *p = (gc_job_manager_impl *) arg;
+  p->event_handler_loop();
+  return 0;
+}
+
 void
 gc_job_manager_impl::create_event_handler()
 {
@@ -298,7 +319,7 @@
     memset(&eu, 0, sizeof(eu));
     eu.events = SPE_EVENT_ALL_EVENTS;
     eu.spe = d_worker[i].spe_ctx;
-    eu.data.u32 = i;   // available in events returned by spe_event_wait
+    eu.data.u32 = i;   // set in events returned by spe_event_wait
 
     if (spe_event_handler_register(d_spe_event_handler.ptr, &eu) != 0){
       perror("spe_event_handler_register");
@@ -306,10 +327,102 @@
     }
   }
 
-  // FIXME create the thread
+  // create our event handling thread
 
+  
+
 }
 
+bool
+gc_job_manager_impl::send_all_spes(uint32_t msg)
+{
+  bool ok = true;
+
+  for (unsigned int i = 0; i < d_options.nspes; i++)
+    ok &= send_spe(i, msg);
+
+  return ok;
+}
+
+bool
+gc_job_manager_impl::send_spe(unsigned int spe, uint32_t msg)
+{
+  return false;
+}
+
+void
+gc_job_manager_impl::set_eh_state(evt_handler_state s)
+{
+  omni_mutex_lock      l(d_eh_mutex);
+  d_eh_state = EHS_DEAD;
+  d_eh_cond.broadcast();
+}
+
+void
+gc_job_manager_impl::print_event(spe_event_unit_t *evt)
+{
+  printf("evt: spe = %d events = (0x%x)", evt->data.u32, evt->events);
+
+  if (evt->events & SPE_EVENT_OUT_INTR_MBOX)
+    printf(" OUT_INTR_MBOX");
+  
+  if (evt->events & SPE_EVENT_IN_MBOX)
+    printf(" IN_MBOX");
+  
+  if (evt->events & SPE_EVENT_TAG_GROUP)
+    printf(" TAG_GROUP");
+  
+  if (evt->events & SPE_EVENT_SPE_STOPPED)
+    printf(" SPE_STOPPED");
+
+  printf("\n");
+}
+
+void
+gc_job_manager_impl::event_handler_loop()
+{
+  static const int MAX_EVENTS = 16;
+  static const int TIMEOUT = 20;       // how long to block in milliseconds
+
+  spe_event_unit_t events[MAX_EVENTS];
+
+  set_eh_state(EHS_RUNNING);
+
+  while (1){
+    switch(d_eh_state){
+
+    case EHS_RUNNING:      // normal stuff
+      if (d_shutdown_requested) {
+       set_eh_state(EHS_SHUTTING_DOWN);
+       send_all_spes(MK_MBOX_MSG(OP_EXIT, 0));
+      }
+      break;
+
+    case EHS_SHUTTING_DOWN:
+      break;
+
+    case EHS_DEAD:
+      return;
+
+    default:
+      set_eh_state(EHS_DEAD);
+      return;
+    }
+
+    // block waiting for events...
+    int nevents = spe_event_wait(d_spe_event_handler.ptr,
+                                events, MAX_EVENTS, TIMEOUT);
+    if (nevents < 0){
+      perror("spe_wait_event");
+      // FIXME bail?
+    }
+    for (int i = 0; i < nevents; i++){
+      print_event(&events[i]);
+      // FIXME do the real work
+    }
+  }
+}
+
 // ------------------------------------------------------------------------
 
 worker_ctx::~worker_ctx()

Modified: gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.h
===================================================================
--- gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.h 
2007-11-24 06:48:59 UTC (rev 7018)
+++ gnuradio/branches/developers/eb/gcell/src/lib/gc_job_manager_impl.h 
2007-11-24 09:29:11 UTC (rev 7019)
@@ -79,14 +79,18 @@
 {
   enum { MAX_SPES =  16 };
 
+
   gc_jm_options                 d_options;
   spe_gang_context_sptr  d_gang;               // boost::shared_ptr
 
   worker_ctx            d_worker[MAX_SPES];    // SPE ctx, thread, etc
 
+  // used to coordinate communication w/ the event handling thread
+  omni_mutex            d_eh_mutex;
+  omni_condition        d_eh_cond;
   pthread_t             d_eh_thread;           // the event handler thread
-  evt_handler_state     d_eh_state;
-  bool                  d_shutdown_requested;
+  volatile evt_handler_state   d_eh_state;
+  volatile bool                        d_shutdown_requested;
   spe_event_handler     d_spe_event_handler;
   
 
@@ -122,8 +126,19 @@
 
 
   void create_event_handler();
+  void set_eh_state(evt_handler_state s);
 
+public:
+  void event_handler_loop();   // really private
+
+private:
+  bool send_all_spes(uint32_t msg);
+  bool send_spe(unsigned int spe, uint32_t msg);
+  void print_event(spe_event_unit_t *evt);
+
+
   friend gc_job_manager *gc_make_job_manager(const gc_jm_options *options);
+  
 
   /*!
    * \param nspes number of SPEs job manager should use.
@@ -146,8 +161,8 @@
   virtual int nspes() const;
 
   /*!
-   * \brief Return a pointer to a properly aligned job descriptor.
-   * Throws if none are available.
+   * \brief Return a pointer to a properly aligned job descriptor,
+   * or zero if none are available.
    */
   virtual gc_job_desc *alloc_job_desc();
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]