[FIX] startup profiling for basic app 09/41809/5
authorAnastasia Lyupa <a.lyupa@samsung.com>
Wed, 17 Jun 2015 13:54:27 +0000 (16:54 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Thu, 18 Jun 2015 09:56:16 +0000 (02:56 -0700)
when app is launched by launchpad_preloading_preinitializing_daemon,
not launchpad-process-pool

Change-Id: I01fcb65538593a658eea901a88a8ddef064b8221
Signed-off-by: Anastasia Lyupa <a.lyupa@samsung.com>
nsp/nsp.c
nsp/nsp.h
nsp/nsp_debugfs.c

index baa8160..e79168f 100644 (file)
--- a/nsp/nsp.c
+++ b/nsp/nsp.c
 static int dlopen_eh(struct uretprobe_instance *ri, struct pt_regs *regs);
 static int dlopen_rh(struct uretprobe_instance *ri, struct pt_regs *regs);
 static struct probe_info_new pin_dlopen = MAKE_URPROBE(dlopen_eh, dlopen_rh, 0);
-struct probe_new p_dlopen = {
+struct probe_new p_dlopen_pool = {
+       .info = &pin_dlopen
+};
+struct probe_new p_dlopen_daemon = {
        .info = &pin_dlopen
 };
 
@@ -50,7 +53,10 @@ struct probe_new p_dlopen = {
 static int dlsym_eh(struct uretprobe_instance *ri, struct pt_regs *regs);
 static int dlsym_rh(struct uretprobe_instance *ri, struct pt_regs *regs);
 static struct probe_info_new pin_dlsym = MAKE_URPROBE(dlsym_eh, dlsym_rh, 0);
-struct probe_new p_dlsym = {
+struct probe_new p_dlsym_pool = {
+       .info = &pin_dlsym
+};
+struct probe_new p_dlsym_daemon = {
        .info = &pin_dlsym
 };
 
@@ -92,8 +98,11 @@ static struct probe_info_otg pin_reset_otg = {
  * =                the variables are initialized by the user                 =
  * ============================================================================
  */
-static const char *lpad_path;
-static struct dentry *lpad_dentry;
+static const char *lpad_path_pool;
+static struct dentry *lpad_dentry_pool;
+
+static const char *lpad_path_daemon;
+static struct dentry *lpad_dentry_daemon;
 
 static const char *libappcore_path;
 static struct dentry *libappcore_dentry;
@@ -107,7 +116,7 @@ static struct {
 
 static bool is_init(void)
 {
-       return lpad_dentry && libappcore_dentry &&
+       return lpad_dentry_pool && lpad_dentry_daemon && libappcore_dentry &&
               cb_offset.flag_create && cb_offset.flag_reset;
 }
 
@@ -129,8 +138,8 @@ static int do_set_offset(enum offset_t os, unsigned long offset)
        return -EINVAL;
 }
 
-static int do_set_lpad_info(const char *path, unsigned long dlopen,
-                           unsigned long dlsym)
+static int do_set_lpad_info(bool is_process_pool, const char *path,
+                           unsigned long dlopen, unsigned long dlsym)
 {
        struct dentry *dentry;
        const char *new_path;
@@ -147,12 +156,19 @@ static int do_set_lpad_info(const char *path, unsigned long dlopen,
                return -ENOMEM;
        }
 
-       kfree(lpad_path);
-
-       lpad_path = new_path;
-       lpad_dentry = dentry;
-       p_dlopen.offset = dlopen;
-       p_dlsym.offset = dlsym;
+       if (is_process_pool) {
+               kfree(lpad_path_pool);
+               lpad_path_pool = new_path;
+               lpad_dentry_pool = dentry;
+               p_dlopen_pool.offset = dlopen;
+               p_dlsym_pool.offset = dlsym;
+       } else {
+               kfree(lpad_path_daemon);
+               lpad_path_daemon = new_path;
+               lpad_dentry_daemon = dentry;
+               p_dlopen_daemon.offset = dlopen;
+               p_dlsym_daemon.offset = dlsym;
+       }
 
        return 0;
 }
@@ -199,11 +215,16 @@ struct nsp_data {
        struct dentry *app_dentry;
 
        struct pf_group *pfg;
+
+       struct dentry *lpad_dentry;
+       struct probe_new *p_dlopen;
+       struct probe_new *p_dlsym;
 };
 
 static LIST_HEAD(nsp_data_list);
 
-static struct nsp_data *nsp_data_create(const char *app_path)
+static struct nsp_data *nsp_data_create(bool is_process_pool,
+                                       const char *app_path)
 {
        struct dentry *dentry;
        struct nsp_data *data;
@@ -225,6 +246,16 @@ static struct nsp_data *nsp_data_create(const char *app_path)
        data->app_dentry = dentry;
        data->pfg = NULL;
 
+       if (is_process_pool) {
+               data->lpad_dentry = lpad_dentry_pool;
+               data->p_dlopen = &p_dlopen_pool;
+               data->p_dlsym = &p_dlsym_pool;
+       } else {
+               data->lpad_dentry = lpad_dentry_daemon;
+               data->p_dlopen = &p_dlopen_daemon;
+               data->p_dlsym = &p_dlsym_daemon;
+       }
+
        return data;
 }
 
@@ -273,15 +304,16 @@ static int nsp_data_inst(struct nsp_data *data)
        int ret;
        struct pf_group *pfg;
 
-       pfg = get_pf_group_by_dentry(lpad_dentry, (void *)data->app_dentry);
+       pfg = get_pf_group_by_dentry(data->lpad_dentry,
+                                   (void *)data->app_dentry);
        if (pfg == NULL)
                return -ENOMEM;
 
-       ret = pin_register(&p_dlsym, pfg, lpad_dentry);
+       ret = pin_register(data->p_dlsym, pfg, data->lpad_dentry);
        if (ret)
                goto put_g;
 
-       ret = pin_register(&p_dlopen, pfg, lpad_dentry);
+       ret = pin_register(data->p_dlopen, pfg, data->lpad_dentry);
        if (ret)
                goto ur_dlsym;
 
@@ -293,9 +325,9 @@ static int nsp_data_inst(struct nsp_data *data)
 
        return 0;
 ur_dlopen:
-       pin_unregister(&p_dlopen, pfg, lpad_dentry);
+       pin_unregister(data->p_dlopen, pfg, data->lpad_dentry);
 ur_dlsym:
-       pin_unregister(&p_dlsym, pfg, lpad_dentry);
+       pin_unregister(data->p_dlsym, pfg, data->lpad_dentry);
 put_g:
        put_pf_group(pfg);
        return ret;
@@ -304,20 +336,21 @@ put_g:
 static void nsp_data_uninst(struct nsp_data *data)
 {
        pin_unregister(&p_appcore, data->pfg, libappcore_dentry);
-       pin_unregister(&p_dlopen, data->pfg, lpad_dentry);
-       pin_unregister(&p_dlsym, data->pfg, lpad_dentry);
+       pin_unregister(data->p_dlopen, data->pfg, data->lpad_dentry);
+       pin_unregister(data->p_dlsym, data->pfg, data->lpad_dentry);
+
        put_pf_group(data->pfg);
        data->pfg = NULL;
 }
 
-static int __nsp_add(const char *app_path)
+static int __nsp_add(bool is_process_pool, const char *app_path)
 {
        struct nsp_data *data;
 
        if (nsp_data_find_by_path(app_path))
                return -EEXIST;
 
-       data = nsp_data_create(app_path);
+       data = nsp_data_create(is_process_pool, app_path);
        if (IS_ERR(data))
                return PTR_ERR(data);
 
@@ -398,6 +431,7 @@ fail:
 #define F_ARG1(m, t, a)                m(t, a)
 #define F_ARG2(m, t, a, ...)   m(t, a), F_ARG1(m, __VA_ARGS__)
 #define F_ARG3(m, t, a, ...)   m(t, a), F_ARG2(m, __VA_ARGS__)
+#define F_ARG4(m, t, a, ...)   m(t, a), F_ARG3(m, __VA_ARGS__)
 #define F_ARG(n, m, ...)       F_ARG##n(m, __VA_ARGS__)
 
 #define M_TYPE_AND_ARG(t, a)   t a
@@ -422,17 +456,19 @@ unlock:                                                   \
 #define DECLARE_SAFE_FUNC1(name, _do, ...)     DECLARE_SAFE_FUNC(1, name, _do, __VA_ARGS__);
 #define DECLARE_SAFE_FUNC2(name, _do, ...)     DECLARE_SAFE_FUNC(2, name, _do, __VA_ARGS__);
 #define DECLARE_SAFE_FUNC3(name, _do, ...)     DECLARE_SAFE_FUNC(3, name, _do, __VA_ARGS__);
+#define DECLARE_SAFE_FUNC4(name, _do, ...)     DECLARE_SAFE_FUNC(4, name, _do, __VA_ARGS__);
 
 
 static DEFINE_MUTEX(stat_mutex);
 static enum nsp_stat stat = NS_OFF;
 
-DECLARE_SAFE_FUNC1(nsp_add, __nsp_add, const char *, app_path);
+DECLARE_SAFE_FUNC2(nsp_add, __nsp_add, bool, is_process_pool,
+                  const char *, app_path);
 DECLARE_SAFE_FUNC1(nsp_rm, __nsp_rm, const char *, app_path);
 DECLARE_SAFE_FUNC0(nsp_rm_all, __nsp_rm_all);
 DECLARE_SAFE_FUNC2(nsp_set_offset, do_set_offset,
                   enum offset_t, os, unsigned long, offset);
-DECLARE_SAFE_FUNC3(nsp_set_lpad_info, do_set_lpad_info,
+DECLARE_SAFE_FUNC4(nsp_set_lpad_info, do_set_lpad_info, bool, is_process_pool,
                   const char *, path, unsigned long, dlopen,
                   unsigned long, dlsym);
 DECLARE_SAFE_FUNC2(nsp_set_appcore_info, do_set_appcore_info,
index 4f8c50e..bed2d62 100644 (file)
--- a/nsp/nsp.h
+++ b/nsp/nsp.h
@@ -38,14 +38,14 @@ int nsp_init(void);
 void nsp_exit(void);
 
 int nsp_set_offset(enum offset_t os, unsigned long offset);
-int nsp_set_lpad_info(const char *path, unsigned long dlopen,
-                     unsigned long dlsym);
+int nsp_set_lpad_info(bool is_process_pool, const char *path,
+                     unsigned long dlopen, unsigned long dlsym);
 int nsp_set_appcore_info(const char *path, unsigned long appcore_efl_main);
 
 int nsp_set_stat(enum nsp_stat st);
 enum nsp_stat nsp_get_stat(void);
 
-int nsp_add(const char *app_path);
+int nsp_add(bool is_process_pool, const char *app_path);
 int nsp_rm(const char *app_path);
 int nsp_rm_all(void);
 
index 3be7894..3237e2f 100644 (file)
@@ -41,16 +41,16 @@ static void rm_endline_symbols(char *buf, size_t len)
 
 /*
  * format:
- *     app_path
+ *     is_process_pool:app_path
  *
  * sample:
- *     /bin/app_sample
+ *     1:/bin/app_sample
  */
 static int do_add(const char *buf, size_t len)
 {
-       int n, ret;
+       int n, ret, pool;
        char *app_path;
-       const char fmt[] = "/%%%ds";
+       const char fmt[] = "%%d:/%%%ds";
        char fmt_buf[64];
 
        n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
@@ -61,16 +61,21 @@ static int do_add(const char *buf, size_t len)
        if (app_path == NULL)
                return -ENOMEM;
 
-       n = sscanf(buf, fmt_buf, app_path + 1);
-       if (n != 1) {
+       n = sscanf(buf, fmt_buf, &pool, app_path + 1);
+       if (n != 2) {
                ret = -EINVAL;
-               goto free_app_path;
+               goto free_app_info;
        }
        app_path[0] = '/';
 
-       ret = nsp_add(app_path);
+       if (pool != 0 && pool != 1) {
+               ret = -EINVAL;
+               goto free_app_info;
+       }
+
+       ret = nsp_add(pool, app_path);
 
-free_app_path:
+free_app_info:
        kfree(app_path);
        return ret;
 }
@@ -135,18 +140,18 @@ par_free:
 
 /*
  * format:
- *     dlopen_addr@plt:dlsym_addr@plt:launchpad_path
+ *     is_process_pool:dlopen_addr@plt:dlsym_addr@plt:launchpad_path
  *
  * sample:
- *     0x000234:0x000342:/usr/bin/launchpad-loader
+ *     1:0x000234:0x000342:/usr/bin/launchpad-loader
  */
 static int do_set_lpad_info(const char *data, size_t len)
 {
-       int n, ret;
+       int n, ret, pool;
        unsigned long dlopen_addr;
        unsigned long dlsym_addr;
        char *lpad_path;
-       const char fmt[] = "%%lx:%%lx:/%%%ds";
+       const char fmt[] = "%%d:%%lx:%%lx:/%%%ds";
        char fmt_buf[64];
 
        n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
@@ -157,14 +162,20 @@ static int do_set_lpad_info(const char *data, size_t len)
        if (lpad_path == NULL)
                return -ENOMEM;
 
-       n = sscanf(data, fmt_buf, &dlopen_addr, &dlsym_addr, lpad_path + 1);
-       if (n != 3) {
+       n = sscanf(data, fmt_buf, &pool, &dlopen_addr, &dlsym_addr,
+                  lpad_path + 1);
+       if (n != 4) {
                ret = -EINVAL;
                goto free_lpad_path;
        }
        lpad_path[0] = '/';
 
-       ret = nsp_set_lpad_info(lpad_path, dlopen_addr, dlsym_addr);
+       if (pool != 0 && pool != 1) {
+               ret = -EINVAL;
+               goto free_lpad_path;
+       }
+
+       ret = nsp_set_lpad_info(pool, lpad_path, dlopen_addr, dlsym_addr);
 
 free_lpad_path:
        kfree(lpad_path);
@@ -291,10 +302,10 @@ static ssize_t read_cmd(struct file *file, char __user *user_buf,
 {
        const char help[] =
                        "use:\n"
-                       "\ta $app_path - add\n"
+                       "\ta $process_pool:$app_path - add\n"
                        "\tr $app_path - remove\n"
                        "\tc - remove all\n"
-                       "\tb $dlopen_addr@plt:$dlsym_addr@plt:$launchpad_path\n"
+                       "\tb $process_pool:$dlopen_addr@plt:$dlsym_addr@plt:$launchpad_path\n"
                        "\tl $appcore_efl_main:$libappcore-efl_path\n"
                        "\ts $param $val - set parameter";
        ssize_t ret;