+++ /dev/null
-// -----------------------------------------------------------------------
-// Copyright (C) 2006 - 2007 FRESCOR consortium partners:
-//
-// Universidad de Cantabria, SPAIN
-// University of York, UK
-// Scuola Superiore Sant'Anna, ITALY
-// Kaiserslautern University, GERMANY
-// Univ. Politecnica Valencia, SPAIN
-// Czech Technical University in Prague, CZECH REPUBLIC
-// ENEA SWEDEN
-// Thales Communication S.A. FRANCE
-// Visual Tools S.A. SPAIN
-// Rapita Systems Ltd UK
-// Evidence ITALY
-//
-// See http://www.frescor.org for a link to partners' websites
-//
-// FRESCOR project (FP6/2005/IST/5-034026) is funded
-// in part by the European Union Sixth Framework Programme
-// The European Union is not liable of any use that may be
-// made of this code.
-//
-// This file is part of the FRSH implementation
-//
-// FRSH is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2, or (at your option)
-// any later version.
-//
-// FRSH is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// distributed with FRSH; see file COPYING. If not, write to the
-// Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// As a special exception, if you include this header file into source
-// files to be compiled, this header file does not by itself cause
-// the resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-// -----------------------------------------------------------------------
-// 13-Jul-2007 SANGORRIN Create this function to consume time in tests using
-// the cpu time clocks.
-// -----------------------------------------------------------------------
-
-#ifndef _EAT_H
-#define _EAT_H
-
-
-#include <time.h>
-#include <frsh_cpp_macros.h>
-
-FRSH_CPP_BEGIN_DECLS
-/**
- * @file eat.h
- **/
-
-extern void inline eat(const struct timespec *cpu_time);
-
-FRSH_CPP_END_DECLS
-
-#endif
**/
/** Initial period of the service thread (timespec) **/
-#define FRSH_SERVICE_THREAD_PERIOD {5,0}
+#define FRSH_SERVICE_THREAD_PERIOD_USECS 5000000 /* 5 secs */
/** Initial budget of the service thread (timespec) **/
-#define FRSH_SERVICE_THREAD_BUDGET {0,1000000}
+#define FRSH_SERVICE_THREAD_BUDGET_USECS 1000 /* 1 msec */
/**
* Initial priority of the service thread, it has to be lower than the
* The cpu time given by the round robin scheduler
* to the threads in the background (timespec)
**/
-#define FRSH_RR_SLICE_CPU_TIME {0,100000000} //3 0.1 sec
+#define FRSH_RR_SLICE_CPU_TIME_USECS 100000 // 0.1 sec
/**
* This function must be supplied by the user to map the preemption
*
* @return 0 if no error \n
* FRSH_ERR_BAD_ARGUMENT : if any of the pointers is NULL
- * or if only one of the timespec values is 0, and also if the
+ * or if only one of the time values is 0, and also if the
* workload or the contract type values are unknown in the
* enumerations.
**/
int frsh_contract_set_basic_params
(frsh_contract_t *contract,
- const struct timespec *budget_min,
- const struct timespec *period_max,
+ const frsh_rel_time_t *budget_min,
+ const frsh_rel_time_t *period_max,
const frsh_workload_t workload,
const frsh_contract_type_t contract_type);
**/
int frsh_contract_get_basic_params
(const frsh_contract_t *contract,
- struct timespec *budget_min,
- struct timespec *period_max,
+ frsh_rel_time_t *budget_min,
+ frsh_rel_time_t *period_max,
frsh_workload_t *workload,
frsh_contract_type_t *contract_type);
int frsh_contract_set_timing_reqs
(frsh_contract_t *contract,
const bool d_equals_t,
- const struct timespec *deadline,
+ const frsh_rel_time_t *deadline,
const frsh_signal_t budget_overrun_signal,
const frsh_signal_info_t budget_overrun_siginfo,
const frsh_signal_t deadline_miss_signal,
int frsh_contract_get_timing_reqs
(const frsh_contract_t *contract,
bool *d_equals_t,
- struct timespec *deadline,
+ frsh_rel_time_t *deadline,
frsh_signal_t *budget_overrun_signal,
frsh_signal_info_t *budget_overrun_siginfo,
frsh_signal_t *deadline_miss_signal,
**/
int frsh_synchobj_wait
(const frsh_synchobj_handle_t synch_handle,
- struct timespec *next_budget,
- struct timespec *next_period,
+ frsh_rel_time_t *next_budget,
+ frsh_rel_time_t *next_period,
bool *was_deadline_missed,
bool *was_budget_overran);
**/
int frsh_synchobj_wait_with_timeout
(const frsh_synchobj_handle_t synch_handle,
- const struct timespec *abs_timeout,
+ const frsh_abs_time_t *abs_timeout,
bool *timed_out,
- struct timespec *next_budget,
- struct timespec *next_period,
+ frsh_rel_time_t *next_budget,
+ frsh_rel_time_t *next_period,
bool *was_deadline_missed,
bool *was_budget_overran);
* @sa frsh_synchobj_wait, frsh_synchobj_wait_with_timeout
**/
int frsh_timed_wait
- (const struct timespec *abs_time,
- struct timespec *next_budget,
- struct timespec *next_period,
+ (const frsh_abs_time_t *abs_time,
+ frsh_rel_time_t *next_budget,
+ frsh_rel_time_t *next_period,
bool *was_deadline_missed,
bool *was_budget_overran);
**/
int frsh_vres_get_usage
(const frsh_vres_id_t vres,
- struct timespec *spent);
+ frsh_rel_time_t *spent);
+
+
+/**
+ * frsh_vres_get_job_usage()
+ *
+ * Get the execution time of the current job of the specified virtual
+ * resource for a bounded or synchronized workload.
+ **/
+int frsh_vres_get_job_usage
+ (const frsh_vres_id_t vres,
+ frsh_rel_time_t *spent);
+
/**
* frsh_vres_get_remaining_budget()
**/
int frsh_vres_get_remaining_budget
(const frsh_vres_id_t vres,
- struct timespec *budget);
+ frsh_rel_time_t *budget);
/**
**/
int frsh_vres_get_budget_and_period
(const frsh_vres_id_t vres,
- struct timespec *budget,
- struct timespec *period);
+ frsh_rel_time_t *budget,
+ frsh_rel_time_t *period);
/*@}*/
* has been cancelled or it is not valid
*
**/
-int frsh_service_thread_set_data (const struct timespec *budget,
- const struct timespec *period,
+int frsh_service_thread_set_data (const frsh_rel_time_t *budget,
+ const frsh_rel_time_t *period,
bool *accepted);
/**
*
**/
int frsh_service_thread_get_data
- (struct timespec *budget,
- struct timespec *period);
+ (frsh_rel_time_t *budget,
+ frsh_rel_time_t *period);
/*@}*/
#define FRSH_CORE_TYPES_H_
#include <stdbool.h>
+#include "frsh_time_types.h"
#include "frsh_configuration_parameters.h"
#include "frsh_opaque_types.h"
#include "frsh_shared_objects_types.h"
typedef fosa_signal_info_t frsh_signal_info_t;
-/* Temporary placement */
-typedef struct timespec frsh_rel_time_t;
-typedef struct timespec frsh_abs_time_t;
-
/** Kind of workload expected in vres: bounded or indeterminate **/
typedef enum {
FRSH_WT_BOUNDED = 0,
- FRSH_WT_INDETERMINATE = 1
+ FRSH_WT_INDETERMINATE = 1,
+ FRSH_WT_SYNCHRONIZED = 2
} frsh_workload_t;
+/**
+ * In the synchronized workload the virtual resource hosts one or more
+ * threads that synchronize the execution of their jobs with the start
+ * of the virtual resource's period. In this kind of workload, once
+ * the threads that were activated at the beginning of the period
+ * finish their current job, the virtual resource may return any
+ * unused capacity to the system. This kind of workload can be
+ * scheduled using a regular periodic server that has the properties
+ * of being simple, having less overhead, and being able to increase
+ * the schedulability of periodic synchronized threads
+ **/
-#define FRSH_NULL_DEADLINE (struct timespec *)NULL
+#define FRSH_NULL_DEADLINE (frsh_rel_time_t *)NULL
// #define FRSH_NULL_SIGNAL 0 /* Defined at frsh_adaption.h */
/** Negotiation status: In_progress, rejected, admitted, not_requested **/
#include <stdio.h> // for vprintf
#include <stdbool.h> // for bool
#include <stdarg.h> // for va_list, va_start and va_end
+#include "fosa.h"
#include "frsh_debug_and_trace_types.h"
-#include "timespec_operations.h"
#include "fosa_configuration_parameters.h" /* FOSA_CLOCK_REALTIME */
#include "fosa_clocks_and_timers.h"
/* These variables live defined in frsh_error.c */
/************************************************/
-extern struct timespec frsh_trace_init_timespec;
+extern fosa_abs_time_t frsh_trace_init_timespec;
extern long frsh_trace_init_timemsec;
extern int global_error_condition; /* Used to propagate error
static inline long int FRSH_GET_TIMESTAMP_MSECS()
{
int terror = -1;
- struct timespec current_time = {-1, -1};
+ fosa_abs_time_t current_time;
long int current_time_msec = -1;
long int result = -1;
PRW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time) );
- current_time_msec = timespec2msec(¤t_time);
+ current_time_msec = fosa_abs_time_to_msec(current_time);
result = current_time_msec - frsh_trace_init_timemsec;
return result;
}
-static inline long int FRSH_TIMESPEC_TO_RELATIVE_MSECS(const struct timespec *tspec)
+static inline long int FRSH_TIMESTAMP_TO_RELATIVE_MSECS(const fosa_abs_time_t *timestamp)
{
long int time_msecs = -1;
- time_msecs = timespec2msec(tspec);
+ time_msecs = fosa_abs_time_to_msec(*timestamp);
return time_msecs - frsh_trace_init_timemsec;
}
int frsh_network_bytes_to_budget
(const frsh_resource_id_t resource_id,
const size_t nbytes,
- struct timespec *budget);
+ frsh_rel_time_t *budget);
/**
* frsh_network_budget_to_bytes()
**/
int frsh_network_budget_to_bytes
(const frsh_resource_id_t resource_id,
- const struct timespec *budget,
+ const frsh_rel_time_t *budget,
size_t *nbytes);
/**
**/
int frsh_network_get_min_effective_budget
(const frsh_resource_id_t resource_id,
- struct timespec *budget);
+ frsh_rel_time_t *budget);
/**
* frsh_contract_set_queueing_info()
* @defgroup energymgmnt Energy Management Module
*
* This module provides the ability to specify different budgets for
- * different CPU power levels.
+ * different power levels.
*
* We model the situation by specifying budget values per power
* level. Thus switching in the power-level would be done by changing
*
* All global FRSH contract operations (those done with the core
* module without specifying the power level) are considered to be
- * applies to the higest power level.
+ * applied to the higest power level, corresponding to a power_level_t
+ * value of 0.
+ *
+ * @note
+ * For all functions that operate on a contract, the resource is
+ * implicitly identified by the contract core parameters resource_type
+ * and resource_id that are either set through the
+ * frsh_contract_set_resource_and_label() function, or implicitly
+ * defined if no such call is made.
+ *
+ * @note
+ * For the power level management operations, only
+ * implementation for resource_type = FRSH_RT_PROCESSOR is mandatory,
+ * if the energy management module is present.
*
* @{
*
/**
- * frsh_contract_set_min_duration()
+ * frsh_contract_set_min_expiration()
*
- * This function sets the minimum duration that the application must
- * be able to run without finishing battery power. 0 would mean no
+ * This function sets the minimum battery expiration time that the
+ * system must be able to sustain without finishing battery power. A
+ * value of (0,0) would mean that the application does not have such
+ * requirement (this is the default if this parameter is not explicitly
+ * set).
**/
-int frsh_contract_set_min_duration(struct timespec min_duration,
- frsh_contract_t *contract);
+int frsh_contract_set_min_expiration(frsh_contract_t *contract,
+ frsh_rel_time_t min_expiration);
/**
- * frsh_contract_get_min_duration()
+ * frsh_contract_get_min_expiration()
*
* Get version of the previous function.
**/
-int frsh_contract_get_min_duration(const frsh_contract_t *contract,
- struct timespec *min_duration);
+int frsh_contract_get_min_expiration(const frsh_contract_t *contract,
+ frsh_rel_time_t *min_expiration);
/**
* frsh_contract_set_min_budget_pow()
*
- * Here we specify the minimum budget values corresponding to the
- * 3 power levels. The element order of the array goes from highest
- * power level to the lowest.
+ * Here we specify the minimum budget value corresponding to a single
+ * power level.
*
- * @param[in] pow_min_budget Pointer to the first element of the
- * minimum budget array. Elements
- * correspond to [0]->Highest PW,
- * [1]->Medium PW, [2]->Lowest PW.
+ * @param contract The affected contract.
+ * @param power_level The power level for which we are specifying the minimum budget.
+ * @param pow_min_budget The minimum budget requested for the power level.
*
* @return 0 if no error \n
- * FRSH_ERR_BAD_ARGUMENT if any of the pointers is NULL or the
- * budget values don't go in descending order.
+ * FRSH_ERR_BAD_ARGUMENT if power_level is greater than or equal to the value
+ * returned by frsh_get_power_levels budget value is not correct.
+ *
+ * @note
+ * If the minimum budget relative to one or more power levels has not been specified, then
+ * the framework may attempt to perform interpolation of the supplied values in
+ * order to infer them, if an accurate model for such operation is available.
+ * Otherwise, the contract is rejected at frsh_negotiate() time.
**/
-int frsh_contract_set_min_budget_pow(const struct timespec pow_min_budget[],
- frsh_contract_t *contract);
+int frsh_contract_set_min_budget_pow(frsh_contract_t *contract,
+ frsh_power_level_t power_level,
+ const frsh_rel_time_t *pow_min_budget);
/**
* frsh_contract_get_min_budget_pow()
* Get version of the previous function.
**/
int frsh_contract_get_min_budget_pow(const frsh_contract_t *contract,
- struct timespec pow_min_budget[]);
+ frsh_power_level_t power_level,
+ frsh_rel_time_t *pow_min_budget);
/**
* frsh_contract_set_max_budget_pow()
*
- * Here we specify the maximum budget values corresponding to the 3
- * power levels. The element order of the array goes from highest
- * power level to the lowest.
+ * Here we specify the maximum budget for a single power level.
*
- * @param[in] pow_max_budget Pointer to the first element of the
- * maximum budget array. Elements
- * correspond to [0]->Highest PW,
- * [1]->Medium PW, [2]->Lowest PW.
- *
- * @param contract (in/out) Contract
+ * @param contract The affected contract object.
+ * @param power_level The power level for which we are specifying the maximum budget.
+ * @param pow_max_budget The maximum budget requested for the power level.
*
* @return 0 if no error \n
* FRSH_ERR_BAD_ARGUMENT if any of the pointers is NULL or the
* budget values don't go in ascending order.
*
**/
-int frsh_contract_set_max_budget_pow(const struct timespec pow_max_budget[],
- frsh_contract_t *contract);
+int frsh_contract_set_max_budget_pow(frsh_contract_t *contract,
+ frsh_power_level_t power_level,
+ const frsh_rel_time_t *pow_max_budget);
/**
* frsh_contract_get_max_budget_pow()
* Get version of the previous function.
**/
int frsh_contract_get_max_budget_pow(const frsh_contract_t *contract,
- struct timespec pow_max_budget[]);
+ frsh_power_level_t power_level,
+ frsh_rel_time_t *pow_max_budget);
/**
- * frsh_contract_set_utilizations_pow()
- *
- * Here we specify pairs of
- * [ (budget_pmax, budget_pmedium, budget_plow) , Period ]
+ * frsh_contract_set_utilization_pow()
*
- * for contracts of discrete granularity.
+ * This function should be used for contracts with a period of
+ * discrete granularity. Here we specify, for each allowed period,
+ * the budget to be used for each power level.
*
- * param[in] utilization_set Discrete series of utilization values.
- * param contract (in/out) Contract object.
+ * @param contract The affected contract object.
+ * @param power_level The power level for which we specify budget and period.
+ * @param budget The budget to be used for the supplied power level and period.
+ * @param period One of the allowed periods (from the discrete set).
+ * @param period The deadline used with the associated period (from the discrete set).
**/
-int frsh_contract_set_utilizations_pow(const frsh_utilization_set_pow_t *utilization_set_pow,
- frsh_contract_t *contract);
+int frsh_contract_set_utilization_pow(frsh_contract_t *contract,
+ frsh_power_level_t power_level,
+ const frsh_rel_time_t *budget,
+ const frsh_rel_time_t *period,
+ const frsh_rel_time_t *deadline);
/**
- * frsh_contract_get_utilizations_pow()
+ * frsh_contract_get_utilization_pow()
*
* Get version of the previous function.
**/
-int frsh_contract_get_utilizations_pow(const frsh_utilization_set_pow_t *utilization_set_pow,
- frsh_contract_t *contract);
+int frsh_contract_get_utilization_pow(const frsh_contract_t *contract,
+ frsh_power_level_t power_level,
+ frsh_rel_time_t *budget,
+ frsh_rel_time_t *period,
+ frsh_rel_time_t *deadline);
//////////////////////////////////////////////////////////////////////
*
* Get the foreseen expiration time of the system battery(ies).
**/
-int frsh_battery_get_expiration(struct timespec *expiration);
+int frsh_battery_get_expiration(frsh_abs_time_t *expiration);
/*@}*/
* Here we define a capacity specification for all power levels.
**/
typedef struct {
- struct timespec budget[3];
- struct timespec period;
+ frsh_rel_time_t budget[3];
+ frsh_rel_time_t period;
} frsh_utilization_line_pow_t;
/**
* No threads must be ever attached to the contract identified by
* spare_id.
**/
-int frsh_feedback_set_spare(const frsh_contract_t *spare_contract);
+int frsh_feedback_set_spare(frsh_vres_id_t spare_id);
/**
* frsh_feedback_get_spare()
*
* Get version of the frsh_feedback_set_spare() function.
**/
-int frsh_feedback_get_spare(frsh_contract_t *spare_contract);
+int frsh_feedback_get_spare(frsh_vres_id_t *p_spare_id);
/**
* frsh_feedback_set_desired_budget()
* @param[in] p_budget_in
* The new budget to set as desired.
**/
-int frsh_feedback_set_desired_budget(frsh_vres_id_t vres_id, struct timespec *p_budget_in);
+int frsh_feedback_set_desired_budget(frsh_vres_id_t vres_id, frsh_rel_time_t *p_budget_in);
/**
* frsh_feedback_get_desired_budget()
* call, or the maximum budget set during contract negotiation, if no such
* call ever occurred.
**/
-int frsh_feedback_get_desired_budget(frsh_vres_id_t vres_id, struct timespec *p_budget_out);
+int frsh_feedback_get_desired_budget(frsh_vres_id_t vres_id, frsh_rel_time_t *p_budget_out);
/**
* frsh_feedback_get_actual_budget()
* for a given vres may change dynamically as a result of a call to the
* frsh_feedback_set_desired_budget() function for the same or other virtual resources.
**/
-int frsh_feedback_get_actual_budget(frsh_vres_id_t vres_id, struct timespec *budget);
+int frsh_feedback_get_actual_budget(frsh_vres_id_t vres_id, frsh_rel_time_t *budget);
/*@}*/
+++ /dev/null
-// -----------------------------------------------------------------------
-// Copyright (C) 2006 - 2007 FRESCOR consortium partners:
-//
-// Universidad de Cantabria, SPAIN
-// University of York, UK
-// Scuola Superiore Sant'Anna, ITALY
-// Kaiserslautern University, GERMANY
-// Univ. Politécnica Valencia, SPAIN
-// Czech Technical University in Prague, CZECH REPUBLIC
-// ENEA SWEDEN
-// Thales Communication S.A. FRANCE
-// Visual Tools S.A. SPAIN
-// Rapita Systems Ltd UK
-// Evidence ITALY
-//
-// See http://www.frescor.org for a link to partners' websites
-//
-// FRESCOR project (FP6/2005/IST/5-034026) is funded
-// in part by the European Union Sixth Framework Programme
-// The European Union is not liable of any use that may be
-// made of this code.
-//
-//
-// This file is part of FRSH Implementation
-//
-// FRSH API is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2, or (at your option)
-// any later version.
-//
-// FRSH API is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// distributed with FRSH API; see file COPYING. If not, write to the
-// Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// As a special exception, if you include this header file into source
-// files to be compiled, this header file does not by itself cause
-// the resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-// -----------------------------------------------------------------------
-//==============================================
-// ******** ******* ******** ** **
-// **///// /**////** **////// /** /**
-// ** /** /** /** /** /**
-// ******* /******* /********* /**********
-// **//// /**///** ////////** /**//////**
-// ** /** //** /** /** /**
-// ** /** //** ******** /** /**
-// // // // //////// // //
-//
-// FRSH(FRescor ScHeduler), pronounced "fresh"
-//==============================================
-//
-
-// This header file defines the interface to a hash table used to map
-// from a string key into an integer value. The number of entries in
-// the hash table is bounded by a maximum value, and therefore it is
-// not necessary to have a dynamic size table. The integer values are
-// non negative, so a negative value can be used as an error
-// indication. The key strings are assumed constant, so there is no
-// need to copy them.
-
-
-#ifndef FRSH_HASH_TABLE
-#define FRSH_HASH_TABLE
-
-#include <stdbool.h>
-
-/**
- * A configurable constant that defines the maximum length of the string keys
- */
-
-#define FRSH_HASH_TABLE_MAX_CHARS 21
-
-// Type that contains the status of an entry
-typedef enum {frsh_hash_empty, frsh_hash_valid, frsh_hash_cleaned}
-frsh_hash_entry_status_t;
-
-/**
- * Type that defines a table entry
- */
-typedef struct {
- char key[FRSH_HASH_TABLE_MAX_CHARS]; // array where the key is stored
- unsigned int value; // unsigned integer value
- frsh_hash_entry_status_t status; // indicates the entry status
-} frsh_hash_entry_t;
-
-/**
- * Type that defines a hash table
- */
-typedef struct {
- int size; // size of the table
- int max_chars; // maximum characters of the key strings
- int num; // current number of entries
- int cleaned; // current number of cleaned entries
- frsh_hash_entry_t * entry; // pointer to table of entries
- frsh_hash_entry_t * old_entry; // pointer to old table of entries, used
- // to recreate the table when necessary
-} frsh_hash_table_t;
-
-/**
- * Function that maps a string key into an integer value
- */
-unsigned int frsh_hash_function (const char *str, int max_chars);
-
-
-/**
- * Create a hash table to store up to the specified number of
- * keys equal to max_size. The maximum size of the String values
- * is specified in max_chars.
- * Returns: 0 if successful
- * FRSH_ERR_NO_SPACE if there is not enough memory available
- * FRSH_ERR_TOO_LARGE if max_chars exceeds FRSH_HASH_TABLE_MAX_CHARS
- */
-int frsh_hash_table_init (frsh_hash_table_t *table,
- int max_size, int max_chars);
-
-/**
- * Delete a hash table, eliminating the resources allocated to it
- */
-void frsh_hash_table_destroy (frsh_hash_table_t *table);
-
-/**
- * Empty a hash table, eliminating all entries from it
- */
-void frsh_hash_table_clean (frsh_hash_table_t *table);
-
-/**
- * Assign a value to a key. An older value is removed if present
- * Returns: 0 if successful
- * FRSH_ERR_NO_SPACE if the maximum number of keys would be exceeded
- */
-int frsh_hash_table_put (frsh_hash_table_t *table,
- const char * key, unsigned int value);
-
-/**
- * Get the value assigned to a key.
- * Returns 0 if successful or -1 if the key is not present
- */
-int frsh_hash_table_get (frsh_hash_table_t *table,
- const char * key, unsigned int * value);
-
-/**
- * Indicate whether or not the specified key is contained in the table
- */
-bool frsh_hash_table_contains_key (frsh_hash_table_t *table, const char * key);
-
-/**
- * Remove an entry from the table given a key
- * Returns 0 if successful, or -1 if the key is not contained in the table
- */
-int frsh_hash_table_remove (frsh_hash_table_t *table, const char * key);
-
-
-#endif // FRSH_HASH_TABLE
-
-
-
* The params member is a pointer to one of the
* following:
* FP: int (priority)
- * EDF: struct timespec (deadline)
+ * EDF: frsh_rel_time_t (deadline)
* RR: none
* TABLE_DRIVEN : struct frsh_table_driven_params_t
**/
* list of target windows
**/
typedef struct {
- struct timespec start;
- struct timespec end;
- struct timespec comp_time;
+ frsh_rel_time_t start;
+ frsh_rel_time_t end;
+ frsh_rel_time_t comp_time;
} frsh_target_window_t;
/**
* It shall be one of the following:
* FP: none
* EDF: none
- * RR: struct timespec (slice duration)
- * TABLE_DRIVEN : struct timespec (schedule duration)
+ * RR: frsh_rel_time_t (slice duration)
+ * TABLE_DRIVEN : frsh_rel_time_t (schedule duration)
**/
typedef void * frsh_sched_init_info_t;
**/
/**
- * frsh_contract_set_memory_reqs()
+ * frsh_contract_set_min_memory()
*
- * This function specifies in the contract the minimum and maximum
+ * This function specifies in the contract the minimum
* memory needed by the application.
*
* @param[in] min_memory Minimum needed memory in bytes.
* @param contract Contract, in-out argument.
*
* @return 0 if no error \n
- * FRSH_ERR_BAD_ARGUMENT if min_memory > max_memory
+ * FRSH_ERR_BAD_ARGUMENT if min_memory <0
*
**/
-int frsh_contract_set_memory_reqs(size_t min_memory,
- size_t max_memory,
+int frsh_contract_set_min_memory(size_t min_memory,
frsh_contract_t *contract);
/**
- * frsh_contract_get_memory_reqs()
+ * frsh_contract_get_min_memory()
*
- * This function gets the memory parameters from the contract.
+ * This function gets the minimum memory parameter from the contract.
*
* @param[in] contract Contract object
* @param[out] min_memory Placeholder for the minimum required
* memory.
+ *
+ * @return 0 if no error \n
+ * FRSH_ERR_BAD_ARGUMENT if one of the pointers is NULL
+ **/
+int frsh_contract_get_min_memory(const frsh_contract_t *contract,
+ size_t *min_memory);
+
+// frsh_contract_set_max_memory() is new
+// frsh_contract_get_max_memory() is new
+
+/**
+ * frsh_contract_set_max_memory()
+ *
+ * This function specifies in the contract the minimum
+ * memory needed by the application.
+ *
+ * @param[in] max_memory Maximum needed memory in bytes.
+ * @param contract Contract, in-out argument.
+ *
+ * FRSH_ERR_BAD_ARGUMENT if min_memory > max_memory
+ *
+ **/
+int frsh_contract_set_max_memory(size_t max_memory,
+ frsh_contract_t *contract);
+
+
+/**
+ * frsh_contract_get_max_memory()
+ *
+ * This function gets the maximum memory parameter from the contract.
+ *
+ * @param[in] contract Contract object
* @param[out] max_memory Placeholder for the maximum required
* memory.
*
* @return 0 if no error \n
* FRSH_ERR_BAD_ARGUMENT if one of the pointers is NULL
**/
-int frsh_contract_get_memory_reqs(const frsh_contract_t *contract,
- size_t *min_memory,
+int frsh_contract_get_max_memory(const frsh_contract_t *contract,
size_t *max_memory);
\
/** Minimum budget needed to perform a job. With the energy
module this will be an array **/ \
- struct timespec budget_min; \
+ frsh_rel_time_t budget_min; \
\
/** Maximum period that the system system can sustain **/ \
- struct timespec period_max; \
+ frsh_rel_time_t period_max; \
\
/** Maximum budget that the vres can use
(and would be happy to have). With the energy module
this will be an array **/ \
- struct timespec budget_max; \
+ frsh_rel_time_t budget_max; \
\
/** Minimum period for that
the system can use (and would be happy to have) **/ \
- struct timespec period_min; \
+ frsh_rel_time_t period_min; \
\
/** Set of discrete values for budget and period. With the
energy module this will be an array **/ \
bool d_equals_t; \
\
/** Deadline (will be ignored if d_equals_t is TRUE **/ \
- struct timespec deadline; \
+ frsh_rel_time_t deadline; \
\
/** Signal parameters for the case of
attempting to use too much budget **/ \
the allocated budget and capacity will be
maintained across negotiations and will
not be affected for dynamic spare capacity **/ \
- struct timespec stability_time; \
+ frsh_rel_time_t stability_time; \
\
/** Low level parameter related with the elegibility
preempt other threads **/ \
#define FRSH_CSECT_T_OPAQUE struct { \
frsh_csect_op_kind_t op_kind; \
frsh_sharedobj_handle_t obj_handle; \
- struct timespec wcet; \
- struct timespec blocking; \
+ frsh_rel_time_t wcet; \
+ frsh_rel_time_t blocking; \
frsh_csect_op_t op; \
frsh_memory_areas_t areas; \
frsh_memory_areas_t storage; \
**/
int frsh_csect_init
(frsh_sharedobj_handle_t obj_handle,
- struct timespec wcet,
+ frsh_rel_time_t wcet,
frsh_csect_t *csect);
**/
int frsh_csect_get_wcet
(const frsh_csect_t *csect,
- struct timespec *wcet);
+ frsh_rel_time_t *wcet);
/**
**/
int frsh_csect_get_blocking_time
(const frsh_csect_t *csect,
- struct timespec *blocking);
+ frsh_rel_time_t *blocking);
/**
#define FRSH_SHARED_OBJECTS_TYPES_H_
#include <time.h>
-#include "frsh_opaque_types.h"
+#include "frsh_core_types.h"
#include "frsh_configuration_parameters.h"
FRSH_CPP_BEGIN_DECLS
* awakening and replenishment periods.
* @param granularity FRSH_CONTINUOUS: Use min-max values,
* FRSH_DISCRETE: Use utilization_set.
- * @param utilization_set A structure of discrete pairs (budget,period)
+ * @param utilization_set A structure of discrete triples (budget,
+ * period, deadline)
* @param importance non-cooperative urgency indicator. Vres with
* higher importance will get all spare capacity des
* @param weight cooperative urgency indicator. At equal
* importance, spare capacity will be distributed
* proportionally to weight levels.
*
+ *
* @return 0 if successful \n
* FRSH_ERR_BAD_ARGUMENT : if contract is NULL \b or \n
* (budget_max value is grater than period_max or smaller than budget_min) \b or \n
*
**/
int frsh_contract_set_reclamation_params(frsh_contract_t *contract,
- const struct timespec *stability_time,
- const struct timespec *budget_max,
- const struct timespec *period_min,
+ const frsh_rel_time_t *stability_time,
+ const frsh_rel_time_t *budget_max,
+ const frsh_rel_time_t *period_min,
frsh_granularity_t granularity,
const frsh_utilization_set_t *utilization_set,
int importance,
**/
int frsh_contract_get_reclamation_params
(const frsh_contract_t *contract,
- struct timespec *stability_time,
- struct timespec *budget_max,
- struct timespec *period_min,
+ frsh_rel_time_t *stability_time,
+ frsh_rel_time_t *budget_max,
+ frsh_rel_time_t *period_min,
frsh_granularity_t *granularity,
frsh_utilization_set_t *utilization_set,
int *importance,
*
**/
int frsh_vres_get_remaining_stability_time(frsh_vres_id_t vres,
- struct timespec *stability_time);
+ frsh_rel_time_t *stability_time);
+
+
+/**
+ * frsh_vres_set_stability_time:
+ *
+ * Dynamically set the stability time for a given virtual resource to
+ * the specified interval. This operation sets a new value for the
+ * stability time associated with the virtual resource. As a result of
+ * this call the system may change the allocation of resources to the
+ * current virtual resource. Regardless of whether the resources are
+ * reallocated or not, the call resets the stability period so that
+ * the level of resources allocated to the virtual resource is kept
+ * stable for at least the duration of the requested interval. The
+ * possibly new values of budget and period are returned in the
+ * corresponding parameters
+ */
+
+int frsh_vres_set_stability_time
+ (frsh_vres_id_t vres,
+ const frsh_rel_time_t *stability_time,
+ frsh_rel_time_t *budget,
+ frsh_rel_time_t *period);
+
/**
* frsh_resource_get_capacity()
*
**/
int frsh_vres_decrease_capacity(frsh_vres_id_t vres,
- struct timespec new_budget,
- struct timespec new_period);
+ frsh_rel_time_t new_budget,
+ frsh_rel_time_t new_period);
/*@}*/
/** Granularity of spare capacity requirements: continuous or discrete **/
typedef enum {FRSH_GR_CONTINUOUS, FRSH_GR_DISCRETE} frsh_granularity_t;
-/** Utilization (C and T) **/
+/** Utilization (C, T, and D) **/
typedef struct {
- struct timespec budget; // Execution time
- struct timespec period; // Period
+ frsh_rel_time_t budget; // Execution time
+ frsh_rel_time_t period; // Period
+ frsh_rel_time_t deadline; // Deadline
} frsh_utilization_t;
/** List of utilization values **/
-/*
-** fosa_time.h
-**
-** Made by Miguel marciano
-** Login <miguel@namir.ctr.unican.es>
-**
-** Started on Mon Jan 21 20:01:04 2008 Miguel marciano
-** Last update Mon Jan 21 20:01:04 2008 Miguel marciano
-*/
+// -----------------------------------------------------------------------
+// Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//
+// Universidad de Cantabria, SPAIN
+// University of York, UK
+// Scuola Superiore Sant'Anna, ITALY
+// Kaiserslautern University, GERMANY
+// Univ. Politécnica Valencia, SPAIN
+// Czech Technical University in Prague, CZECH REPUBLIC
+// ENEA SWEDEN
+// Thales Communication S.A. FRANCE
+// Visual Tools S.A. SPAIN
+// Rapita Systems Ltd UK
+// Evidence ITALY
+//
+// See http://www.frescor.org for a link to partners' websites
+//
+// FRESCOR project (FP6/2005/IST/5-034026) is funded
+// in part by the European Union Sixth Framework Programme
+// The European Union is not liable of any use that may be
+// made of this code.
+//
+//
+// based on previous work (FSF) done in the FIRST project
+//
+// Copyright (C) 2005 Mälardalen University, SWEDEN
+// Scuola Superiore S.Anna, ITALY
+// Universidad de Cantabria, SPAIN
+// University of York, UK
+//
+// FSF API web pages: http://marte.unican.es/fsf/docs
+// http://shark.sssup.it/contrib/first/docs/
+//
+// This file is part of FRSH API
+//
+// FRSH API is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// FRSH API is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// distributed with FRSH API; see file COPYING. If not, write to the
+// Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// As a special exception, if you include this header file into source
+// files to be compiled, this header file does not by itself cause
+// the resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+// -----------------------------------------------------------------------
+//frsh_spare_capacity_types.h
+//==============================================
+// ******** ******* ******** ** **
+// **///// /**////** **////// /** /**
+// ** /** /** /** /** /**
+// ******* /******* /********* /**********
+// **//// /**///** ////////** /**//////**
+// ** /** //** /** /** /**
+// ** /** //** ******** /** /**
+// // // // //////// // //
+//
+// FRSH(FRescor ScHeduler), pronounced "fresh"
+//==============================================
+
#ifndef FRSH_TIME_H_
#define FRSH_TIME_H_
-#include <frsh_core_types.h>
-#include <frsh_core.h>
+#include "frsh_core_types.h"
+#include "frsh_core.h"
FRSH_CPP_BEGIN_DECLS
+/**
+ * @file frsh_time.h
+ **/
+
+
+/**
+ * \addtogroup core
+ **/
+/*@{*/
+
+/***********************
+ * Relational operations
+ ***********************/
+
+/**
+ * frsh_abs_time_smaller()
+ *
+ * Check if an absolute time is smaller than another one.
+ **/
+static inline bool frsh_abs_time_smaller(frsh_abs_time_t t1, frsh_abs_time_t t2)
+{
+ return fosa_abs_time_smaller(t1, t2);
+}
+
+/**
+ * frsh_rel_time_smaller()
+ *
+ * Check if a relative interval is smaller than another one.
+ **/
+static inline bool frsh_rel_time_smaller(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+ return fosa_rel_time_smaller(t1, t2);
+}
+
+/**
+ * frsh_abs_time_smaller_or_equal()
+ *
+ * Check if an absolute time is smaller than or equal to another one.
+ **/
+static inline bool frsh_abs_time_smaller_or_equal(frsh_abs_time_t t1, frsh_abs_time_t t2)
+{
+ return fosa_abs_time_smaller_or_equal(t1, t2);
+}
+
+/**
+ * frsh_rel_time_smaller_or_equal()
+ *
+ * Check if a relative interval is smaller than or equal to another one.
+ **/
+static inline bool frsh_rel_time_smaller_or_equal(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+ return fosa_rel_time_smaller_or_equal(t1, t2);
+}
+
+
+/***********************
+ * Arithmetic operations
+ ***********************/
+
+/**
+ * frsh_abs_time_incr()
+ *
+ * Add a relative interval to an absolute time.
+ */
+static inline frsh_abs_time_t frsh_abs_time_incr(frsh_abs_time_t base, frsh_rel_time_t interval)
+{
+ return fosa_abs_time_incr(base, interval);
+}
+
+/**
+ * frsh_rel_time_add()
+ *
+ * Add a relative interval to another one.
+ */
+static inline frsh_rel_time_t frsh_rel_time_add(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+ return fosa_rel_time_add(t1, t2);
+}
+
+/**
+ * frsh_abs_time_decr
+ *
+ * Subtract a relative interval from an absolute time.
+ */
+static inline frsh_abs_time_t frsh_abs_time_decr(frsh_abs_time_t time, frsh_rel_time_t interval)
+{
+ return fosa_abs_time_decr(time, interval);
+}
+
+/**
+ * frsh_rel_time_decr()
+ *
+ * Subtract a relative interval from another one.
+ */
+static inline frsh_rel_time_t frsh_rel_time_decr(frsh_rel_time_t total, frsh_rel_time_t part)
+{
+ return fosa_rel_time_decr(total, part);
+}
+
+
+/**
+ * frsh_abs_time_extract_interval()
+ *
+ * Subtract two absolute times to get a relative interval.
+ */
+static inline frsh_rel_time_t frsh_abs_time_extract_interval(frsh_abs_time_t past, frsh_abs_time_t future)
+{
+ return frsh_abs_time_extract_interval(past, future);
+}
+
+/**
+ * frsh_rel_time_times_integer()
+ *
+ * Multiplies a relative time by an integer
+ */
+static inline frsh_rel_time_t frsh_rel_time_times_integer(frsh_rel_time_t time, long multiplier)
+{
+ return fosa_rel_time_times_integer(time, multiplier);
+}
+
+/**
+ * frsh_rel_time_times_integer()
+ *
+ * Multiplies a relative time by an integer
+ **/
+static inline frsh_rel_time_t frsh_rel_time_divided_by_integer(frsh_rel_time_t time, long divider)
+{
+ return fosa_rel_time_divided_by_integer(time, divider);
+}
+
+
+/************************************
+ * Conversion to-from natural formats
+ * Note: Overflows may occur
+ ************************************/
+
+/**
+ * frsh_msec_to_rel_time()
+ *
+ * Convert an integer value of milliseconds into a relative time interval.
+ */
+static inline frsh_rel_time_t frsh_msec_to_rel_time(long msec)
+{
+ return fosa_msec_to_rel_time(msec);
+}
+
+/**
+ * frsh_rel_time_to_msec()
+ *
+ * Convert a relative interval into an integer number of milliseconds.
+ */
+static inline long frsh_rel_time_to_msec(frsh_rel_time_t interval)
+{
+ return fosa_rel_time_to_msec(interval);
+}
+
+/**
+ * frsh_msec_to_abs_time()
+ *
+ * Convert an integer value of milliseconds into an absolute time instant
+ */
+static inline frsh_abs_time_t frsh_msec_to_abs_time(long msec)
+{
+ return fosa_msec_to_abs_time(msec);
+}
+
+/**
+ * frsh_abs_time_to_msec()
+ *
+ * Convert an absolute instant into an integer number of milliseconds.
+ */
+static inline long frsh_abs_time_to_msec(frsh_abs_time_t instant)
+{
+ return fosa_abs_time_to_msec(instant);
+}
+
+/**
+ * frsh_usec_to_abs_time()
+ *
+ * Convert an integer value of microseconds into an absolute instant.
+ */
+static inline frsh_abs_time_t frsh_usec_to_abs_time(long usec)
+{
+ return fosa_usec_to_abs_time(usec);
+}
+
+
+/**
+ * frsh_rel_time_to_usec()
+ *
+ * Convert a relative interval into an integer number of microseconds.
+ */
+static inline long frsh_rel_time_to_usec(frsh_rel_time_t interval)
+{
+ return fosa_rel_time_to_usec(interval);
+}
+
+/******************************************
+ * Conversion to-from POSIX timespec format
+ ******************************************/
+
+/**
+ * frsh_timespec_to_rel_time()
+ *
+ * Convert a POSIX timespec value into a relative time interval.
+ */
+static inline frsh_rel_time_t frsh_timespec_to_rel_time(struct timespec interval)
+{
+ return fosa_timespec_to_rel_time(interval);
+}
+
+/**
+ * frsh_rel_time_to_timespec()
+ *
+ * Convert a relative interval into a POSIX timespec value.
+ */
+static inline struct timespec frsh_rel_time_to_timespec(frsh_rel_time_t interval)
+{
+ return fosa_rel_time_to_timespec(interval);
+}
+
+/**
+ * frsh_timespec_to_abs_time()
+ *
+ * Convert a POSIX timespec value into an absolute time.
+ */
+static inline frsh_abs_time_t frsh_timespec_to_abs_time(struct timespec time)
+{
+ return fosa_timespec_to_abs_time(time);
+}
+
+/**
+ * frsh_abs_time_to_timespec()
+ *
+ * Convert an absolute time into a POSIX timespec value.
+ */
+static inline struct timespec frsh_abs_time_to_timespec(frsh_abs_time_t time)
+{
+ return fosa_abs_time_to_timespec(time);
+}
+
+
/**
* frsh_eat()
*
- * Eat some time using system clock facilities
+ * Keep the thread busy executing for a given period of time.
**/
-static void inline frsh_eat(const struct timespec *cpu_time)
+static inline void frsh_eat(frsh_rel_time_t *cpu_time)
{
fosa_eat(cpu_time);
}
+/*@}*/
+
FRSH_CPP_END_DECLS
#endif /* !FOSA_TIME_H_ */
// made of this code.
//
//
-// This file is part of FRSH Implementation
+// based on previous work (FSF) done in the FIRST project
+//
+// Copyright (C) 2005 Mälardalen University, SWEDEN
+// Scuola Superiore S.Anna, ITALY
+// Universidad de Cantabria, SPAIN
+// University of York, UK
+//
+// FSF API web pages: http://marte.unican.es/fsf/docs
+// http://shark.sssup.it/contrib/first/docs/
+//
+// This file is part of FRSH API
//
// FRSH API is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// reasons why the executable file might be covered by the GNU General
// Public License.
// -----------------------------------------------------------------------
+//frsh_spare_capacity_types.h
//==============================================
// ******** ******* ******** ** **
// **///// /**////** **////// /** /**
//
// FRSH(FRescor ScHeduler), pronounced "fresh"
//==============================================
-//
-// This header file defines the interface to a pair of functions used
-// to manage a sinly linked list that is used to find free cells in
-// some external table.
-//
-// Parallel to the external table, there is a table of indexes
-// organized as a singly linked list; it is the free list. A separate
-// index, free_cell, indicates which is the first element of the sibly
-// linked list. The list is terminated with an index of -1.
+#ifndef FRSH_TIME_TYPES_H_
+#define FRSH_TIME_TYPES_H_
-#ifndef FRSH_FREELIST
-#define FRSH_FREELIST
+/**
+ * @file frsh_time_types.h
+ **/
-typedef struct {
- int * freelist;
- int first_free;
-} frsh_freelist_t;
/**
- * Initialize a free list adding all the cells to the list of free cells
- * The size of the list is specified by size.
- * Returns: 0 if successful
- * FRSH_ERR_NO_SPACE if there is not enough memory available
- */
-int frsh_freelist_init(frsh_freelist_t *list, int size);
+ * \addtogroup core
+ **/
+/*@{*/
-/**
- * Obtain the index of a free cell from the free list specified by list
- * the cell is removed from the list
- * Returns the index to the requested cell, or -1 if there are no free cells
- */
-int frsh_freelist_alloc(frsh_freelist_t *list);
+/** the time types shall have assignment and equal operators **/
+typedef fosa_abs_time_t frsh_abs_time_t;
+typedef fosa_rel_time_t frsh_rel_time_t;
-/**
- * Deallocate the cell specified by index cell adding it to the list
- * of free cells specified by list
- * Returns 0 if successful, or -1 if the cell was already free
- */
-int frsh_freelist_free(frsh_freelist_t *list, int cell);
+/*@}*/
-#endif // FRSH_FREELIST
+#endif /* !FRSH_TIME_TYPES_H_ */
+++ /dev/null
-// -----------------------------------------------------------------------
-// Copyright (C) 2006 - 2007 FRESCOR consortium partners:
-//
-// Universidad de Cantabria, SPAIN
-// University of York, UK
-// Scuola Superiore Sant'Anna, ITALY
-// Kaiserslautern University, GERMANY
-// Univ. Politécnica Valencia, SPAIN
-// Czech Technical University in Prague, CZECH REPUBLIC
-// ENEA SWEDEN
-// Thales Communication S.A. FRANCE
-// Visual Tools S.A. SPAIN
-// Rapita Systems Ltd UK
-// Evidence ITALY
-//
-// See http://www.frescor.org for a link to partners' websites
-//
-// FRESCOR project (FP6/2005/IST/5-034026) is funded
-// in part by the European Union Sixth Framework Programme
-// The European Union is not liable of any use that may be
-// made of this code.
-//
-//
-// based on previous work (FSF) done in the FIRST project
-//
-// Copyright (C) 2005 Mälardalen University, SWEDEN
-// Scuola Superiore S.Anna, ITALY
-// Universidad de Cantabria, SPAIN
-// University of York, UK
-//
-// FSF API web pages: http://marte.unican.es/fsf/docs
-// http://shark.sssup.it/contrib/first/docs/
-//
-// This file is part of FRSH API
-//
-// FRSH API is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2, or (at your option)
-// any later version.
-//
-// FRSH API is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// distributed with FRSH API; see file COPYING. If not, write to the
-// Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// As a special exception, if you include this header file into source
-// files to be compiled, this header file does not by itself cause
-// the resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-// -----------------------------------------------------------------------
-/*-----------------------------------------------------------------------
- * V1.0 Dec 2001
- *
- * 't i m e s p e c _ o p e r a t i o n s'
- *
- * H
- *
- * File 'timespec_operations.h' by MAR.
- * (july 2002) transformed into macros by Jul.
- * Some basic operations with the type 'timespec'.
- *
- * ----------------------------------------------------------------------
- * Copyright (C) 2001 Universidad de Cantabria, SPAIN
- *
- * Authors: Mario Aldea Rivas aldeam@ctr.unican.es
- * Michael Gonzalez Harbour mgh@ctr.unican.es
- *
- * MaRTE OS is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * MaRTE OS is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * distributed with MaRTE OS; see file COPYING. If not, write to the
- * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * As a special exception, if you link this unit with other files to
- * produce an executable, this unit does not by itself cause the
- * resulting executable to be covered by the GNU General Public License.
- * This exception does not however invalidate any other reasons why the
- * executable file might be covered by the GNU Public License.
- *
- *---------------------------------------------------------------------------*/
-// 16-Jul-2007 SANGORRIN corrections to msec_addto_timespec and msec2timespec
-// 23-Jul-2007 SANGORRIN moved t2d and d2t from frsh_time_operations
-// (TODO: test for __ALL__ the functions)
-// -----------------------------------------------------------------------
-
-#ifndef _MARTE_MISC_TIMESPEC_OPERATIONS_H_
-#define _MARTE_MISC_TIMESPEC_OPERATIONS_H_
-
-/**
- * @file timespec_operations.h
- **/
-
-#include <time.h> // for timespec
-#include <string.h> // for memset
-
-#define smaller_timespec(t1, t2) \
- ( \
- (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \
- (t1)->tv_nsec < (t2)->tv_nsec) \
- )
-
-#define smaller_or_equal_timespec(t1, t2) \
- ( \
- (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \
- (t1)->tv_nsec <= (t2)->tv_nsec) \
- )
-
-#define incr_timespec(t1, t2) \
-do { \
- (t1)->tv_sec += (t2)->tv_sec; \
- (t1)->tv_nsec += (t2)->tv_nsec; \
- if ((t1)->tv_nsec >= 1000000000) { \
- (t1)->tv_sec ++; \
- (t1)->tv_nsec -= 1000000000; \
- } \
-} while (0)
-
-#define decr_timespec(t1, t2) \
-do { \
- if ((t1)->tv_nsec < (t2)->tv_nsec) { \
- (t1)->tv_sec -= (t2)->tv_sec + 1; \
- (t1)->tv_nsec = (t1)->tv_nsec + 1000000000 - (t2)->tv_nsec; \
- } else { \
- (t1)->tv_sec -= (t2)->tv_sec; \
- (t1)->tv_nsec -= (t2)->tv_nsec; \
- } \
-} while (0)
-
-#define add_timespec( sum , t1 , t2 ) \
-do { \
- (sum)->tv_sec = (t1)->tv_sec + (t2)->tv_sec; \
- (sum)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \
- if ((sum)->tv_nsec >= 1000000000) { \
- (sum)->tv_sec ++; \
- (sum)->tv_nsec -= 1000000000; \
- } \
-} while (0)
-
-#define float_to_timespec( f1 , t1 ) \
-( \
- (t1)->tv_sec = (int)(f1), \
- (t1)->tv_nsec = (int)(((f1)-(float)((t1)->tv_sec))*1000000000.0), \
- (t1) \
-)
-
-#define float_to_timespec_value(f1, t1) \
-( \
- (t1).tv_sec = (int)(f1), \
- (t1).tv_nsec = (int)(((f1)-(float)((t1).tv_sec))*1000000000.0), \
- (t1) \
-)
-
-//---------------//
-// msec2timespec //
-//---------------//
-
-static inline struct timespec msec2timespec(long msec)
-{
- struct timespec result = {-1, -1};
-
- if (msec >= 1000) {
- result.tv_sec = msec/1000;
- result.tv_nsec = (msec % 1000) * 1000000;
- } else {
- result.tv_sec = 0;
- result.tv_nsec = msec * 1000000;
- }
-
- return result;
-}
-
-static inline long timespec2msec(const struct timespec *timespec)
-{
-
- return (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000;
-}
-
-
-#define HOURS_IN_MSECS 3600000
-#define MINUTES_IN_MSECS 60000
-
-#define HOURS_IN_TS 1000000
-#define MINUTES_IN_TS 100000
-
-static inline long timespec2msects(const struct timespec *timespec)
-{
- long msec_total = -1;
- long minutes = -1;
- long hours = -1;
-
- long remainder_msecs = -1;
- long timestamp = -1;
-
- msec_total = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000;
-
- hours = msec_total / HOURS_IN_MSECS;
- minutes = (msec_total % HOURS_IN_MSECS) / MINUTES_IN_MSECS;
- remainder_msecs = ( (msec_total % HOURS_IN_MSECS) % MINUTES_IN_MSECS);
-
- timestamp = hours*HOURS_IN_TS + minutes*MINUTES_IN_TS + remainder_msecs;
-
- return timestamp;
-}
-
-
-//------------------------//
-// timespec_lessthan_msec //
-//------------------------//
-
-static inline int timespec_lessthan_msec(struct timespec *timespec, long msec)
-{
- struct timespec msec_timespec = {0, 0};
-
- msec_timespec = msec2timespec(msec);
- return smaller_timespec(timespec, &msec_timespec);
-}
-
-//---------------------//
-// msec_addto_timespec //
-//---------------------//
-
-static inline void msec_addto_timespec(long msec, struct timespec *timespec)
-{
- struct timespec msec_timespec = {0, 0};
-
- msec_timespec = msec2timespec(msec);
- incr_timespec(timespec, &msec_timespec);
-}
-
-//--------------------------//
-// t2d (timespec to double) //
-//--------------------------//
-
-static inline double t2d(struct timespec time)
-{
- return time.tv_nsec*0.000000001 + (double)time.tv_sec;
-}
-
-//--------------------------//
-// d2t (double to timespec) //
-//--------------------------//
-
-static inline struct timespec d2t(double time)
-{
- struct timespec tmp;
-
- tmp.tv_sec = (long) time;
- tmp.tv_nsec = (long)((time - (double)tmp.tv_sec) * 1000000000);
-
- return tmp;
-}
-
-#endif /* _MARTE_MISC_TIMESPEC_OPERATIONS_H_ */