Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:21

0001 /*
0002  * SPDX-License-Identifier: BSD-2-Clause
0003  *
0004  * Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <rtems/record.h>
0033 #include <rtems/score/threadimpl.h>
0034 
0035 bool _Record_Thread_create(
0036   struct _Thread_Control *executing,
0037   struct _Thread_Control *created
0038 )
0039 {
0040   rtems_record_data data;
0041   char              name[ 2 * THREAD_DEFAULT_MAXIMUM_NAME_SIZE ];
0042   rtems_record_item items[ 1 + sizeof( name ) / sizeof( data ) ];
0043   size_t            len;
0044   size_t            used;
0045 
0046   items[ 0 ].event = RTEMS_RECORD_THREAD_CREATE;
0047   items[ 0 ].data = created->Object.id;
0048 
0049   len = _Thread_Get_name( created, name, sizeof( name ) );
0050   used = _Record_String_to_items(
0051     RTEMS_RECORD_THREAD_NAME,
0052     name,
0053     len,
0054     &items[ 1 ],
0055     RTEMS_ARRAY_SIZE( items ) - 1
0056   );
0057   rtems_record_produce_n( items, used + 1 );
0058 
0059   return true;
0060 }
0061 
0062 void _Record_Thread_start(
0063   struct _Thread_Control *executing,
0064   struct _Thread_Control *started
0065 )
0066 {
0067   rtems_record_produce(
0068     RTEMS_RECORD_THREAD_START,
0069     started->Object.id
0070   );
0071 }
0072 
0073 void _Record_Thread_restart(
0074   struct _Thread_Control *executing,
0075   struct _Thread_Control *restarted
0076 )
0077 {
0078   rtems_record_produce(
0079     RTEMS_RECORD_THREAD_RESTART,
0080     restarted->Object.id
0081   );
0082 }
0083 
0084 void _Record_Thread_delete(
0085   struct _Thread_Control *executing,
0086   struct _Thread_Control *deleted
0087 )
0088 {
0089   rtems_record_produce(
0090     RTEMS_RECORD_THREAD_DELETE,
0091     deleted->Object.id
0092   );
0093 }
0094 
0095 void _Record_Thread_switch(
0096   struct _Thread_Control *executing,
0097   struct _Thread_Control *heir
0098 )
0099 {
0100   rtems_record_item items[ 3 ];
0101 
0102   items[ 0 ].event = RTEMS_RECORD_THREAD_SWITCH_OUT;
0103   items[ 0 ].data = executing->Object.id;
0104   items[ 1 ].event = RTEMS_RECORD_THREAD_STACK_CURRENT;
0105   items[ 1 ].data =
0106 #if defined(__GNUC__)
0107     (uintptr_t) __builtin_frame_address( 0 )
0108       - (uintptr_t) executing->Start.Initial_stack.area;
0109 #else
0110     0;
0111 #endif
0112   items[ 2 ].event = RTEMS_RECORD_THREAD_SWITCH_IN;
0113   items[ 2 ].data = heir->Object.id;
0114   rtems_record_produce_n( items, RTEMS_ARRAY_SIZE( items ) );
0115 }
0116 
0117 void _Record_Thread_begin( struct _Thread_Control *executing )
0118 {
0119   rtems_record_produce(
0120     RTEMS_RECORD_THREAD_BEGIN,
0121     executing->Object.id
0122   );
0123 }
0124 
0125 void _Record_Thread_exitted( struct _Thread_Control *executing )
0126 {
0127   rtems_record_produce(
0128     RTEMS_RECORD_THREAD_EXITTED,
0129     executing->Object.id
0130   );
0131 }
0132 
0133 void _Record_Thread_terminate( struct _Thread_Control *executing )
0134 {
0135   rtems_record_produce(
0136     RTEMS_RECORD_THREAD_TERMINATE,
0137     executing->Object.id
0138   );
0139 }