Merge "fastboot: create Transport object (take 2)."
diff --git a/include/log/log.h b/include/log/log.h
index e0dc3a3..1cdf7bc 100644
--- a/include/log/log.h
+++ b/include/log/log.h
@@ -616,12 +616,7 @@
* Use the per-tag properties "log.tag.<tagname>" to generate a runtime
* result of non-zero to expose a log.
*/
-/* default prio ANDROID_LOG_VERBOSE to ANDROID_LOG_FATAL if no property */
-#define ANDROID_LOGGABLE_FLAG_DEFAULT_MASK 0x000F
-/* Save 2 syscalls if caller guarantees to never call within signal handler */
-#define ANDROID_LOGGABLE_FLAG_NOT_WITHIN_SIGNAL 0x8000
-
-int __android_log_is_loggable(int prio, const char *tag, int flag);
+int __android_log_is_loggable(int prio, const char *tag, int def);
int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
uint32_t dataLen);
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index fcdb6c9..8a8ece2 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -24,7 +24,6 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <signal.h>
#include <stdlib.h>
#include <string.h>
@@ -98,33 +97,18 @@
*/
static pthread_mutex_t fakeLogDeviceLock = PTHREAD_MUTEX_INITIALIZER;
-static void lock(sigset_t *sigflags)
+static void lock()
{
- /*
- * If we trigger a signal handler in the middle of locked activity and the
- * signal handler logs a message, we could get into a deadlock state.
- */
- sigset_t all;
-
- sigfillset(&all);
- pthread_sigmask(SIG_BLOCK, &all, sigflags);
pthread_mutex_lock(&fakeLogDeviceLock);
}
-static void unlock(sigset_t *sigflags)
+static void unlock()
{
pthread_mutex_unlock(&fakeLogDeviceLock);
- pthread_sigmask(SIG_UNBLOCK, sigflags, NULL);
}
-
-#define DECLARE_SIGSET(name) sigset_t name
-
#else // !defined(_WIN32)
-
-#define lock(sigflags) ((void)0)
-#define unlock(sigflags) ((void)0)
-#define DECLARE_SIGSET(name)
-
+#define lock() ((void)0)
+#define unlock() ((void)0)
#endif // !defined(_WIN32)
@@ -170,9 +154,8 @@
static void deleteFakeFd(int fd)
{
LogState *ls;
- DECLARE_SIGSET(sigflags);
- lock(&sigflags);
+ lock();
ls = fdToLogState(fd);
if (ls != NULL) {
@@ -181,7 +164,7 @@
free(ls);
}
- unlock(&sigflags);
+ unlock();
}
/*
@@ -565,13 +548,12 @@
static ssize_t logWritev(int fd, const struct iovec* vector, int count)
{
LogState* state;
- DECLARE_SIGSET(sigflags);
/* Make sure that no-one frees the LogState while we're using it.
* Also guarantees that only one thread is in showLog() at a given
* time (if it matters).
*/
- lock(&sigflags);
+ lock();
state = fdToLogState(fd);
if (state == NULL) {
@@ -616,10 +598,10 @@
}
bail:
- unlock(&sigflags);
+ unlock();
return vector[0].iov_len + vector[1].iov_len + vector[2].iov_len;
error:
- unlock(&sigflags);
+ unlock();
return -1;
}
@@ -639,9 +621,8 @@
{
LogState *logState;
int fd = -1;
- DECLARE_SIGSET(sigflags);
- lock(&sigflags);
+ lock();
logState = createLogState();
if (logState != NULL) {
@@ -651,7 +632,7 @@
errno = ENFILE;
}
- unlock(&sigflags);
+ unlock();
return fd;
}
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c
index 9d043ff..814d96d 100644
--- a/liblog/log_is_loggable.c
+++ b/liblog/log_is_loggable.c
@@ -16,39 +16,12 @@
#include <ctype.h>
#include <pthread.h>
-#include <signal.h>
#include <stdlib.h>
#include <string.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
#include <android/log.h>
-#include <log/log.h>
-
-static pthread_mutex_t lock_loggable = PTHREAD_MUTEX_INITIALIZER;
-
-static void lock(sigset_t *sigflags)
-{
- /*
- * If we trigger a signal handler in the middle of locked activity and the
- * signal handler logs a message, we could get into a deadlock state.
- */
- if (sigflags) {
- sigset_t all;
-
- sigfillset(&all);
- pthread_sigmask(SIG_BLOCK, &all, sigflags);
- }
- pthread_mutex_lock(&lock_loggable);
-}
-
-static void unlock(sigset_t *sigflags)
-{
- pthread_mutex_unlock(&lock_loggable);
- if (sigflags) {
- pthread_sigmask(SIG_UNBLOCK, sigflags, NULL);
- }
-}
struct cache {
const prop_info *pinfo;
@@ -76,7 +49,9 @@
cache->c = buf[0];
}
-static int __android_log_level(const char *tag, int flag)
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+
+static int __android_log_level(const char *tag, int def)
{
/* sizeof() is used on this array below */
static const char log_namespace[] = "persist.log.tag.";
@@ -108,11 +83,10 @@
{ NULL, -1, 0 },
{ NULL, -1, 0 }
};
- sigset_t sigflags;
strcpy(key, log_namespace);
- lock((flag & ANDROID_LOGGABLE_FLAG_NOT_WITHIN_SIGNAL) ? NULL : &sigflags);
+ pthread_mutex_lock(&lock);
current_global_serial = __system_property_area_serial();
@@ -182,7 +156,7 @@
global_serial = current_global_serial;
- unlock((flag & ANDROID_LOGGABLE_FLAG_NOT_WITHIN_SIGNAL) ? NULL : &sigflags);
+ pthread_mutex_unlock(&lock);
switch (toupper(c)) {
case 'V': return ANDROID_LOG_VERBOSE;
@@ -194,46 +168,36 @@
case 'A': return ANDROID_LOG_FATAL;
case 'S': return -1; /* ANDROID_LOG_SUPPRESS */
}
- return flag & ANDROID_LOGGABLE_FLAG_DEFAULT_MASK;
+ return def;
}
-int __android_log_is_loggable(int prio, const char *tag, int flag)
+int __android_log_is_loggable(int prio, const char *tag, int def)
{
- int logLevel = __android_log_level(tag, flag);
+ int logLevel = __android_log_level(tag, def);
return logLevel >= 0 && prio >= logLevel;
}
-/*
- * Timestamp state generally remains constant, since a change is
- * rare, we can accept a trylock failure gracefully.
- */
-static pthread_mutex_t lock_timestamp = PTHREAD_MUTEX_INITIALIZER;
-
char android_log_timestamp()
{
static struct cache r_time_cache = { NULL, -1, 0 };
static struct cache p_time_cache = { NULL, -1, 0 };
+ static uint32_t serial;
+ uint32_t current_serial;
char retval;
- if (pthread_mutex_trylock(&lock_timestamp)) {
- /* We are willing to accept some race in this context */
- if (!(retval = p_time_cache.c)) {
- retval = r_time_cache.c;
- }
- } else {
- static uint32_t serial;
- uint32_t current_serial = __system_property_area_serial();
- if (current_serial != serial) {
- refresh_cache(&r_time_cache, "ro.logd.timestamp");
- refresh_cache(&p_time_cache, "persist.logd.timestamp");
- serial = current_serial;
- }
- if (!(retval = p_time_cache.c)) {
- retval = r_time_cache.c;
- }
+ pthread_mutex_lock(&lock);
- pthread_mutex_unlock(&lock_timestamp);
+ current_serial = __system_property_area_serial();
+ if (current_serial != serial) {
+ refresh_cache(&r_time_cache, "ro.logd.timestamp");
+ refresh_cache(&p_time_cache, "persist.logd.timestamp");
+ serial = current_serial;
}
+ if (!(retval = p_time_cache.c)) {
+ retval = r_time_cache.c;
+ }
+
+ pthread_mutex_unlock(&lock);
return tolower(retval ?: 'r');
}
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index a8ecc8d..a4310ae 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -20,7 +20,6 @@
#include <fcntl.h>
#if !defined(_WIN32)
#include <pthread.h>
-#include <signal.h>
#endif
#include <stdarg.h>
#include <stdatomic.h>
@@ -55,43 +54,14 @@
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
+#if !defined(_WIN32)
+static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
#ifndef __unused
#define __unused __attribute__((__unused__))
#endif
-#if !defined(_WIN32)
-static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static void lock(sigset_t *sigflags)
-{
- /*
- * If we trigger a signal handler in the middle of locked activity and the
- * signal handler logs a message, we could get into a deadlock state.
- */
- sigset_t all;
-
- sigfillset(&all);
- pthread_sigmask(SIG_BLOCK, &all, sigflags);
- pthread_mutex_lock(&log_init_lock);
-}
-
-static void unlock(sigset_t *sigflags)
-{
- pthread_mutex_unlock(&log_init_lock);
- pthread_sigmask(SIG_UNBLOCK, sigflags, NULL);
-}
-
-#define DECLARE_SIGSET(name) sigset_t name
-
-#else /* !defined(_WIN32) */
-
-#define lock(sigflags) ((void)0)
-#define unlock(sigflags) ((void)0)
-#define DECLARE_SIGSET(name)
-
-#endif /* !defined(_WIN32) */
-
#if FAKE_LOG_DEVICE
static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 };
#else
@@ -305,15 +275,17 @@
*/
ret = TEMP_FAILURE_RETRY(writev(logd_fd, newVec + 1, i - 1));
if (ret < 0) {
- DECLARE_SIGSET(sigflags);
-
ret = -errno;
if (ret == -ENOTCONN) {
- lock(&sigflags);
+#if !defined(_WIN32)
+ pthread_mutex_lock(&log_init_lock);
+#endif
close(logd_fd);
logd_fd = -1;
ret = __write_to_log_initialize();
- unlock(&sigflags);
+#if !defined(_WIN32)
+ pthread_mutex_unlock(&log_init_lock);
+#endif
if (ret < 0) {
return ret;
@@ -357,16 +329,18 @@
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
{
- DECLARE_SIGSET(sigflags);
-
- lock(&sigflags);
+#if !defined(_WIN32)
+ pthread_mutex_lock(&log_init_lock);
+#endif
if (write_to_log == __write_to_log_init) {
int ret;
ret = __write_to_log_initialize();
if (ret < 0) {
- unlock(&sigflags);
+#if !defined(_WIN32)
+ pthread_mutex_unlock(&log_init_lock);
+#endif
#if (FAKE_LOG_DEVICE == 0)
if (pstore_fd >= 0) {
__write_to_log_daemon(log_id, vec, nr);
@@ -378,7 +352,9 @@
write_to_log = __write_to_log_daemon;
}
- unlock(&sigflags);
+#if !defined(_WIN32)
+ pthread_mutex_unlock(&log_init_lock);
+#endif
return write_to_log(log_id, vec, nr);
}
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index c2f71d1..fd5c066 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -191,9 +191,7 @@
prio = *msg;
tag = msg + 1;
}
- if (!__android_log_is_loggable(prio, tag,
- ANDROID_LOG_VERBOSE |
- ANDROID_LOGGABLE_FLAG_NOT_WITHIN_SIGNAL)) {
+ if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
// Log traffic received to total
pthread_mutex_lock(&mLogElementsLock);
stats.add(elem);
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index f10dccf..c4c302b 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -107,9 +107,7 @@
LogBuffer *parent) {
static const char tag[] = "chatty";
- if (!__android_log_is_loggable(ANDROID_LOG_INFO, tag,
- ANDROID_LOG_VERBOSE |
- ANDROID_LOGGABLE_FLAG_NOT_WITHIN_SIGNAL)) {
+ if (!__android_log_is_loggable(ANDROID_LOG_INFO, tag, ANDROID_LOG_VERBOSE)) {
return 0;
}
diff --git a/metricsd/metrics_daemon.cc b/metricsd/metrics_daemon.cc
index b606fd0..e711660 100644
--- a/metricsd/metrics_daemon.cc
+++ b/metricsd/metrics_daemon.cc
@@ -74,11 +74,6 @@
const char kMeminfoFileName[] = "/proc/meminfo";
const char kVmStatFileName[] = "/proc/vmstat";
-// Thermal CPU throttling.
-
-const char kMetricScaledCpuFrequencyName[] =
- "Platform.CpuFrequencyThermalScaling";
-
} // namespace
// Zram sysfs entries.
@@ -169,8 +164,6 @@
bool dbus_enabled,
MetricsLibraryInterface* metrics_lib,
const string& diskstats_path,
- const string& scaling_max_freq_path,
- const string& cpuinfo_max_freq_path,
const base::TimeDelta& upload_interval,
const string& server,
const base::FilePath& metrics_directory) {
@@ -221,8 +214,6 @@
weekly_cycle_.reset(new PersistentInteger("weekly.cycle"));
version_cycle_.reset(new PersistentInteger("version.cycle"));
- scaling_max_freq_path_ = scaling_max_freq_path;
- cpuinfo_max_freq_path_ = cpuinfo_max_freq_path;
disk_usage_collector_.reset(new DiskUsageCollector(metrics_lib_));
averaged_stats_collector_.reset(
new AveragedStatisticsCollector(metrics_lib_, diskstats_path,
@@ -461,63 +452,6 @@
averaged_stats_collector_->ScheduleWait();
}
-
-bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) {
- const FilePath sysfs_path(sysfs_file_name);
- string value_string;
- if (!base::ReadFileToString(sysfs_path, &value_string)) {
- LOG(WARNING) << "cannot read " << sysfs_path.value().c_str();
- return false;
- }
- if (!base::RemoveChars(value_string, "\n", &value_string)) {
- LOG(WARNING) << "no newline in " << value_string;
- // Continue even though the lack of newline is suspicious.
- }
- if (!base::StringToInt(value_string, value)) {
- LOG(WARNING) << "cannot convert " << value_string << " to int";
- return false;
- }
- return true;
-}
-
-void MetricsDaemon::SendCpuThrottleMetrics() {
- // |max_freq| is 0 only the first time through.
- static int max_freq = 0;
- if (max_freq == -1)
- // Give up, as sysfs did not report max_freq correctly.
- return;
- if (max_freq == 0 || testing_) {
- // One-time initialization of max_freq. (Every time when testing.)
- if (!ReadFreqToInt(cpuinfo_max_freq_path_, &max_freq)) {
- max_freq = -1;
- return;
- }
- if (max_freq == 0) {
- LOG(WARNING) << "sysfs reports 0 max CPU frequency\n";
- max_freq = -1;
- return;
- }
- if (max_freq % 10000 == 1000) {
- // Special case: system has turbo mode, and max non-turbo frequency is
- // max_freq - 1000. This relies on "normal" (non-turbo) frequencies
- // being multiples of (at least) 10 MHz. Although there is no guarantee
- // of this, it seems a fairly reasonable assumption. Otherwise we should
- // read scaling_available_frequencies, sort the frequencies, compare the
- // two highest ones, and check if they differ by 1000 (kHz) (and that's a
- // hack too, no telling when it will change).
- max_freq -= 1000;
- }
- }
- int scaled_freq = 0;
- if (!ReadFreqToInt(scaling_max_freq_path_, &scaled_freq))
- return;
- // Frequencies are in kHz. If scaled_freq > max_freq, turbo is on, but
- // scaled_freq is not the actual turbo frequency. We indicate this situation
- // with a 101% value.
- int percent = scaled_freq > max_freq ? 101 : scaled_freq / (max_freq / 100);
- SendLinearSample(kMetricScaledCpuFrequencyName, percent, 101, 102);
-}
-
void MetricsDaemon::ScheduleMeminfoCallback(int wait) {
if (testing_) {
return;
diff --git a/metricsd/metrics_daemon.h b/metricsd/metrics_daemon.h
index f12b02e..54ae188 100644
--- a/metricsd/metrics_daemon.h
+++ b/metricsd/metrics_daemon.h
@@ -51,8 +51,6 @@
bool dbus_enabled,
MetricsLibraryInterface* metrics_lib,
const std::string& diskstats_path,
- const std::string& cpuinfo_max_freq_path,
- const std::string& scaling_max_freq_path,
const base::TimeDelta& upload_interval,
const std::string& server,
const base::FilePath& metrics_directory);
@@ -92,12 +90,10 @@
FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown);
FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash);
FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency);
- FRIEND_TEST(MetricsDaemonTest, ReadFreqToInt);
FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval);
FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval);
FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval);
FRIEND_TEST(MetricsDaemonTest, SendSample);
- FRIEND_TEST(MetricsDaemonTest, SendCpuThrottleMetrics);
FRIEND_TEST(MetricsDaemonTest, SendZramMetrics);
// Type of scale to use for meminfo histograms. For most of them we use
@@ -215,12 +211,6 @@
// Parses meminfo data and sends it to UMA.
bool ProcessMemuse(const std::string& meminfo_raw);
- // Sends stats for thermal CPU throttling.
- void SendCpuThrottleMetrics();
-
- // Reads an integer CPU frequency value from sysfs.
- bool ReadFreqToInt(const std::string& sysfs_file_name, int* value);
-
// Reads the current OS version from /etc/lsb-release and hashes it
// to a unsigned 32-bit int.
uint32_t GetOsVersionHash();
@@ -301,9 +291,6 @@
scoped_ptr<DiskUsageCollector> disk_usage_collector_;
scoped_ptr<AveragedStatisticsCollector> averaged_stats_collector_;
- std::string scaling_max_freq_path_;
- std::string cpuinfo_max_freq_path_;
-
base::TimeDelta upload_interval_;
std::string server_;
diff --git a/metricsd/metrics_daemon_main.cc b/metricsd/metrics_daemon_main.cc
index 8573f68..9bb67e8 100644
--- a/metricsd/metrics_daemon_main.cc
+++ b/metricsd/metrics_daemon_main.cc
@@ -25,10 +25,6 @@
#include "constants.h"
#include "metrics_daemon.h"
-const char kScalingMaxFreqPath[] =
- "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq";
-const char kCpuinfoMaxFreqPath[] =
- "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
// Returns the path to the disk stats in the sysfs. Returns the null string if
// it cannot find the disk stats file.
@@ -112,8 +108,6 @@
FLAGS_withdbus,
&metrics_lib,
MetricsMainDiskStatsPath(),
- kScalingMaxFreqPath,
- kCpuinfoMaxFreqPath,
base::TimeDelta::FromSeconds(FLAGS_upload_interval_secs),
FLAGS_server,
base::FilePath(FLAGS_metrics_directory));
diff --git a/metricsd/metrics_daemon_test.cc b/metricsd/metrics_daemon_test.cc
index d3c9a23..2e8a85b 100644
--- a/metricsd/metrics_daemon_test.cc
+++ b/metricsd/metrics_daemon_test.cc
@@ -45,11 +45,6 @@
virtual void SetUp() {
brillo::FlagHelper::Init(0, nullptr, "");
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
- scaling_max_freq_path_ = temp_dir_.path().Append("scaling_max");
- cpu_max_freq_path_ = temp_dir_.path().Append("cpu_freq_max");
-
- CreateUint64ValueFile(cpu_max_freq_path_, 10000000);
- CreateUint64ValueFile(scaling_max_freq_path_, 10000000);
chromeos_metrics::PersistentInteger::SetMetricsDirectory(
temp_dir_.path().value());
@@ -58,8 +53,6 @@
true,
&metrics_lib_,
"",
- scaling_max_freq_path_.value(),
- cpu_max_freq_path_.value(),
base::TimeDelta::FromMinutes(30),
metrics::kMetricsServer,
temp_dir_.path());
@@ -120,10 +113,6 @@
// Temporary directory used for tests.
base::ScopedTempDir temp_dir_;
- // Path for the fake files.
- base::FilePath scaling_max_freq_path_;
- base::FilePath cpu_max_freq_path_;
-
// Mocks. They are strict mock so that all unexpected
// calls are marked as failures.
StrictMock<MetricsLibraryMock> metrics_lib_;
@@ -209,33 +198,6 @@
EXPECT_FALSE(daemon_.ProcessMeminfo(meminfo));
}
-TEST_F(MetricsDaemonTest, ReadFreqToInt) {
- const int fake_scaled_freq = 1666999;
- const int fake_max_freq = 2000000;
- int scaled_freq = 0;
- int max_freq = 0;
- CreateUint64ValueFile(scaling_max_freq_path_, fake_scaled_freq);
- CreateUint64ValueFile(cpu_max_freq_path_, fake_max_freq);
- EXPECT_TRUE(daemon_.testing_);
- EXPECT_TRUE(daemon_.ReadFreqToInt(scaling_max_freq_path_.value(),
- &scaled_freq));
- EXPECT_TRUE(daemon_.ReadFreqToInt(cpu_max_freq_path_.value(), &max_freq));
- EXPECT_EQ(fake_scaled_freq, scaled_freq);
- EXPECT_EQ(fake_max_freq, max_freq);
-}
-
-TEST_F(MetricsDaemonTest, SendCpuThrottleMetrics) {
- CreateUint64ValueFile(cpu_max_freq_path_, 2001000);
- // Test the 101% and 100% cases.
- CreateUint64ValueFile(scaling_max_freq_path_, 2001000);
- EXPECT_TRUE(daemon_.testing_);
- EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, 101, 101));
- daemon_.SendCpuThrottleMetrics();
- CreateUint64ValueFile(scaling_max_freq_path_, 2000000);
- EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, 100, 101));
- daemon_.SendCpuThrottleMetrics();
-}
-
TEST_F(MetricsDaemonTest, SendZramMetrics) {
EXPECT_TRUE(daemon_.testing_);