Add part of datausage code. 28/20628/1
authorPrzemyslaw Kedzierski <p.kedzierski@samsung.com>
Fri, 9 May 2014 15:23:35 +0000 (17:23 +0200)
committerPrzemyslaw Kedzierski <p.kedzierski@samsung.com>
Fri, 9 May 2014 15:59:31 +0000 (17:59 +0200)
    The datausage module is used for network traffic statistics.
    This commit adds parts of code of datausage module,
    used in resourced module.

Change-Id: Idc695eeaf0f1e50dbdc83a9b7274f1b7d7fb950f
Signed-off-by: Przemyslaw Kedzierski <p.kedzierski@samsung.com>
CMakeLists/init-needed-environment.txt
CMakeLists/libs.txt
CMakeLists/resourced.txt
src/datausage/counter.c [new file with mode: 0644]
src/datausage/daemon-options.c [moved from src/resourced/daemon-options.c with 100% similarity]
src/datausage/join-local.c [new file with mode: 0644]
src/proc-stat/proc-main.c
src/resourced/init.c

index 9dce736..e7fbf56 100644 (file)
@@ -1,5 +1,4 @@
 SET(fw_name "resourced")
-SET(RESOURCED resourced)
 
 
 SET(RESOURCED resourced)
index 02d6e29..dc80f3e 100644 (file)
@@ -1,6 +1,9 @@
 INCLUDE_DIRECTORIES(${RESOURCED_INCLUDEDIR}
+                   ${DATAUSAGE_SOURCE_DIR}/include
                    ${APP-STAT_SOURCE_DIR}/include
-                   ${RESOURCED_SOURCE_DIR})
+                   ${RESOURCED_SOURCE_DIR}
+                   ${NETWORK_SOURCE_DIR}/include
+            )
 
 INCLUDE(FindPkgConfig)
 
index fdeec5c..eb1a624 100644 (file)
@@ -9,12 +9,15 @@ INCLUDE_DIRECTORIES(${RESOURCED_INCLUDEDIR}
   ${MEMORY_SOURCE_DIR}
   ${PROC-STAT_SOURCE_DIR}/include
   ${APP-STAT_SOURCE_DIR}/include
+  ${DATAUSAGE_SOURCE_DIR}/include
   ${NETWORK_SOURCE_DIR}/include)
 
 CONFIGURE_FILE(${INCLUDE_COMMON_DIR}/config.h.in
   ${INCLUDE_COMMON_DIR}/config.h)
 
 SET (HEADERS
+  ${DATAUSAGE_SOURCE_DIR}/include/daemon-options.h
+  ${DATAUSAGE_SOURCE_DIR}/include/datausage-vconf-callbacks.h
   ${INCLUDE_COMMON_DIR}/config.h
   ${INCLUDE_COMMON_DIR}/config-parser.h
   ${INCLUDE_COMMON_DIR}/const.h
@@ -38,7 +41,9 @@ SET (SOURCES
   ${COMMON_SOURCE_DIR}/file-helper.c
   ${COMMON_SOURCE_DIR}/module-data.c
   ${COMMON_SOURCE_DIR}/module.c
-  ${RESOURCED_SOURCE_DIR}/daemon-options.c
+  ${DATAUSAGE_SOURCE_DIR}/counter.c
+  ${DATAUSAGE_SOURCE_DIR}/daemon-options.c
+  ${DATAUSAGE_SOURCE_DIR}/join-local.c
   ${COMMON_SOURCE_DIR}/lowmem-common.c
   ${COMMON_SOURCE_DIR}/swap-common.c
   ${COMMON_SOURCE_DIR}/cpu-common.c
diff --git a/src/datausage/counter.c b/src/datausage/counter.c
new file mode 100644 (file)
index 0000000..4c84d89
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * resourced
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ *  @file: counter.c
+ *  @desc Entity for working with datausage counter.
+ *
+ */
+
+#include "app-stat.h"
+#include "counter.h"
+#include "macro.h"
+#include "trace.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+
+struct counter_arg *init_counter_arg(struct daemon_opts *opts)
+{
+       struct counter_arg *result =
+               (struct counter_arg *)calloc(1, sizeof(struct counter_arg));
+
+       ret_value_msg_if(result == NULL, NULL, "Not enough memory\n");
+       result->pid = getpid();
+       result->opts = opts;
+       return result;
+}
+
+void finalize_carg(struct counter_arg *carg)
+{
+       free(carg);
+}
+
+void reschedule_count_timer(const struct counter_arg *carg, const double delay)
+{
+       ret_value_msg_if(!carg || !carg->ecore_timer, ,
+                        "Invalid counter argument or carg_timer is null\n");
+       ecore_timer_delay(carg->ecore_timer,
+                         delay - ecore_timer_pending_get(carg->ecore_timer));
+}
diff --git a/src/datausage/join-local.c b/src/datausage/join-local.c
new file mode 100644 (file)
index 0000000..5b53fad
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * resourced
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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.
+ *
+ */
+
+/**
+ * @file join.c
+ * @desc Implement Performance API. Joining performance control.
+ *    Entity for creation cgroup
+ */
+
+#include "datausage-common.h"
+#include "macro.h"
+#include "module.h"
+#include "trace.h"
+
+resourced_ret_c join_net_cls(const char *app_id, const pid_t pid)
+{
+       struct netstat_data_type net_data;
+       int ret = RESOURCED_ERROR_NONE;
+       uint32_t args[2];
+       static const struct module_ops *net_stat;
+
+       if (net_stat == NULL) {
+               net_stat = find_module("datausage");
+               ret_value_msg_if(net_stat == NULL, ret,
+                       "Can't find datausage module!");
+       }
+
+       args[0] = (uint32_t)app_id;
+       args[1] = (uint32_t)pid;
+
+       net_data.op_type = JOIN_NET_CLS;
+       net_data.args = args;
+
+       if (net_stat->control)
+               ret = net_stat->control(&net_data);
+       return ret;
+}
+
+
index 9976702..7214e99 100644 (file)
 #include <Ecore_File.h>
 
 #include "classid-helper.h"
+#include "datausage-common.h"
 #include "proc-process.h"
 #include "proc-main.h"
 
+#include "cgroup.h"
 #include "proc-noti.h"
 #include "trace.h"
 #include "proc-winstate.h"
@@ -220,7 +222,14 @@ int resourced_proc_status_change(int type, pid_t pid, char* app_name)
                }
                _SD("launch request %s, %d", app_name, pid);
 
-               raise_update_classid();
+               /* init oom score adj value for preventing killing application during launching */
+               ret = join_net_cls(app_name, pid);
+               if (ret != RESOURCED_ERROR_NONE)
+                       _E("Failed to start network counting.");
+               else
+                       /* update_classid function is called
+                          only in datausage modules */
+                       raise_update_classid();
 
                break;
        case PROC_CGROUP_SET_RESUME_REQUEST:
@@ -247,6 +256,7 @@ int resourced_proc_status_change(int type, pid_t pid, char* app_name)
                if (ret != 0)
                        break;
 
+               proc_add_visibiliry(pid);
                break;
        case PROC_CGROUP_SET_INACTIVE:
                ret = proc_set_inactive(pid, oom_score_adj);
index b46a990..857c8c4 100644 (file)
@@ -150,11 +150,6 @@ static int assert_root(void)
        return RESOURCED_ERROR_NONE;
 }
 
-void reschedule_count_timer(const struct counter_arg *carg, const double delay)
-{
-            ecore_timer_delay(carg->ecore_timer,
-                                  delay - ecore_timer_pending_get(carg->ecore_timer));
-}
 
 static void sig_term_handler(int sig)
 {