summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2014-03-05 07:41:49 -0800
committerMark Salyzyn <salyzyn@google.com>2014-03-05 16:12:28 -0800
commit7e2f83c0bcc3ad8a2840a48be14d302ed79d671c (patch)
treee2d2ed4a9a9e218e046cb0796607cca8fc5ed97f
parent51ebffd8a5536af09b60950bf7cf6f020c962f8a (diff)
downloadcore-7e2f83c0bcc3ad8a2840a48be14d302ed79d671c.tar.gz
core-7e2f83c0bcc3ad8a2840a48be14d302ed79d671c.tar.bz2
core-7e2f83c0bcc3ad8a2840a48be14d302ed79d671c.zip
logd: liblog: 64-bit issues
- structure packing - move towards log_time from struct timespec - extend log_time to cover differences between log_time and struct timespec Change-Id: I106ed0b609917306d170044054b5b32645f2a295
-rw-r--r--include/log/log_read.h59
-rw-r--r--include/log/logger.h8
-rw-r--r--liblog/logd_write.c5
-rw-r--r--liblog/tests/liblog_benchmark.cpp2
-rw-r--r--liblog/tests/liblog_test.cpp2
-rw-r--r--logd/LogBuffer.cpp6
-rw-r--r--logd/LogBuffer.h10
-rw-r--r--logd/LogBufferElement.cpp8
-rw-r--r--logd/LogBufferElement.h6
9 files changed, 81 insertions, 25 deletions
diff --git a/include/log/log_read.h b/include/log/log_read.h
index 2601622e0..7edfe3c4d 100644
--- a/include/log/log_read.h
+++ b/include/log/log_read.h
@@ -19,21 +19,38 @@
#include <time.h>
+/* struct log_time is a wire-format variant of struct timespec */
#define NS_PER_SEC 1000000000ULL
#ifdef __cplusplus
-struct log_time : public timespec {
+struct log_time {
public:
+ uint32_t tv_sec; // good to Feb 5 2106
+ uint32_t tv_nsec;
+
log_time(const timespec &T)
{
tv_sec = T.tv_sec;
tv_nsec = T.tv_nsec;
}
+ log_time(const log_time &T)
+ {
+ tv_sec = T.tv_sec;
+ tv_nsec = T.tv_nsec;
+ }
+ log_time(uint32_t sec, uint32_t nsec)
+ {
+ tv_sec = sec;
+ tv_nsec = nsec;
+ }
log_time()
{
}
log_time(clockid_t id)
{
- clock_gettime(id, (timespec *) this);
+ timespec T;
+ clock_gettime(id, &T);
+ tv_sec = T.tv_sec;
+ tv_nsec = T.tv_nsec;
}
log_time(const char *T)
{
@@ -41,6 +58,8 @@ public:
tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24);
}
+
+ // timespec
bool operator== (const timespec &T) const
{
return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
@@ -67,13 +86,45 @@ public:
{
return !(*this > T);
}
+
+ // log_time
+ bool operator== (const log_time &T) const
+ {
+ return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
+ }
+ bool operator!= (const log_time &T) const
+ {
+ return !(*this == T);
+ }
+ bool operator< (const log_time &T) const
+ {
+ return (tv_sec < T.tv_sec)
+ || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
+ }
+ bool operator>= (const log_time &T) const
+ {
+ return !(*this < T);
+ }
+ bool operator> (const log_time &T) const
+ {
+ return (tv_sec > T.tv_sec)
+ || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
+ }
+ bool operator<= (const log_time &T) const
+ {
+ return !(*this > T);
+ }
+
uint64_t nsec() const
{
return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
}
-};
+} __attribute__((__packed__));
#else
-typedef struct timespec log_time;
+typedef struct log_time {
+ uint32_t tv_sec;
+ uint32_t tv_nsec;
+} __attribute__((__packed__)) log_time;
#endif
#endif /* define _LIBS_LOG_LOG_READ_H */
diff --git a/include/log/logger.h b/include/log/logger.h
index bea002234..881061553 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -30,7 +30,7 @@ struct logger_entry {
int32_t sec; /* seconds since Epoch */
int32_t nsec; /* nanoseconds */
char msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
/*
* The userspace structure for version 2 of the logger_entry ABI.
@@ -46,18 +46,18 @@ struct logger_entry_v2 {
int32_t nsec; /* nanoseconds */
uint32_t euid; /* effective UID of logger */
char msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
struct logger_entry_v3 {
uint16_t len; /* length of the payload */
- uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
+ uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
int32_t pid; /* generating process's pid */
int32_t tid; /* generating process's tid */
int32_t sec; /* seconds since Epoch */
int32_t nsec; /* nanoseconds */
uint32_t lid; /* log id of the payload */
char msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
/*
* The maximum size of the log entry payload that can be
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index d3ee167bd..c3efc33f7 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -117,8 +117,11 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
newVec[0].iov_base = (unsigned char *) &log_id_buf;
newVec[0].iov_len = sizeof_log_id_t;
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
log_time realtime_ts;
- clock_gettime(CLOCK_REALTIME, &realtime_ts);
+ realtime_ts.tv_sec = ts.tv_sec;
+ realtime_ts.tv_nsec = ts.tv_nsec;
newVec[1].iov_base = (unsigned char *) &realtime_ts;
newVec[1].iov_len = sizeof(log_time);
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index 19406fbab..39fe2ad84 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -143,7 +143,7 @@ static void BM_log_latency(int iters) {
for (int j = 0, i = 0; i < iters && j < 10*iters; ++i, ++j) {
log_time ts;
LOG_FAILURE_RETRY((
- clock_gettime(CLOCK_REALTIME, &ts),
+ ts = log_time(CLOCK_REALTIME),
android_btWriteLog(0, EVENT_TYPE_LONG, &ts, sizeof(ts))));
for (;;) {
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index d71d97a8d..ffb7fd1ca 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -171,7 +171,7 @@ static void caught_blocking(int signum)
++signaled;
if ((signal_time.tv_sec == 0) && (signal_time.tv_nsec == 0)) {
- clock_gettime(CLOCK_MONOTONIC, &signal_time);
+ signal_time = log_time(CLOCK_MONOTONIC);
signal_time.tv_sec += 2;
}
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 7340a36d8..c5760f7c1 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -36,7 +36,7 @@ LogBuffer::LogBuffer(LastLogTimes *times)
pthread_mutex_init(&mLogElementsLock, NULL);
}
-void LogBuffer::log(log_id_t log_id, struct timespec realtime,
+void LogBuffer::log(log_id_t log_id, log_time realtime,
uid_t uid, pid_t pid, const char *msg,
unsigned short len) {
if ((log_id >= LOG_ID_MAX) || (log_id < 0)) {
@@ -182,8 +182,8 @@ unsigned long LogBuffer::getSize(log_id_t /*id*/) {
return LOG_BUFFER_SIZE;
}
-struct timespec LogBuffer::flushTo(
- SocketClient *reader, const struct timespec start, bool privileged,
+log_time LogBuffer::flushTo(
+ SocketClient *reader, const log_time start, bool privileged,
bool (*filter)(const LogBufferElement *element, void *arg), void *arg) {
LogBufferElementCollection::iterator it;
log_time max = start;
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 7c69f1bdc..1b50a8f85 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -40,12 +40,12 @@ public:
LogBuffer(LastLogTimes *times);
- void log(log_id_t log_id, struct timespec realtime,
+ void log(log_id_t log_id, log_time realtime,
uid_t uid, pid_t pid, const char *msg, unsigned short len);
- struct timespec flushTo(SocketClient *writer, const struct timespec start,
- bool privileged,
- bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
- void *arg = NULL);
+ log_time flushTo(SocketClient *writer, const log_time start,
+ bool privileged,
+ bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
+ void *arg = NULL);
void clear(log_id_t id);
unsigned long getSize(log_id_t id);
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index 1c55623c3..01cc9de38 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -24,9 +24,11 @@
#include "LogBufferElement.h"
#include "LogReader.h"
-const struct timespec LogBufferElement::FLUSH_ERROR = { 0, 0 };
+const log_time LogBufferElement::FLUSH_ERROR(0, 0);
-LogBufferElement::LogBufferElement(log_id_t log_id, struct timespec realtime, uid_t uid, pid_t pid, const char *msg, unsigned short len)
+LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime,
+ uid_t uid, pid_t pid, const char *msg,
+ unsigned short len)
: mLogId(log_id)
, mUid(uid)
, mPid(pid)
@@ -41,7 +43,7 @@ LogBufferElement::~LogBufferElement() {
delete [] mMsg;
}
-struct timespec LogBufferElement::flushTo(SocketClient *reader) {
+log_time LogBufferElement::flushTo(SocketClient *reader) {
struct logger_entry_v3 entry;
memset(&entry, 0, sizeof(struct logger_entry_v3));
entry.hdr_size = sizeof(struct logger_entry_v3);
diff --git a/logd/LogBufferElement.h b/logd/LogBufferElement.h
index 390c97c23..1da09aea6 100644
--- a/logd/LogBufferElement.h
+++ b/logd/LogBufferElement.h
@@ -32,7 +32,7 @@ class LogBufferElement {
const log_time mRealTime;
public:
- LogBufferElement(log_id_t log_id, struct timespec realtime,
+ LogBufferElement(log_id_t log_id, log_time realtime,
uid_t uid, pid_t pid, const char *msg, unsigned short len);
virtual ~LogBufferElement();
@@ -43,8 +43,8 @@ public:
log_time getMonotonicTime(void) const { return mMonotonicTime; }
log_time getRealTime(void) const { return mRealTime; }
- static const struct timespec FLUSH_ERROR;
- struct timespec flushTo(SocketClient *writer);
+ static const log_time FLUSH_ERROR;
+ log_time flushTo(SocketClient *writer);
};
#endif