From 432b4e5f7d9ea722d13bbe4c117a4f9b78091e4f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Aug 2008 16:20:29 +0200 Subject: don't use PA_GCC_UNUSED anymore --- src/daemon/cpulimit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon/cpulimit.c') diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 42a71f7e..b5ed71e0 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -235,7 +235,7 @@ void pa_cpu_limit_done(void) { #else /* HAVE_SIGXCPU */ -int pa_cpu_limit_init(PA_GCC_UNUSED pa_mainloop_api *m) { +int pa_cpu_limit_init(pa_mainloop_api *m) { return 0; } -- cgit From b7026bf248948a6a30386ddbcc137f48f369a51e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 Aug 2008 22:39:54 +0200 Subject: add a few more gcc warning flags and fix quite a few problems found by doing so --- src/daemon/cpulimit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon/cpulimit.c') diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index b5ed71e0..c6e13d83 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -100,7 +100,7 @@ static void reset_cpu_time(int t) { n = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec + t; pa_assert_se(getrlimit(RLIMIT_CPU, &rl) >= 0); - rl.rlim_cur = n; + rl.rlim_cur = (rlim_t) n; pa_assert_se(setrlimit(RLIMIT_CPU, &rl) >= 0); } @@ -130,7 +130,7 @@ static void signal_handler(int sig) { write_err(t); #endif - if (CPUTIME_INTERVAL_SOFT >= ((now-last_time)*(double)CPUTIME_PERCENT/100)) { + if ((double) CPUTIME_INTERVAL_SOFT >= ((double) (now-last_time)*(double)CPUTIME_PERCENT/100)) { static const char c = 'X'; write_err("Soft CPU time limit exhausted, terminating.\n"); -- cgit From 8e7178755193949d42bfe5a6c487e7fcdd0c51bd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 Aug 2008 23:03:37 +0200 Subject: rework cpu limit logic to use monotonic instead of wall clock time --- src/daemon/cpulimit.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/daemon/cpulimit.c') diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index c6e13d83..59552828 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -24,11 +24,13 @@ #endif #include +#include #include #include #include #include +#include #include "cpulimit.h" @@ -67,7 +69,7 @@ #define CPUTIME_INTERVAL_HARD (5) /* Time of the last CPU load check */ -static time_t last_time = 0; +static pa_usec_t last_time = 0; /* Pipe for communicating with the main loop */ static int the_pipe[2] = {-1, -1}; @@ -117,20 +119,21 @@ static void signal_handler(int sig) { pa_assert(sig == SIGXCPU); if (phase == PHASE_IDLE) { - time_t now; + pa_usec_t now, elapsed; #ifdef PRINT_CPU_LOAD char t[256]; #endif - time(&now); + now = pa_rtclock_usec(); + elapsed = now - last_time; #ifdef PRINT_CPU_LOAD - pa_snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", (double)CPUTIME_INTERVAL_SOFT/(now-last_time)*100); + pa_snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", ((double) CPUTIME_INTERVAL_SOFT * (double) PA_USEC_PER_SEC) / (double) elapsed * 100.0); write_err(t); #endif - if ((double) CPUTIME_INTERVAL_SOFT >= ((double) (now-last_time)*(double)CPUTIME_PERCENT/100)) { + if (((double) CPUTIME_INTERVAL_SOFT * (double) PA_USEC_PER_SEC) >= ((double) elapsed * (double) CPUTIME_PERCENT / 100.0)) { static const char c = 'X'; write_err("Soft CPU time limit exhausted, terminating.\n"); @@ -179,7 +182,7 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { pa_assert(the_pipe[1] == -1); pa_assert(!installed); - time(&last_time); + last_time = pa_rtclock_usec(); /* Prepare the main loop pipe */ if (pipe(the_pipe) < 0) { -- cgit