From 5c8e141653df488eaefd495f239a9aef51c9e0a7 Mon Sep 17 00:00:00 2001 From: sangorrin Date: Tue, 22 Apr 2008 09:27:04 +0000 Subject: [PATCH] add the infraestructure for storing the negotiated contracts and performing the analysis through the analysis module. TODO: perform a test with those contracts to admit them. In the end the module implementation could be replaced by the cpu implementation. Spare capacity is not done yet. Now we have to implement negotiation and cancel of contracts. git-svn-id: http://www.frescor.org/private/svn/frescor/fna/trunk@1135 35b4ef3e-fd22-0410-ab77-dab3279adceb --- src_frescan/frescan_bwres.c | 45 ++++--- src_frescan/frescan_bwres.h | 3 +- src_frescan/frescan_bwres_analysis.c | 123 ++++++++++++++---- src_frescan/frescan_bwres_analysis.h | 80 ++++++++---- src_frescan/frescan_bwres_fna.c | 20 +-- src_frescan/frescan_bwres_messages.c | 21 +-- src_frescan/frescan_bwres_requests.h | 21 +-- src_frescan/frescan_bwres_threads.c | 32 ++++- src_frescan/frescan_config.h | 2 + src_frescan/frescan_data.h | 31 ++++- src_frescan/frescan_debug.h | 5 +- tests/tests_frescan/test_frescan_bwres_init.c | 2 +- .../test_frescan_bwres_negotiate_in_master.c | 25 +++- .../test_frescan_bwres_negotiate_in_slave.c | 23 ++-- 14 files changed, 311 insertions(+), 122 deletions(-) diff --git a/src_frescan/frescan_bwres.c b/src_frescan/frescan_bwres.c index 875138f..33918f2 100644 --- a/src_frescan/frescan_bwres.c +++ b/src_frescan/frescan_bwres.c @@ -18,6 +18,7 @@ #include "frescan_bwres_requests.h" #include "frescan_bwres_messages.h" #include "frescan_bwres_threads.h" +#include "frescan_bwres_analysis.h" #include "frescan_data.h" #include "frescan_debug.h" #include "frescan_config.h" @@ -32,19 +33,27 @@ int frescan_bwres_init(frescan_network_t net) { int ret; - frescan_server_params_t params; + frescan_server_params_t server_params; // TODO: improve this... + frescan_sa_init_params_t sa_init_params; // TODO: improve this... - // TODO: server params must be configurable - // TODO: initialization tree like in DTM - params.values.budget = 5; - params.values.period.tv_sec = 1; - params.values.period.tv_nsec = 0; - params.prio = FRESCAN_BWRES_NEG_MESSAGES_PRIO; + sa_init_params.max_prio = 30; + sa_init_params.min_prio = 1; - ret = frescan_servers_create(net, ¶ms, + ret = frescan_sa_init(&the_networks[net].scenario, + &sa_init_params); + if (ret != 0) return ret; + + server_params.values.budget = 5; + server_params.values.period.tv_sec = 1; + server_params.values.period.tv_nsec = 0; + server_params.prio = FRESCAN_BWRES_NEG_MESSAGES_PRIO; + + ret = frescan_servers_create(net, &server_params, &the_networks[net].neg_messages_ss_id); if (ret != 0) return ret; + // TODO: we have to add this negotiation contracts to the sa table + ret = frescan_bwres_robjs_init(FRESCAN_REPLY_OBJECTS_MX_CEILING); if (ret != 0) return ret; @@ -77,7 +86,8 @@ int frescan_bwres_init(frescan_network_t net) int frescan_bwres_negotiate(frescan_network_t net, const frescan_contract_t *contract, - frescan_ss_t *id) + frescan_ss_t *id, + bool *accepted) { int ret; frescan_request_id_t req; @@ -125,22 +135,18 @@ int frescan_bwres_negotiate(frescan_network_t net, switch (req_data->return_value) { case FRESCAN_REQ_ACCEPTED: DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation OK\n"); + *accepted = true; *id = req_data->ss; - ret = 0; + server_params.prio = req_data->final_values.server_prio; + ret = frescan_servers_update(net, &server_params, *id); + if (ret != 0) return ret; break; case FRESCAN_REQ_NOT_ACCEPTED: DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation FAIL\n"); + *accepted = false; ret = frescan_servers_destroy(net, req_data->ss); if (ret != 0) return ret; - ret = -1; - break; - - case FRESCAN_REQ_ERROR: - DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation ERROR\n"); - ret = frescan_servers_destroy(net, req_data->ss); - if (ret != 0) return ret; - ret = -1; break; default: @@ -149,6 +155,5 @@ int frescan_bwres_negotiate(frescan_network_t net, } frescan_requests_free(req); - - return ret; // TODO: distinguish errors and failed negotiations + return 0; } diff --git a/src_frescan/frescan_bwres.h b/src_frescan/frescan_bwres.h index 830ac76..af476d6 100644 --- a/src_frescan/frescan_bwres.h +++ b/src_frescan/frescan_bwres.h @@ -24,7 +24,8 @@ extern int frescan_bwres_init(frescan_network_t net); extern int frescan_bwres_negotiate(frescan_network_t net, const frescan_contract_t *contract, - frescan_ss_t *id); + frescan_ss_t *id, + bool *accepted); // TODO: add other functions: renegotiate, cancel... diff --git a/src_frescan/frescan_bwres_analysis.c b/src_frescan/frescan_bwres_analysis.c index eda9c8c..cda54ee 100644 --- a/src_frescan/frescan_bwres_analysis.c +++ b/src_frescan/frescan_bwres_analysis.c @@ -75,77 +75,121 @@ #include "frescan_bwres_analysis.h" #undef ERROR #include "frescan_debug.h" -// #include "frsh_sa_tools.h" - /** * frescan_sa_init() - init the scenario + * + * @scenario: the scenario (in out) + * @params: init params (in) */ -int frescan_sa_init(frsh_sa_scenario_t *scenario, // in out - const frsh_sa_init_params_t *params) // in +int frescan_sa_init(frescan_sa_scenario_t *scenario, + const frescan_sa_init_params_t *params) { // int ret; // // ret = frsh_sa_scenario_init(scenario, params); // return ret; - WARNING("not implemented, returning 0\n"); + + INIT_LIST_HEAD(&scenario->contracts_head.list); + scenario->init_params = *params; return 0; } /** * frescan_sa_add_contract() - add a contract to the scenario + * + * @scenario: the scenario (in out) + * @contract: the new contract (in) + * @ss: the preallocated ss identificator (in) + * @node: the node this contract belongs to (in) */ -int frescan_sa_add_contract(frsh_sa_scenario_t *scenario, // in out - const frsh_contract_t *contract, // in - frsh_vres_index_t id) // in +int frescan_sa_add_contract(frescan_sa_scenario_t *scenario, + const frescan_contract_t *contract, + frescan_ss_t ss, + frescan_node_t node) { // int ret; // // ret = frsh_sa_scenario_add_vres(scenario, contract, id); // return ret; - WARNING("not implemented, returning 0\n"); + frescan_sa_contract_t *sa_contract; + + sa_contract = &scenario->contracts[node][ss]; + + sa_contract->contract = *contract; + sa_contract->node = node; + sa_contract->ss = ss; + + list_add_tail(&sa_contract->list, + &scenario->contracts_head.list); + return 0; } /** * frescan_sa_update_contract() - update a contract in the scenario + * + * @scenario: the scenario (in out) + * @ss: the ss identificator (in) + * @contract: the values to update the contract (in) + * @node: the node this contract belongs to (in) */ -int frescan_sa_update_contract(frsh_sa_scenario_t *scenario, // in out - frsh_vres_index_t id, // in - const frsh_contract_t *contract) // in +int frescan_sa_update_contract(frescan_sa_scenario_t *scenario, + frescan_ss_t ss, + const frescan_contract_t *contract, + frescan_node_t node) { // int ret; // // ret = frsh_sa_scenario_modify_vres(scenario, id, *contract); // return ret; - WARNING("not implemented, returning 0\n"); + frescan_sa_contract_t *sa_contract; + + sa_contract = &scenario->contracts[node][ss]; + + sa_contract->contract = *contract; + sa_contract->node = node; + sa_contract->ss = ss; + return 0; } /** * frescan_sa_remove_contract() - remove a contract from the scenario + * + * @scenario: the scenario (in out) + * @ss: the ss to remove (in) + * @node: the node this contract belongs to (in) */ -int frescan_sa_remove_contract(frsh_sa_scenario_t *scenario, // in out - frsh_vres_index_t id) // in +int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario, + frescan_ss_t ss, + frescan_node_t node) { // int ret; // // ret = frsh_sa_scenario_del_vres(scenario, id); // return ret; - WARNING("not implemented, returning 0\n"); + frescan_sa_contract_t *sa_contract; + + sa_contract = &scenario->contracts[node][ss]; + list_del(&sa_contract->list); + return 0; } /** * frescan_sa_sched_test() - perform a scheduling test on the scenario + * + * @scenario: the scenario (in out) + * @success: if the scenario is schedulable or not (out) */ -int frescan_sa_sched_test(frsh_sa_scenario_t *scenario, // in out - bool *success) // out +int frescan_sa_sched_test(frescan_sa_scenario_t *scenario, + bool *success) { // int ret; // @@ -169,15 +213,35 @@ int frescan_sa_sched_test(frsh_sa_scenario_t *scenario, // in out // error: // *success = false; // return ret; - WARNING("not implemented, returning 0\n"); + + struct list_head *pos; + frescan_sa_contract_t *sa_contract; + + list_for_each(pos, &scenario->contracts_head.list) { + sa_contract = list_entry(pos, frescan_sa_contract_t, list); + sa_contract->final_values.server_prio = sa_contract->contract.prio; + DEBUG(FRESCAN_SA_ENABLE_DEBUG, + "sa_contract, node:%d ss:%d, c:%d t:(%d,%d) p:%d\n", + sa_contract->node, sa_contract->ss, + sa_contract->contract.min_values.budget, + sa_contract->contract.min_values.period.tv_sec, + sa_contract->contract.min_values.period.tv_nsec, + sa_contract->contract.prio); + } + + WARNING("test not implemented, returning 0 and success by default\n"); + *success = true; + return 0; } /** * frescan_sa_spare_capacity() - distribute the remaining spare capacity + * + * @scenario: the scenario (in out) */ -int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out +int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario) { // int ret; // @@ -189,18 +253,27 @@ int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out } /** - * sa_get_final_values() - get the final values + * frescan_sa_get_final_values() - get the final values + * + * @scenario: the scenario (in) + * @ss: the ss from which we want the final values (in) + * @node: the node this contract belongs to (in) + * @final_values: the final values (out) */ -int sa_get_final_values(const frsh_sa_scenario_t *scenario, // in - frsh_vres_index_t id, // in - frescan_sa_final_values_t *final_values) // out + +int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario, + frescan_ss_t ss, + frescan_node_t node, + frescan_sa_final_values_t *final_values) { // final_values->budget = scenario->sa_vres_alloc[id].c; // final_values->period = scenario->sa_vres_alloc[id].t; // final_values->deadline = scenario->sa_vres_alloc[id].d; // final_values->priority = scenario->sa_vres_alloc[id].p; // return 0; - WARNING("not implemented, returning 0\n"); + + *final_values = scenario->contracts[node][ss].final_values; + return 0; } diff --git a/src_frescan/frescan_bwres_analysis.h b/src_frescan/frescan_bwres_analysis.h index c2e2e5b..ad9fca6 100644 --- a/src_frescan/frescan_bwres_analysis.h +++ b/src_frescan/frescan_bwres_analysis.h @@ -72,66 +72,92 @@ * */ -#ifndef _FRESCAN_SCHED_ANALYSIS_H_ -#define _FRESCAN_SCHED_ANALYSIS_H_ +#ifndef _FRESCAN_BWRES_ANALYSIS_H_ +#define _FRESCAN_BWRES_ANALYSIS_H_ -#include "frsh.h" - -// #include "frsh_sa_scenario.h" -typedef int frsh_sa_scenario_t; -typedef int frsh_sa_init_params_t; -typedef int frsh_vres_index_t; -typedef int frescan_sa_final_values_t; +#include "frescan.h" +#include "frescan_data.h" /** * frescan_sa_init() - init the scenario + * + * @scenario: the scenario (in out) + * @params: init params (in) */ -extern int frescan_sa_init(frsh_sa_scenario_t *scenario, // in out - const frsh_sa_init_params_t *params); // in +extern int frescan_sa_init(frescan_sa_scenario_t *scenario, + const frescan_sa_init_params_t *params); /** * frescan_sa_add_contract() - add a contract to the scenario + * + * @scenario: the scenario (in out) + * @contract: the new contract (in) + * @ss: the preallocated ss identificator (in) + * @node: the node this contract belongs to (in) */ -extern int frescan_sa_add_contract(frsh_sa_scenario_t *scenario, // in out - const frsh_contract_t *contract, // in - frsh_vres_index_t id); // in +extern int frescan_sa_add_contract(frescan_sa_scenario_t *scenario, + const frescan_contract_t *contract, + frescan_ss_t ss, + frescan_node_t node); /** * frescan_sa_update_contract() - update a contract in the scenario + * + * @scenario: the scenario (in out) + * @ss: the ss identificator (in) + * @contract: the values to update the contract (in) + * @node: the node this contract belongs to (in) */ -extern int frescan_sa_update_contract(frsh_sa_scenario_t *scenario, // in out - frsh_vres_index_t id, // in - const frsh_contract_t *contract);// in +extern int frescan_sa_update_contract(frescan_sa_scenario_t *scenario, + frescan_ss_t ss, + const frescan_contract_t *contract, + frescan_node_t node); /** * frescan_sa_remove_contract() - remove a contract from the scenario + * + * @scenario: the scenario (in out) + * @ss: the ss to remove (in) + * @node: the node this contract belongs to (in) */ -extern int frescan_sa_remove_contract(frsh_sa_scenario_t *scenario, // in out - frsh_vres_index_t id); // in +extern int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario, + frescan_ss_t ss, + frescan_node_t node); /** * frescan_sa_sched_test() - perform a scheduling test on the scenario + * + * @scenario: the scenario (in out) + * @success: if the scenario is schedulable or not (out) */ -extern int frescan_sa_sched_test(frsh_sa_scenario_t *scenario, // in out - bool *success); // out +extern int frescan_sa_sched_test(frescan_sa_scenario_t *scenario, + bool *success); /** * frescan_sa_spare_capacity() - distribute the remaining spare capacity + * + * @scenario: the scenario (in out) */ -extern int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario); // in out +extern int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario); /** - * sa_get_final_values() - get the final values + * frescan_sa_get_final_values() - get the final values + * + * @scenario: the scenario (in) + * @ss: the ss from which we want the final values (in) + * @node: the node this contract belongs to (in) + * @final_values: the final values (out) */ -extern int sa_get_final_values(const frsh_sa_scenario_t *scenario, // in - frsh_vres_index_t id, // in - frescan_sa_final_values_t *final_values); // out +extern int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario, + frescan_ss_t ss, + frescan_node_t node, + frescan_sa_final_values_t *final_values); -#endif // _FRESCAN_REQUESTS_QUEUE_H_ +#endif // _FRESCAN_BWRES_ANALYSIS_H_ diff --git a/src_frescan/frescan_bwres_fna.c b/src_frescan/frescan_bwres_fna.c index 10babf2..2262ac6 100644 --- a/src_frescan/frescan_bwres_fna.c +++ b/src_frescan/frescan_bwres_fna.c @@ -111,35 +111,39 @@ int frescan_fna_contract_negotiate const frsh_contract_t *contract, fna_vres_id_t *vres) { - int accepted; + int ret; + bool accepted; frescan_ss_t ss; frescan_contract_t frescan_contract; DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "frsh contract->frescan contract\n"); - // TODO: budget is stored as number of can frames in tv_sec + // NOTE: budget is stored as number of can frames in tv_sec frescan_contract.min_values.budget = contract->budget_min.tv_sec; frescan_contract.min_values.period = contract->period_max; frescan_contract.max_values.budget = contract->budget_max.tv_sec; frescan_contract.max_values.period = contract->period_min; + // TODO: put 0 if we want the sa module to assign the prios frescan_contract.prio = contract->preemption_level; DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "calling frescan_bwres_negotiate\n"); - accepted = frescan_bwres_negotiate((frescan_network_t)resource_id, - &frescan_contract, - &ss); // TODO: associate the contract with the ss + ret = frescan_bwres_negotiate((frescan_network_t)resource_id, + &frescan_contract, + &ss, + &accepted); + if (ret != 0) return -1; - if (accepted == 0) { + if (accepted == true) { DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "contract accepted\n"); *vres = (fna_vres_id_t)ss; + return 0; } else { DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "contract not accepted\n"); + return -1; // TODO: change to constant FNA_REJECTED } - - return accepted; } /** diff --git a/src_frescan/frescan_bwres_messages.c b/src_frescan/frescan_bwres_messages.c index df69e1f..6d1982a 100644 --- a/src_frescan/frescan_bwres_messages.c +++ b/src_frescan/frescan_bwres_messages.c @@ -208,20 +208,21 @@ static int frescan_cancel_message_to_request(const uint8_t *msg, * ======================= * This message is sent from the MASTER to a slave as a reply to a * FRESCAN_REQ_NEG or a FRESCAN_REQ_RENEG, to say if they were admited. - * It contains the type 'REPNEG', the request ID of the slave and a - * return value to say if the contract is admited, not admited or if - * there was an error. + * It contains the type 'REPNEG', the request ID of the slave, a + * return value to say if the contract is admited or not, and the final + * values if it was admited * - * +-------------------------------+ - * | 'REPNEG' | REQ | RETURN_VALUE | - * +-------------------------------+ + * +----------------------------------------------+ + * | 'REPNEG' | REQ | RETURN_VALUE | FINAL_VALUES | + * +----------------------------------------------+ * */ struct frescan_rep_neg_message_t { - frescan_request_type_t type; - frescan_request_id_t req; - frescan_request_retval_t return_value; + frescan_request_type_t type; + frescan_request_id_t req; + frescan_request_retval_t return_value; + frescan_sa_final_values_t final_values; } __attribute__ ((packed)); static int frescan_request_to_repneg_message(const frescan_request_data_t *data, @@ -234,6 +235,7 @@ static int frescan_request_to_repneg_message(const frescan_request_data_t *data, repneg_msg->type = FRESCAN_REP_NEG; repneg_msg->req = data->req; repneg_msg->return_value = data->return_value; + repneg_msg->final_values = data->final_values; return sizeof(struct frescan_rep_neg_message_t); } @@ -248,6 +250,7 @@ static int frescan_repneg_message_to_request(const uint8_t *msg, data->type = FRESCAN_REP_NEG; data->req = repneg_msg->req; data->return_value = repneg_msg->return_value; + data->final_values = repneg_msg->final_values; return 0; } diff --git a/src_frescan/frescan_bwres_requests.h b/src_frescan/frescan_bwres_requests.h index b25e203..5bc4485 100644 --- a/src_frescan/frescan_bwres_requests.h +++ b/src_frescan/frescan_bwres_requests.h @@ -32,7 +32,8 @@ * @ss: the local sporadic server ID * @request_node: the node that performed the request * @req: the request id of the SLAVE to identify the request in the reply - * @return_value: the value returned in a Reply + * @return_value: the value returned in a Reply (accepted or not) + * @final_values: the values for the ss after the negotiation * @net: the network instance where this request belongs to * @robj: a reply object to wait until a negotiation is completed * @@ -50,18 +51,18 @@ typedef enum { typedef enum { FRESCAN_REQ_ACCEPTED = 0, // the (re)negotiation is accepted FRESCAN_REQ_NOT_ACCEPTED = 1, // the (re)negotiation is not accepted - FRESCAN_REQ_ERROR = 2, // error during the (re)negotiation } frescan_request_retval_t; typedef struct { - frescan_request_type_t type; - frescan_contract_t *contract; - frescan_ss_t ss; - frescan_node_t request_node; - frescan_request_id_t req; - frescan_request_retval_t return_value; - frescan_network_t net; - frescan_robj_id_t robj; + frescan_request_type_t type; + frescan_contract_t *contract; + frescan_ss_t ss; + frescan_node_t request_node; + frescan_request_id_t req; + frescan_request_retval_t return_value; + frescan_sa_final_values_t final_values; + frescan_network_t net; + frescan_robj_id_t robj; } frescan_request_data_t; /** diff --git a/src_frescan/frescan_bwres_threads.c b/src_frescan/frescan_bwres_threads.c index 86eda2e..3216a1b 100644 --- a/src_frescan/frescan_bwres_threads.c +++ b/src_frescan/frescan_bwres_threads.c @@ -19,6 +19,7 @@ #include "frescan_bwres_threads.h" #include "frescan_bwres_messages.h" #include "frescan_bwres_requests.h" +#include "frescan_bwres_analysis.h" #include "frescan_config.h" #include "frescan_debug.h" #include "frescan_data.h" @@ -175,19 +176,37 @@ static void frescan_manager_neg(frescan_request_data_t *req_data) DEBUG(FRESCAN_MANAGER_ENABLE_DEBUG, "negotiation request\n"); if (the_networks[req_data->net].local_node == FRESCAN_NEG_MASTER_NODE) { + // scheduling analysis + ret = frescan_sa_add_contract + (&the_networks[req_data->net].scenario, + req_data->contract, + req_data->ss, + req_data->request_node); + assert(ret == 0); - // NOTE: req_data->ss is an INPUT parameter - accepted = true; // TODO: sched analysis - ret = 0; // TODO: sched analysis + ret = frescan_sa_sched_test + (&the_networks[req_data->net].scenario, + &accepted); + assert(ret == 0); if (accepted) { + ret = frescan_sa_get_final_values + (&the_networks[req_data->net].scenario, + req_data->ss, + req_data->request_node, + &req_data->final_values); + assert(ret == 0); req_data->return_value = FRESCAN_REQ_ACCEPTED; } else { - req_data->return_value = (ret == 0) ? - FRESCAN_REQ_NOT_ACCEPTED : - FRESCAN_REQ_ERROR; + ret = frescan_sa_remove_contract + (&the_networks[req_data->net].scenario, + req_data->ss, + req_data->request_node); + assert(ret == 0); + req_data->return_value = FRESCAN_REQ_NOT_ACCEPTED; } + // signal or reply the results if (req_data->request_node == FRESCAN_NEG_MASTER_NODE) { DEBUG(FRESCAN_MANAGER_ENABLE_DEBUG, "master local\n"); ret = frescan_bwres_robjs_signal(req_data->robj); @@ -241,6 +260,7 @@ static void frescan_manager_repneg(frescan_request_data_t *req_data) assert(ret == 0); neg_req_data->return_value = req_data->return_value; + neg_req_data->final_values = req_data->final_values; ret = frescan_bwres_robjs_signal(neg_req_data->robj); assert(ret == 0); diff --git a/src_frescan/frescan_config.h b/src_frescan/frescan_config.h index d19f1b3..0bb0c9b 100644 --- a/src_frescan/frescan_config.h +++ b/src_frescan/frescan_config.h @@ -45,6 +45,8 @@ #define FRESCAN_ACCEPTOR_THREAD_PRIO FRESCAN_NEG_THREAD_PRIO + 1 #define FRESCAN_BWRES_NEG_MESSAGES_PRIO 8 #define FRESCAN_NEG_CHANNEL 0 +#define FRESCAN_MX_NODES 2 +#define FRESCAN_MX_CONTRACTS (FRESCAN_MX_NODES*FRESCAN_MX_IDS) #define FRESCAN_MLOCK_T unsigned #define FRESCAN_CREATE_LOCK(l) diff --git a/src_frescan/frescan_data.h b/src_frescan/frescan_data.h index 2c7070c..7135432 100644 --- a/src_frescan/frescan_data.h +++ b/src_frescan/frescan_data.h @@ -116,6 +116,33 @@ typedef struct { frescan_prio_t prio; } frescan_contract_t; +/** + * frescan_sa_xxx scheduling analysis types + */ + +typedef struct { + frescan_prio_t server_prio; +} frescan_sa_final_values_t; + +typedef struct { + frescan_contract_t contract; + frescan_node_t node; + frescan_ss_t ss; + frescan_sa_final_values_t final_values; + struct list_head list; +} frescan_sa_contract_t; + +typedef struct { + frescan_prio_t max_prio; + frescan_prio_t min_prio; +} frescan_sa_init_params_t; + +typedef struct { + frescan_sa_contract_t contracts[FRESCAN_MX_NODES][FRESCAN_MX_IDS]; + frescan_sa_contract_t contracts_head; + frescan_sa_init_params_t init_params; +} frescan_sa_scenario_t; + /** * frescan_prio_queue_t - priority queue * @@ -177,6 +204,7 @@ typedef struct { * @id_fp_queues: the same as id_queues but for fp messages, which have * id=FRESCAN_MX_IDS and are distinguised through their * priorities. + * @scenario: the scheduling analysis scenario for the network * * the implementation can handle several FRESCAN networks at the same time * in the same node, so we need a place to store its internal data. The data @@ -197,6 +225,7 @@ typedef struct { frescan_prio_t last_packet_prio; frescan_packet_t *id_queues[FRESCAN_MX_IDS]; // TODO: alloc at init frescan_packet_t *id_fp_queues[FRESCAN_MX_PRIOS]; // TODO: alloc at init + frescan_sa_scenario_t scenario; } frescan_network_data_t; extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS]; @@ -208,6 +237,4 @@ extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS]; extern int frescan_data_init(int fd, frescan_init_params_t *params); - - #endif // _MARTE_FRESCAN_DATA_H_ diff --git a/src_frescan/frescan_debug.h b/src_frescan/frescan_debug.h index 18909e2..2cdaaa6 100644 --- a/src_frescan/frescan_debug.h +++ b/src_frescan/frescan_debug.h @@ -40,7 +40,7 @@ * DEBUGGING FLAGS to enable/disable debugging messages **/ -#define FRESCAN_SERVERS_ENABLE_DEBUG true +#define FRESCAN_SERVERS_ENABLE_DEBUG false #define FRESCAN_PACKETPOOL_ENABLE_DEBUG false #define FRESCAN_FRAG_ENABLE_DEBUG false #define FRESCAN_INIT_ENABLE_DEBUG false @@ -50,7 +50,7 @@ #define FRESCAN_SENT_HOOK_ENABLE_DEBUG false #define FRESCAN_QUEUES_ENABLE_DEBUG false #define FRESCAN_HW_BUFFER_ENABLE_DEBUG false -#define FRESCAN_REPLENSH_ENABLE_DEBUG true +#define FRESCAN_REPLENSH_ENABLE_DEBUG false #define FRESCAN_ROBJS_ENABLE_DEBUG false #define FRESCAN_BWRES_ENABLE_DEBUG false #define FRESCAN_REQUESTS_ENABLE_DEBUG false @@ -58,5 +58,6 @@ #define FRESCAN_ACCEPTOR_ENABLE_DEBUG false #define FRESCAN_FNA_ENABLE_DEBUG false #define FRESCAN_MESSAGES_ENABLE_DEBUG false +#define FRESCAN_SA_ENABLE_DEBUG false #endif // _MARTE_FRESCAN_DEBUG_H_ diff --git a/tests/tests_frescan/test_frescan_bwres_init.c b/tests/tests_frescan/test_frescan_bwres_init.c index 1de4734..19b1127 100644 --- a/tests/tests_frescan/test_frescan_bwres_init.c +++ b/tests/tests_frescan/test_frescan_bwres_init.c @@ -8,7 +8,7 @@ #define ERROR(s) {perror (s); exit (-1);} #define NETWORK 0 -#define LOCAL_NODE 0 +#define LOCAL_NODE 1 int main () { diff --git a/tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c b/tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c index 224d78d..9bea770 100644 --- a/tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c +++ b/tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c @@ -16,6 +16,8 @@ int main () frescan_init_params_t init_params; frescan_ss_t ss; frescan_contract_t contract; + bool accepted; + frescan_server_params_t server_params; init_params.net = NETWORK; init_params.node = LOCAL_NODE; @@ -31,8 +33,27 @@ int main () ret = frescan_bwres_init(NETWORK); if (ret != 0) ERROR ("could not init BWRES"); - ret = frescan_bwres_negotiate(NETWORK, &contract, &ss); - if (ret != 0) ERROR ("could not negotiate succesfully"); + contract.min_values.budget = 5; + contract.min_values.period.tv_sec = 3; + contract.min_values.period.tv_nsec = 69; + contract.prio = 7; + + ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted); + if (ret != 0) ERROR ("could not negotiate"); + + if (accepted) { + printf("The contract was accepted, ss:%u\n", ss); + ret = frescan_servers_get_data(NETWORK, &server_params, ss); + if (ret != 0) ERROR ("could not get servers data"); + + printf("B:%u, T=(%u,%u), P:%u\n", + server_params.values.budget, + server_params.values.period.tv_sec, + server_params.values.period.tv_nsec, + server_params.prio); + } else { + printf("The contract was not accepted\n"); + } while (1) { sleep(1); diff --git a/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c b/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c index b81d4b7..3a01915 100644 --- a/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c +++ b/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c @@ -18,6 +18,7 @@ int main () frescan_ss_t ss; frescan_contract_t contract; frescan_server_params_t server_params; + bool accepted; init_params.net = NETWORK; init_params.node = LOCAL_NODE; @@ -42,18 +43,22 @@ int main () contract.prio = 5; printf("Negotiating a contract\n"); - ret = frescan_bwres_negotiate(NETWORK, &contract, &ss); + ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted); if (ret != 0) ERROR ("could not negotiate succesfully"); - printf("negotiation was succesful, ss:%u\n", ss); - ret = frescan_servers_get_data(NETWORK, &server_params, ss); - if (ret != 0) ERROR ("could not get servers data"); + if (accepted) { + printf("The contract was accepted, ss:%u\n", ss); + ret = frescan_servers_get_data(NETWORK, &server_params, ss); + if (ret != 0) ERROR ("could not get servers data"); - printf("B:%u, T=(%u,%u), P:%u\n", - server_params.values.budget, - server_params.values.period.tv_sec, - server_params.values.period.tv_nsec, - server_params.prio); + printf("B:%u, T=(%u,%u), P:%u\n", + server_params.values.budget, + server_params.values.period.tv_sec, + server_params.values.period.tv_nsec, + server_params.prio); + } else { + printf("The contract was not accepted\n"); + } while (1) { sleep(1); -- 2.39.2