mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: Dmitry Torokhov <dtor_core@ameritech.net>
Cc: Pavel Machek <pavel@suse.cz>,
	linux-kernel@vger.kernel.org, vojtech@suse.cz
Subject: Re: locking in psmouse
Date: Thu, 29 Apr 2004 21:43:45 +0200	[thread overview]
Message-ID: <20040429194344.GB468@openzaurus.ucw.cz> (raw)
In-Reply-To: <200404290740.18182.dtor_core@ameritech.net>

Hi!

> > Anyway, locking still seems to be needed: 
> > 
> >         while (psmouse->cmdcnt && timeout--) {
> > 
> >                 if (psmouse->cmdcnt == 1 && command == PSMOUSE_CMD_RESET_BAT &&
> >                                 timeout > 100000) /* do not run in a endless loop */
> >                         timeout = 100000; /* 1 sec */
> > 
> >                 if (psmouse->cmdcnt == 1 && command == PSMOUSE_CMD_GETID &&
> >                     psmouse->cmdbuf[1] != 0xab && psmouse->cmdbuf[1] != 0xac) {
> >                         psmouse->cmdcnt = 0;
> >                         break;
> >                 }
> > 
> >                 spin_unlock_irq(&psmouse_lock);
> >                 udelay(1);
> >                 spin_lock_irq(&psmouse_lock);
> >         }
> > 
> > racing with
> > 
> >         if (psmouse->cmdcnt) {
> >                 psmouse->cmdbuf[--psmouse->cmdcnt] = data;
> >                 goto out;
> >         }
> > 
> > now... if each runs on different CPU, it can be possible that
> > psmouse->cmdcnt is seen as 1 but data are not yet in
> > psmouse->cmdbuf... Locking seems neccessary here.
> 
> I see.. but this particular case can be resolved but rearranging the code to
> write command response first and then decrementing the counter... and putting
> a barrier? Or just make cmdcnt atomic... spin_lock_irq feels heavier than
> absolutely necessary.

cmdcnt would have to be atomic_t, ack too, state too, and
you'd have to be very carefull with memory barriers...
I guess spinlock is better solution.
				Pavel
-- 
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         


  reply	other threads:[~2004-04-29 20:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-28 21:30 Pavel Machek
2004-04-29  4:47 ` Dmitry Torokhov
2004-04-29  9:58   ` Pavel Machek
2004-04-29 12:40     ` Dmitry Torokhov
2004-04-29 19:43       ` Pavel Machek [this message]
2004-06-06 17:41       ` Vojtech Pavlik
2004-06-06 18:51         ` Pavel Machek
2004-06-06 19:34           ` Vojtech Pavlik
2004-04-29 16:02     ` Vojtech Pavlik

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=20040429194344.GB468@openzaurus.ucw.cz \
    --to=pavel@suse.cz \
    --cc=dtor_core@ameritech.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.cz \
    /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®