Discussion:
[PATCH 4/5] cpuuse: Move is_executing_on_a_core to threadimpl.h
Jennifer Averett
2014-09-22 14:00:09 UTC
Permalink
---
cpukit/libmisc/cpuuse/cpuusagereport.c | 25 +------------------------
1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
index 296fa28..62bb81a 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereport.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -30,29 +30,6 @@
#include <rtems/score/todimpl.h>
#include <rtems/score/watchdogimpl.h>

-#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
- static bool is_executing_on_a_core(
- Thread_Control *the_thread,
- Timestamp_Control *time_of_context_switch
- )
- {
- #ifndef RTEMS_SMP
- if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
- *time_of_context_switch = _Thread_Time_of_last_context_switch;
- return true;
- }
- #else
- /* FIXME: Locking */
- if ( _Thread_Is_executing_on_a_processor( the_thread ) ) {
- *time_of_context_switch =
- _Thread_Get_CPU( the_thread )->time_of_last_context_switch;
- return true;
- }
- #endif
- return false;
- }
-#endif
-
/*
* rtems_cpu_usage_report
*/
@@ -149,7 +126,7 @@ void rtems_cpu_usage_report_with_plugin(
* since the last context switch.
*/
ran = the_thread->cpu_time_used;
- if ( is_executing_on_a_core( the_thread, &last ) ) {
+ if ( _Thread_is_executing_on_a_core( the_thread, &last ) ) {
Timestamp_Control used;
_TOD_Get_uptime( &uptime );
_Timestamp_Subtract( &last, &uptime, &used );
--
1.8.1.4
Jennifer Averett
2014-09-22 14:00:10 UTC
Permalink
This involved adding a new variable record to the capture buffer
and modifing the trace method to read those records.
---
testsuites/libtests/capture01/init.c | 112 ++++++++++++++++++++++++++---------
1 file changed, 85 insertions(+), 27 deletions(-)

diff --git a/testsuites/libtests/capture01/init.c b/testsuites/libtests/capture01/init.c
index 21895b9..ae70501 100644
--- a/testsuites/libtests/capture01/init.c
+++ b/testsuites/libtests/capture01/init.c
@@ -113,6 +113,73 @@ static void cwlist ()
}
}

+/*
+ * rtems_catpure_cli_print_uptime
+ *
+ * DESCRIPTION::148
+ *
+ *
+ * This function prints the nanosecond uptime to stdout.
+ */
+static void
+rtems_capture_cli_print_timestamp (uint64_t uptime)
+{
+ uint32_t hours;
+ uint32_t minutes;
+ uint32_t seconds;
+ uint32_t nanosecs;
+
+ seconds = uptime / 1000000000LLU;
+ minutes = seconds / 60;
+ hours = minutes / 60;
+ minutes = minutes % 60;
+ seconds = seconds % 60;
+ nanosecs = uptime % 1000000000;
+
+ fprintf (stdout, "%5lu:%02lu:%02lu.%09lu", hours, minutes, seconds, nanosecs);
+}
+static void
+rtems_caputre_cli_print_record_task(rtems_capture_record_t* rec)
+{
+ rtems_capture_task_record_t* task_rec = (rtems_capture_task_record_t*) rec;
+
+ rtems_capture_cli_print_timestamp (rec->time);
+ fprintf (stdout, " ");
+ rtems_monitor_dump_id (rec->task_id);
+ fprintf (stdout, " %c%c%c%c",
+ (char) (task_rec->name >> 24) & 0xff,
+ (char) (task_rec->name >> 16) & 0xff,
+ (char) (task_rec->name >> 8) & 0xff,
+ (char) (task_rec->name >> 0) & 0xff);
+ fprintf (stdout, " %3" PRId32 " %3" PRId32 "\n",
+ task_rec->start_priority,
+ task_rec->stack_size);
+}
+
+static void
+rtems_caputure_cli_print_record_std(rtems_capture_record_t* rec, uint64_t diff)
+{
+ uint32_t event;
+ int e;
+
+ event = rec->events >> RTEMS_CAPTURE_EVENT_START;
+
+ for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
+ {
+ if (event & 1)
+ {
+ rtems_capture_cli_print_timestamp (rec->time);
+ fprintf (stdout, " %9" PRId64 " ", diff);
+ rtems_monitor_dump_id (rec->task_id);
+ fprintf(stdout, " %3" PRId32 " %3" PRId32 " %s\n",
+ (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
+ (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
+ rtems_capture_event_text (e));
+ }
+ event >>= 1;
+ }
+}
+
static void ctrace()
{
rtems_status_code sc;
@@ -122,6 +189,8 @@ static void ctrace()
int count;
uint32_t read;
rtems_capture_record_t* rec;
+ uint8_t* ptr;
+ rtems_capture_time_t last_t = 0;

total = dump_total;

@@ -148,43 +217,32 @@ static void ctrace()
}

count = total < read ? total : read;
-
+ ptr = (uint8_t *) rec;
while (count--)
{
+ rec = (rtems_capture_record_t*) ptr;
+
if (csv)
- fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32
+ fprintf (stdout, "%08" PRIu32 ",%03" PRIu32
",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n",
- (uintptr_t) rec->task,
+ rec->task_id,
(rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
(rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
(rec->events >> RTEMS_CAPTURE_EVENT_START),
(uint64_t) rec->time);
- else
- {
- uint32_t event;
- int e;
-
- event = rec->events >> RTEMS_CAPTURE_EVENT_START;
-
- for (e = RTEMS_CAPTURE_EVENT_START; e <= RTEMS_CAPTURE_EVENT_END; e++)
- {
- if (event & 1)
- {
- rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
- fprintf (stdout, " %c%c%c%c",
- (char) (rec->task->name >> 24) & 0xff,
- (char) (rec->task->name >> 16) & 0xff,
- (char) (rec->task->name >> 8) & 0xff,
- (char) (rec->task->name >> 0) & 0xff);
- fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n",
- (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
- (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
- rtems_capture_event_text (e));
- }
- event >>= 1;
+ else {
+ if ((rec->events >> RTEMS_CAPTURE_EVENT_START) == 0)
+ rtems_caputre_cli_print_record_task( rec );
+ else {
+ uint64_t diff = 0;
+ if (last_t)
+ diff = rec->time - last_t;
+ last_t = rec->time;
+
+ rtems_caputure_cli_print_record_std( rec, diff );
}
}
- rec++;
+ ptr += rec->size;
}

count = total < read ? total : read;
--
1.8.1.4
Jennifer Averett
2014-09-22 14:00:08 UTC
Permalink
---
cpukit/score/include/rtems/score/threadimpl.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 9321c01..77126eb 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -467,6 +467,7 @@ RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
return ( the_thread == _Thread_Executing );
}

+
#if defined(RTEMS_SMP)
/**
* @brief Returns @true in case the thread executes currently on some processor
@@ -483,6 +484,31 @@ RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_on_a_processor(
}
#endif

+RTEMS_INLINE_ROUTINE bool _Thread_is_executing_on_a_core(
+ Thread_Control *the_thread,
+ Timestamp_Control *time_of_context_switch
+)
+{
+ bool retval = false;
+
+ _Thread_Disable_dispatch();
+ #ifndef RTEMS_SMP
+ if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
+ *time_of_context_switch = _Thread_Time_of_last_context_switch;
+ retval = true;
+ }
+ #else
+ if ( _Thread_Is_executing_on_a_processor( the_thread ) ) {
+ *time_of_context_switch =
+ _Thread_Get_CPU( the_thread )->time_of_last_context_switch;
+ retval = true;
+ }
+ #endif
+ _Thread_Enable_dispatch();
+ return retval;
+}
+
+
/**
* This function returns true if the_thread is the heir
* thread, and false otherwise.
--
1.8.1.4
Sebastian Huber
2014-09-23 04:39:00 UTC
Permalink
Post by Jennifer Averett
---
cpukit/score/include/rtems/score/threadimpl.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 9321c01..77126eb 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -467,6 +467,7 @@ RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
return ( the_thread == _Thread_Executing );
}
+
Extra empty line.
Post by Jennifer Averett
#if defined(RTEMS_SMP)
/**
@@ -483,6 +484,31 @@ RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_on_a_processor(
}
#endif
+RTEMS_INLINE_ROUTINE bool _Thread_is_executing_on_a_core(
+ Thread_Control *the_thread,
+ Timestamp_Control *time_of_context_switch
+)
I would rather name this _Thread_Get_time_of_last_context_switch(). The return
value should be documented.
Post by Jennifer Averett
+{
+ bool retval = false;
+
+ _Thread_Disable_dispatch();
+ #ifndef RTEMS_SMP
+ if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
+ *time_of_context_switch = _Thread_Time_of_last_context_switch;
+ retval = true;
+ }
+ #else
+ if ( _Thread_Is_executing_on_a_processor( the_thread ) ) {
+ *time_of_context_switch =
+ _Thread_Get_CPU( the_thread )->time_of_last_context_switch;
+ retval = true;
+ }
+ #endif
+ _Thread_Enable_dispatch();
+ return retval;
+}
+
+
/**
* This function returns true if the_thread is the heir
* thread, and false otherwise.
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber-L1vi/***@public.gmane.org
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Jennifer Averett
2014-09-22 14:00:07 UTC
Permalink
---
cpukit/score/include/rtems/score/thread.h | 7 +++++++
cpukit/score/src/threadinitialize.c | 3 +++
2 files changed, 10 insertions(+)

diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index be35789..59e0f9e 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -537,6 +537,11 @@ typedef struct {
#endif
} Thread_Scheduler_control;

+typedef struct {
+ uint32_t flags;
+ void * control;
+}Thread_Capture_control;
+
/**
* This structure defines the Thread Control Block (TCB).
*/
@@ -649,6 +654,8 @@ struct Thread_Control_struct {
*/
Thread_Life_control Life;

+ Thread_Capture_control capture;
+
/**
* @brief Variable length array of user extension pointers.
*
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index e56e4e6..6c1ab36 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -228,6 +228,9 @@ bool _Thread_Initialize(
the_thread->Life.state = THREAD_LIFE_NORMAL;
the_thread->Life.terminator = NULL;

+ the_thread->capture.flags = 0;
+ the_thread->capture.control = NULL;
+
/*
* Open the object
*/
--
1.8.1.4
Sebastian Huber
2014-09-23 04:31:13 UTC
Permalink
Post by Jennifer Averett
+ Thread_Capture_control capture;
+
This should be "Capture".
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber-L1vi/***@public.gmane.org
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Loading...