AMD moves to system session 03/102403/8
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 5 Dec 2016 13:59:05 +0000 (22:59 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Sun, 18 Dec 2016 22:22:35 +0000 (14:22 -0800)
- Make aul directories
- Send launch/dead signal to amd
- Make default slots by cpu usage

Change-Id: Ie41fbeb3155a14b5c382d79cad53b5c4c7393934
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
inc/launchpad_common.h
packaging/launchpad-process-pool.service
src/launchpad.c
src/launchpad_common.c

index f1907c1..8016469 100644 (file)
 #define PAD_CMD_REMOVE_LOADER  12
 #define PAD_CMD_MAKE_DEFAULT_SLOTS     13
 #define PAD_CMD_DEMAND         14
+#define PAD_CMD_PING           15
+
+#define LAUNCHPAD_LAUNCH_SIGNAL 85
+#define LAUNCHPAD_DEAD_SIGNAL 61
 
 #define PAD_LOADER_ID_STATIC   0
 #define PAD_LOADER_ID_DIRECT   1
@@ -85,6 +89,7 @@ typedef struct {
 
 void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd);
 
+int _send_cmd_to_amd(int cmd);
 int _create_server_sock(const char *name);
 app_pkt_t *_recv_pkt_raw(int fd, int *clifd, struct ucred *cr);
 int _send_pkt_raw(int client_fd, app_pkt_t *pkt);
index 2d633ec..c890e2d 100644 (file)
@@ -5,11 +5,15 @@
 [Unit]
 Description=Start the USER Access Control Agent
 DefaultDependencies=false
+Requires=enlightenment-user.service
+After=enlightenment-user.service
 
 [Service]
 ExecStartPre=-/usr/bin/mkdir -p /run/aul/daemons/%U
 ExecStartPre=-/usr/bin/chmod 0777 /run/aul/daemons/%U
 ExecStartPre=-/usr/bin/mkdir -p /run/aul/apps/%U
 ExecStartPre=-/usr/bin/chmod 0700 /run/aul/apps/%U
+ExecStartPre=-/usr/bin/mkdir -p /run/aul/dbspace/%U
+ExecStartPre=-/usr/bin/chmod 0700 /run/aul/dbspace/%U
 ExecStart=/bin/sh -l -c "/usr/bin/launchpad-process-pool"
 Sockets=launchpad-process-pool.socket
index 6416bc1..5305dc6 100755 (executable)
@@ -1319,6 +1319,10 @@ static gboolean __handle_launch_event(gpointer data)
                __real_send(clifd, ret);
                clifd = -1;
                goto end;
+       case PAD_CMD_PING:
+               __real_send(clifd, 0);
+               clifd = -1;
+               goto end;
        }
 
        INIT_PERF(kb);
@@ -1575,7 +1579,8 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
        candidate_process_context_t *cpc;
        bundle_raw *extra = NULL;
        int len;
-       int ret;
+       long long total = 0;
+       long long idle = 0;
 
        if (!strcmp(info->exe, "null")) {
                cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
@@ -1600,11 +1605,11 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
                if (cpc == NULL)
                        return;
 
-               ret = __prepare_candidate_process(
-                               LAUNCHPAD_TYPE_USER + user_slot_offset,
-                               PAD_LOADER_ID_STATIC);
-               if (ret != 0)
-                       return;
+               _get_cpu_idle(&total, &idle);
+               cpc->cpu_idle_time = idle;
+               cpc->cpu_total_time = total;
+               cpc->idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT,
+                               __handle_idle_checker, cpc);
 
                info->type = LAUNCHPAD_TYPE_USER + user_slot_offset;
                user_slot_offset++;
@@ -1672,13 +1677,21 @@ static int __before_loop(int argc, char **argv)
                                VCONFKEY_SETAPPL_APP_HW_ACCELERATION);
        }
 
+       __add_default_slots();
        launcher_info_list = _launcher_info_load(LAUNCHER_INFO_PATH);
 
+       ret = _send_cmd_to_amd(LAUNCHPAD_LAUNCH_SIGNAL);
+       if (ret < 0)
+               _W("Failed to send cmd(%d) to amd", LAUNCHPAD_LAUNCH_SIGNAL);
+
        return 0;
 }
 
 static void __after_loop(void)
 {
+       if (_send_cmd_to_amd(LAUNCHPAD_DEAD_SIGNAL) < 0)
+               _W("Failed to send cmd(%d) to amd", LAUNCHPAD_DEAD_SIGNAL);
+
        _debug_fini();
        _launcher_info_unload(launcher_info_list);
 
index aa4b909..ddb4432 100644 (file)
@@ -43,6 +43,7 @@
 #define CONNECT_RETRY_TIME (100 * 1000)
 #define CONNECT_RETRY_COUNT 3
 #define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int))
+#define PATH_AMD_SOCK "/run/aul/daemons/.amd-sock"
 
 static int __read_proc(const char *path, char *buf, int size)
 {
@@ -208,6 +209,72 @@ static int __parse_app_path(const char *arg, char *out, int out_size)
        return -2;
 }
 
+int _send_cmd_to_amd(int cmd)
+{
+       struct sockaddr_un addr = {0,};
+       int fd;
+       int ret;
+       int res;
+       int retry = CONNECT_RETRY_COUNT;
+       app_pkt_t pkt = {0,};
+
+       fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+       /*  support above version 2.6.27*/
+       if (fd < 0) {
+               if (errno == EINVAL) {
+                       fd = socket(AF_UNIX, SOCK_STREAM, 0);
+                       if (fd < 0) {
+                               _E("second chance - socket create error");
+                               return -1;
+                       }
+               } else {
+                       _E("socket error");
+                       return -1;
+               }
+       }
+
+       addr.sun_family = AF_UNIX;
+       snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", PATH_AMD_SOCK);
+       while (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+               if (errno != ETIMEDOUT || retry <= 0) {
+                       _E("Failed to connect error(%d)", errno);
+                       close(fd);
+                       return -1;
+               }
+
+               usleep(CONNECT_RETRY_TIME);
+               --retry;
+               _D("re-connect to %s (%d)", addr.sun_path, retry);
+       }
+
+       pkt.cmd = cmd;
+       ret = send(fd, &pkt, sizeof(app_pkt_t), 0);
+       if (ret <= 0) {
+               _E("Failed to send cmd(%d), errno(%d)", cmd, errno);
+               close(fd);
+               return -ECOMM;
+       }
+
+retry_recv:
+       ret = recv(fd, &res, sizeof(int), 0);
+       if (ret <= 0) {
+               if (errno == EAGAIN) {
+                       _E("recv timeout");
+                       res = -EAGAIN;
+               } else if (errno == EINTR) {
+                       _D("Interrupted system call");
+                       goto retry_recv;
+               } else {
+                       _E("recv error(%d)", errno);
+                       res = -ECOMM;
+               }
+       }
+
+       close(fd);
+
+       return res;
+}
+
 int _create_server_sock(const char *name)
 {
        struct sockaddr_un saddr;