linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Grant Likely" <grant.likely@secretlab.ca>
To: "Stephen Neuendorffer" <stephen.neuendorffer@xilinx.com>
Cc: linuxppc-dev@ozlabs.org
Subject: Re: [PATCH] [POWERPC] Xilinx: hwicap driver
Date: Thu, 31 Jan 2008 16:12:54 -0700	[thread overview]
Message-ID: <fa686aa40801311512l16b31df8q4d5bf940210389e@mail.gmail.com> (raw)
In-Reply-To: <20080131223933.4DC0115B937D@mail113-dub.bigfish.com>

On 1/31/08, Stephen Neuendorffer <stephen.neuendorffer@xilinx.com> wrote:
> > Also, this isn't sufficient to prevent 2 processes from having the
> > device open.  If a process has already opened it and then calls
> > fork(), then *both* processes will have it opened even though the open
> > fop was only called once.  (It might not matter for this particular
> > driver as the use case is limited; but it is something you should be
> > aware of.)
>
> The fork I'm somewhat less concerned about, I think.  If someone calls
> fork(), then it's up to them to synchronize their code correctly and
> only call close() once.  The only reason to block the open is that it's
> the simplest way to keep track of the state between reads and writes.

<interesting trivia> You're thinking of threads; not fork.  When fork
is called you get a whole new process which has all the same file
descriptors open as the parent process.  This is what the timeline
would look like:

p1: open(/dev/hwcap0)
--- open fop called here (and struct file is allocated)
p1: fork()
--- p2 is created
p1: do stuff
p2: do stuff
p1: close()
p2: do more stuff
p2: close()
--- release fop called here (and struct file is released)

Notice how close is called twice (the correct behavour) yet release is
only called once?  :-)  That means there are 2 processes sharing the
same file structure.

> > > +static int __devinit hwicap_setup(struct device *dev, int id,
> > > +               const struct resource *regs_res,
> > > +               const struct hwicap_driver_config *config,
> > > +               const struct config_registers *config_regs)
> > > +{
> > > +       dev_t devt;
> > > +       struct hwicap_drvdata *drvdata = NULL;
> > > +       int retval = 0;
> > > +
> > > +       dev_info(dev, "Xilinx icap port driver\n");
> > > +
> > > +       if (id < 0) {
> > > +               for (id = 0; id < HWICAP_DEVICES; id++)
> > > +                       if (!probed_devices[id])
> > > +                               break;
> > > +       }
> > > +       if (id < 0 || id >= HWICAP_DEVICES) {
> > > +               dev_err(dev, "%s%i too large\n", DRIVER_NAME, id);
> > > +               return -EINVAL;
> > > +       }
> > > +       if (probed_devices[id]) {
> > > +               dev_err(dev, "cannot assign to %s%i; it is already
> in use\n",
> > > +                       DRIVER_NAME, id);
> > > +               return -EBUSY;
> > > +       }
> > > +
> > > +       probed_devices[id] = 1;
> >
> > Hmmm, I'm not thrilled with the fixed array of HWICAP devices.  That
> > sort of thing just ends up causing headaches down the road.  Can the
> > driver just allocate a new structure and the next available ID at
> > probe time?  (I hold my nose every time I write something like the
> > above because I know I'm going to regret it later).  sysfs/udev can
> > provide details about which one is which.
>
> Can you suggest a good driver to crib?

What I would do is use a static struct list_head to hold a list of all
instantiated devices.  When you register a new device you can use
list_for_each_entry to look for a free id.  That way you don't have to
preallocate an array for all the possible device numbers.

OTOH, how many of these devices are likely to be present on any one
bitstream?  If it is only 1 or 2 then it might be that the overhead
isn't worth the savings.  I won't complain if you decide it's better
the way it is now.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

  reply	other threads:[~2008-01-31 23:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-04 23:57 [PATCH] [XILINX][HWICAP] Xilinx Internal Configuration Access Port device driver Stephen Neuendorffer
2007-12-05  0:05 ` Grant Likely
2007-12-05 12:20 ` Peter Korsgaard
2008-01-31 18:41   ` Stephen Neuendorffer
2008-01-31 18:47   ` [PATCH] [POWERPC] Xilinx: hwicap driver Stephen Neuendorffer
2008-01-31 19:58     ` Grant Likely
2008-01-31 22:39       ` Stephen Neuendorffer
2008-01-31 23:12         ` Grant Likely [this message]
2008-01-31 23:51           ` Stephen Neuendorffer
     [not found] <1201805233-15112-1-git-send-email-stephen.neuendorffer@xilinx.com>
2008-02-01  1:02 ` Stephen Neuendorffer
2008-02-01  5:21   ` Grant Likely
     [not found] ` <1201827769-7439-1-git-send-email-stephen.neuendorffer@xilinx.com>
2008-02-01  5:01   ` Stephen Neuendorffer
2008-02-01  5:56     ` Nathan Lynch
2008-02-01 17:31       ` Stephen Neuendorffer
2008-02-01 18:22   ` Stephen Neuendorffer
2008-02-01 18:42     ` Grant Likely
     [not found] <1201890163-12219-1-git-send-email-stephen.neuendorffer@xilinx.com>
2008-02-01 20:03 ` Stephen Neuendorffer
2008-02-01 20:11   ` Grant Likely
2008-02-01 21:12     ` Stephen Neuendorffer
     [not found]     ` <1201900363-25230-1-git-send-email-stephen.neuendorffer@xilinx.com>
2008-02-05  0:38       ` Stephen Neuendorffer
     [not found] <47AB6552.7040503@gmail.com>
2008-02-08  2:17 ` Stephen Neuendorffer
2008-02-08  9:10   ` Jiri Slaby
2008-02-08 16:49   ` Randy Dunlap

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=fa686aa40801311512l16b31df8q4d5bf940210389e@mail.gmail.com \
    --to=grant.likely@secretlab.ca \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=stephen.neuendorffer@xilinx.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;
as well as URLs for NNTP newsgroup(s).