Skip to contentSkip to conversation

ASoC: core: Convert single bit wide bitfields into bools

PATCH In review Mark Brown 2 participants 5 messages Feb 8, 2012

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 ASoC: core: Convert single bit wide bitfields into bools

It's what they are, we've just been using these for historical reasons.

---
 include/sound/soc-dai.h  |   12 ++++++------
 include/sound/soc-dapm.h |   26 +++++++++++++-------------
 include/sound/soc.h      |   32 ++++++++++++++++----------------
 3 files changed, 35 insertions(+), 35 deletions(-)
include/sound/soc-dai.h +6 -6
index 1a2b08c..53f9a1f 100644
@@ -208,7 +208,7 @@ struct snd_soc_dai_driver {
 	/* DAI capabilities */
 	struct snd_soc_pcm_stream capture;
 	struct snd_soc_pcm_stream playback;
-	unsigned int symmetric_rates:1;
+	bool symmetric_rates;
 
 	/* probe ordering - for components with runtime dependencies */
 	int probe_order;
@@ -230,13 +230,13 @@ struct snd_soc_dai {
 	struct snd_soc_dai_driver *driver;
 
 	/* DAI runtime info */
-	unsigned int capture_active:1;		/* stream is in use */
-	unsigned int playback_active:1;		/* stream is in use */
-	unsigned int symmetric_rates:1;
+	bool capture_active;		/* stream is in use */
+	bool playback_active;		/* stream is in use */
+	bool symmetric_rates;
 	struct snd_pcm_runtime *runtime;
 	unsigned int active;
-	unsigned char pop_wait:1;
-	unsigned char probed:1;
+	bool pop_wait;
+	bool probed;
 
 	/* DAI DMA data */
 	void *playback_dma_data;
include/sound/soc-dapm.h +13 -13
index db8435a..99661c0 100644
@@ -456,9 +456,9 @@ struct snd_soc_dapm_path {
 	struct snd_kcontrol *kcontrol;
 
 	/* status */
-	u32 connect:1;	/* source and sink widgets are connected */
-	u32 walked:1;	/* path has been walked */
-	u32 weak:1;	/* path ignored for power management */
+	bool connect;	/* source and sink widgets are connected */
+	bool walked;	/* path has been walked */
+	bool weak;	/* path ignored for power management */
 
 	int (*connected)(struct snd_soc_dapm_widget *source,
 			 struct snd_soc_dapm_widget *sink);
@@ -488,16 +488,16 @@ struct snd_soc_dapm_widget {
 	unsigned int mask;			/* non-shifted mask */
 	unsigned int on_val;			/* on state value */
 	unsigned int off_val;			/* off state value */
-	unsigned char power:1;			/* block power status */
-	unsigned char invert:1;			/* invert the power bit */
-	unsigned char active:1;			/* active stream on DAC, ADC's */
-	unsigned char connected:1;		/* connected codec pin */
-	unsigned char new:1;			/* cnew complete */
-	unsigned char ext:1;			/* has external widgets */
-	unsigned char force:1;			/* force state */
-	unsigned char ignore_suspend:1;         /* kept enabled over suspend */
-	unsigned char new_power:1;		/* power from this run */
-	unsigned char power_checked:1;		/* power checked this run */
+	bool power;				/* block power status */
+	bool invert;				/* invert the power bit */
+	bool active;				/* active stream on DAC, ADC's */
+	bool connected;				/* connected codec pin */
+	bool new;				/* cnew complete */
+	bool ext;				/* has external widgets */
+	bool force;				/* force state */
+	bool ignore_suspend;		        /* kept enabled over suspend */
+	bool new_power;				/* power from this run */
+	bool power_checked;			/* power checked this run */
 	int subseq;				/* sort within widget type */
 
 	int (*power_check)(struct snd_soc_dapm_widget *w);
include/sound/soc.h +16 -16
index d1e7a6a..466b1f3 100644
@@ -571,14 +571,14 @@ struct snd_soc_codec {
 	/* runtime */
 	struct snd_ac97 *ac97;  /* for ad-hoc ac97 devices */
 	unsigned int active;
-	unsigned int cache_bypass:1; /* Suppress access to the cache */
-	unsigned int suspended:1; /* Codec is in suspend PM state */
-	unsigned int probed:1; /* Codec has been probed */
-	unsigned int ac97_registered:1; /* Codec has been AC97 registered */
-	unsigned int ac97_created:1; /* Codec has been created by SoC */
-	unsigned int sysfs_registered:1; /* codec has been sysfs registered */
-	unsigned int cache_init:1; /* codec cache has been initialized */
-	unsigned int using_regmap:1; /* using regmap access */
+	bool cache_bypass; /* Suppress access to the cache */
+	bool suspended; /* Codec is in suspend PM state */
+	bool probed; /* Codec has been probed */
+	bool ac97_registered; /* Codec has been AC97 registered */
+	bool ac97_created; /* Codec has been created by SoC */
+	bool sysfs_registered; /* codec has been sysfs registered */
+	bool cache_init; /* codec cache has been initialized */
+	bool using_regmap; /* using regmap access */
 	u32 cache_only;  /* Suppress writes to hardware */
 	u32 cache_sync; /* Cache needs to be synced to hardware */
 
@@ -598,7 +598,7 @@ struct snd_soc_codec {
 
 	/* dapm */
 	struct snd_soc_dapm_context dapm;
-	unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
+	bool ignore_pmdown_time; /* pmdown_time is ignored at stop */
 
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_codec_root;
@@ -712,8 +712,8 @@ struct snd_soc_platform {
 	struct device *dev;
 	struct snd_soc_platform_driver *driver;
 
-	unsigned int suspended:1; /* platform is suspended */
-	unsigned int probed:1;
+	bool suspended; /* platform is suspended */
+	bool probed;
 
 	struct snd_soc_card *card;
 	struct list_head list;
@@ -737,13 +737,13 @@ struct snd_soc_dai_link {
 	unsigned int dai_fmt;           /* format to set on init */
 
 	/* Keep DAI active over suspend */
-	unsigned int ignore_suspend:1;
+	bool ignore_suspend;
 
 	/* Symmetry requirements */
-	unsigned int symmetric_rates:1;
+	bool symmetric_rates;
 
 	/* pmdown_time is ignored at stop */
-	unsigned int ignore_pmdown_time:1;
+	bool ignore_pmdown_time;
 
 	/* codec/machine specific init - e.g. add machine controls */
 	int (*init)(struct snd_soc_pcm_runtime *rtd);
@@ -876,8 +876,8 @@ struct snd_soc_pcm_runtime {
 	enum snd_soc_pcm_subclass pcm_subclass;
 	struct snd_pcm_ops ops;
 
-	unsigned int complete:1;
-	unsigned int dev_registered:1;
+	bool complete;
+	bool dev_registered;
 
 	long pmdown_time;
 
Signature · 1 line
1.7.9.rc1
#1 lore raw

Aren't you increasing the size of some of these structs considerably?

Quoted 167 lines · Mark Brown

It's what they are, we've just been using these for historical reasons.

---
 include/sound/soc-dai.h  |   12 ++++++------ include/sound/soc-dapm.h |   26 +++++++++++++------------- include/sound/soc.h      |   32 ++++++++++++++++----------------

 3 files changed, 35 insertions(+), 35 deletions(-)
include/sound/soc-dai.h +6 -6
index 1a2b08c..53f9a1f 100644
@@ -208,7 +208,7 @@ struct snd_soc_dai_driver {
        /* DAI capabilities */
        struct snd_soc_pcm_stream capture;
        struct snd_soc_pcm_stream playback;
-       unsigned int symmetric_rates:1;
+       bool symmetric_rates;
 
        /* probe ordering - for components with runtime dependencies */
        int probe_order;
@@ -230,13 +230,13 @@ struct snd_soc_dai {
        struct snd_soc_dai_driver *driver;
 
        /* DAI runtime info */
-       unsigned int capture_active:1;          /* stream is in use */
-       unsigned int playback_active:1;         /* stream is in use */
-       unsigned int symmetric_rates:1;
+       bool capture_active;            /* stream is in use */
+       bool playback_active;           /* stream is in use */
+       bool symmetric_rates;
        struct snd_pcm_runtime *runtime;
        unsigned int active;
-       unsigned char pop_wait:1;
-       unsigned char probed:1;
+       bool pop_wait;
+       bool probed;
 
        /* DAI DMA data */
        void *playback_dma_data;
include/sound/soc-dapm.h +3 -3
index db8435a..99661c0 100644
@@ -456,9 +456,9 @@ struct snd_soc_dapm_path {
        struct snd_kcontrol *kcontrol;
 
        /* status */
-       u32 connect:1;  /* source and sink widgets are connected */
-       u32 walked:1;   /* path has been walked */
-       u32 weak:1;     /* path ignored for power management */
+       bool connect;   /* source and sink widgets are connected */
+       bool walked;    /* path has been walked */
+       bool weak;      /* path ignored for power management */
 
        int (*connected)(struct snd_soc_dapm_widget *source,
                         struct snd_soc_dapm_widget *sink);
@@ -488,16 +488,16 @@ struct snd_soc_dapm_widget {

       unsigned int mask;                      /* non-shifted mask */ unsigned int on_val;                    /* on state value */ unsigned int off_val;                   /* off state value */
-       unsigned char power:1;                  /* block power status */
-       unsigned char invert:1;                 /* invert the power bit */
-       unsigned char active:1;                 /* active stream on DAC, ADC's */
-       unsigned char connected:1;              /* connected codec pin */
-       unsigned char new:1;                    /* cnew complete */
-       unsigned char ext:1;                    /* has external widgets */
-       unsigned char force:1;                  /* force state */
-       unsigned char ignore_suspend:1;         /* kept enabled over suspend */
-       unsigned char new_power:1;              /* power from this run */
-       unsigned char power_checked:1;          /* power checked this run */
+       bool power;                             /* block power status */
+       bool invert;                            /* invert the power bit */
+       bool active;                            /* active stream on DAC, ADC's */
+       bool connected;                         /* connected codec pin */
+       bool new;                               /* cnew complete */
+       bool ext;                               /* has external widgets */
+       bool force;                             /* force state */
+       bool ignore_suspend;                    /* kept enabled over suspend */
+       bool new_power;                         /* power from this run */
+       bool power_checked;                     /* power checked this run */ int subseq;                             /* sort within widget type */

       int (*power_check)(struct snd_soc_dapm_widget *w);

include/sound/soc.h +0 -0
index d1e7a6a..466b1f3 100644
@@ -571,14 +571,14 @@ struct snd_soc_codec {
        /* runtime */

       struct snd_ac97 *ac97;  /* for ad-hoc ac97 devices */ unsigned int active;
-       unsigned int cache_bypass:1; /* Suppress access to the cache */
-       unsigned int suspended:1; /* Codec is in suspend PM state */
-       unsigned int probed:1; /* Codec has been probed */
-       unsigned int ac97_registered:1; /* Codec has been AC97 registered */
-       unsigned int ac97_created:1; /* Codec has been created by SoC */
-       unsigned int sysfs_registered:1; /* codec has been sysfs registered */
-       unsigned int cache_init:1; /* codec cache has been initialized */
-       unsigned int using_regmap:1; /* using regmap access */
+       bool cache_bypass; /* Suppress access to the cache */
+       bool suspended; /* Codec is in suspend PM state */
+       bool probed; /* Codec has been probed */
+       bool ac97_registered; /* Codec has been AC97 registered */
+       bool ac97_created; /* Codec has been created by SoC */
+       bool sysfs_registered; /* codec has been sysfs registered */
+       bool cache_init; /* codec cache has been initialized */
+       bool using_regmap; /* using regmap access */
       u32 cache_only;  /* Suppress writes to hardware */
       u32 cache_sync; /* Cache needs to be synced to hardware */

include/sound/soc.h +3 -3
@@ -598,7 +598,7 @@ struct snd_soc_codec {
 
        /* dapm */
        struct snd_soc_dapm_context dapm;
-       unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
+       bool ignore_pmdown_time; /* pmdown_time is ignored at stop */
 
  #ifdef CONFIG_DEBUG_FS
        struct dentry *debugfs_codec_root;
@@ -712,8 +712,8 @@ struct snd_soc_platform {
        struct device *dev;
        struct snd_soc_platform_driver *driver;
 
-       unsigned int suspended:1; /* platform is suspended */
-       unsigned int probed:1;
+       bool suspended; /* platform is suspended */
+       bool probed;
 
        struct snd_soc_card *card;
        struct list_head list;
@@ -737,13 +737,13 @@ struct snd_soc_dai_link {

       unsigned int dai_fmt;           /* format to set on init */

       /* Keep DAI active over suspend */
-       unsigned int ignore_suspend:1;
+       bool ignore_suspend;

       /* Symmetry requirements */
-       unsigned int symmetric_rates:1;
+       bool symmetric_rates;

       /* pmdown_time is ignored at stop */
-       unsigned int ignore_pmdown_time:1;
+       bool ignore_pmdown_time;

       /* codec/machine specific init - e.g. add machine controls */ int (*init)(struct snd_soc_pcm_runtime *rtd);

include/sound/soc.h +2 -3
@@ -876,8 +876,8 @@ struct snd_soc_pcm_runtime {
        enum snd_soc_pcm_subclass pcm_subclass;
        struct snd_pcm_ops ops;
 
-       unsigned int complete:1;
-       unsigned int dev_registered:1;
+       bool complete;
+       bool dev_registered;
 
        long pmdown_time;
 
--

1.7.9.rc1

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

author
#2 lore raw

On Wed, Feb 08, 2012 at 02:08:05PM -0500, Trent Piepho wrote:

Don't top post and trim the context from your replies. This is basic stuff...

Quoted 1 line

Aren't you increasing the size of some of these structs considerably?

Hrm, possibly. I'd rather have hoped that the bool type would work a bit more sanely here.

#3 lore raw
Quoted 5 lines · Mark Brown
Quoted 1 line · Trent Piepho

Aren't you increasing the size of some of these structs considerably?

Hrm, possibly.  I'd rather have hoped that the bool type would work a bit more sanely here.

Linux defines bool as _Bool, which is a native type from C99. _Bools in structs appear to be the same as unsigned char. They each take one byte and have an alignment of one.

So in this struct:

@@ -208,7 +208,7 @@ struct snd_soc_dai_driver {
       /* DAI capabilities */
       struct snd_soc_pcm_stream capture;
       struct snd_soc_pcm_stream playback;

- unsigned int symmetric_rates:1;
+ bool symmetric_rates;

       /* probe ordering - for components with runtime dependencies */
       int probe_order;

Changing from a bitfield to a bool doesn't make any difference, since both will consume 4 bytes as the int probe_order will need that for alignment. Of course it might be possible to have less passing space by placing the bool or bitfield near other < 4 bytes members.

This struct:

@@ -230,13 +230,13 @@ struct snd_soc_dai {
       struct snd_soc_dai_driver *driver;

       /* DAI runtime info */
-       unsigned int capture_active:1;          /* stream is in use */
-       unsigned int playback_active:1;         /* stream is in use */
-       unsigned int symmetric_rates:1;
+       bool capture_active;            /* stream is in use */
+       bool playback_active;           /* stream is in use */
+       bool symmetric_rates;
       struct snd_pcm_runtime *runtime;
       unsigned int active;
-       unsigned char pop_wait:1;
-       unsigned char probed:1;
+       bool pop_wait;
+       bool probed;

Doesn't actually take more space either, 8 bytes total. But if it was re-ordered so these bitfields were all together then bitfields with take four bytes vs 8 for the bools.

This struct on the other hand:
@@ -488,16 +488,16 @@ struct snd_soc_dapm_widget {

       unsigned int mask;                      /* non-shifted mask */
       unsigned int on_val;                    /* on state value */
       unsigned int off_val;                   /* off state value */
-       unsigned char power:1;                  /* block power status */
-       unsigned char invert:1;                 /* invert the power bit */
-       unsigned char active:1;                 /* active stream on
DAC, ADC's */
-       unsigned char connected:1;              /* connected codec pin */
-       unsigned char new:1;                    /* cnew complete */
-       unsigned char ext:1;                    /* has external widgets */
-       unsigned char force:1;                  /* force state */
-       unsigned char ignore_suspend:1;         /* kept enabled over suspend */
-       unsigned char new_power:1;              /* power from this run */
-       unsigned char power_checked:1;          /* power checked this run */
+       bool power;                             /* block power status */
+       bool invert;                            /* invert the power bit */
+       bool active;                            /* active stream on
DAC, ADC's */
+       bool connected;                         /* connected codec pin */
+       bool new;                               /* cnew complete */
+       bool ext;                               /* has external widgets */
+       bool force;                             /* force state */
+       bool ignore_suspend;                    /* kept enabled over suspend */
+       bool new_power;                         /* power from this run */
+       bool power_checked;                     /* power checked this run */

int subseq; /* sort within widget type */

It uses 12 bytes for bools and 4 for bitfields.

author
#4 lore raw
Quoted 3 lines · Trent Piepho

Linux defines bool as _Bool, which is a native type from C99. _Bools in structs appear to be the same as unsigned char. They each take one byte and have an alignment of one.

Well, that's a bit of a failure isn't it? Let's not bother then.