Changes since V1:
 - Restored __hugetlbfs_debug so it can be used for adding debug code

The default verbosity level in libhugetlbfs is 1, meaning that only errors are
printed.  Many of the new library features can have outcomes that are very
meaningful warnings which should be displayed by default.  For example, if a
user specifies an incorrect page size in HUGETLB_ELFMAP, a warning is issued
and segment remapping is disabled.  Under the current verbosity default, this
important message is suppressed.  We should switch the default verbosity to 2
so that such warnings are displayed.

Simply increasing the default verbosity is not a complete solution.  Some
messages that have been classified as warnings are more informational in nature
and should not always be printed.  Add a new INFO verbosity level for detailed
messages about normal library operation.

The library currently makes a strange differentiation between verbosity levels
and whether debugging mode is enabled.  Verbosity is controlled by one
enviroment variable and debugging by another.  Thus, a user could set verbosity
to 0 (no messages) and enable debugging (resulting in output with out of place
debugging info and non-obvious slow downs.

One can argue that debugging mode is equivalent to the highest verbosity level.
Making the switch simplifies the library and interface.

So after this patch is applied, we have the following four verbosity levels
with their intended uses as defined herein.

ERROR   - Severe, unrecoverable errors
WARNING - Recoverable condition, but may result in altered semantics
INFO    - Detailed information about normal library operations
DEBUG   - Diagnostic information for debugging, potential runtime overhead

Signed-off-by: Adam Litke <[EMAIL PROTECTED]>
---

 debug.c                 |    4 +++-
 libhugetlbfs_debug.h    |   17 +++++++++++++----
 libhugetlbfs_internal.h |   17 +++++++++++++----
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/debug.c b/debug.c
index e854dff..7082aeb 100644
--- a/debug.c
+++ b/debug.c
@@ -46,8 +46,10 @@ static void __hugetlbfs_init_debug(void)
                __hugetlbfs_verbose = atoi(env);
 
        env = getenv("HUGETLB_DEBUG");
-       if (env)
+       if (env) {
                __hugetlbfs_debug = 1;
+               __hugetlbfs_verbose = VERBOSE_DEBUG;
+       }
 
        env = getenv("HUGETLB_NO_PREFAULT");
        if (env)
diff --git a/libhugetlbfs_debug.h b/libhugetlbfs_debug.h
index 7eb8f4e..cd490ad 100644
--- a/libhugetlbfs_debug.h
+++ b/libhugetlbfs_debug.h
@@ -20,14 +20,23 @@
 #ifndef _LIBHUGETLBFS_DEBUG_H
 #define _LIBHUGETLBFS_DEBUG_H
 
+/* Severe, unrecoverable errors */
 #define ERROR(...)             REPORT(1, "ERROR", ##__VA_ARGS__)
 #define ERROR_CONT(...)                REPORT_CONT(1, "ERROR", ##__VA_ARGS__)
+
+/* A condition that is recoverable, but may result in altered semantics */
 #define WARNING(...)           REPORT(2, "WARNING", ##__VA_ARGS__)
 #define WARNING_CONT(...)      REPORT_CONT(2, "WARNING", ##__VA_ARGS__)
-#define DEBUG(...)             REPORT(3, "DEBUG", ##__VA_ARGS__)
-#define DEBUG_CONT(...)                REPORT_CONT(3, "DEBUG", ##__VA_ARGS__)
 
-#define VERBOSITY_MAX 3
-#define VERBOSITY_DEFAULT 1
+/* Detailed information about normal library operations */
+#define INFO(...)              REPORT(3, "INFO", ##__VA_ARGS__)
+#define INFO_CONT(...)         REPORT_CONT(3, "INFO", ##__VA_ARGS__)
+
+/* Diagnostic information used for debugging problems */
+#define DEBUG(...)             REPORT(4, "DEBUG", ##__VA_ARGS__)
+#define DEBUG_CONT(...)                REPORT_CONT(4, "DEBUG", ##__VA_ARGS__)
+
+#define VERBOSITY_MAX 4
+#define VERBOSITY_DEFAULT 2
 
 #endif
diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h
index 6ebe9c0..fb283f2 100644
--- a/libhugetlbfs_internal.h
+++ b/libhugetlbfs_internal.h
@@ -90,12 +90,21 @@ extern long parse_page_size(const char *str);
 #ifndef REPORT_UTIL
 #define REPORT_UTIL "libhugetlbfs"
 #endif
+
+#define VERBOSE_ERROR  1
+#define VERBOSE_WARNING        2
+#define VERBOSE_INFO   3
+#define VERBOSE_DEBUG  4
+
 #ifndef REPORT
 #define REPORT(level, prefix, format, ...) \
        do { \
-               if (__hugetlbfs_debug || __hugetlbfs_verbose >= level) { \
-                       fprintf(stderr, REPORT_UTIL " [%s:%d]: " prefix ": " \
-                               format, __hugetlbfs_hostname, getpid(), \
+               if (__hugetlbfs_verbose >= level) { \
+                       fprintf(stderr, REPORT_UTIL); \
+                       if (__hugetlbfs_verbose >= VERBOSE_DEBUG) \
+                               fprintf(stderr, " [%s:%d]", \
+                                       __hugetlbfs_hostname, getpid()); \
+                       fprintf(stderr, ": " prefix ": " format, \
                                ##__VA_ARGS__); \
                        fflush(stderr); \
                } \
@@ -103,7 +112,7 @@ extern long parse_page_size(const char *str);
 
 #define REPORT_CONT(level, prefix, ...) \
        do { \
-               if (__hugetlbfs_debug || __hugetlbfs_verbose >= level) { \
+               if (__hugetlbfs_verbose >= level) { \
                        fprintf(stderr, ##__VA_ARGS__); \
                        fflush(stderr); \
                } \


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to