All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Clifford Wolf <clifford-cPpHkPqGOEfk7+2FdBfRIA@public.gmane.org>
Cc: David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>,
	Linux I2C <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>
Subject: Re: Handling of i2c arbitration loss
Date: Fri, 20 Feb 2009 12:45:46 +0100	[thread overview]
Message-ID: <20090220124546.193e49f2@hyperion.delvare> (raw)
In-Reply-To: <20090219212325.GC16107-cPpHkPqGOEfk7+2FdBfRIA@public.gmane.org>

On Thu, 19 Feb 2009 22:23:25 +0100, Clifford Wolf wrote:
> Hi Jean,
> 
> On Thu, Feb 19, 2009 at 05:26:05PM +0100, Jean Delvare wrote:
> > > @@ -1000,7 +1000,8 @@ module_exit(i2c_exit);
> > >   */
> > >  int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
> > >  {
> > > -	int ret;
> > > +	unsigned long orig_jiffies = jiffies;
> > 
> > I think you should initialize orig_jiffies *after* you get the bus
> > lock. Otherwise the behavior depends on how long you had to wait to get
> > control of the bus. Or was is intended?
> 
> phew! this is a good question...
> 
> to be honest: I haven't thought about that one yet.
> 
> I think both approaches (including the wait for the lock in the timeout on
> the one hand and just counting the time spent after getting the lock on the
> other hand) would be valid..
>
> But I think it would be better to not include the wait-for-lock time and
> move the initialization of orig_jiffies to after locking the mutex.

I agree... Please send an updated patch.

> In the case of including the wait-for-lock time there should be a timeout
> handling added to the lock code so it only tries to get the lock for not
> longer than the timeout... So my code is broken eighter way... ;-)

That's a different issue. But I don't think we really need to handle
this case. You should never wait long before you get access to the bus.
If you do then there is a design problem which needs to be solved, and
timing out if you don't get the bus lock in a given amount of time
isn't going to solve it. If one really can't afford waiting for the bus
then the i2c_transfer() function should return immediately (as it
already does in the can't-sleep case.)

> > This assumes that adap->timeout is expressed in jiffies. Which
> > according to a comment in include/linux/i2c-dev.h, is the case, but
> > this must be for historical reasons. This never made sense to me, as it
> > means that the actual timeout value depends on the value of HZ.
> > 
> > The key problem here is that the timeout value is exported to
> > user-space and can be changed by user-space. And user-space normally
> > doesn't know the value of HZ... So the timeout value should be
> > expressed in a constant time unit.
> 
> I haven't had a look at the code but would it be so hard to convert the
> timeout value to ms or something alike when exporting the value to
> user-space and convert in the other direction on reading from user-space?

You are perfectly right. I came out to the same conclusion as I woke up
this morning. Sleep over it...

> imo jiffies is the best unit for time within the kernel and I would prefer
> having one place for the convertion instead of duplicating it in every
> single driver and multiple places in i2c-core..

Well you have to do the conversion in each driver either way, as
hard-coding a number of jiffies is a bad idea (makes the timeout depend
on the value of HZ). But I agree it is better to convert from ms to
jiffies once at initialization rather than each time we need to use the
timeout value.

I'll send a patch to the list now, addressing the issue in i2c-dev.
Your own work is unaffected by this.

-- 
Jean Delvare

  parent reply	other threads:[~2009-02-20 11:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-22 21:01 + i2c-fix-i2c-mpc-driver-for-multi-master-i2c-busses.patch added to -mm tree akpm
     [not found] ` <20090108154604.2cade06e@hyperion.delvare>
     [not found] ` <20090109100145.GA12376@clifford.at>
     [not found]   ` <20090214121745.39dfddf9@hyperion.delvare>
     [not found]     ` <200902151653.36860.david-b@pacbell.net>
     [not found]       ` <200902151653.36860.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2009-02-16  8:20         ` Jean Delvare
     [not found]           ` <20090216092000.13af2d74-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-02-16 11:58             ` David Brownell
     [not found]               ` <200902160358.48176.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2009-02-16 12:41                 ` Clifford Wolf
2009-02-16 13:08                 ` Handling of i2c arbitration loss (Was: i2c-fix-i2c-mpc-driver-for-multi-master-i2c-busses.patch added to -mm tree) Jean Delvare
     [not found]                   ` <20090216140809.01acaea1-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-02-19 19:15                     ` David Brownell
     [not found]                       ` <200902191115.07289.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2009-02-19 21:08                         ` Clifford Wolf
2009-02-19 21:31                         ` Jean Delvare
     [not found]     ` <20090214180014.GA19352@clifford.at>
     [not found]       ` <20090215113122.5bcc3f3d@hyperion.delvare>
     [not found]         ` <20090216131026.GA17437@clifford.at>
     [not found]           ` <20090216131026.GA17437-cPpHkPqGOEfk7+2FdBfRIA@public.gmane.org>
2009-02-19 16:26             ` Handling of i2c arbitration loss Jean Delvare
     [not found]               ` <20090219172605.7e70a797-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-02-19 21:23                 ` Clifford Wolf
     [not found]                   ` <20090219212325.GC16107-cPpHkPqGOEfk7+2FdBfRIA@public.gmane.org>
2009-02-20 11:45                     ` Jean Delvare [this message]
     [not found]                       ` <20090220124546.193e49f2-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-04-09  6:47                         ` Jean Delvare
     [not found]                           ` <20090409084726.3f2bd193-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-04-09  8:35                             ` Clifford Wolf
     [not found]                               ` <20090409083553.GA20058-cPpHkPqGOEfk7+2FdBfRIA@public.gmane.org>
2009-04-23 12:24                                 ` Jean Delvare

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=20090220124546.193e49f2@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=clifford-cPpHkPqGOEfk7+2FdBfRIA@public.gmane.org \
    --cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.