Commit 36ce99c1 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: Add debug module option

Add debug module option to snd core.
This controls the debug print level.  When CONFIG_SND_DEBUG_VERBOSE
is set, you can suppress the debug messages by giving or changing this
parameter to a lower value.  debug=0 means no debug messsages.
As default, it's set to the verbose level 2.

Since this option can be changed dynamically via sysfs file, you can
suppress the verbose debug messages on the fly, which wasn't possible
before.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 1b0053a0
...@@ -60,6 +60,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed. ...@@ -60,6 +60,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
slots - Reserve the slot index for the given driver. slots - Reserve the slot index for the given driver.
This option takes multiple strings. This option takes multiple strings.
See "Module Autoloading Support" section for details. See "Module Autoloading Support" section for details.
debug - Specifies the debug message level
(0 = disable debug prints, 1 = normal debug messages,
2 = verbose debug messages)
This option appears only when CONFIG_SND_DEBUG=y.
This option can be dynamically changed via sysfs
/sys/modules/snd/parameters/debug file.
Module snd-pcm-oss Module snd-pcm-oss
------------------ ------------------
......
...@@ -340,18 +340,17 @@ unsigned int snd_dma_pointer(unsigned long dma, unsigned int size); ...@@ -340,18 +340,17 @@ unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
struct resource; struct resource;
void release_and_free_resource(struct resource *res); void release_and_free_resource(struct resource *res);
#ifdef CONFIG_SND_VERBOSE_PRINTK
void snd_verbose_printk(const char *file, int line, const char *format, ...)
__attribute__ ((format (printf, 3, 4)));
#endif
#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
void snd_verbose_printd(const char *file, int line, const char *format, ...)
__attribute__ ((format (printf, 3, 4)));
#endif
/* --- */ /* --- */
#ifdef CONFIG_SND_VERBOSE_PRINTK #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
void __snd_printk(unsigned int level, const char *file, int line,
const char *format, ...)
__attribute__ ((format (printf, 4, 5)));
#else
#define __snd_printk(level, file, line, format, args...) \
prinkt(format, ##args)
#endif
/** /**
* snd_printk - printk wrapper * snd_printk - printk wrapper
* @fmt: format string * @fmt: format string
...@@ -360,15 +359,9 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...) ...@@ -360,15 +359,9 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
* when configured with CONFIG_SND_VERBOSE_PRINTK. * when configured with CONFIG_SND_VERBOSE_PRINTK.
*/ */
#define snd_printk(fmt, args...) \ #define snd_printk(fmt, args...) \
snd_verbose_printk(__FILE__, __LINE__, fmt ,##args) __snd_printk(0, __FILE__, __LINE__, fmt, ##args)
#else
#define snd_printk(fmt, args...) \
printk(fmt ,##args)
#endif
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
#ifdef CONFIG_SND_VERBOSE_PRINTK
/** /**
* snd_printd - debug printk * snd_printd - debug printk
* @fmt: format string * @fmt: format string
...@@ -377,11 +370,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...) ...@@ -377,11 +370,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
* Ignored when CONFIG_SND_DEBUG is not set. * Ignored when CONFIG_SND_DEBUG is not set.
*/ */
#define snd_printd(fmt, args...) \ #define snd_printd(fmt, args...) \
snd_verbose_printd(__FILE__, __LINE__, fmt ,##args) __snd_printk(1, __FILE__, __LINE__, fmt, ##args)
#else
#define snd_printd(fmt, args...) \
printk(fmt ,##args)
#endif
/** /**
* snd_BUG - give a BUG warning message and stack trace * snd_BUG - give a BUG warning message and stack trace
...@@ -428,9 +417,10 @@ static inline int __snd_bug_on(int cond) ...@@ -428,9 +417,10 @@ static inline int __snd_bug_on(int cond)
* Works like snd_printk() for debugging purposes. * Works like snd_printk() for debugging purposes.
* Ignored when CONFIG_SND_DEBUG_VERBOSE is not set. * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
*/ */
#define snd_printdd(format, args...) snd_printk(format, ##args) #define snd_printdd(format, args...) \
__snd_printk(2, __FILE__, __LINE__, format, ##args)
#else #else
#define snd_printdd(format, args...) /* nothing */ #define snd_printdd(format, args...) do { } while (0)
#endif #endif
......
...@@ -24,6 +24,20 @@ ...@@ -24,6 +24,20 @@
#include <linux/ioport.h> #include <linux/ioport.h>
#include <sound/core.h> #include <sound/core.h>
#ifdef CONFIG_SND_DEBUG
#ifdef CONFIG_SND_DEBUG_VERBOSE
#define DEFAULT_DEBUG_LEVEL 2
#else
#define DEFAULT_DEBUG_LEVEL 1
#endif
static int debug = DEFAULT_DEBUG_LEVEL;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Debug level (0 = disable)");
#endif /* CONFIG_SND_DEBUG */
void release_and_free_resource(struct resource *res) void release_and_free_resource(struct resource *res)
{ {
if (res) { if (res) {
...@@ -35,6 +49,7 @@ void release_and_free_resource(struct resource *res) ...@@ -35,6 +49,7 @@ void release_and_free_resource(struct resource *res)
EXPORT_SYMBOL(release_and_free_resource); EXPORT_SYMBOL(release_and_free_resource);
#ifdef CONFIG_SND_VERBOSE_PRINTK #ifdef CONFIG_SND_VERBOSE_PRINTK
/* strip the leading path if the given path is absolute */
static const char *sanity_file_name(const char *path) static const char *sanity_file_name(const char *path)
{ {
if (*path == '/') if (*path == '/')
...@@ -43,48 +58,44 @@ static const char *sanity_file_name(const char *path) ...@@ -43,48 +58,44 @@ static const char *sanity_file_name(const char *path)
return path; return path;
} }
void snd_verbose_printk(const char *path, int line, const char *format, ...) /* print file and line with a certain printk prefix */
static int print_snd_pfx(unsigned int level, const char *path, int line,
const char *format)
{ {
const char *file = sanity_file_name(path); const char *file = sanity_file_name(path);
va_list args;
if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
char tmp[] = "<0>"; char tmp[] = "<0>";
const char *pfx = level ? KERN_DEBUG : KERN_DEFAULT;
int ret = 0;
if (format[0] == '<' && format[2] == '>') {
tmp[1] = format[1]; tmp[1] = format[1];
printk("%sALSA %s:%d: ", tmp, file, line); pfx = tmp;
format += 3; ret = 1;
} else {
printk("ALSA %s:%d: ", file, line);
} }
va_start(args, format); printk("%sALSA %s:%d: ", pfx, file, line);
vprintk(format, args); return ret;
va_end(args);
} }
#else
EXPORT_SYMBOL(snd_verbose_printk); #define print_snd_pfx(level, path, line, format) 0
#endif #endif
#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK) #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
void snd_verbose_printd(const char *path, int line, const char *format, ...) void __snd_printk(unsigned int level, const char *path, int line,
const char *format, ...)
{ {
const char *file = sanity_file_name(path);
va_list args; va_list args;
if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') { #ifdef CONFIG_SND_DEBUG
char tmp[] = "<0>"; if (debug < level)
tmp[1] = format[1]; return;
printk("%sALSA %s:%d: ", tmp, file, line); #endif
format += 3;
} else {
printk(KERN_DEBUG "ALSA %s:%d: ", file, line);
}
va_start(args, format); va_start(args, format);
if (print_snd_pfx(level, path, line, format))
format += 3; /* skip the printk level-prefix */
vprintk(format, args); vprintk(format, args);
va_end(args); va_end(args);
} }
EXPORT_SYMBOL_GPL(__snd_printk);
EXPORT_SYMBOL(snd_verbose_printd);
#endif #endif
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment