From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Oded Gabbay <ogabbay@kernel.org>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>,
Jeffrey Hugo <quic_jhugo@quicinc.com>,
Arnd Bergmann <arnd@arndb.de>,
Thomas Zimmermann <tzimmermann@suse.de>,
John Hubbard <jhubbard@nvidia.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Yuji Ishikawa <yuji2.ishikawa@toshiba.co.jp>,
Jagan Teki <jagan@amarulasolutions.com>,
Jason Gunthorpe <jgg@nvidia.com>, Jiho Chu <jiho.chu@samsung.com>,
Alex Deucher <alexander.deucher@amd.com>,
Christoph Hellwig <hch@infradead.org>,
Maciej Kwapulinski <maciej.kwapulinski@linux.intel.com>,
Kevin Hilman <khilman@baylibre.com>
Subject: Re: [RFC PATCH 2/3] drm: define new accel major and register it
Date: Sun, 23 Oct 2022 14:40:11 +0200 [thread overview]
Message-ID: <Y1U2K+fAnGbYug/+@kroah.com> (raw)
In-Reply-To: <20221022214622.18042-3-ogabbay@kernel.org>
On Sun, Oct 23, 2022 at 12:46:21AM +0300, Oded Gabbay wrote:
> The accelerator devices will be exposed to the user space with a new,
> dedicated major number - 261.
>
> The drm core registers the new major number as a char device and create
> corresponding sysfs and debugfs root entries, same as for the drm major.
>
> In case CONFIG_ACCEL is not selected, this code is not compiled in.
>
> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
> ---
> Documentation/admin-guide/devices.txt | 5 +++
> drivers/gpu/drm/drm_drv.c | 45 +++++++++++++++++++++++
> drivers/gpu/drm/drm_internal.h | 3 ++
> drivers/gpu/drm/drm_sysfs.c | 52 +++++++++++++++++++++++++++
> include/drm/drm_ioctl.h | 1 +
> 5 files changed, 106 insertions(+)
>
> diff --git a/Documentation/admin-guide/devices.txt b/Documentation/admin-guide/devices.txt
> index 9764d6edb189..06c525e01ea5 100644
> --- a/Documentation/admin-guide/devices.txt
> +++ b/Documentation/admin-guide/devices.txt
> @@ -3080,6 +3080,11 @@
> ...
> 255 = /dev/osd255 256th OSD Device
>
> + 261 char Compute Acceleration Devices
> + 0 = /dev/accel/accel0 First acceleration device
> + 1 = /dev/accel/accel1 Second acceleration device
> + ...
> +
> 384-511 char RESERVED FOR DYNAMIC ASSIGNMENT
> Character devices that request a dynamic allocation of major
> number will take numbers starting from 511 and downward,
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 8214a0b1ab7f..b58ffb1433d6 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -67,6 +67,10 @@ static bool drm_core_init_complete;
>
> static struct dentry *drm_debugfs_root;
>
> +#ifdef CONFIG_ACCEL
> +static struct dentry *accel_debugfs_root;
> +#endif
> +
> DEFINE_STATIC_SRCU(drm_unplug_srcu);
>
> /*
> @@ -1031,9 +1035,19 @@ static const struct file_operations drm_stub_fops = {
> .llseek = noop_llseek,
> };
>
> +static void accel_core_exit(void)
> +{
> +#ifdef CONFIG_ACCEL
> + unregister_chrdev(ACCEL_MAJOR, "accel");
> + debugfs_remove(accel_debugfs_root);
> + accel_sysfs_destroy();
> +#endif
> +}
Why is all of this in drm_drv.c?
Why not put it in drm/accel/accel.c or something like that? Then put
the proper stuff into a .h file and then you have no #ifdef in the .c
files.
Keeping #ifdef out of C files is key, please do not do things like you
have here. Especially as it ends up with this kind of mess:
> +static int __init accel_core_init(void)
> +{
> +#ifdef CONFIG_ACCEL
> + int ret;
> +
> + ret = accel_sysfs_init();
> + if (ret < 0) {
> + DRM_ERROR("Cannot create ACCEL class: %d\n", ret);
> + goto error;
> + }
> +
> + accel_debugfs_root = debugfs_create_dir("accel", NULL);
> +
> + ret = register_chrdev(ACCEL_MAJOR, "accel", &drm_stub_fops);
> + if (ret < 0)
> + goto error;
> +
> +error:
> + /* Any cleanup will be done in drm_core_exit() that will call
> + * to accel_core_exit()
> + */
> + return ret;
> +#else
> + return 0;
> +#endif
> +}
That's just a mess.
thanks,
greg k-h
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Oded Gabbay <ogabbay@kernel.org>
Cc: David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Jason Gunthorpe <jgg@nvidia.com>,
John Hubbard <jhubbard@nvidia.com>,
Alex Deucher <alexander.deucher@amd.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Yuji Ishikawa <yuji2.ishikawa@toshiba.co.jp>,
Jiho Chu <jiho.chu@samsung.com>,
Daniel Stone <daniel@fooishbar.org>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
Jeffrey Hugo <quic_jhugo@quicinc.com>,
Christoph Hellwig <hch@infradead.org>,
Kevin Hilman <khilman@baylibre.com>,
Jagan Teki <jagan@amarulasolutions.com>,
Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>,
Maciej Kwapulinski <maciej.kwapulinski@linux.intel.com>
Subject: Re: [RFC PATCH 2/3] drm: define new accel major and register it
Date: Sun, 23 Oct 2022 14:40:11 +0200 [thread overview]
Message-ID: <Y1U2K+fAnGbYug/+@kroah.com> (raw)
In-Reply-To: <20221022214622.18042-3-ogabbay@kernel.org>
On Sun, Oct 23, 2022 at 12:46:21AM +0300, Oded Gabbay wrote:
> The accelerator devices will be exposed to the user space with a new,
> dedicated major number - 261.
>
> The drm core registers the new major number as a char device and create
> corresponding sysfs and debugfs root entries, same as for the drm major.
>
> In case CONFIG_ACCEL is not selected, this code is not compiled in.
>
> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
> ---
> Documentation/admin-guide/devices.txt | 5 +++
> drivers/gpu/drm/drm_drv.c | 45 +++++++++++++++++++++++
> drivers/gpu/drm/drm_internal.h | 3 ++
> drivers/gpu/drm/drm_sysfs.c | 52 +++++++++++++++++++++++++++
> include/drm/drm_ioctl.h | 1 +
> 5 files changed, 106 insertions(+)
>
> diff --git a/Documentation/admin-guide/devices.txt b/Documentation/admin-guide/devices.txt
> index 9764d6edb189..06c525e01ea5 100644
> --- a/Documentation/admin-guide/devices.txt
> +++ b/Documentation/admin-guide/devices.txt
> @@ -3080,6 +3080,11 @@
> ...
> 255 = /dev/osd255 256th OSD Device
>
> + 261 char Compute Acceleration Devices
> + 0 = /dev/accel/accel0 First acceleration device
> + 1 = /dev/accel/accel1 Second acceleration device
> + ...
> +
> 384-511 char RESERVED FOR DYNAMIC ASSIGNMENT
> Character devices that request a dynamic allocation of major
> number will take numbers starting from 511 and downward,
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 8214a0b1ab7f..b58ffb1433d6 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -67,6 +67,10 @@ static bool drm_core_init_complete;
>
> static struct dentry *drm_debugfs_root;
>
> +#ifdef CONFIG_ACCEL
> +static struct dentry *accel_debugfs_root;
> +#endif
> +
> DEFINE_STATIC_SRCU(drm_unplug_srcu);
>
> /*
> @@ -1031,9 +1035,19 @@ static const struct file_operations drm_stub_fops = {
> .llseek = noop_llseek,
> };
>
> +static void accel_core_exit(void)
> +{
> +#ifdef CONFIG_ACCEL
> + unregister_chrdev(ACCEL_MAJOR, "accel");
> + debugfs_remove(accel_debugfs_root);
> + accel_sysfs_destroy();
> +#endif
> +}
Why is all of this in drm_drv.c?
Why not put it in drm/accel/accel.c or something like that? Then put
the proper stuff into a .h file and then you have no #ifdef in the .c
files.
Keeping #ifdef out of C files is key, please do not do things like you
have here. Especially as it ends up with this kind of mess:
> +static int __init accel_core_init(void)
> +{
> +#ifdef CONFIG_ACCEL
> + int ret;
> +
> + ret = accel_sysfs_init();
> + if (ret < 0) {
> + DRM_ERROR("Cannot create ACCEL class: %d\n", ret);
> + goto error;
> + }
> +
> + accel_debugfs_root = debugfs_create_dir("accel", NULL);
> +
> + ret = register_chrdev(ACCEL_MAJOR, "accel", &drm_stub_fops);
> + if (ret < 0)
> + goto error;
> +
> +error:
> + /* Any cleanup will be done in drm_core_exit() that will call
> + * to accel_core_exit()
> + */
> + return ret;
> +#else
> + return 0;
> +#endif
> +}
That's just a mess.
thanks,
greg k-h
next prev parent reply other threads:[~2022-10-23 12:40 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-22 21:46 [RFC PATCH 0/3] new subsystem for compute accelerator devices Oded Gabbay
2022-10-22 21:46 ` Oded Gabbay
2022-10-22 21:46 ` [RFC PATCH 1/3] drivers/accel: add new kconfig and update MAINTAINERS Oded Gabbay
2022-10-22 21:46 ` Oded Gabbay
2022-10-23 12:40 ` Greg Kroah-Hartman
2022-10-23 12:40 ` Greg Kroah-Hartman
2022-10-24 7:19 ` Oded Gabbay
2022-10-24 7:19 ` Oded Gabbay
2022-10-24 15:01 ` Jeffrey Hugo
2022-10-24 15:01 ` Jeffrey Hugo
2022-10-22 21:46 ` [RFC PATCH 2/3] drm: define new accel major and register it Oded Gabbay
2022-10-22 21:46 ` Oded Gabbay
2022-10-23 12:40 ` Greg Kroah-Hartman [this message]
2022-10-23 12:40 ` Greg Kroah-Hartman
2022-10-24 7:23 ` Oded Gabbay
2022-10-24 7:23 ` Oded Gabbay
2022-10-24 7:52 ` Dave Airlie
2022-10-24 7:52 ` Dave Airlie
2022-10-24 15:08 ` Jeffrey Hugo
2022-10-24 15:08 ` Jeffrey Hugo
2022-10-22 21:46 ` [RFC PATCH 3/3] drm: add dedicated minor for accelerator devices Oded Gabbay
2022-10-22 21:46 ` Oded Gabbay
2022-10-23 12:41 ` Greg Kroah-Hartman
2022-10-23 12:41 ` Greg Kroah-Hartman
2022-10-24 7:23 ` Oded Gabbay
2022-10-24 7:23 ` Oded Gabbay
2022-10-24 15:21 ` Jeffrey Hugo
2022-10-24 15:21 ` Jeffrey Hugo
2022-10-24 17:43 ` Oded Gabbay
2022-10-24 17:43 ` Oded Gabbay
2022-10-25 13:26 ` Michał Winiarski
2022-10-25 13:26 ` Michał Winiarski
2022-10-26 6:38 ` Oded Gabbay
2022-10-26 6:38 ` Oded Gabbay
2022-10-25 6:43 ` Jiho Chu
2022-10-25 6:43 ` Jiho Chu
2022-10-26 6:38 ` Oded Gabbay
2022-10-26 6:38 ` Oded Gabbay
2022-10-28 6:56 ` Jiho Chu
2022-10-28 6:56 ` Jiho Chu
2022-10-23 14:02 ` [RFC PATCH 0/3] new subsystem for compute " Bagas Sanjaya
2022-10-23 14:02 ` Bagas Sanjaya
2022-10-23 14:14 ` Greg Kroah-Hartman
2022-10-23 14:14 ` Greg Kroah-Hartman
2022-10-24 11:55 ` Thomas Zimmermann
2022-10-24 11:55 ` Thomas Zimmermann
2022-10-24 12:35 ` Greg Kroah-Hartman
2022-10-24 12:35 ` Greg Kroah-Hartman
2022-10-24 12:43 ` Oded Gabbay
2022-10-24 12:43 ` Oded Gabbay
2022-10-25 2:21 ` John Hubbard
2022-10-25 2:21 ` John Hubbard
2022-10-25 2:27 ` Dave Airlie
2022-10-25 2:27 ` Dave Airlie
2022-10-25 11:15 ` Jason Gunthorpe
2022-10-25 11:15 ` Jason Gunthorpe
2022-10-25 14:21 ` Alex Deucher
2022-10-25 14:21 ` Alex Deucher
2022-10-25 14:34 ` Jason Gunthorpe
2022-10-25 14:34 ` Jason Gunthorpe
2022-10-25 14:43 ` Alex Deucher
2022-10-25 14:43 ` Alex Deucher
2022-10-24 13:55 ` Alex Deucher
2022-10-24 13:55 ` Alex Deucher
2022-10-24 14:41 ` Oded Gabbay
2022-10-24 14:41 ` Oded Gabbay
2022-10-24 15:10 ` Alex Deucher
2022-10-24 15:10 ` Alex Deucher
2022-10-26 6:10 ` Oded Gabbay
2022-10-26 6:10 ` Oded Gabbay
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=Y1U2K+fAnGbYug/+@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=alexander.deucher@amd.com \
--cc=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@infradead.org \
--cc=jacek.lawrynowicz@linux.intel.com \
--cc=jagan@amarulasolutions.com \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=jiho.chu@samsung.com \
--cc=khilman@baylibre.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.kwapulinski@linux.intel.com \
--cc=ogabbay@kernel.org \
--cc=quic_jhugo@quicinc.com \
--cc=tvrtko.ursulin@linux.intel.com \
--cc=tzimmermann@suse.de \
--cc=yuji2.ishikawa@toshiba.co.jp \
/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.