capture: Fix use of per-processor data

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

Close #2707.
This commit is contained in:
Sebastian Huber
2016-05-12 13:08:49 +02:00
parent d449c12df3
commit df23f464be
2 changed files with 31 additions and 27 deletions

View File

@@ -92,17 +92,12 @@ static rtems_capture_global_data capture_global = {
#define capture_reader_on_cpu( _cpu ) capture_per_cpu[ _cpu ].reader #define capture_reader_on_cpu( _cpu ) capture_per_cpu[ _cpu ].reader
#define capture_lock_on_cpu( _cpu ) capture_per_cpu[ _cpu ].lock #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_flags_global capture_global.flags
#define capture_controls capture_global.controls #define capture_controls capture_global.controls
#define capture_extension_index capture_global.extension_index #define capture_extension_index capture_global.extension_index
#define capture_timestamp capture_global.timestamp #define capture_timestamp capture_global.timestamp
#define capture_ceiling capture_global.ceiling #define capture_ceiling capture_global.ceiling
#define capture_floor capture_global.floor #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 #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. * This function records a capture record into the capture buffer.
*/ */
void * void *
rtems_capture_record_open (rtems_tcb* tcb, rtems_capture_record_open (rtems_tcb* tcb,
uint32_t events, uint32_t events,
size_t size, size_t size,
rtems_interrupt_lock_context* lock_context) rtems_capture_record_context_t* context)
{ {
uint8_t* ptr; rtems_capture_per_cpu_data* per_cpu;
rtems_capture_record_t* capture_in; 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; capture_in = (rtems_capture_record_t *) ptr;
if ( capture_in ) if ( capture_in )
{ {
capture_count++; ++per_cpu->count;
capture_in->size = size; capture_in->size = size;
capture_in->task_id = tcb->Object.id; capture_in->task_id = tcb->Object.id;
capture_in->events = (events | capture_in->events = (events |
@@ -476,14 +475,14 @@ rtems_capture_record_open (rtems_tcb* tcb,
ptr = ptr + sizeof(*capture_in); ptr = ptr + sizeof(*capture_in);
} }
else else
capture_flags_per_cpu |= RTEMS_CAPTURE_OVERFLOW; per_cpu->flags |= RTEMS_CAPTURE_OVERFLOW;
return ptr; 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);
} }
/* /*

View File

@@ -185,8 +185,8 @@ bool rtems_capture_filter( rtems_tcb* task,
*/ */
#define rtems_capture_begin_add_record( _task, _events, _size, _rec) \ #define rtems_capture_begin_add_record( _task, _events, _size, _rec) \
do { \ do { \
rtems_interrupt_lock_context _lock_context; \ rtems_capture_record_context_t _context; \
*_rec = rtems_capture_record_open( _task, _events, _size, &_lock_context ); *_rec = rtems_capture_record_open( _task, _events, _size, &_context );
/** /**
* @brief Capture append to record. * @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 * @param[in] _rec specifies the end of the capture record
*/ */
#define rtems_capture_end_add_record( _rec ) \ #define rtems_capture_end_add_record( _rec ) \
rtems_capture_record_close( _rec, &_lock_context ); \ rtems_capture_record_close( _rec, &_context ); \
} while (0) } 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); 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. * @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] task specifies the caputre task block
* @param[in] events specifies the events * @param[in] events specifies the events
* @param[in] size specifies capture record size * @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 * @retval This method returns a pointer to the next location in
* the capture record to store data. * the capture record to store data.
*/ */
void* rtems_capture_record_open (rtems_tcb* task, void* rtems_capture_record_open (rtems_tcb* task,
uint32_t events, uint32_t events,
size_t size, size_t size,
rtems_interrupt_lock_context* lock_context); rtems_capture_record_context_t* context);
/** /**
* @brief Capture record close. * @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. * method should only be used by rtems_capture_end_add_record.
* *
* @param[in] rec specifies the 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);
/** /**