public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matti Aarnio <matti.aarnio@zmailer.org>
To: Michael Kerrisk <mtk-manpages@gmx.net>
Cc: Davide Libenzi <davidel@xmailserver.org>,
	rdunlap@xenotime.net, Andrew Morton <akpm@linux-foundation.org>,
	hch@lst.de, geoff@gclare.org.uk, tglx@linutronix.de,
	david@hardeman.nu, Ulrich Drepper <drepper@redhat.com>,
	subrata@linux.vnet.ibm.com, corbet@lwn.net,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Man page for revised timerfd API
Date: Wed, 3 Oct 2007 11:14:53 +0300	[thread overview]
Message-ID: <20071003081453.GS6372@mea-ext.zmailer.org> (raw)
In-Reply-To: <47033BA1.7070901@gmx.net>

On Wed, Oct 03, 2007 at 08:50:09AM +0200, Michael Kerrisk wrote:
> Davide Libenzi wrote:
> > On Thu, 27 Sep 2007, Michael Kerrisk wrote:
> > 
> >> Davide,
> >>
> >> A further question: what is the expected behavior in the
> >> following scenario:
> >>
> >> 1. Create a timerfd and arm it.
> >> 2. Wait until M timer expirations have occurred
> >> 3. Modify the settings of the timer
> >> 4. Wait for N further timer expirations have occurred
> >> 5. read() from the timerfd
> >>
> >> Does the buffer returned by the read() contain the value
> >> N or (M+N)?  In other words, should modifying the timer
> >> settings reset the expiration count to zero?
> > 
> > Every timerfd_settime() zeroes the tick counter. So in your scenario it'll 
> > return N.
> 
> Thanks Davide.
> 
> I modified the first para of the read description to make this clear:
> 
>        read(2)
>               If the timer has already expired one or more times
>               since   its  settings  were  last  modified  using
>               timerfd_settime(), or since  the  last  successful
>               read(2),  then the buffer given to read(2) returns
>               an unsigned 8-byte integer  (uint64_t)  containing
>               the number of expirations that have occurred.

When returning multi-byte long numeric values via read(2) as byte streams,
my default question is:

   Can you explicitely state what is the byte order ?

It _probably_ is the host-byte-order as kernel- and userspaces can hardly
run with different ones and this does not sound like an API to be used
over the network, but nevertheless...


In the code-example:

    for (tot_exp = 0; tot_exp < max_exp;) {
        s = read(fd, &exp, sizeof(uint64_t));
        if (s != sizeof(uint64_t))
            die("read");
        tot_exp += exp;
        print_elapsed_time();
        printf("read: %llu; total=%d\\n", exp, tot_exp);
    }

If I may suggest some alterations:

    for (tot_exp = 0; tot_exp < max_exp;) {
        s = read(fd, &exp, sizeof(exp));
        if (s < 0) {
            /* add: EINTR etc. processing */
            continue;
        }
        if (s != sizeof(exp))
            die("read");
        tot_exp += exp;
        print_elapsed_time();
        printf("read: %lu; total=%d\\n", (unsigned long) exp, tot_exp);
    }

The "die if surprised" -strategy is not nice.
Somebody will take example out of that code.

Indeed defining all possible error modes may be impossible, but it may
be possible to define those errors that result in so severe dysfunction
that closing and re-creating the timer-handle may be your only choice.
(About the impossibility:  Solaris STREAMS based network accept() does/did
 yield all kinds of odd errors out from the STREAMS stack in addition to
 those listed in the syscall man-page.  Reacting on all unknown errors
 by dying is not really a smart thing on a program.)


> (In the earlier version of the page the text talked about expirations
> "since the timer was created".)
> 
> Cheers,
> 
> Michael
> -- 
> Michael Kerrisk
> maintainer of Linux man pages Sections 2, 3, 4, 5, and 7

  /Matti Aarnio  <matti.aarnio@zmailer.org>

  reply	other threads:[~2007-10-03  8:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-26  7:12 Man page for revised timerfd API Michael Kerrisk
2007-09-26 18:06 ` Davide Libenzi
2007-09-26 21:13   ` Michael Kerrisk
2007-09-27 10:35   ` Michael Kerrisk
2007-09-27 16:45     ` Davide Libenzi
2007-10-03  6:50       ` Michael Kerrisk
2007-10-03  8:14         ` Matti Aarnio [this message]
2007-10-04 18:19           ` Michael Kerrisk
2007-09-27  8:20 ` Geoff Clare
2007-09-27 10:50   ` Michael Kerrisk
     [not found] <20070927072726.50350@gmx.net>
2007-09-27 16:42 ` Davide Libenzi

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=20071003081453.GS6372@mea-ext.zmailer.org \
    --to=matti.aarnio@zmailer.org \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=david@hardeman.nu \
    --cc=davidel@xmailserver.org \
    --cc=drepper@redhat.com \
    --cc=geoff@gclare.org.uk \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtk-manpages@gmx.net \
    --cc=rdunlap@xenotime.net \
    --cc=subrata@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    /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