]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - fres/resalloc/fra_generic.h
Fixed race condition in allocator registration
[frescor/frsh.git] / fres / resalloc / fra_generic.h
index 09e4362254896c2dfffc3883acf66e930bd9fb02..650e3df6630bef6715dcd1def280b235a3e700d6 100644 (file)
@@ -1,3 +1,49 @@
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 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 (FRescor ScHeduler)                        */
+/*                                                                       */
+/* FRSH is free software; you can redistribute it and/or modify it       */
+/* under 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 along with FRSH; see file      */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                             */
+/*                                                                       */
+/* As a special exception, including FRSH header files in a file,        */
+/* instantiating FRSH generics or templates, or linking other files      */
+/* with FRSH objects to produce an executable application, does not      */
+/* by itself cause the resulting executable application 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.                                    */
+/**************************************************************************/
+
 /**
  * @file   fra_generic.h
  * @author Michal Sojka <sojkam1@fel.cvut.cz>
@@ -35,6 +81,26 @@ GAVL_CUST_NODE_INT_DEC(fres_vreses_nolock /* cust_prefix */,
 
 extern struct fres_vreses fres_vreses;
 
+struct fres_vres *
+fres_vreses_find_label(fres_block_label *label, fres_block_resource *res);
+
+/** Registry of all threads in an application that are bound to a VRES. */
+struct fres_threads_vres {
+        fosa_mutex_t mutex;     /**< Mutex for manipulation with vreses tree. If all allocators are executed from one executor, locking can be avoided. */
+        gavl_cust_root_field_t threads; /**< Container of all virtual resources */
+};
+
+GAVL_CUST_NODE_INT_DEC(fres_threads_vres_nolock        /* cust_prefix */,
+                      struct fres_threads_vres /* cust_root_t */,
+                      struct fres_thread_vres  /* cust_item_t */,
+                      fres_thread_vres_key_t   /* cust_key_t */,
+                      threads                  /* cust_root_node */,
+                      node                     /* cust_item_node */,
+                      thread_vres              /* cust_item_key */,
+                      fres_thread_vres_cmp     /* cust_cmp_fnc */)
+
+extern struct fres_threads_vres fres_threads_vres;
+
 
 /**
  * Structure describing FRES allocator. It is used as a parameter to
@@ -53,7 +119,7 @@ struct fres_allocator {
         * fres_vres::new.
         * 
         * @param vres VRES to create.
-        * @param priv
+        * @param priv User supplied pointer registered by fra_register()
         * 
         * @return Zero in case of success, nonzero error code on error.
         */
@@ -63,19 +129,32 @@ struct fres_allocator {
         * parameters in fres_vres::new. The currenlty allocated
         * parameters are in fres_vres::allocated. This function
         * should change the fres_vres::perceived to @a fres_vres::new
-        * at some point in time (depending on the kind of the change)
-        * as the fres_vres::allocated parameters will be freed after
-        * the return of this function.
+        * at some point in time (depending on the kind of the change).
+        * The fres_vres::allocated parameters will be freed after
+        * the return of this function and then fres_vres::allocated
+        * will be set to fres_vres::new.
         * 
         * @param vres VRES to change.
-        * @param priv
+        * @param priv User supplied pointer registered by fra_register()
         * 
         * @return Zero in case of success, nonzero error code on error.
         */
        int (*change_vres)(fres_vres_t *vres, void *priv);
+       /** 
+        * Cancel the CRES
+        * 
+        * @param cancel_vres VRES to cancel
+        * 
+        * @return Zero on succaess, non-zero error code on error.
+        */
+       int (*cancel_vres)(fres_vres_t *vres, void *priv);
        /*@}*/
+
        /** @name Full interface
-        * The allocator can influence the order of applying changes. */
+        * 
+        * Full interface provides a way for the allocator to
+        * influence the order of applying changes.
+        */
        /*@{*/
        /**
         * A more general (and more compilcated) allocator
@@ -90,7 +169,8 @@ struct fres_allocator {
         * fres_vres::perceived to @a fres_vres::new at some point in
         * time (depending on the kind of the change) as the
         * fres_vres::allocated parameters will be freed after the
-        * return of this function.
+        * return of this function. When the fres_vres::new contains
+        * no blocks, the VRES should be canceled.
         * 
         * @param vreses Array of pointers to VRESes.
         * @param length The number of elements in @a vreses.
@@ -101,26 +181,54 @@ struct fres_allocator {
        int (*apply_vres_changes)(fres_vres_t *vreses[], unsigned length, void *priv);
        /*@}*/
 
-       /** 
-        * 
-        * 
-        * @param cancel_vres 
-        * 
-        * @return 
-        */
-       int (*cancel_vres)(fres_vres_t *vres, void *priv);
+       /** @name Feedback module support */
+       /*@{*/
+       int (*set_spare_bandwidth)(fres_vres_t *vres);
+       int (*get_desired_budget)(fres_vres_t *vres, frsh_rel_time_t *p_budget_out);
+       int (*set_desired_budget)(fres_vres_t *vres_id, frsh_rel_time_t *p_budget_in);
+       int (*get_actual_budget)(fres_vres_t *vres_id, frsh_rel_time_t *budget);
+       /*@}*/
+
+       int (*bind_thread)(fres_vres_t *vres, fosa_thread_id_t thread);
+       int (*unbind_thread)(fosa_thread_id_t thread);
+
+       int (*vres_get_job_usage)(const fres_vres_t *vres, frsh_rel_time_t *spent);
+       int (*vres_get_remaining_budget)(const fres_vres_t *vres, frsh_rel_time_t *budget);
+       int (*vres_get_usage)(const fres_vres_t *vres, frsh_rel_time_t *spent);
+
        void *priv;             /**< Pointer to allocator's private data */
+
+       /**
+        * A callback called whenever the resource allocator is to be
+        * activated by fra_activate().
+        */
+       int (*activate_callback)(forb_orb orb);
 };
 
 fres_resource_allocator fra_new(forb_orb orb,
                                forb_executor_t *executor,
                                struct fres_allocator *allocator);
 
-int fra_register(forb_orb orb,
-                fres_contract_broker fcb,
-                forb_executor_t *executor,
-                struct fres_allocator *allocator);
+int fra_registry_init(forb_orb            orb,
+                     fres_contract_broker fcb,
+                     forb_executor_t      *executor);
+int fra_register(struct fres_allocator *allocator);
+int fra_activate(frsh_resource_type_t res_type,
+                frsh_resource_id_t   res_id);
+struct fres_allocator *fra_get(frsh_resource_type_t res_type,
+                              frsh_resource_id_t   res_id);
 
 fres_vres_t *fra_get_vres(fres_contract_id_t *id);
 
+int fra_insert_thread_vres(const fosa_thread_id_t *id,
+                          int vres_type,
+                          fres_vres_t *vres);
+int fra_delete_thread_vres(const fosa_thread_id_t *id,
+                          int vres_type);
+fres_thread_vres_t *fra_get_thread_vres(const fosa_thread_id_t *id,
+                                       int vres_type);
+fres_vres_t *fra_get_vres_thread_vres(const fosa_thread_id_t *id,
+                                     int vres_type);
+
 #endif
+