Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief Constants and Structures Associated
0007  * with the QoS RES library in RTEMS
0008  *
0009  * This include file contains all the constants and structures
0010  * associated with the QoS RES library in RTEMS.
0011  *
0012  * @note The library is available only together with CBS scheduler.
0013  */
0014 
0015 /*
0016  *  Copyright (C) 2011 Petr Benes.
0017  *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
0018  *
0019  * Redistribution and use in source and binary forms, with or without
0020  * modification, are permitted provided that the following conditions
0021  * are met:
0022  * 1. Redistributions of source code must retain the above copyright
0023  *    notice, this list of conditions and the following disclaimer.
0024  * 2. Redistributions in binary form must reproduce the above copyright
0025  *    notice, this list of conditions and the following disclaimer in the
0026  *    documentation and/or other materials provided with the distribution.
0027  *
0028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0029  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0030  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0031  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0032  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0033  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0034  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0035  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0036  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0037  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0038  * POSSIBILITY OF SUCH DAMAGE.
0039  */
0040 
0041 #ifndef CONFIGURE_SCHEDULER_CBS
0042   #error "qreslib.h available only with CONFIGURE_SCHEDULER_CBS"
0043 #endif
0044 
0045 #ifndef _QRESLIB_H
0046 #define _QRESLIB_H
0047 
0048 #ifdef __cplusplus
0049 extern "C" {
0050 #endif
0051 
0052 #include <stdint.h>
0053 #include <rtems/score/schedulercbs.h>
0054 
0055 /** Return values. */
0056 typedef int qos_rv;
0057 
0058 /* Return codes. */
0059 #define QOS_OK                   SCHEDULER_CBS_OK
0060 #define QOS_E_GENERIC            SCHEDULER_CBS_ERROR_GENERIC
0061 #define QOS_E_NO_MEMORY          SCHEDULER_CBS_ERROR_NO_MEMORY
0062 #define QOS_E_INVALID_PARAM      SCHEDULER_CBS_ERROR_INVALID_PARAMETER
0063 #define QOS_E_UNAUTHORIZED       SCHEDULER_CBS_ERROR_UNAUTHORIZED
0064 #define QOS_E_UNIMPLEMENTED      SCHEDULER_CBS_ERROR_UNIMPLEMENTED
0065 #define QOS_E_MISSING_COMPONENT  SCHEDULER_CBS_ERROR_MISSING_COMPONENT
0066 #define QOS_E_INCONSISTENT_STATE SCHEDULER_CBS_ERROR_INCONSISTENT_STATE
0067 #define QOS_E_SYSTEM_OVERLOAD    SCHEDULER_CBS_ERROR_SYSTEM_OVERLOAD
0068 #define QOS_E_INTERNAL_ERROR     SCHEDULER_CBS_ERROR_INTERNAL_ERROR
0069 #define QOS_E_NOT_FOUND          SCHEDULER_CBS_ERROR_NOT_FOUND
0070 #define QOS_E_FULL               SCHEDULER_CBS_ERROR_FULL
0071 #define QOS_E_EMPTY              SCHEDULER_CBS_ERROR_EMPTY
0072 #define QOS_E_NOSERVER           SCHEDULER_CBS_ERROR_NOSERVER
0073 
0074 /** Server id. */
0075 typedef Scheduler_CBS_Server_id qres_sid_t;
0076 
0077 /** Task id. */
0078 typedef rtems_id tid_t;
0079 
0080 /** Time value. */
0081 typedef time_t qres_time_t;
0082 
0083 /** Absolute time value */
0084 typedef time_t qres_atime_t;
0085 
0086 /** Server parameters. */
0087 typedef struct {
0088   /** Relative deadline of the server. */
0089   qres_time_t P;
0090   /** Budget (computation time) of the server. */
0091   qres_time_t Q;
0092 } qres_params_t;
0093 
0094 /**
0095  *  @brief qres init
0096  *
0097  *  Initializes the QoS RES library.
0098  *
0099  *  @return status code.
0100  */
0101 static inline qos_rv qres_init ( void )
0102 {
0103   return _Scheduler_CBS_Initialize();
0104 }
0105 
0106 /**
0107  *  @brief qres cleanup
0108  *
0109  *  Cleanup resources associated to the QoS RES Library.
0110  *
0111  *  @return status code.
0112  */
0113 static inline qos_rv qres_cleanup ( void )
0114 {
0115   return _Scheduler_CBS_Cleanup();
0116 }
0117 
0118 /**
0119  *  @brief qres create server
0120  *
0121  *  Create a new server with specified parameters.
0122  *
0123  *  @return status code.
0124  */
0125 static inline qos_rv qres_create_server (
0126   qres_params_t *params,
0127   qres_sid_t    *server_id
0128 )
0129 {
0130   return _Scheduler_CBS_Create_server(
0131              (Scheduler_CBS_Parameters *) params,
0132              NULL,
0133              server_id
0134          );
0135 }
0136 
0137 /**
0138  *  @brief qres attach thread
0139  *
0140  *  Attach a task to an already existing server.
0141  *
0142  *  @return status code.
0143  */
0144 static inline qos_rv qres_attach_thread (
0145   qres_sid_t server_id,
0146   pid_t      pid,
0147   tid_t      task_id
0148 )
0149 {
0150   return _Scheduler_CBS_Attach_thread( server_id, task_id );
0151 }
0152 
0153 /**
0154  *  @brief qres detach thread
0155  *
0156  *  Detach from the QoS Server.
0157  *
0158  *  @return status code.
0159  */
0160 static inline qos_rv qres_detach_thread (
0161   qres_sid_t server_id,
0162   pid_t      pid,
0163   tid_t      task_id
0164 )
0165 {
0166   return _Scheduler_CBS_Detach_thread( server_id, task_id );
0167 }
0168 
0169 /**
0170  *  @brief qres destroy server
0171  *
0172  *  Detach all tasks from a server and destroy it.
0173  *
0174  *  @return status code.
0175  */
0176 static inline qos_rv qres_destroy_server (
0177   qres_sid_t server_id
0178 )
0179 {
0180   return _Scheduler_CBS_Destroy_server( server_id );
0181 }
0182 
0183 /**
0184  *  @brief qres get server id
0185  *
0186  *  Get a thread server id, or QOS_E_NOT_FOUND if it is not
0187  *  attached to any server.
0188  *
0189  *  @return status code.
0190  */
0191 static inline qos_rv qres_get_sid (
0192   pid_t       pid,
0193   tid_t       task_id,
0194   qres_sid_t *server_id
0195 )
0196 {
0197   return _Scheduler_CBS_Get_server_id( task_id, server_id );
0198 }
0199 
0200 /**
0201  *  @brief qres get params
0202  *
0203  *  Retrieve QoS scheduling parameters.
0204  *
0205  *  @return status code.
0206  */
0207 static inline qos_rv qres_get_params (
0208   qres_sid_t     server_id,
0209   qres_params_t *params
0210 )
0211 {
0212   return _Scheduler_CBS_Get_parameters(
0213              server_id,
0214              (Scheduler_CBS_Parameters *) params
0215          );
0216 }
0217 
0218 /**
0219  *  @brief qres set params
0220  *
0221  *  Change QoS scheduling parameters.
0222  *
0223  *  @return status code.
0224  */
0225 static inline qos_rv qres_set_params (
0226   qres_sid_t     server_id,
0227   qres_params_t *params
0228 )
0229 {
0230   return _Scheduler_CBS_Set_parameters(
0231              server_id,
0232              (Scheduler_CBS_Parameters *) params
0233          );
0234 }
0235 
0236 /**
0237  *  @brief qres get execution time
0238  *
0239  *  Retrieve time info relative to the current server.
0240  *
0241  *  @return status code.
0242  */
0243 static inline qos_rv qres_get_exec_time (
0244   qres_sid_t    server_id,
0245   qres_time_t  *exec_time,
0246   qres_atime_t *abs_time
0247 )
0248 {
0249   return _Scheduler_CBS_Get_execution_time( server_id, exec_time, abs_time );
0250 }
0251 
0252 /**
0253  *  @brief qres get current budget
0254  *
0255  *  Retrieve remaining budget for the current server instance.
0256  *
0257  *  @return status code.
0258  */
0259 static inline qos_rv qres_get_curr_budget (
0260   qres_sid_t   server_id,
0261   qres_time_t *current_budget
0262 )
0263 {
0264   return _Scheduler_CBS_Get_remaining_budget( server_id, current_budget );
0265 }
0266 
0267 /**
0268  *  @brief qres get approved budget
0269  *
0270  *  Retrieve the budget that has been approved for the subsequent
0271  *  server instances.
0272  *
0273  *  @return status code.
0274  */
0275 static inline qos_rv qres_get_appr_budget (
0276   qres_sid_t   server_id,
0277   qres_time_t *appr_budget
0278 )
0279 {
0280   return _Scheduler_CBS_Get_approved_budget( server_id, appr_budget );
0281 }
0282 
0283 #ifdef __cplusplus
0284 }
0285 #endif
0286 
0287 #endif
0288 /* end of include file */