Skip to contentSkip to conversation

Profile likely/unlikely macros -v2

PATCH In review Daniel Walker 3 participants 3 messages Apr 26, 2006 – Apr 27, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Profile likely/unlikely macros -v2

Changes are switched to test_and_set_bit()/clear_bit() , comment explaining test_and_set_bit(), and most every other comment ..

include/linux/compiler.h +32 -2
Index: linux-2.6.16/include/linux/compiler.h
===================================================================
@@ -53,14 +53,44 @@ extern void __chk_io_ptr(void __iomem *)
 # include <linux/compiler-intel.h>
 #endif
 
+#if defined(CONFIG_PROFILE_LIKELY) && !(defined(CONFIG_MODULE_UNLOAD) && defined(MODULE))
+struct likeliness {
+	const char *func;
+	char *file;
+	int line;
+	int type;
+	unsigned int count[2]; 
+	struct likeliness *next;
+};
+
+extern int do_check_likely(struct likeliness *likeliness, int exp);
+
+# define LP_UNSEEN	4
+
+# define __check_likely(exp, is_likely)							\
+	({										\
+		static __attribute__((__section__(".likely.data")))			\
+			struct likeliness likeliness = {				\
+				.func = __func__,					\
+				.file = __FILE__,					\
+				.line = __LINE__,					\
+				.type = is_likely | LP_UNSEEN,				\
+			};								\
+		do_check_likely(&likeliness, !!(exp));					\
+	})
+
+# define likely(x)	__check_likely(x, 1)
+# define unlikely(x)	__check_likely(x, 0)
+#else
 /*
  * Generic compiler-dependent macros required for kernel
  * build go below this comment. Actual compiler/compiler version
  * specific implementations come from the above header files
  */
 
-#define likely(x)	__builtin_expect(!!(x), 1)
-#define unlikely(x)	__builtin_expect(!!(x), 0)
+# define likely(x)	__builtin_expect(!!(x), 1)
+# define unlikely(x)	__builtin_expect(!!(x), 0)
+#endif
 
 /* Optimization barrier */
 #ifndef barrier
lib/Kconfig.debug +7 -0
Index: linux-2.6.16/lib/Kconfig.debug
===================================================================
@@ -223,3 +223,10 @@ config RCU_TORTURE_TEST
 	  at boot time (you probably don't).
 	  Say M if you want the RCU torture tests to build as a module.
 	  Say N if you are unsure.
+config	PROFILE_LIKELY 
+	bool "Record return values from likely/unlikely macros"
+	default n
+	help
+	  Adds profiling on likely/unlikly macros . To see the
+	  results of the profiling you can view the following,
+		/proc/likely_prof
lib/Makefile +2 -0
Index: linux-2.6.16/lib/Makefile
===================================================================
@@ -49,6 +49,8 @@ obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o
 
 obj-$(CONFIG_SWIOTLB) += swiotlb.o
 
+obj-$(CONFIG_PROFILE_LIKELY) += likely_prof.o
+
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
 
lib/likely_prof.c new file +141 -0

141 lines not on this page · raw message

#2 lore raw
In reply to Daniel Walker
Quoted 4 lines · Daniel Walker

Changes are switched to test_and_set_bit()/clear_bit() ,
comment explaining test_and_set_bit(), and most every other comment ..

I too am getting undefined you_cannot_kmalloc_that_much on x86_64. Coming out of

	cache_kobject[cpu] = kmalloc(sizeof(struct kobject), GFP_KERNEL);

in arch/i386/kernel/cpu/intel_cacheinfo.c

It has to be a compiler bug, I think.

	gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

I cannot use this patch until we find a workaround.