From 5da41047f7e070597bf10cc99363fc1b6af4f714 Mon Sep 17 00:00:00 2001 From: hyunil park Date: Wed, 24 Apr 2024 09:40:40 +0900 Subject: [PATCH] [ml-service] Add time limit for required data Add the time limit for receiving the necessary data from remote sender Signed-off-by: hyunil park --- c/src/ml-api-service-training-offloading.c | 19 ++++++++++++++++--- .../config/training_offloading_receiver.conf | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index d237856..a591438 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -24,6 +24,9 @@ /** combined with trained model file name set in conf */ #define TRAINED_MODEL_FILE "@TRAINED_MODEL_FILE@" +/** default receive time limit (second) */ +#define DEFAULT_TIME_LIMIT 10 + /** * @brief Internal enumeration for ml-service training offloading types. */ @@ -74,6 +77,7 @@ typedef struct gchar *path; /* Readable and writable path set by the app */ gboolean is_received; + gint time_limit; /* second, For receiving the data necessary for training */ GMutex received_lock; GCond received_cond; GThread *received_thread; @@ -240,6 +244,14 @@ _training_offloading_conf_parse_json (ml_service_s * mls, JsonObject * object) training_node = json_object_get_member (object, "training"); training_obj = json_node_get_object (training_node); + if (json_object_has_member (training_obj, "time-limit")) { + training_s->time_limit = + json_object_get_int_member (training_obj, "time-limit"); + } else { + _ml_logw + ("The default time-limit(10 sec) is set because `time-limit` is not set."); + } + val = json_object_get_string_member (training_obj, "sender-pipeline"); training_s->sender_pipe = g_strdup (val); @@ -419,6 +431,7 @@ _training_offloading_create (ml_service_s * mls) g_mutex_init (&training_s->received_lock); training_s->type = ML_TRAINING_OFFLOADING_TYPE_UNKNOWN; + training_s->time_limit = DEFAULT_TIME_LIMIT; ml_service_offloading_set_mode (mls, ML_SERVICE_OFFLOADING_MODE_TRAINING, training_s); @@ -602,12 +615,11 @@ static gpointer _check_received_data_thread (gpointer data) { ml_training_services_s *training_s = (ml_training_services_s *) data; - /** @todo FIXME: let's value by conf */ - int loop = 100; + int usec = training_s->time_limit * 1000000; g_return_val_if_fail (training_s != NULL, NULL); - while (loop--) { + while (usec > 0) { g_usleep (100000); if (training_s->receiver_pipe_json_str != NULL) { _ml_logd @@ -622,6 +634,7 @@ _check_received_data_thread (gpointer data) g_mutex_unlock (&training_s->received_lock); return NULL; } + usec -= 100000; } _ml_loge ("Required data is null, receive_pipe:%s", diff --git a/tests/test_models/config/training_offloading_receiver.conf b/tests/test_models/config/training_offloading_receiver.conf index 35f16bb..927602f 100644 --- a/tests/test_models/config/training_offloading_receiver.conf +++ b/tests/test_models/config/training_offloading_receiver.conf @@ -8,6 +8,7 @@ "topic" : "offloading_service_test_topic", "training" : { + "time-limit" : 10, "transfer-data" : { "service_1" : "@APP_RW_PATH@/trained-model.bin" -- 2.7.4