Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
courtc committed Oct 31, 2013
0 parents commit 4139506
Show file tree
Hide file tree
Showing 31 changed files with 3,740 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
thermanager
out
57 changes: 57 additions & 0 deletions Android.mk
@@ -0,0 +1,57 @@
# Copyright (C) 2008 The Android Open Source Project
#
# 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.

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES := external/libxml2/include external/icu4c/common
LOCAL_SRC_FILES := \
src/configuration.c \
src/control.c \
src/mitigation.c \
src/resource.c \
src/threshold.c \
src/dom.c \
src/libxml2parser.c \
src/watch.c \
src/thermal_zone.c \
src/cpufreq.c \
src/util.c \
src/main.c \

LOCAL_SHARED_LIBRARIES := liblog libicuuc
LOCAL_STATIC_LIBRARIES := libxml2
LOCAL_MODULE := thermanager
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
# C89 3.5.7 "Initialization - Sematics":
# If there are fewer initializers in a list than there are members of an
# aggregate, the remainder of the aggregate shall be initialized implicitly
# the same as objects that have static storage duration.
# C99 6.7.8/21 "Initialization - Sematics":
# If there are fewer initializers in a brace-enclosed list than there are
# elements or members of an aggregate, or fewer characters in a string
# literal used to initialize an array of known size than there are elements
# in the array, the remainder of the aggregate shall be initialized
# implicitly the same as objects that have static storage duration.
#
# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750
LOCAL_CFLAGS := -Wno-missing-field-initializers

LOCAL_SRC_FILES := thermonitor.c
LOCAL_MODULE := thermonitor
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
45 changes: 45 additions & 0 deletions Makefile
@@ -0,0 +1,45 @@
CFLAGS := -Wall -g -I/usr/include/libxml2
LDFLAGS := -l xml2

proj := thermanager
srcs := \
src/configuration.c \
src/control.c \
src/mitigation.c \
src/resource.c \
src/threshold.c \
src/dom.c \
src/libxml2parser.c \
src/watch.c \
src/thermal_zone.c \
src/cpufreq.c \
src/util.c \
src/main.c \

out := out
src_to_obj = $(patsubst %.c,$(out)/obj/%.o,$(1))
src_to_dep = $(patsubst %.c,$(out)/dep/%.d,$(1))

all_srcs := $(sort $(srcs))
all_objs := $(call src_to_obj,$(all_srcs))
all_deps := $(call src_to_dep,$(all_srcs))

all: $(proj)

$(out)/obj/%.o: %.c
@echo "CC $<"
@$(CC) -MM -MF $(call src_to_dep,$<) -MP -MT "$@ $(call src_to_dep,$<)" $(CFLAGS) $<
@$(CC) -o $@ -c $< $(CFLAGS)

$(proj): $(call src_to_obj,$(all_srcs))
@echo "LD $@"
@$(CC) -o $@ $^ $(LDFLAGS) -lfuse -ldl

clean:
@echo CLEAN
@$(RM) -r $(proj) $(out)

ifneq ("$(MAKECMDGOALS)","clean")
cmd-goal-1 := $(shell mkdir -p $(sort $(dir $(all_objs) $(all_deps))))
-include $(all_deps)
endif
24 changes: 24 additions & 0 deletions NOTICE
@@ -0,0 +1,24 @@
Copyright (c) 2013, Sony Mobile Communications AB.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the organization nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
99 changes: 99 additions & 0 deletions example-config.xml
@@ -0,0 +1,99 @@
<thermanager>
<resources>
<!-- thermal zones -->
<resource name="zone0" type="tz">/sys/class/thermal/thermal_zone0</resource>
<resource name="zone1" type="tz">/sys/class/thermal/thermal_zone1</resource>
<resource name="zone2" type="tz">/sys/class/thermal/thermal_zone2</resource>
<resource name="zone3" type="tz">/sys/class/thermal/thermal_zone3</resource>
<resource name="zone4" type="tz">/sys/class/thermal/thermal_zone4</resource>

<resource name="gpu-fan" type="sysfs">/sys/class/fan/gpu0/rpm</resource>

<!-- generic cpufreq -->
<resource name="cpu0-freq" type="cpufreq">/sys/devices/system/cpu/cpu0/cpufreq</resource>
<resource name="cpu1-freq" type="cpufreq">/sys/devices/system/cpu/cpu1/cpufreq</resource>
<resource name="cpu2-freq" type="cpufreq">/sys/devices/system/cpu/cpu2/cpufreq</resource>
<resource name="cpu3-freq" type="cpufreq">/sys/devices/system/cpu/cpu3/cpufreq</resource>

<resource name="cpu-freq" type="union">
<resource name="cpu0-freq" />
<resource name="cpu1-freq" />
<resource name="cpu2-freq" />
<resource name="cpu3-freq" />
</resource>

<resource name="cpu-temp" type="union">
<resource name="zone0" />
<resource name="zone1" />
<resource name="zone2" />
<resource name="zone3" />
</resource>

<resource name="gpu-temp" type="alias" resource="zone4" />
<resource name="shutdown" type="halt" delay="5" />
</resources>

<control name="cpu-ctrl">
<mitigation level="off"><value resource="cpu-freq">1512000</value></mitigation>
<mitigation level="1"><value resource="cpu-freq">1350000</value></mitigation>
<mitigation level="2"><value resource="cpu-freq">1134000</value></mitigation>
<mitigation level="3"><value resource="cpu-freq">810000</value></mitigation>
<mitigation level="4"><value resource="cpu-freq">702000</value></mitigation>
<mitigation level="5"><value resource="cpu-freq">594000</value></mitigation>
<mitigation level="6"><value resource="cpu-freq">486000</value></mitigation>
<mitigation level="7"><value resource="cpu-freq">384000</value></mitigation>
<mitigation level="8"><value resource="shutdown" /></mitigation>
</control>

<control name="gpu-ctrl">
<mitigation level="off"><value resource="gpu-fan">0</value></mitigation>
<mitigation level="1"><value resource="gpu-fan">1000</value></mitigation>
<mitigation level="2"><value resource="gpu-fan">2500</value></mitigation>
<mitigation level="3"><value resource="gpu-fan">3000</value></mitigation>
</control>

<configuration sensor="gpu-temp">
<threshold>
<mitigation name="gpu-ctrl" level="off" />
</threshold>
<threshold trigger="95000" clear="90000">
<mitigation name="gpu-ctrl" level="1" />
</threshold>
<threshold trigger="110000" clear="105000">
<mitigation name="gpu-ctrl" level="2" />
</threshold>
<threshold trigger="115000" clear="110000">
<mitigation name="gpu-ctrl" level="3" />
</threshold>
</configuration>

<configuration sensor="cpu-temp">
<threshold>
<mitigation name="cpu-ctrl" level="off" />
</threshold>
<threshold trigger="70000" clear="67000">
<mitigation name="cpu-ctrl" level="1" />
</threshold>
<threshold trigger="90000" clear="85000">
<mitigation name="cpu-ctrl" level="2" />
</threshold>
<threshold trigger="95000" clear="90000">
<mitigation name="cpu-ctrl" level="3" />
</threshold>
<threshold trigger="100000" clear="95000">
<mitigation name="cpu-ctrl" level="4" />
</threshold>
<threshold trigger="105000" clear="100000">
<mitigation name="cpu-ctrl" level="5" />
</threshold>
<threshold trigger="110000" clear="105000">
<mitigation name="cpu-ctrl" level="6" />
</threshold>
<threshold trigger="115000" clear="110000">
<mitigation name="cpu-ctrl" level="7" />
</threshold>
<threshold trigger="120000" clear="115000">
<mitigation name="cpu-ctrl" level="8" />
</threshold>
</configuration>
</thermanager>

0 comments on commit 4139506

Please sign in to comment.