linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Michael Ira Krufky <mkrufky@linuxtv.org>
Cc: "Linux Media Mailing List" <linux-media@vger.kernel.org>,
	"Mauro Carvalho Chehab" <mchehab@infradead.org>,
	"Max Kellermann" <max.kellermann@gmail.com>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	"Буди Романто, AreMa Inc" <knightrider@are.ma>
Subject: Re: [PATCH 03/25] media: dvbdev: convert DVB device types into an enum
Date: Thu, 21 Sep 2017 12:38:36 -0300	[thread overview]
Message-ID: <20170921123836.5f4804af@recife.lan> (raw)
In-Reply-To: <CAOcJUbyoW9D8cyngc1VFpLLwOCPPqpzfhYEZ3n+nYyaLux4Hug@mail.gmail.com>

Em Thu, 21 Sep 2017 09:06:54 -0400
Michael Ira Krufky <mkrufky@linuxtv.org> escreveu:

> On Wed, Sep 20, 2017 at 3:11 PM, Mauro Carvalho Chehab
> <mchehab@s-opensource.com> wrote:

> > +enum dvb_device_type {
> > +       DVB_DEVICE_SEC,
> > +       DVB_DEVICE_FRONTEND,
> > +       DVB_DEVICE_DEMUX,
> > +       DVB_DEVICE_DVR,
> > +       DVB_DEVICE_CA,
> > +       DVB_DEVICE_NET,
> > +
> > +       DVB_DEVICE_VIDEO,
> > +       DVB_DEVICE_AUDIO,
> > +       DVB_DEVICE_OSD,
> > +};  
> 
> maybe instead:
> ```
> enum dvb_device_type {
>  DVB_DEVICE_SEC      = 0,
>  DVB_DEVICE_FRONTEND = 1,
>  DVB_DEVICE_DEMUX    = 2,
>  DVB_DEVICE_DVR      = 3,
>  DVB_DEVICE_CA       = 4,
>  DVB_DEVICE_NET      = 5,
> 
>  DVB_DEVICE_VIDEO    = 6,
>  DVB_DEVICE_AUDIO    = 7,
>  DVB_DEVICE_OSD      = 8,
> };
> ```
> 
> ...and then maybe `nums2minor()` can be optimized to take advantage of
> that assignment.

That will break userspace :-) The DVB minor ranges are
(from Documentation/drivers.txt):

 212 char	LinuxTV.org DVB driver subsystem
		  0 = /dev/dvb/adapter0/video0    first video decoder of first c
ard
		  1 = /dev/dvb/adapter0/audio0    first audio decoder of first c
ard
		  2 = /dev/dvb/adapter0/sec0      (obsolete/unused)
		  3 = /dev/dvb/adapter0/frontend0 first frontend device of first
 card
		  4 = /dev/dvb/adapter0/demux0    first demux device of first ca
rd
		  5 = /dev/dvb/adapter0/dvr0      first digital video recoder de
vice of first card
		  6 = /dev/dvb/adapter0/ca0       first common access port of fi
rst card
		  7 = /dev/dvb/adapter0/net0      first network device of first 
card
		  8 = /dev/dvb/adapter0/osd0      first on-screen-display device
 of first card

Btw, the main reason to add a switch at nums2minor() is due to that:
it requires an specific number for each device type, and it is very easy
to forget about that when looking at the implementation.

As some day we may get rid of video/audio/osd types, it sounded worth to 
add an extra code. Please notice, however, that nums2minor only exists
if !CONFIG_DVB_DYNAMIC_MINORS.

I suspect that, except for some embedded devices, the default is
to have it enabled everywhere.

Yet, after revisiting it and checking the generated assembly code,
I guess we could fold the enclosed patch, in order to simplify the
static minor support of the DVB core:


--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -68,22 +68,20 @@ static const char * const dnames[] = {
 #else
 #define DVB_MAX_IDS            4
 
-static int nums2minor(int num, enum dvb_device_type type, int id)
-{
-       int n = (num << 6) | (id << 4);
+static const u8 minor_type[] = {
+       [DVB_DEVICE_VIDEO]      = 0,
+       [DVB_DEVICE_AUDIO]      = 1,
+       [DVB_DEVICE_SEC]        = 2,
+       [DVB_DEVICE_FRONTEND]   = 3,
+       [DVB_DEVICE_DEMUX]      = 4,
+       [DVB_DEVICE_DVR]        = 5,
+       [DVB_DEVICE_CA]         = 6,
+       [DVB_DEVICE_NET]        = 7,
+       [DVB_DEVICE_OSD]        = 8,
+};
 
-       switch (type) {
-       case DVB_DEVICE_VIDEO:          return n;
-       case DVB_DEVICE_AUDIO:          return n | 1;
-       case DVB_DEVICE_SEC:            return n | 2;
-       case DVB_DEVICE_FRONTEND:       return n | 3;
-       case DVB_DEVICE_DEMUX:          return n | 4;
-       case DVB_DEVICE_DVR:            return n | 5;
-       case DVB_DEVICE_CA:             return n | 6;
-       case DVB_DEVICE_NET:            return n | 7;
-       case DVB_DEVICE_OSD:            return n | 8;
-       }
-}
+#define nums2minor(num, type, id) \
+       (((num) << 6) | ((id) << 4) | minor_type[type])
 
 #define MAX_DVB_MINORS         (DVB_MAX_ADAPTERS*64)
 #endif

With the above change, it seems that the code is likely only a few bytes
longer than the original code, and make it clearer about the
static minor numbering requirements.

The generated i386 asm code at the read only data segment is:

minor_type:
	.byte	2
	.byte	3
	.byte	4
	.byte	5
	.byte	6
	.byte	7
	.byte	0
	.byte	1
	.byte	8

And at the code segment:

# drivers/media/dvb-core/dvbdev.c:511: 	minor = nums2minor(adap->num, type, id);
	.loc 1 511 0
	movl	-20(%ebp), %eax	# %sfp, adap
.LVL295:
	movl	(%eax), %eax	# adap_29(D)->num, adap_29(D)->num
.LVL296:
	movl	%eax, -24(%ebp)	# adap_29(D)->num, %sfp
	movl	%eax, %edx	# adap_29(D)->num, adap_29(D)->num
	movl	12(%ebp), %eax	# type, tmp265
	sall	$6, %edx	#, adap_29(D)->num
	movzbl	minor_type(%eax), %eax	# minor_type, tmp193
	orl	%eax, %edx	# tmp193, tmp194
	movl	-16(%ebp), %eax	# %sfp, tmp195
	movl	%edx, %edi	# tmp194, tmp194
	sall	$4, %eax	#, tmp195
	orl	%eax, %edi	# tmp195, tmp194

That seems good enough on my eyes.

Thanks,
Mauro

  reply	other threads:[~2017-09-21 15:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-20 19:11 [PATCH 00/25] DVB cleanups and documentation improvements Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 01/25] media: dvb_frontend: better document the -EPERM condition Mauro Carvalho Chehab
2017-09-20 21:29   ` Shuah Khan
2017-09-20 19:11 ` [PATCH 02/25] media: dvb_frontend: fix return values for FE_SET_PROPERTY Mauro Carvalho Chehab
2017-09-21 14:19   ` Shuah Khan
2017-09-20 19:11 ` [PATCH 03/25] media: dvbdev: convert DVB device types into an enum Mauro Carvalho Chehab
2017-09-21 13:06   ` Michael Ira Krufky
2017-09-21 15:38     ` Mauro Carvalho Chehab [this message]
2017-09-20 19:11 ` [PATCH 04/25] media: dvbdev: fully document its functions Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 05/25] media: dvb_frontend.h: improve kernel-doc markups Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 06/25] media: dtv-core.rst: add chapters and introductory tests for common parts Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 07/25] media: dtv-core.rst: split into multiple files Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 08/25] media: dtv-demux.rst: minor markup improvements Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 09/25] media: dvb_demux.h: add an enum for DMX_TYPE_* and document Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 10/25] media: dvb_demux.h: add an enum for DMX_STATE_* " Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 11/25] media: dvb_demux.h: get rid of unused timer at struct dvb_demux_filter Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 12/25] media: dvb_demux: mark a boolean field as such Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 13/25] media: dvb_demux: dvb_demux_feed.pusi_seen is boolean Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 14/25] media: dvb_demux.h: get rid of DMX_FEED_ENTRY() macro Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 15/25] media: dvb_demux: fix type of dvb_demux_feed.ts_type Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 16/25] media: dvb_demux: document dvb_demux_filter and dvb_demux_feed Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 17/25] media: dvb_frontend: dtv_property_process_set() cleanups Mauro Carvalho Chehab
2017-09-21 14:32   ` Shuah Khan
2017-09-21 16:00     ` Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 18/25] media: dvb_frontend: get rid of dtv_get_property_dump() Mauro Carvalho Chehab
2017-09-21 14:52   ` Shuah Khan
2017-09-20 19:11 ` [PATCH 19/25] media: dvb_demux.h: document structs defined on it Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 20/25] media: dvb_demux.h: document functions Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 21/25] scripts: kernel-doc: fix nexted handling Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 22/25] media: dmxdev.h: add kernel-doc markups for data types and functions Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 23/25] media: dtv-demux.rst: parse other demux headers with kernel-doc Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 24/25] media: dvb-net.rst: document DVB network kAPI interface Mauro Carvalho Chehab
2017-09-20 19:11 ` [PATCH 25/25] media: dvb uAPI docs: get rid of examples section Mauro Carvalho Chehab

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=20170921123836.5f4804af@recife.lan \
    --to=mchehab@s-opensource.com \
    --cc=knightrider@are.ma \
    --cc=linux-media@vger.kernel.org \
    --cc=max.kellermann@gmail.com \
    --cc=mchehab@infradead.org \
    --cc=mkrufky@linuxtv.org \
    --cc=sakari.ailus@linux.intel.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).