Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup ScoreCpuValPerf
0007  */
0008 
0009 /*
0010  * Copyright (C) 2023 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 /*
0035  * This file is part of the RTEMS quality process and was automatically
0036  * generated.  If you find something that needs to be fixed or
0037  * worded better please post a report or patch to an RTEMS mailing list
0038  * or raise a bug report:
0039  *
0040  * https://www.rtems.org/bugs.html
0041  *
0042  * For information on updating and regenerating please refer to the How-To
0043  * section in the Software Requirements Engineering chapter of the
0044  * RTEMS Software Engineering manual.  The manual is provided as a part of
0045  * a release.  For development sources please refer to the online
0046  * documentation at:
0047  *
0048  * https://docs.rtems.org
0049  */
0050 
0051 #ifdef HAVE_CONFIG_H
0052 #include "config.h"
0053 #endif
0054 
0055 #include <rtems/score/cpuimpl.h>
0056 
0057 #include "tx-support.h"
0058 
0059 #include <rtems/test.h>
0060 
0061 /**
0062  * @defgroup ScoreCpuValPerf spec:/score/cpu/val/perf
0063  *
0064  * @ingroup TestsuitesPerformanceNoClock0
0065  *
0066  * @brief This test case provides a context to run CPU port performance tests.
0067  *
0068  * @{
0069  */
0070 
0071 /**
0072  * @brief Test context for spec:/score/cpu/val/perf test case.
0073  */
0074 typedef struct {
0075   /**
0076    * @brief This member references the measure runtime context.
0077    */
0078   T_measure_runtime_context *context;
0079 
0080   /**
0081    * @brief This member provides the measure runtime request.
0082    */
0083   T_measure_runtime_request request;
0084 
0085   /**
0086    * @brief This member provides an optional measurement begin time point.
0087    */
0088   T_ticks begin;
0089 
0090   /**
0091    * @brief This member provides an optional measurement end time point.
0092    */
0093   T_ticks end;
0094 } ScoreCpuValPerf_Context;
0095 
0096 static ScoreCpuValPerf_Context
0097   ScoreCpuValPerf_Instance;
0098 
0099 static void ScoreCpuValPerf_Setup_Context( ScoreCpuValPerf_Context *ctx )
0100 {
0101   T_measure_runtime_config config;
0102 
0103   memset( &config, 0, sizeof( config ) );
0104   config.sample_count = 100;
0105   ctx->request.arg = ctx;
0106   ctx->request.flags = T_MEASURE_RUNTIME_REPORT_SAMPLES;
0107   ctx->context = T_measure_runtime_create( &config );
0108   T_assert_not_null( ctx->context );
0109 }
0110 
0111 static void ScoreCpuValPerf_Setup_Wrap( void *arg )
0112 {
0113   ScoreCpuValPerf_Context *ctx;
0114 
0115   ctx = arg;
0116   ScoreCpuValPerf_Setup_Context( ctx );
0117 }
0118 
0119 static T_fixture ScoreCpuValPerf_Fixture = {
0120   .setup = ScoreCpuValPerf_Setup_Wrap,
0121   .stop = NULL,
0122   .teardown = NULL,
0123   .scope = NULL,
0124   .initial_context = &ScoreCpuValPerf_Instance
0125 };
0126 
0127 /**
0128  * @defgroup ScoreCpuReqPerfEmpty spec:/score/cpu/req/perf-empty
0129  *
0130  * @{
0131  */
0132 
0133 /**
0134  * @brief Do nothing and just return.
0135  */
0136 static void ScoreCpuReqPerfEmpty_Body( ScoreCpuValPerf_Context *ctx )
0137 {
0138   /* No code */
0139 }
0140 
0141 static void ScoreCpuReqPerfEmpty_Body_Wrap( void *arg )
0142 {
0143   ScoreCpuValPerf_Context *ctx;
0144 
0145   ctx = arg;
0146   ScoreCpuReqPerfEmpty_Body( ctx );
0147 }
0148 
0149 /**
0150  * @brief Discard samples interrupted by a clock tick.
0151  */
0152 static bool ScoreCpuReqPerfEmpty_Teardown(
0153   ScoreCpuValPerf_Context *ctx,
0154   T_ticks                 *delta,
0155   uint32_t                 tic,
0156   uint32_t                 toc,
0157   unsigned int             retry
0158 )
0159 {
0160   return tic == toc;
0161 }
0162 
0163 static bool ScoreCpuReqPerfEmpty_Teardown_Wrap(
0164   void        *arg,
0165   T_ticks     *delta,
0166   uint32_t     tic,
0167   uint32_t     toc,
0168   unsigned int retry
0169 )
0170 {
0171   ScoreCpuValPerf_Context *ctx;
0172 
0173   ctx = arg;
0174   return ScoreCpuReqPerfEmpty_Teardown( ctx, delta, tic, toc, retry );
0175 }
0176 
0177 /** @} */
0178 
0179 /**
0180  * @defgroup ScoreCpuReqPerfNops spec:/score/cpu/req/perf-nops
0181  *
0182  * @{
0183  */
0184 
0185 /**
0186  * @brief Execute exactly 1000 no-operation instructions.
0187  */
0188 static void ScoreCpuReqPerfNops_Body( ScoreCpuValPerf_Context *ctx )
0189 {
0190   #define NOPS_10 \
0191     _CPU_Instruction_no_operation(); _CPU_Instruction_no_operation(); \
0192     _CPU_Instruction_no_operation(); _CPU_Instruction_no_operation(); \
0193     _CPU_Instruction_no_operation(); _CPU_Instruction_no_operation(); \
0194     _CPU_Instruction_no_operation(); _CPU_Instruction_no_operation(); \
0195     _CPU_Instruction_no_operation(); _CPU_Instruction_no_operation();
0196   #define NOPS_100 NOPS_10 NOPS_10 NOPS_10 NOPS_10 NOPS_10 NOPS_10 NOPS_10 \
0197     NOPS_10 NOPS_10 NOPS_10
0198   NOPS_100
0199   NOPS_100
0200   NOPS_100
0201   NOPS_100
0202   NOPS_100
0203   NOPS_100
0204   NOPS_100
0205   NOPS_100
0206   NOPS_100
0207   NOPS_100
0208 }
0209 
0210 static void ScoreCpuReqPerfNops_Body_Wrap( void *arg )
0211 {
0212   ScoreCpuValPerf_Context *ctx;
0213 
0214   ctx = arg;
0215   ScoreCpuReqPerfNops_Body( ctx );
0216 }
0217 
0218 /**
0219  * @brief Discard samples interrupted by a clock tick.
0220  */
0221 static bool ScoreCpuReqPerfNops_Teardown(
0222   ScoreCpuValPerf_Context *ctx,
0223   T_ticks                 *delta,
0224   uint32_t                 tic,
0225   uint32_t                 toc,
0226   unsigned int             retry
0227 )
0228 {
0229   return tic == toc;
0230 }
0231 
0232 static bool ScoreCpuReqPerfNops_Teardown_Wrap(
0233   void        *arg,
0234   T_ticks     *delta,
0235   uint32_t     tic,
0236   uint32_t     toc,
0237   unsigned int retry
0238 )
0239 {
0240   ScoreCpuValPerf_Context *ctx;
0241 
0242   ctx = arg;
0243   return ScoreCpuReqPerfNops_Teardown( ctx, delta, tic, toc, retry );
0244 }
0245 
0246 /** @} */
0247 
0248 /**
0249  * @fn void T_case_body_ScoreCpuValPerf( void )
0250  */
0251 T_TEST_CASE_FIXTURE( ScoreCpuValPerf, &ScoreCpuValPerf_Fixture )
0252 {
0253   ScoreCpuValPerf_Context *ctx;
0254 
0255   ctx = T_fixture_context();
0256 
0257   ctx->request.name = "ScoreCpuReqPerfEmpty";
0258   ctx->request.setup = NULL;
0259   ctx->request.body = ScoreCpuReqPerfEmpty_Body_Wrap;
0260   ctx->request.teardown = ScoreCpuReqPerfEmpty_Teardown_Wrap;
0261   T_measure_runtime( ctx->context, &ctx->request );
0262 
0263   ctx->request.name = "ScoreCpuReqPerfNops";
0264   ctx->request.setup = NULL;
0265   ctx->request.body = ScoreCpuReqPerfNops_Body_Wrap;
0266   ctx->request.teardown = ScoreCpuReqPerfNops_Teardown_Wrap;
0267   T_measure_runtime( ctx->context, &ctx->request );
0268 }
0269 
0270 /** @} */