From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sven-Thorsten Dietrich Subject: [PATCH] clock_nanosleep interrupt Date: Wed, 01 Jul 2009 18:57:43 -0700 Message-ID: <1246499863.32598.3.camel@sven.thebigcorporation.com> References: <20090429155011.09e2218f@torg> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: RT , Daniel Gollub To: Clark Williams Return-path: Received: from wf-out-1314.google.com ([209.85.200.173]:21630 "EHLO wf-out-1314.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbZGBB5n (ORCPT ); Wed, 1 Jul 2009 21:57:43 -0400 Received: by wf-out-1314.google.com with SMTP id 26so512700wfd.4 for ; Wed, 01 Jul 2009 18:57:47 -0700 (PDT) In-Reply-To: <20090429155011.09e2218f@torg> Sender: linux-rt-users-owner@vger.kernel.org List-ID: Subject: Avoid segfault of cyclictest if it gets immediately interrupted. From: Daniel Gollub If clock_nanosleep() gets interrupted this could result in a negative time diff from calcdiff(). With the histogram patch this leads to a segfault, since the time diff is used as index for the histogram array: Core was generated by `/usr/bin/cyclictest -n -q -p 99 -t 2 -i 500 -l 1000000 -h 20000'. Program terminated with signal 11, Segmentation fault. #0 0x0000000000402324 in timerthread (param=) at src/cyclictest/cyclictest.c:339 339 stat->hist_array[diff] += 1; (gdb) p diff $1 = -751974 Signed-off-by: Daniel Gollub Acked-by: Sven-Thorsten Dietrich --- src/cyclictest/cyclictest.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) Index: rt-tests/src/cyclictest/cyclictest.c =================================================================== --- rt-tests.orig/src/cyclictest/cyclictest.c +++ rt-tests/src/cyclictest/cyclictest.c @@ -376,7 +376,7 @@ void *timerthread(void *param) while (!shutdown) { long diff; - int sigs; + int sigs, ret; /* Wait for next period */ switch (par->mode) { @@ -387,17 +387,24 @@ void *timerthread(void *param) break; case MODE_CLOCK_NANOSLEEP: - if (par->timermode == TIMER_ABSTIME) - clock_nanosleep(par->clock, TIMER_ABSTIME, + if (par->timermode == TIMER_ABSTIME) { + ret = clock_nanosleep(par->clock, TIMER_ABSTIME, &next, NULL); - else { + } else { clock_gettime(par->clock, &now); - clock_nanosleep(par->clock, TIMER_RELTIME, + ret = clock_nanosleep(par->clock, TIMER_RELTIME, &interval, NULL); next.tv_sec = now.tv_sec + interval.tv_sec; next.tv_nsec = now.tv_nsec + interval.tv_nsec; tsnorm(&next); } + + /* Avoid negative calcdiff result if clock_nanosleep() + * gets interrupted. + */ + if (ret == EINTR) + goto out; + break; case MODE_SYS_NANOSLEEP: