From 1658402070deb09f24881f49cc3328323de19d02 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 14 Apr 2017 10:07:05 +0900 Subject: [PATCH 01/16] packaging: Remove the ExclusiveArch keyword from pass.spec The commit c2af7de627fef ("packaging: Remove unneeded script code") used the 'ExclusiveArch' keyword for both armv7l and aarch64 architecture. It is wrong patch because PASS is common daemon for all profiles and architectures. So, this patch remove the specific ExclusiveArch keyword in order to remove the specific build dependency. Change-Id: Ia3d33fe2ca2a2ad40d4ed729f42725ae89fe70a9 Signed-off-by: Chanwoo Choi --- packaging/pass.spec | 2 -- 1 file changed, 2 deletions(-) diff --git a/packaging/pass.spec b/packaging/pass.spec index 268f252..ad84e72 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -13,8 +13,6 @@ Source0: %{name}-%{version}.tar.gz Source1: %{name}.manifest Source2: %{hal_name}.manifest -ExclusiveArch: %{arm} aarch64 - BuildRequires: cmake BuildRequires: libattr-devel BuildRequires: gettext-devel -- 2.7.4 From 4e20a19059e26c0b74db76320f74046ac56ce4c4 Mon Sep 17 00:00:00 2001 From: Wook Song Date: Tue, 28 Mar 2017 17:08:36 +0900 Subject: [PATCH 02/16] pass: hal: Add a function for putting resource This patch adds the pass_put_resource function, which is paired up with pass_get_resource(). When the main daemon is terminated, every hardware resources resources (which are opened by pass_get_resource()) are closed via HAL by this function. Change-Id: I454d931979c5753ad070c44e58e9256429e6f7f7 Signed-off-by: Wook Song Reviewed-by: Chanwoo Choi --- src/pass/pass-hal.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/pass/pass-hal.h | 3 ++- src/pass/pass.c | 8 ++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/pass/pass-hal.c b/src/pass/pass-hal.c index 129d025..8b1f3b1 100644 --- a/src/pass/pass-hal.c +++ b/src/pass/pass-hal.c @@ -533,6 +533,47 @@ int pass_get_resource(struct pass *pass) return 0; } +int pass_put_resource(struct pass *pass) +{ + struct pass_resource_common *common; + struct pass_resource_info *info; + int i, ret; + + for (i = 0; i < pass->num_resources; i++) { + struct pass_resource *pass_res = &pass->res[i]; + struct pass_conf_data *cdata = &pass_res->cdata; + int res_type = cdata->res_type; + + switch (res_type) { + case PASS_RESOURCE_CPU_ID: + common = (struct pass_resource_common*)pass_res->hal.cpu; + info = pass_res->hal.cpu->common.info; + ret = info->close(common); + break; + case PASS_RESOURCE_BUS_ID: + common = (struct pass_resource_common*)pass_res->hal.bus; + info = pass_res->hal.bus->common.info; + ret = info->close(common); + break; + case PASS_RESOURCE_GPU_ID: + common = (struct pass_resource_common*)pass_res->hal.gpu; + info = pass_res->hal.gpu->common.info; + ret = info->close(common); + break; + default: + return -EINVAL; + }; + + if (ret < 0) { + _E("Failed to close %s h/w resource\n", info->name); + return -EINVAL; + } + + _D("Complete the closing for %s h/w resource\n", info->name); + } + + return 0; +} /* * FXIME: Following function is not standard interface. * Following functions will be altered by the standard interface on later. diff --git a/src/pass/pass-hal.h b/src/pass/pass-hal.h index 09eb879..6700eea 100644 --- a/src/pass/pass-hal.h +++ b/src/pass/pass-hal.h @@ -55,8 +55,9 @@ int pass_set_online_max_num(struct pass_resource *res, int num); int pass_get_temp(struct pass_resource *res); int pass_get_policy(struct pass_resource *res, char *policy); -/* Load the h/w resource. */ +/* Get and put the h/w resource. */ int pass_get_resource(struct pass *pass); +int pass_put_resource(struct pass *pass); /* * FXIME: Following function is not standard interface. diff --git a/src/pass/pass.c b/src/pass/pass.c index 40ae215..33e08f3 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -268,7 +268,6 @@ static int pass_exit_done(void) { int i, ret; - ret = 0; for (i = 0; i < g_pass.num_resources; i++) { struct pass_resource *pass_res = &g_pass.res[i]; struct pass_policy *policy = &pass_res->policy; @@ -276,10 +275,15 @@ static int pass_exit_done(void) ret = pass_resource_exit(policy); if (ret < 0) { _E("failed to clean up the pass resource #%d\n", i); - break; + goto exit; } } + ret = pass_put_resource(&g_pass); + if (ret < 0) + _E("cannot put the pass resource\n"); + +exit: return ret; } -- 2.7.4 From 8a79b122ede1c5d63ef30f628cd8605da594c646 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 26 Apr 2017 16:09:44 +0900 Subject: [PATCH 03/16] hal: Add new argument of resource name to close and open function The open and close functions in the struct pass_resource_info are used to get/put the h/w resource. And the open and close functions in the hal implementation save/restore the h/w resource state. In this case, these functions need the unique resource name in order to identify the h/w resource. Change-Id: Icd7977619ed1f09186756a7cacf2c801c4284f1a Signed-off-by: Chanwoo Choi --- src/hal/hal.h | 4 ++-- src/pass/pass-hal.c | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/hal/hal.h b/src/hal/hal.h index 3972b7f..895e74b 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -90,9 +90,9 @@ struct pass_resource_info { void *dso; uint32_t reserved[8]; - int (*open)(struct pass_resource_info *info, + int (*open)(char *res_name, struct pass_resource_info *info, struct pass_resource_common **common); - int (*close)(struct pass_resource_common *common); + int (*close)(char *res_name, struct pass_resource_common *common); }; struct pass_resource_common { diff --git a/src/pass/pass-hal.c b/src/pass/pass-hal.c index 8b1f3b1..74a2811 100644 --- a/src/pass/pass-hal.c +++ b/src/pass/pass-hal.c @@ -473,6 +473,7 @@ int pass_get_resource(struct pass *pass) struct pass_resource *pass_res = &pass->res[i]; struct pass_conf_data *cdata = &pass_res->cdata; int res_type = cdata->res_type; + char *res_name = cdata->res_name; char name[10]; switch (res_type) { @@ -509,25 +510,27 @@ int pass_get_resource(struct pass *pass) switch (res_type) { case PASS_RESOURCE_CPU_ID: - ret = info->open(info, + ret = info->open(res_name, info, (struct pass_resource_common**)&pass_res->hal.cpu); break; case PASS_RESOURCE_BUS_ID: - ret = info->open(info, + ret = info->open(res_name, info, (struct pass_resource_common**)&pass_res->hal.bus); break; case PASS_RESOURCE_GPU_ID: - ret = info->open(info, + ret = info->open(res_name, info, (struct pass_resource_common**)&pass_res->hal.gpu); break; }; if (ret < 0) { - _E("Failed to open %s h/w resource\n", name); + _E("Failed to open %s h/w resource (%s)\n", + name, res_name); return -EINVAL; } - _D("Complete the loading for %s h/w resource\n", name); + _D("Complete the loading for %s h/w resource (%s)\n", + name, res_name); } return 0; @@ -542,34 +545,37 @@ int pass_put_resource(struct pass *pass) for (i = 0; i < pass->num_resources; i++) { struct pass_resource *pass_res = &pass->res[i]; struct pass_conf_data *cdata = &pass_res->cdata; + char *res_name = cdata->res_name; int res_type = cdata->res_type; switch (res_type) { case PASS_RESOURCE_CPU_ID: common = (struct pass_resource_common*)pass_res->hal.cpu; info = pass_res->hal.cpu->common.info; - ret = info->close(common); + ret = info->close(res_name, common); break; case PASS_RESOURCE_BUS_ID: common = (struct pass_resource_common*)pass_res->hal.bus; info = pass_res->hal.bus->common.info; - ret = info->close(common); + ret = info->close(res_name, common); break; case PASS_RESOURCE_GPU_ID: common = (struct pass_resource_common*)pass_res->hal.gpu; info = pass_res->hal.gpu->common.info; - ret = info->close(common); + ret = info->close(res_name, common); break; default: return -EINVAL; }; if (ret < 0) { - _E("Failed to close %s h/w resource\n", info->name); + _E("Failed to close %s h/w resource (%s)\n", + info->name, res_name); return -EINVAL; } - _D("Complete the closing for %s h/w resource\n", info->name); + _D("Complete the closing for %s h/w resource (%s)\n", + info->name, res_name); } return 0; -- 2.7.4 From 7858885da4d66ea5f4c5a74f5be6e777dced5a60 Mon Sep 17 00:00:00 2001 From: Wook Song Date: Thu, 18 May 2017 17:07:37 +0900 Subject: [PATCH 04/16] core: Modify device notifier registering/unregistering mechanism This patch modifies the registering and unregistering mechanism of device_notifier to use a static array instead of dynamically allocated memory. A bug in the unregister_notifier function is also fixed. Since the prototype of the function is changed, all locations where this function is called are also slightly modified. Change-Id: Iac5afc5f5c283f277220ac49d173bf420e3fb4ee Signed-off-by: Wook Song Reviewed-by: Chanwoo Choi --- src/core/device-notifier.c | 65 ++++++++++++++++++++++++++-------------------- src/core/device-notifier.h | 11 +++++++- src/core/udev.c | 10 ++++--- src/pass/pass-gov.c | 15 +++++++---- src/pass/pass.c | 7 ++--- src/pmqos/pmqos.c | 3 ++- 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index 1195d0c..7588281 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -22,35 +22,49 @@ #include "list.h" #include "common.h" -struct device_notifier { - bool deleted; - enum device_notifier_type status; - int (*func)(void *data, void *user_data); - void *user_data; -}; +#define DEVICE_NOTIFIER_MAX_COUNT 255 static dd_list *device_notifier_list; static Ecore_Idler *idl; +static struct device_notifier device_notifiers[DEVICE_NOTIFIER_MAX_COUNT]; + +#define FIND_NOTIFIER(a, b, c, d, e, f) \ + DD_LIST_FOREACH(a, b, c) \ + if (d == c->d && e == (c->e) && f == (c->f)) + +static struct device_notifier *get_device_notifier(void) { + static int pos = 0; + + if ((pos < DEVICE_NOTIFIER_MAX_COUNT) && + (!device_notifiers[pos].is_used)) { + device_notifiers[pos].is_used = true; + return &device_notifiers[pos++]; + } else { + for (pos = 0; pos < DEVICE_NOTIFIER_MAX_COUNT; pos++) { + if (!device_notifiers[pos].is_used) { + device_notifiers[pos].is_used = true; + return &device_notifiers[pos]; + } + } + } -#define FIND_NOTIFIER(a, b, d, e, f) \ - DD_LIST_FOREACH(a, b, d) \ - if (e == d->e && f == (d->f)) + return NULL; +} int register_notifier(enum device_notifier_type status, int (*func)(void *data, void *user_data), void *user_data) { struct device_notifier *notifier; - if (!func) { - _E("invalid func address!"); + if (status >= DEVICE_NOTIFIER_MAX) + return -EINVAL; + + if (!func) return -EINVAL; - } - notifier = calloc(1, sizeof(struct device_notifier)); - if (!notifier) { - _E("Fail to malloc for notifier!"); + notifier = get_device_notifier(); + if (!notifier) return -ENOMEM; - } notifier->status = status; notifier->func = func; @@ -62,19 +76,14 @@ int register_notifier(enum device_notifier_type status, } int unregister_notifier(enum device_notifier_type status, - int (*func)(void *data, void *user_data)) + int (*func)(void *data, void *user_data), void *user_data) { dd_list *n; struct device_notifier *notifier; - if (!func) { - _E("invalid func address!"); - return -EINVAL; - } - - FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { - _I("[%d, %x]", status, func); - notifier->deleted = true; + FIND_NOTIFIER(device_notifier_list, n, notifier, status, func, + user_data) { + notifier->is_used = false; } return 0; @@ -87,9 +96,9 @@ static Eina_Bool delete_unused_notifier_cb(void *data) struct device_notifier *notifier; DD_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier) { - if (notifier->deleted) { + if (!notifier->is_used) { + memset(notifier, 0, sizeof(*notifier)); DD_LIST_REMOVE_LIST(device_notifier_list, n); - free(notifier); } } @@ -103,7 +112,7 @@ void device_notify(enum device_notifier_type status, void *data) struct device_notifier *notifier; DD_LIST_FOREACH(device_notifier_list, n, notifier) { - if (!notifier->deleted && status == notifier->status) { + if (notifier->is_used && status == notifier->status) { if (notifier->func) notifier->func(data, notifier->user_data); } diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 9ae29be..77c571f 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -20,6 +20,8 @@ #ifndef __DEVICE_NOTIFIER_H__ #define __DEVICE_NOTIFIER_H__ +#include + enum device_notifier_type { DEVICE_NOTIFIER_BOOTING_DONE, DEVICE_NOTIFIER_PMQOS, @@ -27,13 +29,20 @@ enum device_notifier_type { DEVICE_NOTIFIER_MAX, }; +struct device_notifier { + bool is_used; + enum device_notifier_type status; + int (*func)(void *data, void *user_data); + void *user_data; +}; + /* * This is for internal callback method. */ int register_notifier(enum device_notifier_type status, int (*func)(void *data, void *user_data), void *user_data); int unregister_notifier(enum device_notifier_type status, - int (*func)(void *data, void *user_data)); + int (*func)(void *data, void *user_data), void *user_data); void device_notify(enum device_notifier_type status, void *value); #endif /* __DEVICE_NOTIFIER_H__ */ diff --git a/src/core/udev.c b/src/core/udev.c index 39e49d9..3e8deff 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -328,8 +328,11 @@ static void udev_init(void *data) { int ret; - register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff, - NULL); + ret = register_notifier(DEVICE_NOTIFIER_POWEROFF, + device_change_poweroff, NULL); + if (ret < 0) + _E("cannot register power-off notifier for the udev (%d)\n", + ret); ret = register_edbus_method(PASS_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); @@ -345,7 +348,8 @@ static void udev_init(void *data) static void udev_exit(void *data) { - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); + unregister_notifier(DEVICE_NOTIFIER_POWEROFF, + device_change_poweroff, NULL); } static const struct device_ops udev_device_ops = { diff --git a/src/pass/pass-gov.c b/src/pass/pass-gov.c index 0decd8b..13f16a2 100644 --- a/src/pass/pass-gov.c +++ b/src/pass/pass-gov.c @@ -71,9 +71,8 @@ static int pass_notifier_pmqos(void *data, void *user_data) static int pass_notifier_init(struct pass_policy *policy) { /* Register DEVICE_NOTIFIER_PMQOS */ - register_notifier(DEVICE_NOTIFIER_PMQOS, pass_notifier_pmqos, policy); - - return 0; + return register_notifier(DEVICE_NOTIFIER_PMQOS, pass_notifier_pmqos, + policy); } /* @@ -83,7 +82,8 @@ static int pass_notifier_init(struct pass_policy *policy) static int pass_notifier_exit(struct pass_policy *policy) { /* Un-register DEVICE_NOTIFIER_PMQOS */ - unregister_notifier(DEVICE_NOTIFIER_PMQOS, pass_notifier_pmqos); + unregister_notifier(DEVICE_NOTIFIER_PMQOS, pass_notifier_pmqos, + policy); return 0; } @@ -500,6 +500,7 @@ static int __pass_governor_init(struct pass_policy *policy) { struct pass_resource *res = to_pass_resource(policy); struct pass_conf_data *cdata = &res->cdata; + int ret; if(policy->gov_timeout < 0) { _E("invalid timeout value [%d]!", policy->gov_timeout); @@ -509,7 +510,11 @@ static int __pass_governor_init(struct pass_policy *policy) /* Set default PASS state */ policy->gov_state = PASS_GOV_STOP; - pass_notifier_init(policy); + ret = pass_notifier_init(policy); + if (ret < 0) { + _E("cannot initialize notifier for the pmqos (%d)\n", ret); + return ret; + } _I("Initialize governor for '%s' resource", cdata->res_name); diff --git a/src/pass/pass.c b/src/pass/pass.c index 33e08f3..4500f61 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -308,7 +308,8 @@ static void pass_exit(void *data) { int ret; - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, pass_init_done); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, + pass_init_done, NULL); ret = pass_exit_done(); if (ret < 0) { @@ -348,8 +349,8 @@ static int pass_probe(void *data) ret = register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, pass_init_done, NULL); if (ret < 0) { - _E("cannot register a callback function \ - for the booting-done event (%d)\n", ret); + _E("cannot register booting-done notifier for the pass (%d)\n", + ret); return ret; } diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 1caa7bb..f6a4db4 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -535,7 +535,8 @@ static void pmqos_free(void) static void pmqos_exit(void *data) { - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, pmqos_init_done); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, + pmqos_init_done, NULL); pmqos_free(); } -- 2.7.4 From 8d040dedc5d921023f101eb8af59c764687980f7 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 Jun 2017 15:50:04 +0900 Subject: [PATCH 05/16] pass: pmqos: Specify the resource name on log message This patch just adds the correct resource name to pmqos's log message in order to improve the readability of pmqos's operation. Example, - Before: "cannot support 'AppLaunch' scenario (support=0)" - After : "cannot support 'AppLaunch' scenario for 'cpu0' resource" Change-Id: Ie337e73a5b310fc72428a7bfce1d5690f07a2863 Signed-off-by: Chanwoo Choi --- src/pass/pass-pmqos.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pass/pass-pmqos.c b/src/pass/pass-pmqos.c index 3929dff..e2dcbbb 100644 --- a/src/pass/pass-pmqos.c +++ b/src/pass/pass-pmqos.c @@ -120,15 +120,16 @@ int pass_notifier_pmqos_func(struct pass_policy *policy, void *data) locked = is_pmqos_locked(data, name); index = find_scenario_index(scenario, name); if (index < 0) { - _W("Unknown scenario (%s)\n", data); + _W("Unknown scenario (%s) for '%s' resource\n", + data, cdata->res_name); return -EINVAL; } scn = &scenario->list[index]; /* Check the state of each scenario whether to support or not */ if (scn->state != PASS_ON) { - _W("cannot support '%s' scenario (support=%d)\n", - name, scn->state); + _W("cannot support '%s' scenario for '%s' resource\n", + name, cdata->res_name); return 0; } @@ -137,8 +138,9 @@ int pass_notifier_pmqos_func(struct pass_policy *policy, void *data) * if state is same as existing state */ if (scn->locked == locked) { - _E("'%s' scenario is already %s\n", - name, locked ? "Locked" : "Unlocked"); + _E("'%s' scenario is already %s for '%s' resource\n", + name, locked ? "Locked" : "Unlocked", + cdata->res_name); return 0; } scn->locked = locked; -- 2.7.4 From 9d25ee92c086b040eb35da5cf35f63d87a379765 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 Jun 2017 15:58:46 +0900 Subject: [PATCH 06/16] pmqos: Staticize set_pmqos function The set_pmqos is accessed only in this file so it can be made as static. Change-Id: I3e836c8a4d4c3a17621a21b6ad3cc57767397df0 Signed-off-by: Chanwoo Choi --- src/pmqos/pmqos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index f6a4db4..9e8cbbc 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -88,7 +88,7 @@ static DBusMessage* e_dbus_stop_cb(E_DBus_Object *obj, DBusMessage* msg) return ret_dbus; } -int set_pmqos(const char *name, int val) +static int set_pmqos(const char *name, int val) { char scenario[100]; -- 2.7.4 From 4f09e9aa4e7cef7fc97504450356cce416092a48 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 Jun 2017 16:32:44 +0900 Subject: [PATCH 07/16] pass: Remove unneeded log message This patch removes the unneeded and duplicate log messages in order to simplify the log during init/exit of PASS. Also, this patch shows the supported scenarios except for un-supported scenarios. Change-Id: I5053e9b5b323ed2eb3a83c4ec0418995cbecf9a7 Signed-off-by: Chanwoo Choi --- src/core/main.c | 6 ++---- src/pass/pass-gov.c | 4 ---- src/pass/pass.c | 2 +- src/pmqos/pmqos.c | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 233ef0e..f174544 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -50,7 +50,7 @@ static void sig_quit(int signo) static void sig_usr1(int signo) { - _D("received SIGUSR1 signal %d, PASS'll be finished!", signo); + _D("received SIGUSR1 signal %d", signo); ecore_main_loop_quit(); } @@ -63,10 +63,8 @@ static int pass_main(int argc, char **argv) devices_init(NULL); add_booting_done_handler(NULL); ret = booting_finished(); - if (ret == 1) { - _I("notify relaunch"); + if (ret == 1) device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &ret); - } signal(SIGTERM, sig_quit); signal(SIGUSR1, sig_usr1); diff --git a/src/pass/pass-gov.c b/src/pass/pass-gov.c index 13f16a2..eec38d8 100644 --- a/src/pass/pass-gov.c +++ b/src/pass/pass-gov.c @@ -516,8 +516,6 @@ static int __pass_governor_init(struct pass_policy *policy) return ret; } - _I("Initialize governor for '%s' resource", cdata->res_name); - if (policy->state == PASS_ON) pass_governor_update(policy, PASS_GOV_START); @@ -568,8 +566,6 @@ static int __pass_governor_exit(struct pass_policy *policy) policy->governor = NULL; - _I("Exit governor for '%s' resource", cdata->res_name); - return 0; } diff --git a/src/pass/pass.c b/src/pass/pass.c index 4500f61..1c52750 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -317,7 +317,7 @@ static void pass_exit(void *data) return; } - _I("exit PASS daemon without any errors\n"); + _I("Exit PASS daemon without any errors\n"); } /* diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 9e8cbbc..248d5e4 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -388,10 +388,8 @@ static int get_methods_from_conf(const char *path, struct edbus_method **edbus_m for (i = 0; i < scenarios.num; ++i) { /* if this scenario does not support */ - if (!scenarios.list[i].support) { - _I("do not support [%s] scenario", scenarios.list[i].name); + if (!scenarios.list[i].support) continue; - } methods[i].member = scenarios.list[i].name; methods[i].signature = "i"; -- 2.7.4 From 1823eec981985bb3b6137104661609464d7d7b4e Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 Jun 2017 17:49:53 +0900 Subject: [PATCH 08/16] pmqos: Remove hard-coded scenario names This patch removes the hard-coded scenario names and unused functions. When you want to add or remove the scenarios, you have to modify the /etc/pass/pass-pmqos.conf file without any changes of pmqos code. Change-Id: Ia267b4de362746aa370b94ed53ad783ad7ff6954 Signed-off-by: Chanwoo Choi --- src/pmqos/pmqos.c | 112 +----------------------------------------------------- 1 file changed, 2 insertions(+), 110 deletions(-) diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 248d5e4..26083ec 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -303,58 +303,6 @@ error: return reply; } -static DBusMessage *dbus_wifi_pmqos_handler(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - const char *member; - char name[NAME_MAX]; - int bps, val, ret; - - if (!dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &bps, - DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID)) { - _E("there is no message"); - ret = -EINVAL; - goto error; - } - - if (bps < 0 || val < 0) { - ret = -EINVAL; - goto error; - } - - member = dbus_message_get_member(msg); - - /* combine bps and member */ - snprintf(name, sizeof(name), "%s%d", member, bps); - - if (val) - ret = pmqos_request(name, val); - else - ret = pmqos_cancel(name); - -error: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - -static DBusMessage *dbus_getdefaultlocktime(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = DEFAULT_PMQOS_TIMER; - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - static int get_methods_from_conf(const char *path, struct edbus_method **edbus_methods) { struct edbus_method *methods; @@ -407,64 +355,8 @@ static int get_methods_from_conf(const char *path, struct edbus_method **edbus_m /* Add pmqos name as alphabetically */ static const struct edbus_method edbus_methods[] = { - { "start", NULL, NULL, e_dbus_start_cb }, - { "stop", NULL, NULL, e_dbus_stop_cb }, - /* - * TODO: The hard-coded scenario info is no longer required. Therefore, - * the following code will be removed. - */ - { "AppLaunch", "i", "i", dbus_pmqos_handler }, - { "AppLaunchHome", "i", "i", dbus_pmqos_handler }, - { "BeautyShot", "i", "i", dbus_pmqos_handler }, - { "Browser", "i", "i", dbus_pmqos_handler }, - { "BrowserDash", "i", "i", dbus_pmqos_handler }, - { "BrowserJavaScript", "i", "i", dbus_pmqos_handler }, - { "BrowserLoading", "i", "i", dbus_pmqos_handler }, - { "BrowserScroll", "i", "i", dbus_pmqos_handler }, - { "CallSound", "i", "i", dbus_pmqos_handler }, - { "CameraBurstShot", "i", "i", dbus_pmqos_handler }, - { "CameraCaptureAtRec", "i", "i", dbus_pmqos_handler }, - { "CameraPreview", "i", "i", dbus_pmqos_handler }, - { "CameraSoundAndShot", "i", "i", dbus_pmqos_handler }, - { "ContactSearch", "i", "i", dbus_pmqos_handler }, - { "Emergency", "i", "i", dbus_pmqos_handler }, - { "GalleryScroll", "i", "i", dbus_pmqos_handler }, - { "GalleryRotation", "i", "i", dbus_pmqos_handler }, - { "GetDefaultLockTime", NULL, "i", dbus_getdefaultlocktime }, - { "GpsSerialCno", "i", "i", dbus_pmqos_handler }, - { "GpuBoost", "i", "i", dbus_pmqos_handler }, - { "GpuWakeup", "i", "i", dbus_pmqos_handler }, - { "HomeScreen", "i", "i", dbus_pmqos_handler }, - { "ImageViewer", "i", "i", dbus_pmqos_handler }, - { "IMEInput", "i", "i", dbus_pmqos_handler }, - { "LockScreen", "i", "i", dbus_pmqos_handler }, - { "LowBattery", "i", "i", dbus_pmqos_handler }, - { "MtpSendFile", "i", "i", dbus_pmqos_handler }, - { "MusicPlayLcdOn", "i", "i", dbus_pmqos_handler }, - { "PowerSaving", "i", "i", dbus_pmqos_handler }, - { "ProcessCrashed", "i", "i", dbus_pmqos_handler }, - { "ReservedMode", "i", "i", dbus_pmqos_handler }, - { "ScreenMirroring", "i", "i", dbus_pmqos_handler }, - { "SmemoZoom", "i", "i", dbus_pmqos_handler }, - { "SVoice", "i", "i", dbus_pmqos_handler }, - { "WebappLaunch", "i", "i", dbus_pmqos_handler }, - { "WifiThroughput", "ii", "i", dbus_wifi_pmqos_handler }, - { "PowerOff", "i", "i", dbus_pmqos_handler }, - { "WebAppDrag", "i", "i", dbus_pmqos_handler }, - { "WebAppFlick", "i", "i", dbus_pmqos_handler }, - { "SensorWakeup", "i", "i", dbus_pmqos_handler }, - { "UgLaunch", "i", "i", dbus_pmqos_handler }, - { "MusicScroll", "i", "i", dbus_pmqos_handler }, - { "FileScroll", "i", "i", dbus_pmqos_handler }, - { "VideoScroll", "i", "i", dbus_pmqos_handler }, - { "EmailScroll", "i", "i", dbus_pmqos_handler }, - { "ContactScroll", "i", "i", dbus_pmqos_handler }, - { "TizenStoreScroll", "i", "i", dbus_pmqos_handler }, - { "CallLogScroll", "i", "i", dbus_pmqos_handler }, - { "MyfilesScroll", "i", "i", dbus_pmqos_handler }, - { "MessageScroll", "i", "i", dbus_pmqos_handler }, - { "SIOP", "i", "i", dbus_pmqos_handler }, - { "UltraPowerSaving", "i", "i", dbus_pmqos_handler }, + { "start", NULL, NULL, e_dbus_start_cb }, + { "stop", NULL, NULL, e_dbus_stop_cb }, }; static int pmqos_init_done(void *data, void *user_data) -- 2.7.4 From 2b3a2095f8a2f2b75915050ee7602f62475753db Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 12 Jun 2017 19:28:43 +0900 Subject: [PATCH 09/16] pmqos: Fix bug of 'support' property of pass-pmqos.conf This patch fixes the bug related to 'support' property of pass-pmqos.conf. PASS PMQoS has the pass-pmqos.conf which contains the supported scenario name and the number of supported scenarios. Each scenario has the 'support' property indicating whether scenario is supported or not on platform. If the 'support' property value is changed from 'yes' to 'no', PASS shows the following error log during the init step. [error log] edbus-handler.c: register_method(713) > fail to add method (null)! edbus-handler.c: register_edbus_method(862) > fail to register /Org/Tizen/System/Pass/Pmqos method(-22) pmqos.c: pmqos_init_done(395) > fail to init edbus method from conf(-22) Change-Id: Icbb0d29c941345f21c3bcc4ae513ff73095a3aff Signed-off-by: Chanwoo Choi --- src/pmqos/pmqos.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 26083ec..1869c00 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -307,7 +307,7 @@ static int get_methods_from_conf(const char *path, struct edbus_method **edbus_m { struct edbus_method *methods; struct pmqos_scenario scenarios = {0,}; - int i, ret; + int i, ret, count = 0; /* get pmqos table from conf */ ret = pmqos_get_scenario(path, &scenarios); @@ -334,20 +334,21 @@ static int get_methods_from_conf(const char *path, struct edbus_method **edbus_m /* set edbus_methods structure */ for (i = 0; i < scenarios.num; ++i) { - /* if this scenario does not support */ if (!scenarios.list[i].support) continue; - methods[i].member = scenarios.list[i].name; - methods[i].signature = "i"; - methods[i].reply_signature = "i"; - methods[i].func = dbus_pmqos_handler; + methods[count].member = scenarios.list[i].name; + methods[count].signature = "i"; + methods[count].reply_signature = "i"; + methods[count].func = dbus_pmqos_handler; + count++; + _D("support [%s] scenario", scenarios.list[i].name); } *edbus_methods = methods; - ret = scenarios.num; + ret = count; pmqos_put_scenario(&scenarios); return ret; -- 2.7.4 From 9946aa5516aa25a96522ccdb5f44122eae3e0e2b Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 12 Jun 2017 20:03:15 +0900 Subject: [PATCH 10/16] pass: pmqos: Modify log when the received scenario is not supported This patch modifies the log when the received scenario is not supported as following: 1. Remove 'Lock' and 'Unlock' word from scenario name. - Before : "Unknown scenario (SIOPLock) for 'cpu0' resource" - After : "Unknown scenario (SIOP) for 'cpu0' resource" 2. Use 'Not supported' instead of 'cannot support'. - Before : "cannot support 'AppLaunch' scenario for 'cpu0' resource" - After : "Not supported 'AppLaunch' scenario for 'cpu0' resource" Change-Id: Ibeeb0f2fba3fc46e27fc1e2b16b74d167d83c3e7 Signed-off-by: Chanwoo Choi --- src/pass/pass-pmqos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pass/pass-pmqos.c b/src/pass/pass-pmqos.c index e2dcbbb..1b58b33 100644 --- a/src/pass/pass-pmqos.c +++ b/src/pass/pass-pmqos.c @@ -121,14 +121,14 @@ int pass_notifier_pmqos_func(struct pass_policy *policy, void *data) index = find_scenario_index(scenario, name); if (index < 0) { _W("Unknown scenario (%s) for '%s' resource\n", - data, cdata->res_name); + name, cdata->res_name); return -EINVAL; } scn = &scenario->list[index]; /* Check the state of each scenario whether to support or not */ if (scn->state != PASS_ON) { - _W("cannot support '%s' scenario for '%s' resource\n", + _W("Not supported '%s' scenario for '%s' resource\n", name, cdata->res_name); return 0; } -- 2.7.4 From 523f73acdfd538a4cedc06252725477112e21fb1 Mon Sep 17 00:00:00 2001 From: Wook Song Date: Tue, 13 Jun 2017 11:22:44 +0900 Subject: [PATCH 11/16] core: edbus-handler: Eliminate unused code and dynamic memory allocation This patch removes the unused code from edbus-handler. In addition, dynamic memory allocation is also eliminated in order to avoid the possibility of memory leak. Change-Id: I7d16b4aac56e2cb59b920db52db6c70a5b445147 Signed-off-by: Wook Song --- src/core/edbus-handler.c | 606 ++--------------------------------------------- src/core/edbus-handler.h | 29 +-- 2 files changed, 27 insertions(+), 608 deletions(-) diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index bcec02a..cbfa75b 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -27,14 +27,7 @@ #include "shared/log.h" #define EDBUS_INIT_RETRY_COUNT 5 -#define NAME_OWNER_CHANGED "NameOwnerChanged" -#define NAME_OWNER_MATCH "type='signal',sender='org.freedesktop.DBus'," \ - "path='/org/freedesktop/DBus',interface='org.freedesktop.DBus'," \ - "member='NameOwnerChanged',arg0='%s'" - -/* -1 is a default timeout value, it's converted to 25*1000 internally. */ -#define DBUS_REPLY_TIMEOUT (-1) -#define RETRY_MAX 5 +#define EDBUS_LIST_POOL_MAX_COUNT 255 struct edbus_list { char *signal_name; @@ -53,81 +46,40 @@ static struct edbus_object { /* Add new object & interface here*/ }; -struct watch_func_info { - bool deleted; - void (*func)(const char *sender, void *data); - void *data; -}; - -struct watch_info { - bool deleted; - char *sender; - dd_list *func_list; -}; - -static dd_list *edbus_object_list; static dd_list *edbus_owner_list; static dd_list *edbus_handler_list; -static dd_list *edbus_watch_list; static int edbus_init_val; static DBusConnection *conn; -static DBusConnection *conn_block; static E_DBus_Connection *edbus_conn; -static E_DBus_Connection *edbus_conn_block; static DBusPendingCall *edbus_request_name; +static struct edbus_list edbus_list_pool[EDBUS_LIST_POOL_MAX_COUNT]; -static DBusHandlerResult message_filter(DBusConnection *connection, - DBusMessage *message, void *data); - -DBusConnection *get_block_dbus_connection(void) -{ - return conn_block; -} - -E_DBus_Object *register_edbus_object(const char *object_path, void *data) -{ - E_DBus_Object *object; - - if (!object_path) { - _E("invalid parameter"); - return NULL; +static bool is_empty_edbus_list(struct edbus_list *list) { + if ((list->signal_name == NULL) && (list->handler == NULL)) { + return true; } - - object = e_dbus_object_add(edbus_conn, object_path, data); - if (!object) { - _E("fail to add object for %s", object_path); - return NULL; - } - - return object; + return false; } -E_DBus_Object *register_block_edbus_object(const char *object_path, void *data) -{ - E_DBus_Object *object; +static void put_edbus_list(struct edbus_list *list) { + memset(list, 0, sizeof(*list)); +} - if (!object_path) { - _E("invalid parameter"); - return NULL; - } +static struct edbus_list *get_edbus_list(void) { + static int pos = 0; - object = e_dbus_object_add(edbus_conn_block, object_path, data); - if (!object) { - _E("fail to add object for %s", object_path); - return NULL; + if ((pos < EDBUS_LIST_POOL_MAX_COUNT) && + is_empty_edbus_list(&edbus_list_pool[pos])) { + return &edbus_list_pool[pos++];; + } else { + for (pos = 0; pos < EDBUS_LIST_POOL_MAX_COUNT; pos++) { + if (is_empty_edbus_list(&edbus_list_pool[pos])) + return &edbus_list_pool[pos]; + } } - return object; -} - -void unregister_edbus_object(E_DBus_Object *object) -{ - if (!object) - return; - - e_dbus_object_free(object); + return NULL; } - static int register_edbus_interface(struct edbus_object *object) { if (!object) { @@ -152,30 +104,6 @@ static int register_edbus_interface(struct edbus_object *object) return 0; } -static int register_block_edbus_interface(struct edbus_object *object) -{ - if (!object) { - _E("object is invalid value!"); - return -1; - } - - object->obj = e_dbus_object_add(edbus_conn_block, object->path, NULL); - if (!object->obj) { - _E("fail to add edbus obj"); - return -1; - } - - object->iface = e_dbus_interface_new(object->interface); - if (!object->iface) { - _E("fail to add edbus interface"); - return -1; - } - - e_dbus_object_interface_attach(object->obj, object->iface); - - return 0; -} - E_DBus_Interface *get_edbus_interface(const char *path) { int i; @@ -261,7 +189,7 @@ static void unregister_edbus_signal_handle(void) e_dbus_signal_handler_del(edbus_conn, entry->handler); DD_LIST_REMOVE(edbus_handler_list, entry); free(entry->signal_name); - free(entry); + put_edbus_list(entry); } } @@ -285,7 +213,7 @@ int register_edbus_signal_handler(const char *path, const char *interface, return -ENOMEM; } - entry = malloc(sizeof(struct edbus_list)); + entry = get_edbus_list(); if (!entry) { e_dbus_signal_handler_del(edbus_conn, handler); @@ -298,7 +226,7 @@ int register_edbus_signal_handler(const char *path, const char *interface, if (!entry->signal_name) { _E("Malloc failed"); e_dbus_signal_handler_del(edbus_conn, handler); - free(entry); + put_edbus_list(entry); return -ENOMEM; } @@ -308,7 +236,7 @@ int register_edbus_signal_handler(const char *path, const char *interface, _E("dd_list_prepend failed"); e_dbus_signal_handler_del(edbus_conn, handler); free(entry->signal_name); - free(entry); + put_edbus_list(entry); return -ENOMEM; } return 0; @@ -325,7 +253,7 @@ int unregister_edbus_signal_handler(const char *path, const char *interface, e_dbus_signal_handler_del(edbus_conn, entry->handler); DD_LIST_REMOVE(edbus_handler_list, entry); free(entry->signal_name); - free(entry); + put_edbus_list(entry); return 0; } } @@ -365,335 +293,6 @@ int broadcast_edbus_signal(const char *path, const char *interface, return 0; } -int broadcast_block_edbus_signal(const char *path, const char *interface, - const char *name, const char *sig, char *param[]) -{ - DBusMessage *msg; - DBusMessageIter iter; - int r; - - msg = dbus_message_new_signal(path, interface, name); - if (!msg) { - _E("fail to allocate new %s.%s signal", interface, name); - return -EPERM; - } - - dbus_message_iter_init_append(msg, &iter); - r = append_variant(&iter, sig, param); - if (r < 0) { - _E("append_variant error(%d)", r); - return -EPERM; - } - - r = dbus_connection_send(conn_block, msg, NULL); - dbus_message_unref(msg); - - if (r != TRUE) { - _E("dbus_connection_send error(%s:%s-%s)", - path, interface, name); - return -ECOMM; - } - - return 0; -} - -static void print_watch_item(void) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - dd_list *e; - - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - _D("watch sender : %s, deleted : %d", - watch->sender, watch->deleted); - DD_LIST_FOREACH(watch->func_list, e, finfo) - _D("\tfunc : %p, deleted : %d", - finfo->func, finfo->deleted); - } -} - -static bool get_valid_watch_item(void) -{ - struct watch_info *watch; - dd_list *elem; - - DD_LIST_FOREACH(edbus_watch_list, elem, watch) { - if (!watch->deleted) - return true; - } - - return false; -} - -static void watch_idler_cb(void *data) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - dd_list *next; - dd_list *elem; - dd_list *enext; - char match[256]; - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - if (!watch->deleted) - continue; - - /* remove dbus match */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_remove_match(conn, match, NULL); - - _I("%s is not watched by dbus!", watch->sender); - - /* remove watch func list */ - DD_LIST_FOREACH_SAFE(watch->func_list, elem, enext, finfo) - free(finfo); - - /* remove watch item */ - DD_LIST_FREE_LIST(watch->func_list); - DD_LIST_REMOVE_LIST(edbus_watch_list, n); - free(watch->sender); - free(watch); - } - - /* if the last request, remove message filter */ - if (!get_valid_watch_item()) - dbus_connection_remove_filter(conn, message_filter, NULL); -} - -static DBusHandlerResult message_filter(DBusConnection *connection, - DBusMessage *message, void *data) -{ - int ret; - const char *iface, *member; - const char *sender; - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - int len; - - if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - iface = dbus_message_get_interface(message); - member = dbus_message_get_member(message); - - if (strncmp(iface, DBUS_INTERFACE_DBUS, - sizeof(DBUS_INTERFACE_DBUS))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - if (strncmp(member, NAME_OWNER_CHANGED, - sizeof(NAME_OWNER_CHANGED))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - ret = dbus_message_get_args(message, NULL, - DBUS_TYPE_STRING, &sender, - DBUS_TYPE_INVALID); - if (!ret) { - _E("no message"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - len = strlen(sender) + 1; - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (!watch->deleted && - !strncmp(watch->sender, sender, len)) - break; - } - - if (!watch) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - DD_LIST_FOREACH(watch->func_list, n, finfo) { - if (!finfo->deleted && - finfo->func) - finfo->func(watch->sender, finfo->data); - } - - /* no interest in this item anymore */ - watch->deleted = true; - - print_watch_item(); - add_idle_request(watch_idler_cb, NULL); - return DBUS_HANDLER_RESULT_HANDLED; -} - -static struct watch_info *get_matched_watch_item(const char *sender) -{ - int len; - dd_list *n; - struct watch_info *watch; - - if (!sender) - return NULL; - - len = strlen(sender) + 1; - /* check the sender&type is already registered */ - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (!watch->deleted && - !strncmp(watch->sender, sender, len)) - return watch; - } - - return NULL; -} - -static struct watch_info *add_watch_item(const char *sender) -{ - DBusError err; - struct watch_info *watch; - char match[256]; - int ret; - - if (!sender) - return NULL; - - watch = calloc(1, sizeof(struct watch_info)); - if (!watch) - return NULL; - - watch->sender = strdup(sender); - if (!watch->sender) - goto out; - - dbus_error_init(&err); - /* add name owner changed match string */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_add_match(conn, match, &err); - - if (dbus_error_is_set(&err)) { - _E("fail to add match for %s [%s:%s]", - sender, err.name, err.message); - dbus_error_free(&err); - goto out; - } - - /* if the first request, add message filter */ - if (!get_valid_watch_item()) { - ret = dbus_connection_add_filter(conn, - message_filter, NULL, NULL); - if (!ret) { - _E("fail to add message filter!"); - dbus_bus_remove_match(conn, match, NULL); - goto out; - } - _I("success to add message filter!"); - } - - /* Add watch to watch list */ - DD_LIST_APPEND(edbus_watch_list, watch); - _I("%s is watched by dbus!", sender); - return watch; - -out: - if (watch) { - free(watch->sender); - free(watch); - } - - return NULL; -} - -int register_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data), void *data) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *elem; - bool isnew = false; - - if (!sender || !func) { - _E("invalid argument : sender(NULL) || func(NULL)"); - return -EINVAL; - } - - watch = get_matched_watch_item(sender); - if (!watch) { - /* create new watch item */ - watch = add_watch_item(sender); - if (!watch) { - _E("fail to add watch item"); - return -EPERM; - } - isnew = true; - } - - /* find the same callback */ - DD_LIST_FOREACH(watch->func_list, elem, finfo) { - if (finfo->func == func) { - _E("there is already the same callback"); - goto out; - } - } - - finfo = calloc(1, sizeof(struct watch_func_info)); - if (!finfo) { - _E("fail to allocate watch func info"); - goto out; - } - - finfo->func = func; - finfo->data = data; - - /* add callback function to the watch list */ - DD_LIST_APPEND(watch->func_list, finfo); - - _I("register watch func(%p) of %s", func, sender); - return 0; -out: - if (isnew) - watch->deleted = true; - - return -EPERM; -} - -int unregister_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data)) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *elem; - bool matched = false; - - if (!sender || !func) { - _E("invalid argument : sender(NULL) || func(NULL)"); - return -EINVAL; - } - - watch = get_matched_watch_item(sender); - if (!watch) { - _E("fail to get matched watch item"); - return -ENODEV; - } - - /* check the no interest function */ - DD_LIST_FOREACH(watch->func_list, elem, finfo) { - if (finfo->func == func) - finfo->deleted = true; - if (!finfo->deleted) - matched = true; - } - - /* if it is the last item */ - if (!matched) - watch->deleted = true; - - _I("unregister watch func(%p) of %s", func, sender); - return 0; -} - -static void unregister_edbus_watch_all(void) -{ - dd_list *n, *next; - struct watch_info *watch; - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) - watch->deleted = true; - - add_idle_request(watch_idler_cb, NULL); -} - static int register_method(E_DBus_Interface *iface, const struct edbus_method *edbus_methods, int size) { @@ -718,129 +317,6 @@ static int register_method(E_DBus_Interface *iface, return 0; } -int register_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size) -{ - struct edbus_object *obj; - dd_list *elem; - int ret; - - if (!path || !interface || !edbus_methods || size < 1) { - _E("invalid parameter"); - return -EINVAL; - } - - /* find matched obj */ - DD_LIST_FOREACH(edbus_object_list, elem, obj) { - if (strncmp(obj->path, path, strlen(obj->path)) == 0 && - strncmp(obj->interface, interface, strlen(obj->interface)) == 0) { - _I("found matched item : obj(%p)", obj); - break; - } - } - - /* if there is no matched obj */ - if (!obj) { - obj = malloc(sizeof(struct edbus_object)); - if (!obj) { - _E("fail to allocate %s interface", path); - return -ENOMEM; - } - - obj->path = strdup(path); - obj->interface = strdup(interface); - - ret = register_edbus_interface(obj); - if (ret < 0) { - _E("fail to register %s interface(%d)", obj->path, ret); - free(obj->path); - free(obj->interface); - free(obj); - return ret; - } - - DD_LIST_APPEND(edbus_object_list, obj); - } - - ret = register_method(obj->iface, edbus_methods, size); - if (ret < 0) { - _E("fail to register %s method(%d)", obj->path, ret); - return ret; - } - - return 0; -} - -int register_block_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size) -{ - struct edbus_object *obj; - dd_list *elem; - int ret; - - if (!path || !interface || !edbus_methods || size < 1) { - _E("invalid parameter"); - return -EINVAL; - } - - /* find matched obj */ - DD_LIST_FOREACH(edbus_object_list, elem, obj) { - if (strncmp(obj->path, path, strlen(obj->path)) == 0 && - strncmp(obj->interface, interface, strlen(obj->interface)) == 0) { - _I("found matched item : obj(%p)", obj); - break; - } - } - - /* if there is no matched obj */ - if (!obj) { - obj = malloc(sizeof(struct edbus_object)); - if (!obj) { - _E("fail to allocate %s interface", path); - return -ENOMEM; - } - - obj->path = strdup(path); - obj->interface = strdup(interface); - - ret = register_block_edbus_interface(obj); - if (ret < 0) { - _E("fail to register %s interface(%d)", obj->path, ret); - free(obj->path); - free(obj->interface); - free(obj); - return ret; - } - - DD_LIST_APPEND(edbus_object_list, obj); - } - - ret = register_method(obj->iface, edbus_methods, size); - if (ret < 0) { - _E("fail to register %s method(%d)", obj->path, ret); - return ret; - } - - return 0; -} - -int unregister_edbus_interface_all(void) -{ - struct edbus_object *obj; - dd_list *elem, *n; - - DD_LIST_FOREACH_SAFE(edbus_object_list, elem, n, obj) { - DD_LIST_REMOVE(edbus_object_list, obj); - free(obj->path); - free(obj->interface); - free(obj); - } - - return 0; -} - int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size) { E_DBus_Interface *iface; @@ -885,7 +361,6 @@ static void request_name_cb(void *data, DBusMessage *msg, DBusError *error) return; } } - static void check_owner_name(void) { DBusError err; @@ -999,18 +474,6 @@ void edbus_init(void *data) retry = 0; do { - conn_block = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); - if (conn_block) - break; - if (retry == EDBUS_INIT_RETRY_COUNT) { - _E("fail to get dbus"); - goto out1; - } - retry++; - } while (retry <= EDBUS_INIT_RETRY_COUNT); - - retry = 0; - do { edbus_conn = e_dbus_connection_setup(conn); if (edbus_conn) break; @@ -1023,18 +486,6 @@ void edbus_init(void *data) retry = 0; do { - edbus_conn_block = e_dbus_connection_setup(conn_block); - if (edbus_conn) - break; - if (retry == EDBUS_INIT_RETRY_COUNT) { - _E("fail to get edbus"); - goto out2; - } - retry++; - } while (retry <= EDBUS_INIT_RETRY_COUNT); - - retry = 0; - do { edbus_request_name = e_dbus_request_name(edbus_conn, PASS_BUS_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, request_name_cb, NULL); if (edbus_request_name) @@ -1051,7 +502,7 @@ void edbus_init(void *data) if (ret < 0) { _E("fail to add obj & interface for %s", edbus_objects[i].interface); - return; + goto out3; } _D("add new obj for %s", edbus_objects[i].interface); } @@ -1061,10 +512,8 @@ void edbus_init(void *data) out3: e_dbus_connection_close(edbus_conn); - e_dbus_connection_close(edbus_conn_block); out2: dbus_connection_set_exit_on_disconnect(conn, FALSE); - dbus_connection_set_exit_on_disconnect(conn_block, FALSE); out1: e_dbus_shutdown(); } @@ -1072,9 +521,6 @@ out1: void edbus_exit(void *data) { unregister_edbus_signal_handle(); - unregister_edbus_watch_all(); - unregister_edbus_interface_all(); e_dbus_connection_close(edbus_conn); - e_dbus_connection_close(edbus_conn_block); e_dbus_shutdown(); } diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h index 13224af..54e7b7d 100644 --- a/src/core/edbus-handler.h +++ b/src/core/edbus-handler.h @@ -31,43 +31,16 @@ struct edbus_method { E_DBus_Method_Cb func; }; -static inline DBusMessage *make_reply_message(DBusMessage *msg, int ret) -{ - DBusMessageIter iter; - DBusMessage *reply; - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - -DBusConnection *get_block_dbus_connection(void); -E_DBus_Object *register_edbus_object(const char *object_path, void *data); -E_DBus_Object *register_block_edbus_object(const char *object_path, void *data); -void unregister_edbus_object(E_DBus_Object *object); -int register_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size); -int register_block_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size); int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size); int register_edbus_signal_handler(const char *path, const char *interface, const char *name, E_DBus_Signal_Cb cb); int unregister_edbus_signal_handler(const char *path, const char *interface, const char *name); -E_DBus_Interface *get_edbus_interface(const char *path); pid_t get_edbus_sender_pid(DBusMessage *msg); int broadcast_edbus_signal(const char *path, const char *interface, const char *name, const char *sig, char *param[]); -int broadcast_block_edbus_signal(const char *path, const char *interface, - const char *name, const char *sig, char *param[]); -int register_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data), void *data); -int unregister_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data)); - void edbus_init(void *data); void edbus_exit(void *data); #endif /* __EDBUS_HANDLE_H__ */ + -- 2.7.4 From ec84e1a64df5edf8dc02fae4e8902d239a6e413a Mon Sep 17 00:00:00 2001 From: Wook Song Date: Tue, 13 Jun 2017 12:03:13 +0900 Subject: [PATCH 12/16] pass: gov: Fix build warnings caused by unused variables This patch fixes build warnings, which are caused by unused variables, in the __pass_governor_init and __pass_governor_exit functions. Change-Id: I9609991e1ef3e2b8136467171a595a68ec000bc3 Signed-off-by: Wook Song --- src/pass/pass-gov.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pass/pass-gov.c b/src/pass/pass-gov.c index eec38d8..e4ae37c 100644 --- a/src/pass/pass-gov.c +++ b/src/pass/pass-gov.c @@ -498,8 +498,6 @@ static void __pass_governor_stop(struct pass_policy *policy) static int __pass_governor_init(struct pass_policy *policy) { - struct pass_resource *res = to_pass_resource(policy); - struct pass_conf_data *cdata = &res->cdata; int ret; if(policy->gov_timeout < 0) { @@ -524,8 +522,6 @@ static int __pass_governor_init(struct pass_policy *policy) static int __pass_governor_exit(struct pass_policy *policy) { - struct pass_resource *res = to_pass_resource(policy); - struct pass_conf_data *cdata = &res->cdata; int i; /* Exit notifier */ -- 2.7.4 From 41a1693a0d6473e57ede302dace0d9b45fa68460 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 15 Jun 2017 19:00:56 +0900 Subject: [PATCH 13/16] pass: Change permission from root to 'system_fw' uid/gid This patch changes the permission from root to 'system_fw' uid/gid for PASS. Basically, Tizen has the policy to reduce the number of root daemon to protect the security issues. If PASS has the system_fw uid, it is enough to handle the h/w resources. Change-Id: I48aef3da083b6f1f4160ed166fdad89293acc5b6 Signed-off-by: Chanwoo Choi --- systemd/pass.service | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/systemd/pass.service b/systemd/pass.service index 070f30d..35e0578 100644 --- a/systemd/pass.service +++ b/systemd/pass.service @@ -1,12 +1,14 @@ [Unit] -Description=System device daemon +Description=PASS daemon [Service] -SmackProcessLabel=System::Privileged +SmackProcessLabel=System ExecStart=/usr/bin/pass Restart=always RestartSec=0 KillSignal=SIGUSR1 +User=system_fw +Group=system_fw [Install] WantedBy=multi-user.target -- 2.7.4 From 00a3aedc61af7040022d26dd34f3b0a398cf934a Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 16 Jun 2017 16:47:19 +0900 Subject: [PATCH 14/16] pass: Remove unused pass.socket file This patch just removes the unused pass.socket file. Change-Id: I76a84018b81d0c6290d10a4b7becc8849709e7de Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 1 - packaging/pass.spec | 2 -- systemd/pass.socket | 10 ---------- 3 files changed, 13 deletions(-) delete mode 100644 systemd/pass.socket diff --git a/CMakeLists.txt b/CMakeLists.txt index 0659710..c936174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,7 +163,6 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PASS_HAL_NAME}.pc DESTINATION ${LIB_ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system FILES_MATCHING PATTERN "*.service" - PATTERN "*.socket" ) ADD_SUBDIRECTORY(src/shared) diff --git a/packaging/pass.spec b/packaging/pass.spec index ad84e72..7138066 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -90,9 +90,7 @@ systemctl daemon-reload %config %{_sysconfdir}/pass/pass-pmqos.conf %{_bindir}/%{daemon_name} %{_unitdir}/multi-user.target.wants/%{daemon_name}.service -%{_unitdir}/sockets.target.wants/%{daemon_name}.socket %{_unitdir}/%{daemon_name}.service -%{_unitdir}/%{daemon_name}.socket %files -n %{hal_name} %defattr(-,root,root,-) diff --git a/systemd/pass.socket b/systemd/pass.socket deleted file mode 100644 index aa36429..0000000 --- a/systemd/pass.socket +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=System server socket - -[Socket] -ListenStream=/tmp/sn -SocketMode=0777 -PassCredentials=yes -SmackLabelIPIn=* -SmackLabelIPOut=@ -Accept=false -- 2.7.4 From b3794e31f49c00e105b3471e94f4cc2244e61bb3 Mon Sep 17 00:00:00 2001 From: Wook Song Date: Mon, 19 Jun 2017 12:57:31 +0900 Subject: [PATCH 15/16] pass: core: Remove unused udev module This patch removes currently unused udev module. Change-Id: If230c74e12e42d253677c0e54aeb23ad66655f28 Signed-off-by: Wook Song --- CMakeLists.txt | 2 - packaging/pass.spec | 1 - src/core/udev.c | 362 ---------------------------------------------------- src/core/udev.h | 44 ------- 4 files changed, 409 deletions(-) delete mode 100644 src/core/udev.c delete mode 100644 src/core/udev.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c936174..dbf5e27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,6 @@ SET(SRCS src/core/log.c src/core/main.c src/core/sig-handler.c - src/core/udev.c src/core/boot.c ) @@ -96,7 +95,6 @@ SET(PKG_MODULES edbus vconf dlog - libudev device-node capi-base-common glib-2.0 diff --git a/packaging/pass.spec b/packaging/pass.spec index 7138066..c1d1a89 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -24,7 +24,6 @@ BuildRequires: pkgconfig(edbus) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) -BuildRequires: pkgconfig(libudev) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(eventsystem) diff --git a/src/core/udev.c b/src/core/udev.c deleted file mode 100644 index 3e8deff..0000000 --- a/src/core/udev.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * PASS (Power Aware System Service) - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "shared/log.h" - -#include "device-notifier.h" -#include "devices.h" -#include "edbus-handler.h" -#include "list.h" -#include "udev.h" - -#define KERNEL "kernel" -#define UDEV "udev" - -#define UDEV_MONITOR_SIZE (10*1024) - -struct uevent_info { - struct udev_monitor *mon; - Ecore_Fd_Handler *fdh; - dd_list *event_list; -}; - -/* Uevent */ -static struct udev *udev; - -static struct uevent_info kevent; /* kernel */ -static struct uevent_info uevent; /* udev */ - -static Eina_Bool uevent_control_cb(void *data, Ecore_Fd_Handler *fd_handler) -{ - struct uevent_info *info = data; - struct udev_device *dev; - struct uevent_handler *l; - dd_list *elem; - const char *subsystem; - int len; - - assert(info); - - dev = udev_monitor_receive_device(info->mon); - if (!dev) - return ECORE_CALLBACK_RENEW; - - subsystem = udev_device_get_subsystem(dev); - if (!subsystem) - goto out; - - len = strlen(subsystem); - DD_LIST_FOREACH(info->event_list, elem, l) { - if (!strncmp(l->subsystem, subsystem, len) && - l->uevent_func) - l->uevent_func(dev); - } - -out: - udev_device_unref(dev); - return ECORE_CALLBACK_RENEW; -} - -static int uevent_control_stop(struct uevent_info *info) -{ - struct udev_device *dev; - - if (!info) - return -EINVAL; - - if (info->fdh) { - ecore_main_fd_handler_del(info->fdh); - info->fdh = NULL; - } - if (info->mon) { - dev = udev_monitor_receive_device(info->mon); - if (dev) - udev_device_unref(dev); - udev_monitor_unref(info->mon); - info->mon = NULL; - } - if (udev) - udev = udev_unref(udev); - return 0; -} - -static int uevent_control_start(const char *type, - struct uevent_info *info) -{ - struct uevent_handler *l; - dd_list *elem; - int fd; - int ret; - - if (!info) - return -EINVAL; - - if (info->mon) { - _E("%s uevent control routine is alreay started", type); - return -EINVAL; - } - - if (!udev) { - udev = udev_new(); - if (!udev) { - _E("error create udev"); - return -EINVAL; - } - } else - udev = udev_ref(udev); - - info->mon = udev_monitor_new_from_netlink(udev, type); - if (info->mon == NULL) { - _E("error udev_monitor create"); - goto stop; - } - - ret = udev_monitor_set_receive_buffer_size(info->mon, - UDEV_MONITOR_SIZE); - if (ret != 0) { - _E("fail to set receive buffer size"); - goto stop; - } - - DD_LIST_FOREACH(info->event_list, elem, l) { - ret = udev_monitor_filter_add_match_subsystem_devtype( - info->mon, - l->subsystem, NULL); - if (ret < 0) { - _E("error apply subsystem filter"); - goto stop; - } - } - - ret = udev_monitor_filter_update(info->mon); - if (ret < 0) - _E("error udev_monitor_filter_update"); - - fd = udev_monitor_get_fd(info->mon); - if (fd == -1) { - _E("error udev_monitor_get_fd"); - goto stop; - } - - info->fdh = ecore_main_fd_handler_add(fd, ECORE_FD_READ, - uevent_control_cb, info, NULL, NULL); - if (!info->fdh) { - _E("error ecore_main_fd_handler_add"); - goto stop; - } - - if (udev_monitor_enable_receiving(info->mon) < 0) { - _E("error unable to subscribe to udev events"); - goto stop; - } - - return 0; -stop: - uevent_control_stop(info); - return -EINVAL; -} - -static int register_uevent_control(struct uevent_info *info, - const struct uevent_handler *uh) -{ - struct uevent_handler *l; - dd_list *elem; - int r; - bool matched = false; - int len; - - if (!info || !uh || !uh->subsystem) - return -EINVAL; - - /* if udev is not initialized, it just will be added list */ - if (!udev || !info->mon) - goto add_list; - - len = strlen(uh->subsystem); - /* check if the same subsystem is already added */ - DD_LIST_FOREACH(info->event_list, elem, l) { - if (!strncmp(l->subsystem, uh->subsystem, len)) { - matched = true; - break; - } - } - - /* the first request to add subsystem */ - if (!matched) { - r = udev_monitor_filter_add_match_subsystem_devtype(info->mon, - uh->subsystem, NULL); - if (r < 0) { - _E("fail to add %s subsystem : %d", uh->subsystem, r); - return -EPERM; - } - } - - r = udev_monitor_filter_update(info->mon); - if (r < 0) - _E("fail to update udev monitor filter : %d", r); - -add_list: - DD_LIST_APPEND(info->event_list, uh); - return 0; -} - -static int unregister_uevent_control(struct uevent_info *info, - const struct uevent_handler *uh) -{ - struct uevent_handler *l; - dd_list *n, *next; - int len; - - if (!info || !uh || !uh->subsystem) - return -EINVAL; - - len = strlen(uh->subsystem); - DD_LIST_FOREACH_SAFE(info->event_list, n, next, l) { - if (!strncmp(l->subsystem, uh->subsystem, len) && - l->uevent_func == uh->uevent_func) { - DD_LIST_REMOVE(info->event_list, l); - return 0; - } - } - - return -ENOENT; -} - -int register_kernel_uevent_control(const struct uevent_handler *uh) -{ - return register_uevent_control(&kevent, uh); -} - -int unregister_kernel_uevent_control(const struct uevent_handler *uh) -{ - return unregister_uevent_control(&kevent, uh); -} - -int register_udev_uevent_control(const struct uevent_handler *uh) -{ - return register_uevent_control(&uevent, uh); -} - -int unregister_udev_uevent_control(const struct uevent_handler *uh) -{ - return unregister_uevent_control(&uevent, uh); -} - -static DBusMessage *dbus_udev_handler(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusError err; - DBusMessageIter iter; - DBusMessage *reply; - pid_t pid; - int ret = 0; - int argc; - char *type_str; - char *argv; - - dbus_error_init(&err); - - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) { - _E("there is no message"); - ret = -EINVAL; - goto out; - } - - if (argc < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - pid = get_edbus_sender_pid(msg); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (strncmp(argv, "start", strlen("start")) == 0) { - uevent_control_start(KERNEL, &kevent); - uevent_control_start(UDEV, &uevent); - } else if (strncmp(argv, "stop", strlen("stop")) == 0) { - uevent_control_stop(&kevent); - uevent_control_stop(&uevent); - } - -out: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - - return reply; -} - -static const struct edbus_method edbus_methods[] = { - { UDEV, "sis", "i", dbus_udev_handler }, -}; - -static int device_change_poweroff(void *data, void *user_data) -{ - uevent_control_stop(&kevent); - uevent_control_stop(&uevent); - return 0; -} - -static void udev_init(void *data) -{ - int ret; - - ret = register_notifier(DEVICE_NOTIFIER_POWEROFF, - device_change_poweroff, NULL); - if (ret < 0) - _E("cannot register power-off notifier for the udev (%d)\n", - ret); - - ret = register_edbus_method(PASS_PATH_SYSNOTI, - edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus method(%d)", ret); - - if (uevent_control_start(KERNEL, &kevent) != 0) - _E("fail uevent kernel control init"); - - if (uevent_control_start(UDEV, &uevent) != 0) - _E("fail uevent udev control init"); -} - -static void udev_exit(void *data) -{ - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, - device_change_poweroff, NULL); -} - -static const struct device_ops udev_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "udev", - .init = udev_init, - .exit = udev_exit, -}; - -DEVICE_OPS_REGISTER(&udev_device_ops) diff --git a/src/core/udev.h b/src/core/udev.h deleted file mode 100644 index 66fc130..0000000 --- a/src/core/udev.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * PASS - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __UDEV_H__ -#define __UDEV_H__ - -#include - -#define UDEV_CHANGE "change" -#define UDEV_ADD "add" -#define UDEV_REMOVE "remove" - -#define UDEV_DEVPATH "DEVPATH" -#define UDEV_DEVTYPE "DEVTYPE" - -struct uevent_handler { - char *subsystem; - void (*uevent_func)(struct udev_device *dev); - void *data; -}; - -int register_kernel_uevent_control(const struct uevent_handler *uh); -int unregister_kernel_uevent_control(const struct uevent_handler *uh); - -int register_udev_uevent_control(const struct uevent_handler *uh); -int unregister_udev_uevent_control(const struct uevent_handler *uh); - -#endif /* __UDEV_H__ */ -- 2.7.4 From 1b0174670bbdcc82245501d1ccf349d1c73cea9f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 19 Jun 2017 14:13:35 +0900 Subject: [PATCH 16/16] pmqos: Add 'scenario_max_timeout_ms' property to set the maximum timeout Each scenario wants to lock the h/w resources within their own timeout. If the specific scenario wants to lock the h/w resources for so long time, it is not reasonable. So, PMQoS core has the maximum timeout in order to protect the excessive occupation of h/w resources. This patch adds the new 'scenario_max_timeout_ms' property which means the maximum timeout for the scenarios on specific h/w board. The owner of PASS daemon can adjust the maximum timeout according to the h/w board. Change-Id: Ic38137f667c34230b90e9217d33549d5859fd5fa Signed-off-by: Chanwoo Choi --- src/pmqos/pass-pmqos.conf | 1 + src/pmqos/pmqos-parser.c | 13 +++++++++++++ src/pmqos/pmqos.c | 18 +++++++++++++++--- src/pmqos/pmqos.h | 1 + 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/pmqos/pass-pmqos.conf b/src/pmqos/pass-pmqos.conf index b55f023..4c4a8bd 100644 --- a/src/pmqos/pass-pmqos.conf +++ b/src/pmqos/pass-pmqos.conf @@ -1,6 +1,7 @@ [PassScenario] # set to "yes" scenario_support (Default value is no) # set scenario_num to be tested +# set scenario_max_timeout_ms (unit:millisecond, default timeout is 3000ms) scenario_support=yes scenario_num=52 diff --git a/src/pmqos/pmqos-parser.c b/src/pmqos/pmqos-parser.c index 6f5a13b..daff810 100644 --- a/src/pmqos/pmqos-parser.c +++ b/src/pmqos/pmqos-parser.c @@ -67,6 +67,14 @@ static int pmqos_parse_scenario(struct parse_result *result, void *user_data, un return -errno; } } + } else if (MATCH(result->name, "scenario_max_timeout_ms")) { + int max_timeout_ms = atoi(result->value); + + if (max_timeout_ms < 0) { + _E("failed to get maximum timeout of scenario"); + return -ERANGE; + } + scenarios->max_timeout_ms = max_timeout_ms; } } @@ -140,6 +148,7 @@ int pmqos_put_scenario(struct pmqos_scenario *scenarios) if (scenarios->num > 0 && !scenarios->list) { scenarios->num = 0; + scenarios->max_timeout_ms = 0; free(scenarios->list); } @@ -150,6 +159,10 @@ int pmqos_get_scenario(const char *path, struct pmqos_scenario *scenarios) { int ret; + /* Initialize the variables before parsing the pass-pmqos.conf */ + scenarios->num = 0; + scenarios->max_timeout_ms = 0; + /* get configuration file */ ret = config_parse(path, pmqos_load_config, scenarios); if (ret < 0) { diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 1869c00..9cf9f6d 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -47,6 +47,7 @@ struct pmqos_cpu { static dd_list *pmqos_head; static Ecore_Timer *unlock_timer; +static int unlock_max_timeout_ms; static struct timespec unlock_timer_start_st; static struct timespec unlock_timer_end_st; static struct pmqos_cpu unlock_timer_owner = {"", 0}; @@ -229,9 +230,10 @@ static int pmqos_request(const char *name, int val) int ret; /* Check valid parameter */ - if (val > DEFAULT_PMQOS_TIMER) { - _I("The timer value cannot be higher than default time value(%dms)", DEFAULT_PMQOS_TIMER); - val = DEFAULT_PMQOS_TIMER; + if (val > unlock_max_timeout_ms) { + _I("Timeout cannot be higher than maximum timeout (%d ms)", + unlock_max_timeout_ms); + val = unlock_max_timeout_ms; } /* find cpu */ DD_LIST_FOREACH(pmqos_head, elem, cpu) { @@ -347,6 +349,16 @@ static int get_methods_from_conf(const char *path, struct edbus_method **edbus_m _D("support [%s] scenario", scenarios.list[i].name); } + /* + * Set maximum timeout for the sceanrio by using the parsed data from + * pass-pmqos.conf. But, if there is no setting from pass-pmqos.conf + * pmqos uses the default timeout value (3000 millisecond). + */ + if (scenarios.max_timeout_ms) + unlock_max_timeout_ms = scenarios.max_timeout_ms; + else + unlock_max_timeout_ms = DEFAULT_PMQOS_TIMER; + *edbus_methods = methods; ret = count; pmqos_put_scenario(&scenarios); diff --git a/src/pmqos/pmqos.h b/src/pmqos/pmqos.h index 8a4d381..2337cb7 100644 --- a/src/pmqos/pmqos.h +++ b/src/pmqos/pmqos.h @@ -29,6 +29,7 @@ struct pmqos_scenario { bool support; } *list; int num; + int max_timeout_ms; bool support; }; -- 2.7.4