public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Michael Krufky <mkrufky@m1k.net>
Cc: linux-kernel@vger.kernel.org, linux-dvb-maintainer@linuxtv.org,
	NooneImportant <nxhxzi702@sneakemail.com>
Subject: Re: [PATCH 18/37] dvb: let other frontends support FE_DISHNETWORK_SEND_LEGACY_CMD
Date: Thu, 3 Nov 2005 13:52:10 +1100	[thread overview]
Message-ID: <20051103135210.21cdcf77.akpm@osdl.org> (raw)
In-Reply-To: <436723DB.2000300@m1k.net>

Michael Krufky <mkrufky@m1k.net> wrote:
>
> +s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
>  +{
>  +	return ((curtime.tv_usec < lasttime.tv_usec) ?
>  +		1000000 - lasttime.tv_usec + curtime.tv_usec :
>  +		curtime.tv_usec - lasttime.tv_usec);
>  +}
>  +EXPORT_SYMBOL(timeval_usec_diff);
>  +
>  +static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
>  +{
>  +	curtime->tv_usec += add_usec;
>  +	if (curtime->tv_usec >= 1000000) {
>  +		curtime->tv_usec -= 1000000;
>  +		curtime->tv_sec++;
>  +	}
>  +}

timeval arithmetic like this really shouldn't be hidden in a dvb driver -
it's generic code.

>  +/*
>  + * Sleep until gettimeofday() > waketime + add_usec
>  + * This needs to be as precise as possible, but as the delay is
>  + * usually between 2ms and 32ms, it is done using a scheduled msleep
>  + * followed by usleep (normally a busy-wait loop) for the remainder
>  + */
>  +void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
>  +{
>  +	struct timeval lasttime;
>  +	s32 delta, newdelta;
>  +
>  +	timeval_usec_add(waketime, add_usec);
>  +
>  +	do_gettimeofday(&lasttime);
>  +	delta = timeval_usec_diff(lasttime, *waketime);
>  +	if (delta > 2500) {
>  +		msleep((delta - 1500) / 1000);
>  +		do_gettimeofday(&lasttime);
>  +		newdelta = timeval_usec_diff(lasttime, *waketime);
>  +		delta = (newdelta > delta) ? 0 : newdelta;
>  +	}
>  +	if (delta > 0)
>  +		udelay(delta);
>  +}
>  +EXPORT_SYMBOL(dvb_frontend_sleep_until);

However I don't believe that the driver should be using timevals and
do_gettimeofday() at all.  Why not use jiffies-based timing like so
many other parts of the kernel?

  reply	other threads:[~2005-11-03  3:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-01  8:14 [PATCH 18/37] dvb: let other frontends support FE_DISHNETWORK_SEND_LEGACY_CMD Michael Krufky
2005-11-03  2:52 ` Andrew Morton [this message]
2005-11-03  4:17   ` NooneImportant

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=20051103135210.21cdcf77.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-dvb-maintainer@linuxtv.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkrufky@m1k.net \
    --cc=nxhxzi702@sneakemail.com \
    /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