All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zhangfei Gao <zhangfei.gao@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	linux-accelerators@lists.ozlabs.org,
	linux-kernel@vger.kernel.org,
	Kenneth Lee <liguozhu@hisilicon.com>,
	Zaibo Xu <xuzaibo@huawei.com>,
	Zhou Wang <wangzhou1@hisilicon.com>
Subject: Re: [PATCH 2/2] uacce: add uacce module
Date: Thu, 15 Aug 2019 16:20:21 +0200	[thread overview]
Message-ID: <20190815142021.GE23267@kroah.com> (raw)
In-Reply-To: <1565775265-21212-3-git-send-email-zhangfei.gao@linaro.org>

On Wed, Aug 14, 2019 at 05:34:25PM +0800, Zhangfei Gao wrote:
> +/* lock to protect all queues management */
> +static DECLARE_RWSEM(uacce_qs_lock);
> +#define uacce_qs_rlock() down_read(&uacce_qs_lock)
> +#define uacce_qs_runlock() up_read(&uacce_qs_lock)
> +#define uacce_qs_wlock() down_write(&uacce_qs_lock)
> +#define uacce_qs_wunlock() up_write(&uacce_qs_lock)

Do not define your own locking macros.  That makes the code impossible
to review.

And are you _sure_ you need a rw lock?  You have benchmarked where it
has a performance impact?

> +/**
> + * uacce_wake_up - Wake up the process who is waiting this queue
> + * @q the accelerator queue to wake up
> + */
> +void uacce_wake_up(struct uacce_queue *q)
> +{
> +	dev_dbg(&q->uacce->dev, "wake up\n");

ftrace is your friend, no need for any such logging lines anywhere in
these files.

> +	wake_up_interruptible(&q->wait);
> +}
> +EXPORT_SYMBOL_GPL(uacce_wake_up);

...

> +static struct attribute *uacce_dev_attrs[] = {
> +	&dev_attr_id.attr,
> +	&dev_attr_api.attr,
> +	&dev_attr_node_id.attr,
> +	&dev_attr_numa_distance.attr,
> +	&dev_attr_flags.attr,
> +	&dev_attr_available_instances.attr,
> +	&dev_attr_algorithms.attr,
> +	&dev_attr_qfrs_offset.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group uacce_dev_attr_group = {
> +	.name	= UACCE_DEV_ATTRS,
> +	.attrs	= uacce_dev_attrs,
> +};

Why is your attribute group in a subdirectory?  Why not in the "normal"
class directory?

You are adding sysfs files to the kernel without any Documentation/ABI/
entries, which is a requirement.  Please fix that up for the next time
you send these.

> +static const struct attribute_group *uacce_dev_attr_groups[] = {
> +	&uacce_dev_attr_group,
> +	NULL
> +};
> +
> +static int uacce_create_chrdev(struct uacce *uacce)
> +{
> +	int ret;
> +
> +	ret = idr_alloc(&uacce_idr, uacce, 0, 0, GFP_KERNEL);
> +	if (ret < 0)
> +		return ret;
> +

Shouldn't this function create the memory needed for this structure?
You are relying ont he caller to do it for you, why?


> +	cdev_init(&uacce->cdev, &uacce_fops);
> +	uacce->dev_id = ret;
> +	uacce->cdev.owner = THIS_MODULE;
> +	device_initialize(&uacce->dev);
> +	uacce->dev.devt = MKDEV(MAJOR(uacce_devt), uacce->dev_id);
> +	uacce->dev.class = uacce_class;
> +	uacce->dev.groups = uacce_dev_attr_groups;
> +	uacce->dev.parent = uacce->pdev;
> +	dev_set_name(&uacce->dev, "%s-%d", uacce->drv_name, uacce->dev_id);
> +	ret = cdev_device_add(&uacce->cdev, &uacce->dev);
> +	if (ret)
> +		goto err_with_idr;
> +
> +	dev_dbg(&uacce->dev, "create uacce minior=%d\n", uacce->dev_id);
> +	return 0;
> +
> +err_with_idr:
> +	idr_remove(&uacce_idr, uacce->dev_id);
> +	return ret;
> +}
> +
> +static void uacce_destroy_chrdev(struct uacce *uacce)
> +{
> +	cdev_device_del(&uacce->cdev, &uacce->dev);
> +	idr_remove(&uacce_idr, uacce->dev_id);
> +}
> +
> +static int uacce_default_get_available_instances(struct uacce *uacce)
> +{
> +	return -1;

Do not make up error values, use the proper -EXXXX value instead.

> +}
> +
> +static int uacce_default_start_queue(struct uacce_queue *q)
> +{
> +	dev_dbg(&q->uacce->dev, "fake start queue");
> +	return 0;

Why even have this function if you do not do anything in it?

> +}
> +
> +static int uacce_dev_match(struct device *dev, void *data)
> +{
> +	if (dev->parent == data)
> +		return -EBUSY;

There should be in-kernel functions for this now, no need for you to
roll your own.

thanks,

greg k-h

  parent reply	other threads:[~2019-08-15 14:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-14  9:34 [PATCH 0/2] A General Accelerator Framework, WarpDrive Zhangfei Gao
2019-08-14  9:34 ` [PATCH 1/2] uacce: Add documents for WarpDrive/uacce Zhangfei Gao
2019-08-14  9:34 ` [PATCH 2/2] uacce: add uacce module Zhangfei Gao
2019-08-15 14:12   ` Greg Kroah-Hartman
     [not found]     ` <5d5a6757.1c69fb81.e0678.2ab2SMTPIN_ADDED_BROKEN@mx.google.com>
2019-08-19 10:22       ` Greg Kroah-Hartman
2019-08-20 12:38         ` zhangfei
2019-08-20 14:31           ` Greg Kroah-Hartman
2019-08-15 14:13   ` Greg Kroah-Hartman
2019-08-20 13:08     ` zhangfei
2019-08-20 16:59       ` Greg Kroah-Hartman
     [not found]         ` <5d5cf0fc.1c69fb81.ec57f.b853SMTPIN_ADDED_BROKEN@mx.google.com>
2019-08-21  9:17           ` Greg Kroah-Hartman
2019-08-21 14:30             ` zhangfei
2019-08-21 16:05               ` Greg Kroah-Hartman
2019-08-26  4:10                 ` Kenneth Lee
2019-08-26  4:29                   ` Greg Kroah-Hartman
2019-08-27 11:42                     ` Kenneth Lee
2019-08-27 18:48                       ` Greg Kroah-Hartman
2019-08-15 14:20   ` Greg Kroah-Hartman [this message]
     [not found]     ` <5d5a6f5b.1c69fb81.9d35e.5303SMTPIN_ADDED_BROKEN@mx.google.com>
2019-08-19 10:24       ` Greg Kroah-Hartman
2019-08-20 12:36         ` zhangfei
2019-08-20 14:33           ` Greg Kroah-Hartman
2019-08-24 12:53             ` zhangfei
2019-08-24 15:40               ` Greg Kroah-Hartman
2019-08-15 16:54   ` Jonathan Cameron
2019-08-23  9:21     ` zhangfei
2019-08-23 16:36       ` Jonathan Cameron
2019-08-23 16:42       ` Jonathan Cameron
2019-08-15 17:04 ` [PATCH 0/2] A General Accelerator Framework, WarpDrive Jerome Glisse
2019-08-20 14:26   ` zhangfei
2019-08-26  4:14   ` Kenneth Lee

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=20190815142021.GE23267@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=liguozhu@hisilicon.com \
    --cc=linux-accelerators@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wangzhou1@hisilicon.com \
    --cc=xuzaibo@huawei.com \
    --cc=zhangfei.gao@linaro.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.