From 54a8eb31f55854ea40e1b07fef86b80b3652e37a Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Fri, 26 Apr 2013 21:05:35 +0200 Subject: [PATCH] infra: add CONFIG_MARS_CHECKS --- kernel/Kconfig | 18 +++++++++++++++++- kernel/brick_checking.h | 12 ++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/kernel/Kconfig b/kernel/Kconfig index 135f5271..0327bc14 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -9,11 +9,27 @@ config MARS ---help--- Experimental storage System. Only compile as a module! +config MARS_CHECKS + bool "enable simple runtime checks in MARS" + depends on MARS + default y + ---help--- + These checks should be rather lightweight. Use them + for beta testing and for production systems where + safety is more important than performance. + In case of bugs in the reference counting, an automatic repair + is attempted, which lowers the risk of memory corruptions. + Disable only if you need the absolutely last grain of + performance. + If unsure, say Y here. + config MARS_DEBUG - bool "enable runtime checks in MARS" + bool "enable full runtime checks and some tracing in MARS" depends on MARS default n ---help--- + Some of these checks and some additional error tracing may + consume noticable amounts of memory. OFF for production systems. ON for testing! config MARS_DEBUG_DEFAULT diff --git a/kernel/brick_checking.h b/kernel/brick_checking.h index 2ef09117..1014007a 100644 --- a/kernel/brick_checking.h +++ b/kernel/brick_checking.h @@ -6,7 +6,7 @@ // checking -#ifdef CONFIG_MARS_DEBUG +#if defined(CONFIG_MARS_DEBUG) || defined(CONFIG_MARS_CHECKS) #define BRICK_CHECKING true #else #define BRICK_CHECKING false @@ -16,7 +16,7 @@ do { \ if (BRICK_CHECKING) { \ int __test = atomic_read(atom); \ - if (__test OP (minval)) { \ + if (unlikely(__test OP (minval))) { \ atomic_set(atom, minval); \ BRICK_ERR("%d: atomic " #atom " " #OP " " #minval " (%d)\n", __LINE__, __test); \ } \ @@ -34,6 +34,7 @@ do { \ } \ } while (0) +#ifdef CONFIG_MARS_DEBUG_MEM #define CHECK_PTR_DEAD(ptr,label) \ do { \ if (BRICK_CHECKING && unlikely((ptr) == (void*)0x5a5a5a5a5a5a5a5a)) { \ @@ -41,6 +42,9 @@ do { \ goto label; \ } \ } while (0) +#else +#define CHECK_PTR_DEAD(ptr,label) /*empty*/ +#endif #define CHECK_PTR_NULL(ptr,label) \ do { \ @@ -51,6 +55,7 @@ do { \ } \ } while (0) +#ifdef CONFIG_MARS_DEBUG #define CHECK_PTR(ptr,label) \ do { \ CHECK_PTR_NULL(ptr, label); \ @@ -59,6 +64,9 @@ do { \ goto label; \ } \ } while (0) +#else +#define CHECK_PTR(ptr,label) CHECK_PTR_NULL(ptr,label) +#endif #define CHECK_ASPECT(a_ptr, o_ptr,label) \ do { \