From 88df7a404e10e6fb38aae06df410be1f7b1f0fe7 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 26 Sep 2013 11:02:43 +0900 Subject: [PATCH] Replace gettimeofday with clock_get_time Change-Id: Ic7bdcd5b139aa2a43b56f02f205d3603a05eb000 --- CMakeLists.txt | 1 + packaging/org.tizen.data-provider-slave.spec | 2 +- src/fault.c | 26 +++++++++++++++++++++++--- src/lb.c | 7 +++++-- src/main.c | 4 +++- src/util.c | 11 ++++++++++- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bcfcdbf..850dc5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ ADD_DEFINITIONS("-DCONF_FILE=\"/usr/share/data-provider-master/conf.ini\"") ADD_DEFINITIONS("-DNDEBUG") #ADD_DEFINITIONS("-D_ENABLE_MCHECK") ADD_DEFINITIONS("-DLOG_TAG=\"DATA_PROVIDER_SLAVE\"") +ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET") ADD_DEFINITIONS(${pkg_CFLAGS}) diff --git a/packaging/org.tizen.data-provider-slave.spec b/packaging/org.tizen.data-provider-slave.spec index cda820e..f454b09 100644 --- a/packaging/org.tizen.data-provider-slave.spec +++ b/packaging/org.tizen.data-provider-slave.spec @@ -2,7 +2,7 @@ Name: org.tizen.data-provider-slave Summary: Plugin type livebox service provider. -Version: 0.12.11 +Version: 0.12.12 Release: 1 Group: HomeTF/Livebox License: Flora License diff --git a/src/fault.c b/src/fault.c index 4d002fa..69344ba 100644 --- a/src/fault.c +++ b/src/fault.c @@ -30,6 +30,7 @@ #include #include +#include #include @@ -42,7 +43,11 @@ #include "util.h" static struct info { +#if defined(_USE_ECORE_TIME_GET) + double alarm_tv; +#else struct timeval alarm_tv; +#endif int marked; int disable_checker; } s_info = { @@ -58,14 +63,24 @@ static void signal_handler(int signum, siginfo_t *info, void *unused) so_fname = util_get_current_module(&symbol); if (info->si_signo == SIGALRM) { - struct timeval tv; - struct timeval res_tv; - if (!s_info.marked) { DbgPrint("Ignore false alarm signal [false]\n"); return; } +#if defined(_USE_ECORE_TIME_GET) + double tv; + tv = ecore_time_get(); + if (tv - s_info.alarm_tv < DEFAULT_LIFE_TIMER) { + DbgPrint("Ignore false alarm signal [%lf]\n", tv - s_info.alarm_tv); + return; + } + + CRITICAL_LOG("ALARM: %lf (%d, %d)\n", tv - s_info.alarm_tv, DEFAULT_LIFE_TIMER, DEFAULT_LOAD_TIMER); +#else + struct timeval tv; + struct timeval res_tv; + if (gettimeofday(&tv, NULL) < 0) { ErrPrint("gettimeofday: %s\n", strerror(errno)); tv.tv_sec = 0; @@ -85,6 +100,7 @@ static void signal_handler(int signum, siginfo_t *info, void *unused) CRITICAL_LOG("ALARM: %d.%d (%d, %d)\n", res_tv.tv_sec, res_tv.tv_usec, DEFAULT_LIFE_TIMER, DEFAULT_LOAD_TIMER); +#endif } else if (so_fname) { int fd; char log_fname[256]; @@ -191,11 +207,15 @@ HAPI int fault_mark_call(const char *pkgname, const char *filename, const char * * Enable alarm for detecting infinite loop */ if (!noalarm) { +#if defined(_USE_ECORE_TIME_GET) + s_info.alarm_tv = ecore_time_get(); +#else if (gettimeofday(&s_info.alarm_tv, NULL) < 0) { ErrPrint("gettimeofday: %s\n", strerror(errno)); s_info.alarm_tv.tv_sec = 0; s_info.alarm_tv.tv_usec = 0; } +#endif s_info.marked = 1; alarm(life_time); } diff --git a/src/lb.c b/src/lb.c index b5ebb0c..1d82a88 100644 --- a/src/lb.c +++ b/src/lb.c @@ -395,8 +395,6 @@ static inline int timer_thaw(struct item *item) static void timer_freeze(struct item *item) { - struct timeval tv; - if (!item->timer) { return; } @@ -407,6 +405,10 @@ static void timer_freeze(struct item *item) return; } +#if defined(_USE_ECORE_TIME_GET) + item->sleep_at = ecore_time_get(); +#else + struct timeval tv; if (gettimeofday(&tv, NULL) < 0) { ErrPrint("gettimeofday: %s\n", strerror(errno)); tv.tv_sec = 0; @@ -414,6 +416,7 @@ static void timer_freeze(struct item *item) } item->sleep_at = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; +#endif } static inline void update_monitor_cnt(struct item *item) diff --git a/src/main.c b/src/main.c index 3626de2..480d0e6 100644 --- a/src/main.c +++ b/src/main.c @@ -387,6 +387,7 @@ static inline void mcheck_cb(enum mcheck_status status) } #endif +#define BIN_PATH "/usr/apps/org.tizen.data-provider-slave/bin/" int main(int argc, char *argv[]) { int ret; @@ -394,7 +395,7 @@ int main(int argc, char *argv[]) const char *option; memset(argv[0], 0, strlen(argv[0])); - strcpy(argv[0], "/usr/apps/org.tizen.data-provider-slave/bin/data-provider-slave"); + strcpy(argv[0], BIN_PATH "data-provider-slave"); DbgPrint("Replace argv[0] with %s\n", argv[0]); #if defined(_ENABLE_MCHECK) @@ -438,6 +439,7 @@ int main(int argc, char *argv[]) ErrPrint("dlclose: %s\n", strerror(errno)); } } + return ret; } diff --git a/src/util.c b/src/util.c index 708541f..6871ccf 100644 --- a/src/util.c +++ b/src/util.c @@ -68,6 +68,9 @@ HAPI int util_get_filesize(const char *filename) HAPI double util_timestamp(void) { +#if defined(_USE_ECORE_TIME_GET) + return ecore_time_get(); +#else struct timeval tv; if (gettimeofday(&tv, NULL) < 0) { @@ -79,6 +82,7 @@ HAPI double util_timestamp(void) } return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; +#endif } HAPI const char *util_basename(const char *name) @@ -164,7 +168,6 @@ HAPI const char *util_uri_to_path(const char *uri) HAPI double util_time_delay_for_compensation(double period) { - struct timeval tv; unsigned long long curtime; unsigned long long _period; unsigned long long remain; @@ -175,12 +178,18 @@ HAPI double util_time_delay_for_compensation(double period) return 0.0f; } +#if defined(_USE_ECORE_TIME_GET) + curtime = ecore_time_get() * 1000000llu; +#else + struct timeval tv; if (gettimeofday(&tv, NULL) < 0) { ErrPrint("gettimeofday: %s\n", strerror(errno)); return period; } curtime = (unsigned long long)tv.tv_sec * 1000000llu + (unsigned long long)tv.tv_usec; +#endif + _period = (unsigned long long)(period * (double)1000000); if (_period == 0llu) { ErrPrint("%lf <> %llu\n", period, _period); -- 2.7.4