Skip to content

Commit

Permalink
Split <sys/debug.h> header
Browse files Browse the repository at this point in the history
To avoid symbol conflicts with dependent packages the debug
header must be split in to several parts.  The <sys/debug.h>
header now only contains the Solaris macro's such as ASSERT
and VERIFY.  The spl-debug.h header contain the spl specific
debugging infrastructure and should be included by any package
which needs to use the spl logging.  Finally the spl-trace.h
header contains internal data structures only used for the log
facility and should not be included by anythign by spl-debug.c.

This way dependent packages can include the standard Solaris
headers without picking up any SPL debug macros.  However, if
the dependant package want to integrate with the SPL debugging
subsystem they can then explicitly include spl-debug.h.

Along with this change I have dropped the CHECK_STACK macros
because the upstream Linux kernel now has much better stack
depth checking built in and we don't need this complexity.

Additionally SBUG has been replaced with PANIC and provided as
part of the Solaris macro set.  While the Solaris version is
really panic() that conflicts with the Linux kernel so we'll
just have to make due to PANIC.  It should rarely be called
directly, the prefered usage would be an ASSERT or VERIFY.

There's lots of change here but this cleanup was overdue.
  • Loading branch information
behlendorf committed Jul 20, 2010
1 parent 8f813bb commit 55abb09
Show file tree
Hide file tree
Showing 25 changed files with 460 additions and 458 deletions.
1 change: 1 addition & 0 deletions include/linux/file_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef _SPL_FILE_COMPAT_H
#define _SPL_FILE_COMPAT_H

#include <linux/fs.h>
#ifdef HAVE_FDTABLE_HEADER
#include <linux/fdtable.h>
#endif
Expand Down
181 changes: 181 additions & 0 deletions include/spl-debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*****************************************************************************\
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
* Copyright (C) 2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
* UCRL-CODE-235197
*
* This file is part of the SPL, Solaris Porting Layer.
* For details, see <http://github.com/behlendorf/spl/>.
*
* The SPL is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* The SPL is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
\*****************************************************************************/

/*
* Available debug functions. These function should be used by any
* package which needs to integrate with the SPL log infrastructure.
*
* CDEBUG() - Log debug message with specified mask.
* CDEBUG_LIMIT() - Log just 1 debug message with specified mask.
* CWARN() - Log a warning message.
* CERROR() - Log an error message.
* CEMERG() - Log an emergency error message.
* CONSOLE() - Log a generic message to the console.
*
* ENTRY - Log entry point to a function.
* EXIT - Log exit point from a function.
* RETURN(x) - Log return from a function.
* GOTO(x, y) - Log goto within a function.
*/

#ifndef _SPL_DEBUG_INTERNAL_H
#define _SPL_DEBUG_INTERNAL_H

#include <linux/limits.h>

#define S_UNDEFINED 0x00000001
#define S_ATOMIC 0x00000002
#define S_KOBJ 0x00000004
#define S_VNODE 0x00000008
#define S_TIME 0x00000010
#define S_RWLOCK 0x00000020
#define S_THREAD 0x00000040
#define S_CONDVAR 0x00000080
#define S_MUTEX 0x00000100
#define S_RNG 0x00000200
#define S_TASKQ 0x00000400
#define S_KMEM 0x00000800
#define S_DEBUG 0x00001000
#define S_GENERIC 0x00002000
#define S_PROC 0x00004000
#define S_MODULE 0x00008000
#define S_CRED 0x00010000

#define D_TRACE 0x00000001
#define D_INFO 0x00000002
#define D_WARNING 0x00000004
#define D_ERROR 0x00000008
#define D_EMERG 0x00000010
#define D_CONSOLE 0x00000020
#define D_IOCTL 0x00000040
#define D_DPRINTF 0x00000080
#define D_OTHER 0x00000100

#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)
#define DEBUG_SUBSYSTEM S_UNDEFINED

#ifdef NDEBUG /* Debugging Disabled */

#define CDEBUG(mask, fmt, a...) ((void)0)
#define CDEBUG_LIMIT(x, y, fmt, a...) ((void)0)
#define CWARN(fmt, a...) ((void)0)
#define CERROR(fmt, a...) ((void)0)
#define CEMERG(fmt, a...) ((void)0)
#define CONSOLE(mask, fmt, a...) ((void)0)

#define ENTRY ((void)0)
#define EXIT ((void)0)
#define RETURN(x) return (x)
#define GOTO(x, y) { ((void)(y)); goto x; }

#else /* Debugging Enabled */

#define __CDEBUG(cdls, subsys, mask, format, a...) \
do { \
if (((mask) & D_CANTMASK) != 0 || \
((spl_debug_mask & (mask)) != 0 && \
(spl_debug_subsys & (subsys)) != 0)) \
spl_debug_msg(cdls, subsys, mask, __FILE__, \
__FUNCTION__, __LINE__, format, ## a); \
} while (0)

#define CDEBUG(mask, format, a...) \
__CDEBUG(NULL, DEBUG_SUBSYSTEM, mask, format, ## a)

#define __CDEBUG_LIMIT(subsys, mask, format, a...) \
do { \
static spl_debug_limit_state_t cdls; \
\
__CDEBUG(&cdls, subsys, mask, format, ## a); \
} while (0)

#define CDEBUG_LIMIT(mask, format, a...) \
__CDEBUG_LIMIT(DEBUG_SUBSYSTEM, mask, format, ## a)

#define CWARN(fmt, a...) CDEBUG_LIMIT(D_WARNING, fmt, ## a)
#define CERROR(fmt, a...) CDEBUG_LIMIT(D_ERROR, fmt, ## a)
#define CEMERG(fmt, a...) CDEBUG_LIMIT(D_EMERG, fmt, ## a)
#define CONSOLE(mask, fmt, a...) CDEBUG(D_CONSOLE | (mask), fmt, ## a)

#define ENTRY CDEBUG(D_TRACE, "Process entered\n")
#define EXIT CDEBUG(D_TRACE, "Process leaving\n")

#define RETURN(rc) \
do { \
typeof(rc) RETURN__ret = (rc); \
CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
(long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret); \
return RETURN__ret; \
} while (0)

#define GOTO(label, rc) \
do { \
long GOTO__ret = (long)(rc); \
CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
#label, (unsigned long)GOTO__ret, (signed long)GOTO__ret, \
(signed long)GOTO__ret); \
goto label; \
} while (0)

#endif /* NDEBUG */

typedef struct {
unsigned long cdls_next;
int cdls_count;
long cdls_delay;
} spl_debug_limit_state_t;

/* Global debug variables */
extern unsigned long spl_debug_subsys;
extern unsigned long spl_debug_mask;
extern unsigned long spl_debug_printk;
extern int spl_debug_mb;
extern unsigned int spl_debug_binary;
extern unsigned int spl_debug_catastrophe;
extern unsigned int spl_debug_panic_on_bug;
extern char spl_debug_file_path[PATH_MAX];
extern unsigned int spl_console_ratelimit;
extern long spl_console_max_delay;
extern long spl_console_min_delay;
extern unsigned int spl_console_backoff;
extern unsigned int spl_debug_stack;

/* Exported debug functions */
extern int spl_debug_mask2str(char *str, int size, unsigned long mask, int ss);
extern int spl_debug_str2mask(unsigned long *mask, const char *str, int ss);
extern unsigned long spl_debug_set_mask(unsigned long mask);
extern unsigned long spl_debug_get_mask(void);
extern unsigned long spl_debug_set_subsys(unsigned long mask);
extern unsigned long spl_debug_get_subsys(void);
extern int spl_debug_set_mb(int mb);
extern int spl_debug_get_mb(void);
extern int spl_debug_dumplog(int flags);
extern void spl_debug_dumpstack(struct task_struct *tsk);
extern int spl_debug_clear_buffer(void);
extern int spl_debug_mark_buffer(char *text);

int debug_init(void);
void debug_fini(void);

#endif /* SPL_DEBUG_INTERNAL_H */
132 changes: 132 additions & 0 deletions include/spl-trace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*****************************************************************************\
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
* Copyright (C) 2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
* UCRL-CODE-235197
*
* This file is part of the SPL, Solaris Porting Layer.
* For details, see <http://github.com/behlendorf/spl/>.
*
* The SPL is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* The SPL is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
\*****************************************************************************/

#ifndef _SPL_TRACE_H
#define _SPL_TRACE_H

#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))
#define TCD_STOCK_PAGES (TCD_MAX_PAGES)
#define TRACE_CONSOLE_BUFFER_SIZE 1024

#define SPL_DEFAULT_MAX_DELAY (600 * HZ)
#define SPL_DEFAULT_MIN_DELAY ((HZ + 1) / 2)
#define SPL_DEFAULT_BACKOFF 2

#define DL_NOTHREAD 0x0001 /* Do not create a new thread */
#define DL_SINGLE_CPU 0x0002 /* Collect pages from this CPU*/

typedef struct dumplog_priv {
wait_queue_head_t dp_waitq;
pid_t dp_pid;
int dp_flags;
atomic_t dp_done;
} dumplog_priv_t;

/* Three trace data types */
typedef enum {
TCD_TYPE_PROC,
TCD_TYPE_SOFTIRQ,
TCD_TYPE_IRQ,
TCD_TYPE_MAX
} tcd_type_t;

union trace_data_union {
struct trace_cpu_data {
/* pages with trace records not yet processed by tracefiled */
struct list_head tcd_pages;
/* number of pages on ->tcd_pages */
unsigned long tcd_cur_pages;
/* Max number of pages allowed on ->tcd_pages */
unsigned long tcd_max_pages;

/*
* preallocated pages to write trace records into. Pages from
* ->tcd_stock_pages are moved to ->tcd_pages by spl_debug_msg().
*
* This list is necessary, because on some platforms it's
* impossible to perform efficient atomic page allocation in a
* non-blockable context.
*
* Such platforms fill ->tcd_stock_pages "on occasion", when
* tracing code is entered in blockable context.
*
* trace_get_tage_try() tries to get a page from
* ->tcd_stock_pages first and resorts to atomic page
* allocation only if this queue is empty. ->tcd_stock_pages
* is replenished when tracing code is entered in blocking
* context (darwin-tracefile.c:trace_get_tcd()). We try to
* maintain TCD_STOCK_PAGES (40 by default) pages in this
* queue. Atomic allocation is only required if more than
* TCD_STOCK_PAGES pagesful are consumed by trace records all
* emitted in non-blocking contexts. Which is quite unlikely.
*/
struct list_head tcd_stock_pages;
/* number of pages on ->tcd_stock_pages */
unsigned long tcd_cur_stock_pages;

unsigned short tcd_shutting_down;
unsigned short tcd_cpu;
unsigned short tcd_type;
/* The factors to share debug memory. */
unsigned short tcd_pages_factor;

/*
* This spinlock is needed to workaround the problem of
* set_cpus_allowed() being GPL-only. Since we cannot
* schedule a thread on a specific CPU when dumping the
* pages, we must use the spinlock for mutual exclusion.
*/
spinlock_t tcd_lock;
unsigned long tcd_lock_flags;
} tcd;
char __pad[L1_CACHE_ALIGN(sizeof(struct trace_cpu_data))];
};

extern union trace_data_union (*trace_data[TCD_TYPE_MAX])[NR_CPUS];

#define tcd_for_each(tcd, i, j) \
for (i = 0; i < TCD_TYPE_MAX && trace_data[i]; i++) \
for (j = 0, ((tcd) = &(*trace_data[i])[j].tcd); \
j < num_possible_cpus(); j++, (tcd) = &(*trace_data[i])[j].tcd)

#define tcd_for_each_type_lock(tcd, i, cpu) \
for (i = 0; i < TCD_TYPE_MAX && trace_data[i] && \
(tcd = &(*trace_data[i])[cpu].tcd) && \
trace_lock_tcd(tcd); trace_unlock_tcd(tcd), i++)

struct trace_page {
struct page *page; /* page itself */
struct list_head linkage; /* Used by trace_data_union */
unsigned int used; /* number of bytes used within this page */
unsigned short cpu; /* cpu that owns this page */
unsigned short type; /* type(context) of this page */
};

struct page_collection {
struct list_head pc_pages;
spinlock_t pc_lock;
int pc_want_daemon_pages;
};

#endif /* SPL_TRACE_H */
Loading

0 comments on commit 55abb09

Please sign in to comment.