public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug time/30559] New: setitimer works incorrectly
@ 2023-06-16 2:51 vladimir.mezentsev at oracle dot com
2023-06-16 6:40 ` [Bug time/30559] " schwab@linux-m68k.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: vladimir.mezentsev at oracle dot com @ 2023-06-16 2:51 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30559
Bug ID: 30559
Summary: setitimer works incorrectly
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: time
Assignee: unassigned at sourceware dot org
Reporter: vladimir.mezentsev at oracle dot com
Target Milestone: ---
A small test below shows the problem with the itimer setting:
% cat sig.c
#include<stdio.h>
#include <stdlib.h>
#include<signal.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#ifndef MY_TIMER
#define MY_TIMER 1000
#endif
static time_t start;
static int sigprof_cnt = 0;
time_t
gethrtime (void)
{
struct timespec tp;
time_t rc = 0;
int r = clock_gettime (CLOCK_MONOTONIC, &tp);
if (r == 0)
rc = ((time_t) tp.tv_sec) * 1e9 + (time_t) tp.tv_nsec;
return rc;
}
static void sigprof_handler(int signo, siginfo_t* info, void *context)
{
if (++sigprof_cnt >= 3)
exit(0);
static struct itimerval t;
memset(&t, 0, sizeof(t));
if (getitimer(ITIMER_PROF, &t) != 0)
printf("getitimer failed\n");
printf("sigprof_handler: it_interval.tv_sec=%lld it_interval.tv_usec=%lld\n"
" it_value.tv_sec=%lld it_value.tv_usec=%lld\n",
(long long) t.it_interval.tv_sec, (long long) t.it_interval.tv_usec,
(long long) t.it_value.tv_sec, (long long) t.it_value.tv_usec);
}
volatile long x; /* temp variable for long calculation */
int
main (int argc, char **argv)
{
long long count = 0;
start = gethrtime ();
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = sigprof_handler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGPROF, &sa, NULL) == -1)
{
perror("sigaction");
return 1;
}
static struct itimerval timer;
memset(&timer, 0, sizeof(timer));
timer.it_interval.tv_usec = MY_TIMER;
timer.it_value.tv_usec = MY_TIMER;
if (setitimer(ITIMER_PROF, &timer, NULL) != 0)
{
printf("Timer could not be initialized \n");
return 1;
}
struct itimerval t;
memset(&t, 0, sizeof(t));
if (getitimer(ITIMER_PROF, &t) != 0)
{
printf("getitimer failed\n");
return 1;
}
printf("After setitimer: it_interval.tv_sec=%lld it_interval.tv_usec=%lld\n"
" it_value.tv_sec=%lld it_value.tv_usec=%lld\n",
(long long) t.it_interval.tv_sec, (long long) t.it_interval.tv_usec,
(long long) t.it_value.tv_sec, (long long) t.it_value.tv_usec);
do
{
x = 0;
for (int j = 0; j < 1000000; j++)
x = x + 1;
count++;
}
while (start + 1e9 / 4 > gethrtime ());
printf("count=%lld x=%lld\n", count, x);
return 0;
}
It is from man page:
% man setitimer
...
setitimer()
If either field in new_value.it_value is nonzero, then the timer is arme
to initially expire at the specified time.
But this is not right on x86_64 and aarch64. I run this test on OL8.
On x86_64 / OL8:
% gcc -DMY_TIMER=1000 sig.c; ./a.out
After setitimer: it_interval.tv_sec=0 it_interval.tv_usec=1000
it_value.tv_sec=0 it_value.tv_usec=2000 <<<<<< this
should be <= 1000 because I set it_value.tv_usec to 1000 in setitimer
sigprof_handler: it_interval.tv_sec=0 it_interval.tv_usec=1000
it_value.tv_sec=0 it_value.tv_usec=23
sigprof_handler: it_interval.tv_sec=0 it_interval.tv_usec=1000
it_value.tv_sec=0 it_value.tv_usec=27
On aarch64 / OL8:
% gcc -DMY_TIMER=1000 sig.c; ./a.out
After setitimer: it_interval.tv_sec=0 it_interval.tv_usec=1000
it_value.tv_sec=0 it_value.tv_usec=5000 <<<<<< Same as
on x86_64
sigprof_handler: it_interval.tv_sec=0 it_interval.tv_usec=1000
it_value.tv_sec=0 it_value.tv_usec=4000 <<<<<< this must be
<= 1000 because it_interval.tv_usec is 1000
sigprof_handler: it_interval.tv_sec=0 it_interval.tv_usec=1000
it_value.tv_sec=0 it_value.tv_usec=4000<<<<<< this
must be <= 1000 because it_interval.tv_usec is 1000
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug time/30559] setitimer works incorrectly
2023-06-16 2:51 [Bug time/30559] New: setitimer works incorrectly vladimir.mezentsev at oracle dot com
@ 2023-06-16 6:40 ` schwab@linux-m68k.org
2023-06-16 19:03 ` vladimir.mezentsev at oracle dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: schwab@linux-m68k.org @ 2023-06-16 6:40 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30559
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |MOVED
--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
This is just a thin wrapper around the syscall, you need to report that to the
kernel developers. Most likely, the timer value is rounded to the clock
resolution.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug time/30559] setitimer works incorrectly
2023-06-16 2:51 [Bug time/30559] New: setitimer works incorrectly vladimir.mezentsev at oracle dot com
2023-06-16 6:40 ` [Bug time/30559] " schwab@linux-m68k.org
@ 2023-06-16 19:03 ` vladimir.mezentsev at oracle dot com
2023-06-19 13:21 ` fweimer at redhat dot com
2023-06-20 20:49 ` ruud.vanderpas at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: vladimir.mezentsev at oracle dot com @ 2023-06-16 19:03 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30559
--- Comment #2 from Vladimir Mezentsev <vladimir.mezentsev at oracle dot com> ---
I did not find how to create a bug against kernel.
Do you know what the Product/Component should be ?
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug time/30559] setitimer works incorrectly
2023-06-16 2:51 [Bug time/30559] New: setitimer works incorrectly vladimir.mezentsev at oracle dot com
2023-06-16 6:40 ` [Bug time/30559] " schwab@linux-m68k.org
2023-06-16 19:03 ` vladimir.mezentsev at oracle dot com
@ 2023-06-19 13:21 ` fweimer at redhat dot com
2023-06-20 20:49 ` ruud.vanderpas at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: fweimer at redhat dot com @ 2023-06-19 13:21 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30559
Florian Weimer <fweimer at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |fweimer at redhat dot com
--- Comment #3 from Florian Weimer <fweimer at redhat dot com> ---
Kernel Bugzilla is at <https://bugzilla.kernel.org/>, it is unrelated to this
Bugzilla instance. Most kernel maintainers do not look at their Bugzilla,
though. You'll have to find out the proper mailing list based on MAINTAINERS
and raise the issue there.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug time/30559] setitimer works incorrectly
2023-06-16 2:51 [Bug time/30559] New: setitimer works incorrectly vladimir.mezentsev at oracle dot com
` (2 preceding siblings ...)
2023-06-19 13:21 ` fweimer at redhat dot com
@ 2023-06-20 20:49 ` ruud.vanderpas at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: ruud.vanderpas at oracle dot com @ 2023-06-20 20:49 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30559
Ruud van der Pas <ruud.vanderpas at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ruud.vanderpas at oracle dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-20 20:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 2:51 [Bug time/30559] New: setitimer works incorrectly vladimir.mezentsev at oracle dot com
2023-06-16 6:40 ` [Bug time/30559] " schwab@linux-m68k.org
2023-06-16 19:03 ` vladimir.mezentsev at oracle dot com
2023-06-19 13:21 ` fweimer at redhat dot com
2023-06-20 20:49 ` ruud.vanderpas at oracle dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).