cpu: add cpu boosting operation
authortaeyoung <ty317.kim@samsung.com>
Fri, 16 Dec 2016 07:00:29 +0000 (16:00 +0900)
committertaeyoung <ty317.kim@samsung.com>
Fri, 16 Dec 2016 07:14:06 +0000 (16:14 +0900)
Currently, the code is experimental. The HAL sends information
via socket, and TRM runs cpu boosting

Change-Id: Ida44cede55252e1e82a543f990cf8d2c4eb01ae0
Signed-off-by: taeyoung <ty317.kim@samsung.com>
CMakeLists.txt
hw/cpu/CMakeLists.txt [new file with mode: 0644]
hw/cpu/cpu.c [new file with mode: 0644]

index 35b74da..d02dc61 100644 (file)
@@ -4,6 +4,7 @@ PROJECT(device-manager-sc7730 C)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
 ADD_SUBDIRECTORY(hw/battery)
+ADD_SUBDIRECTORY(hw/cpu)
 ADD_SUBDIRECTORY(hw/display)
 ADD_SUBDIRECTORY(hw/led)
 ADD_SUBDIRECTORY(hw/external_connection)
diff --git a/hw/cpu/CMakeLists.txt b/hw/cpu/CMakeLists.txt
new file mode 100644 (file)
index 0000000..de64784
--- /dev/null
@@ -0,0 +1,16 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(cpu C)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dlog hwcommon)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${PROJECT_NAME} MODULE cpu.c ../shared.c)
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
diff --git a/hw/cpu/cpu.c b/hw/cpu/cpu.c
new file mode 100644 (file)
index 0000000..6ad5bdc
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * device-node
+ *
+ * Copyright (c) 2016 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 requcpued 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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/types.h>
+#include <linux/un.h>
+
+#include <hw/cpu.h>
+#include "../shared.h"
+
+#define CPU_BOOST_SOCKET_FOR_SCENARIO    "/dev/socket/scenario_info"
+#define BUF_MAX 128
+
+static int cpu_boost_send_socket(char *write_buf)
+{
+       int socket_fd = 0;
+       int ret = 0;
+       struct sockaddr_un addr;
+
+       if (access(CPU_BOOST_SOCKET_FOR_SCENARIO, F_OK) != 0) {
+               _E("CPU boot socket does not exist");
+               return -ENOTSUP;
+       }
+
+       socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+       if (socket_fd < 0) {
+               _E("Failed to get socket fd");
+               return -ENOMEM;
+       }
+
+       memset(&addr, 0, sizeof(addr));
+       snprintf(addr.sun_path, UNIX_PATH_MAX, "%s", CPU_BOOST_SOCKET_FOR_SCENARIO);
+       addr.sun_family = AF_LOCAL;
+
+       ret = connect(socket_fd, (struct sockaddr *)&addr,
+                       sizeof(sa_family_t) + sizeof(CPU_BOOST_SOCKET_FOR_SCENARIO) );
+       if (ret != 0) {
+               ret = -errno;
+               _E("Failed to connect to socket(%d)", ret);
+               close(socket_fd);
+               return ret;
+       }
+
+       ret = send(socket_fd, write_buf, strlen(write_buf), MSG_NOSIGNAL);
+       close(socket_fd);
+       if (ret < 0) {
+               ret = -errno;
+               _E("Failed to send scenario (%s) (%d)", write_buf, ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int cpu_start_boost(void *data)
+{
+       char *scenario = data;
+       char buf[BUF_MAX];
+
+       snprintf(buf, sizeof(buf), "%sLock", scenario);
+       return cpu_boost_send_socket(buf);
+}
+
+static int cpu_stop_boost(void *data)
+{
+       char *scenario = data;
+       char buf[BUF_MAX];
+
+       snprintf(buf, sizeof(buf), "%sUnlock", scenario);
+       return cpu_boost_send_socket(buf);
+}
+
+static int cpu_open(struct hw_info *info,
+               const char *id, struct hw_common **common)
+{
+       struct cpu_device *cpu_dev;
+
+       if (!info || !common)
+               return -EINVAL;
+
+       cpu_dev = calloc(1, sizeof(struct cpu_device));
+       if (!cpu_dev)
+               return -ENOMEM;
+
+       cpu_dev->common.info = info;
+       cpu_dev->start_boost = cpu_start_boost;
+       cpu_dev->stop_boost = cpu_stop_boost;
+
+       *common = (struct hw_common *)cpu_dev;
+       return 0;
+}
+
+static int cpu_close(struct hw_common *common)
+{
+       if (!common)
+               return -EINVAL;
+
+       free(common);
+       return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+       .magic = HARDWARE_INFO_TAG,
+       .hal_version = HARDWARE_INFO_VERSION,
+       .device_version = CPU_HARDWARE_DEVICE_VERSION,
+       .id = CPU_HARDWARE_DEVICE_ID,
+       .name = "cpu",
+       .open = cpu_open,
+       .close = cpu_close,
+};