mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrei Voropaev <avorop@mail.ru>
To: linux-kernel@vger.kernel.org
Subject: with 2.6.7 setitimer called in sequence returns strange values on i686
Date: Tue, 24 Aug 2004 16:42:41 +0200	[thread overview]
Message-ID: <20040824144241.GE1527@avorop.local> (raw)

Hello!

Sorry if I'm taking your time away but to me it looks like I have kernel
problem, so I hoped to find some help in this list. I'm not subscribed
so please CC me on replies.

I'm using setitimer(ITIMER_REAL...) to measure time intervals.
Everything was working fine untill I've installed 2.6.7 kernel. 

bash$ uname -a
Linux avorop 2.6.7 #5 Thu Aug 19 11:53:33 CEST 2004 i686 unknown

Here's little piece of code that reproduces problem on my machine.

===========================================
#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <errno.h>
#include <error.h>
#include <time.h>

void
set_timer(int arg)
{
    struct itimerval n, o;
    struct timespec per;

    n.it_interval.tv_sec = 0;
    n.it_interval.tv_usec = 0;
    n.it_value.tv_sec = arg;
    n.it_value.tv_usec = 0;
    // init timer
    if(setitimer(ITIMER_REAL, &n, &o) != 0) 
       error(EXIT_FAILURE, errno, "Can't set timer");
    printf("Previous value of %d timer is %ld.%ld\n", arg, 
            o.it_value.tv_sec, o.it_value.tv_usec);
    per.tv_sec = arg / 2;
    per.tv_nsec = 0;
    // sleep for half a timer time
    nanosleep(&per, NULL);
    n.it_value.tv_sec = arg;
    n.it_value.tv_usec = 0;
    // check how much time is left and restart it at the same time
    if(setitimer(ITIMER_REAL, &n, &o) != 0) 
       error(EXIT_FAILURE, errno, "Can't set timer");
    printf("Previous value of %d timer is %ld.%ld\n", arg, 
             o.it_value.tv_sec, o.it_value.tv_usec);
    n.it_value.tv_sec = 0;
    n.it_value.tv_usec = 0;
    // check how much time is left. 
    if(setitimer(ITIMER_REAL, &n, &o) != 0) 
        error(EXIT_FAILURE, errno, "Can't set timer");
    printf("Previous value of %d timer is %ld.%ld\n", arg, 
        o.it_value.tv_sec, o.it_value.tv_usec);
}

int
main(void)
{
    pthread_t thr1, thr2;

    pthread_create(&thr1, NULL, (void*)set_timer, (void*)10);
//    pthread_create(&thr2, NULL, (void*)set_timer, (void*)12);

    pthread_join(thr1, NULL);
    pthread_join(thr2, NULL);
    return 0;
}
======================================================
On my machine this program produces

Previous value of 10 timer is 0.0
Previous value of 10 timer is 4.999240
Previous value of 10 timer is 10.479

Note the last line. I've reset timer to 10 seconds and setitimer tells
me that there are 10.479 seconds left.

As I said this code works fine with 2.4.21 kernel. It produces 
Previous value of 10 timer is 0.0
Previous value of 10 timer is 4.980000
Previous value of 10 timer is 10.0

I have one more machine with 2.6.7 kernel. But that machine is Athlon64
and runs 64-bit kernel. There the program also runs correctly.

Any hints on where to look for the problem?

TIA.

Andrei

             reply	other threads:[~2004-08-24 14:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-24 14:42 Andrei Voropaev [this message]
2004-08-24 15:11 ` Michael Kerrisk
2004-08-25  7:17   ` Andrei Voropaev
2004-08-30 12:10 ` Andrei Voropaev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040824144241.GE1527@avorop.local \
    --to=avorop@mail.ru \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®