public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
To: Gregory Haskins <ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH] Add irqdevice interface + userint implementation
Date: Sun, 8 Apr 2007 10:58:53 +0100	[thread overview]
Message-ID: <20070408095853.GA31284@infradead.org> (raw)
In-Reply-To: <4614FF5C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>

> diff --git a/drivers/kvm/kvm_irqdevice.h b/drivers/kvm/kvm_irqdevice.h
> new file mode 100644
> index 0000000..9c91d15
> --- /dev/null
> +++ b/drivers/kvm/kvm_irqdevice.h
> @@ -0,0 +1,206 @@
> +/*
> + * kvm_irqdevice.h

No need to mention the file name in the top of file comment.  Quite contrary,
this comment can easily get out of sync and thus is not encouraged.

> + *
> + * Defines an interface for an abstract interrupt controller.  The model 
> + * consists of a unit with an arbitrary number of input lines (IRQ0-N), an
> + * output line (INTR), and methods for completing an interrupt-acknowledge
> + * cycle (INTA).  A particular implementation of this model will define
> + * various policies, such as irq-to-vector translation, INTA/auto-EOI policy,
> + * etc.  
> + * 
> + * In addition, the INTR callback mechanism allows the unit to be "wired" to
> + * an interruptible source in a very flexible manner. For instance, an 
> + * irqdevice could have its INTR wired to a VCPU (ala LAPIC), or another 
> + * interrupt controller (ala cascaded i8259s)
> + *
> + * Copyright (C) 2007 Novell
> + *
> + * Authors:
> + *   Gregory Haskins <ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
> + * Place - Suite 330, Boston, MA 02111-1307 USA.

It would be nice if you could follow the top of file comment style used
in the rest of the kvm code instead of using a very different one.

> +/*
> + * kvm_irq_init()
> + *
> + * Description:
> + *    Initialized the kvm_irqdevice for use.  Should be called before calling
> + *    any derived implementation init functions
> + * 
> + * Parameters:
> + *    struct kvm_irqdevice *dev: This device
> + *
> + * Returns: (void)
> + */

Please use kernel-doc style comments that can be used to auto-generate
documentation.

> +static inline int kvm_irq_pending(struct kvm_irqdevice *dev, int flags)
> +{
> +	return dev->pending(dev, flags);
> +}

This wrapper is not needed at all, just call the method directly.

> +static inline int kvm_irq_read_vector(struct kvm_irqdevice *dev, int flags)
> +{
> +	return dev->read_vector(dev, flags);
> +}

ditto

> +static inline int kvm_irq_set_pin(struct kvm_irqdevice *dev, int pin, 
> +				  int level, int flags)
> +{
> +	return dev->set_pin(dev, pin, level, flags);
> +}

ditto

> +static inline int kvm_irq_summary(struct kvm_irqdevice *dev, void *data)
> +{
> +	return dev->summary(dev, data);
> +}

ditto.

> +static inline void kvm_irq_register_sink(struct kvm_irqdevice *dev, 
> +					 const struct kvm_irqsink *sink)
> +{
> +	dev->sink = *sink;
> +}

Completely useless wrapper, just do the assignment in the caller.
Also the convention of copying the operation vectors is rather unnatural
for linux, just set the pointer (and make sure the operations regustired
are file-scope not local-scope as in your current code)

> +static inline void kvm_irq_raise_intr(struct kvm_irqdevice *dev)
> +{
> +	struct kvm_irqsink *sink = &dev->sink;
> +	if (sink->raise_intr)
> +		sink->raise_intr(sink, dev);
> +}

Similarly this is rather pointless and could be opencoded in the only caller.

> +/*----------------------------------------------------------------------
> + * optimized bitarray object - works like bitarrays in bitops, but uses 
> + * a summary field to accelerate lookups.  Assumes external locking 
> + *---------------------------------------------------------------------*/
> +
> +struct bitarray {
> +	unsigned long summary; /* 1 per word in pending */
> +	unsigned long pending[NR_IRQ_WORDS];
> +};
> +
> +static inline int bitarray_pending(struct bitarray *this)
> +{
> +	return this->summary ? 1 : 0;	
> +}
> +
> +static inline int bitarray_findhighest(struct bitarray *this)
> +{
> +	if (!this->summary)
> +		return -1;
> +	else {
> +	    int word_index = __ffs(this->summary);
> +	    int bit_index  = __ffs(this->pending[word_index]);
> +
> +	    return word_index * BITS_PER_LONG + bit_index;	
> +	}
> +}
> +
> +static inline void bitarray_set(struct bitarray *this, int nr)
> +{
> +	__set_bit(nr, &this->pending);
> +	__set_bit(nr / BITS_PER_LONG, &this->summary); 
> +} 
> +
> +static inline void bitarray_clear(struct bitarray *this, int nr)
> +{
> +	int word = nr / BITS_PER_LONG;
> +
> +	__clear_bit(nr, &this->pending);
> +	if (!this->pending[word])
> +		__clear_bit(word, &this->summary);
> +}
> +
> +static inline int bitarray_test(struct bitarray *this, int nr)
> +{
> +	return test_bit(nr, &this->pending);
> +}

This should go into a separate header, probably even in include/linux/

> +/*----------------------------------------------------------------------
> + * userint interface - provides the actual kvm_irqdevice implementation
> + *---------------------------------------------------------------------*/
> +
> +typedef struct {
> +	spinlock_t      lock;
> +	struct bitarray irq_pending;
> +	int             nmi_pending;
> +}kvm_userint;

Please just use a struct type instead of the typedef.

> +int kvm_userint_init(struct kvm_irqdevice *dev)
> +{
> +	kvm_userint *s;
> +
> +	s = (kvm_userint *)kzalloc(sizeof(kvm_userint), GFP_KERNEL);

No need to case the kzalloc return value.  But you need to check
the return value for NULL and handle the error.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

  parent reply	other threads:[~2007-04-08  9:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-05 18:53 [PATCH] Add irqdevice interface + userint implementation Gregory Haskins
2007-04-05 21:38 ` Fwd: " Gregory Haskins
     [not found] ` <4614FF5C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-08  6:47   ` Avi Kivity
     [not found]     ` <46189005.2090609-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-09 18:36       ` Gregory Haskins
     [not found]         ` <461A415C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10  7:52           ` Avi Kivity
     [not found]             ` <461B4241.5030101-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 11:36               ` Gregory Haskins
     [not found]                 ` <461B3E61.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 12:01                   ` Avi Kivity
     [not found]                     ` <461B7C81.7040102-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 14:20                       ` Gregory Haskins
     [not found]                         ` <461B64E4.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 14:46                           ` Avi Kivity
     [not found]                             ` <461BA363.5080308-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 15:39                               ` Gregory Haskins
2007-04-10 15:53                                 ` Fwd: " Gregory Haskins
     [not found]                                   ` <461B7AC6.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 16:11                                     ` Avi Kivity
     [not found]                                       ` <461BB738.7040206-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 17:58                                         ` Gregory Haskins
     [not found]                                 ` <461B7755.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 16:08                                   ` Avi Kivity
2007-04-08  9:58   ` Christoph Hellwig [this message]
     [not found]     ` <20070408095853.GA31284-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2007-04-08 10:23       ` Avi Kivity
     [not found]         ` <4618C293.8030902-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-08 10:33           ` Christoph Hellwig
2007-04-09 14:53       ` Gregory Haskins
  -- strict thread matches above, loose matches on Subject: below --
2007-04-09 20:27 Gregory Haskins
     [not found] ` <461A5B6C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10  7:33   ` Avi Kivity
2007-04-10  8:23   ` Christoph Hellwig

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=20070408095853.GA31284@infradead.org \
    --to=hch-wegcikhe2lqwvfeawa7xhq@public.gmane.org \
    --cc=ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox