[rtems commit] capture: Fix use of per-processor data

Sebastian Huber sebh at rtems.org
Thu May 12 11:36:15 UTC 2016


Module:    rtems
Branch:    master
Commit:    df23f464be5733b489eae03428d5449a37b310b9
Changeset: http://git.rtems.org/rtems/commit/?id=df23f464be5733b489eae03428d5449a37b310b9

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu May 12 13:08:49 2016 +0200

capture: Fix use of per-processor data

Get the current processor index only once and with interrupts disabled.

Close #2707.

---

 cpukit/libmisc/capture/capture.c     | 33 ++++++++++++++++-----------------
 cpukit/libmisc/capture/captureimpl.h | 25 +++++++++++++++----------
 2 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
index 7daa1c5..dfde5dd 100644
--- a/cpukit/libmisc/capture/capture.c
+++ b/cpukit/libmisc/capture/capture.c
@@ -92,17 +92,12 @@ static rtems_capture_global_data capture_global = {
 #define capture_reader_on_cpu( _cpu )  capture_per_cpu[ _cpu ].reader
 #define capture_lock_on_cpu( _cpu )    capture_per_cpu[ _cpu ].lock
 
-#define capture_records          capture_records_on_cpu( _SMP_Get_current_processor() )
-#define capture_count            capture_count_on_cpu(  _SMP_Get_current_processor() )
-#define capture_flags_per_cpu    capture_flags_on_cpu( _SMP_Get_current_processor() )
 #define capture_flags_global     capture_global.flags
 #define capture_controls         capture_global.controls
 #define capture_extension_index  capture_global.extension_index
 #define capture_timestamp        capture_global.timestamp
 #define capture_ceiling          capture_global.ceiling
 #define capture_floor            capture_global.floor
-#define capture_reader           capture_reader_on_cpu(  _SMP_Get_current_processor() )
-#define capture_lock_per_cpu     capture_lock_on_cpu( _SMP_Get_current_processor() )
 #define capture_lock_global      capture_global.lock
 
 /*
@@ -447,21 +442,25 @@ bool rtems_capture_filter( rtems_tcb*            tcb,
  * This function records a capture record into the capture buffer.
  */
 void *
-rtems_capture_record_open (rtems_tcb*                    tcb,
-                           uint32_t                      events,
-                           size_t                        size,
-                           rtems_interrupt_lock_context* lock_context)
+rtems_capture_record_open (rtems_tcb*                      tcb,
+                           uint32_t                        events,
+                           size_t                          size,
+                           rtems_capture_record_context_t* context)
 {
-  uint8_t*                     ptr;
-  rtems_capture_record_t*      capture_in;
+  rtems_capture_per_cpu_data* per_cpu;
+  uint8_t*                    ptr;
+  rtems_capture_record_t*     capture_in;
 
-  rtems_interrupt_lock_acquire (&capture_lock_per_cpu, lock_context);
+  rtems_interrupt_lock_interrupt_disable (&context->lock_context);
+  per_cpu = capture_per_cpu_get (rtems_get_current_processor ());
+  context->lock = &per_cpu->lock;
+  rtems_interrupt_lock_acquire_isr (&per_cpu->lock, &context->lock_context);
 
-  ptr = rtems_capture_buffer_allocate(&capture_records, size);
+  ptr = rtems_capture_buffer_allocate (&per_cpu->records, size);
   capture_in = (rtems_capture_record_t *) ptr;
   if ( capture_in )
   {
-    capture_count++;
+    ++per_cpu->count;
     capture_in->size    = size;
     capture_in->task_id = tcb->Object.id;
     capture_in->events  = (events |
@@ -476,14 +475,14 @@ rtems_capture_record_open (rtems_tcb*                    tcb,
     ptr = ptr + sizeof(*capture_in);
   }
   else
-    capture_flags_per_cpu |= RTEMS_CAPTURE_OVERFLOW;
+    per_cpu->flags |= RTEMS_CAPTURE_OVERFLOW;
 
   return ptr;
 }
 
-void rtems_capture_record_close( void *rec, rtems_interrupt_lock_context* lock_context)
+void rtems_capture_record_close( void *rec, rtems_capture_record_context_t* context)
 {
-  rtems_interrupt_lock_release (&capture_lock_per_cpu, lock_context);
+  rtems_interrupt_lock_release (context->lock, &context->lock_context);
 }
 
 /*
diff --git a/cpukit/libmisc/capture/captureimpl.h b/cpukit/libmisc/capture/captureimpl.h
index 549735e..753e41b 100644
--- a/cpukit/libmisc/capture/captureimpl.h
+++ b/cpukit/libmisc/capture/captureimpl.h
@@ -185,8 +185,8 @@ bool rtems_capture_filter( rtems_tcb*            task,
  */
 #define rtems_capture_begin_add_record( _task, _events, _size, _rec) \
   do { \
-    rtems_interrupt_lock_context _lock_context; \
-    *_rec = rtems_capture_record_open( _task, _events, _size, &_lock_context );
+    rtems_capture_record_context_t _context; \
+    *_rec = rtems_capture_record_open( _task, _events, _size, &_context );
 
 /**
  * @brief Capture append to record.
@@ -216,7 +216,7 @@ static inline void *rtems_capture_append_to_record(void*  rec,
  * @param[in] _rec specifies the end of the capture record
  */
 #define rtems_capture_end_add_record( _rec ) \
-    rtems_capture_record_close( _rec, &_lock_context ); \
+    rtems_capture_record_close( _rec, &_context ); \
   } while (0)
 
 /**
@@ -232,6 +232,11 @@ static inline void *rtems_capture_append_to_record(void*  rec,
  */
 void rtems_capture_get_time (rtems_capture_time_t* time);
 
+typedef struct {
+  rtems_interrupt_lock_context  lock_context;
+  rtems_interrupt_lock         *lock;
+} rtems_capture_record_context_t;
+
 /**
  * @brief Capture record open.
  *
@@ -244,15 +249,15 @@ void rtems_capture_get_time (rtems_capture_time_t* time);
  * @param[in] task specifies the caputre task block
  * @param[in] events specifies the events
  * @param[in] size specifies capture record size
- * @param[out] lock_context specifies the lock context
+ * @param[out] context specifies the record context
  *
  * @retval This method returns a pointer to the next location in
  * the capture record to store data.
  */
-void* rtems_capture_record_open (rtems_tcb*                    task,
-                                 uint32_t                      events,
-                                 size_t                        size,
-                                 rtems_interrupt_lock_context* lock_context);
+void* rtems_capture_record_open (rtems_tcb*                      task,
+                                 uint32_t                        events,
+                                 size_t                          size,
+                                 rtems_capture_record_context_t* context);
 /**
  * @brief Capture record close.
  *
@@ -261,9 +266,9 @@ void* rtems_capture_record_open (rtems_tcb*                    task,
  * method should only be used by rtems_capture_end_add_record.
  *
  * @param[in] rec specifies the record
- * @param[out] lock_context specifies the lock context
+ * @param[out] context specifies the record context
  */
-void rtems_capture_record_close( void *rec, rtems_interrupt_lock_context* lock_context);
+void rtems_capture_record_close( void *rec, rtems_capture_record_context_t* context);
 
 
 /**




More information about the vc mailing list