]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
logging: optimize with likely/unlikely macros
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 6 Dec 2010 22:43:44 +0000 (14:43 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 6 Dec 2010 23:38:14 +0000 (15:38 -0800)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/common/debug.h
src/common/likely.h [new file with mode: 0644]

index f75537b4f1233eff9f329e840308b2cf2305cec1..2cb5dee7b56e232bf42d9055c06cb7561be9f83b 100644 (file)
@@ -4,11 +4,12 @@
 #ifndef CEPH_DEBUG_H
 #define CEPH_DEBUG_H
 
+#include "common/likely.h"
 #include "include/assert.h"
 #include "Mutex.h"
 #include "Clock.h"
 
-#include <ostream>
+#include <iosfwd>
 using std::ostream;
 
 // the streams
@@ -26,14 +27,14 @@ extern int dout_create_rank_symlink(int64_t n);
 
 static inline void _dout_check_log() {
   _dout_lock.Lock();
-  if (_dout_need_open)
+  if (unlikely(_dout_need_open))
     _dout_open_log();
   _dout_lock.Unlock();
 }
 
 static inline void _dout_begin_line() {
   _dout_lock.Lock();
-  if (_dout_need_open)
+  if (unlikely(_dout_need_open))
     _dout_open_log();
   *_dout << g_clock.now() << " " << std::hex << pthread_self() << std::dec << " ";
 }
diff --git a/src/common/likely.h b/src/common/likely.h
new file mode 100644 (file)
index 0000000..e8146a3
--- /dev/null
@@ -0,0 +1,24 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_LIKELY_DOT_H
+#define CEPH_LIKELY_DOT_H
+
+/*
+ * Likely / Unlikely macros
+ */
+#define likely(x)       __builtin_expect((x),1)
+#define unlikely(x)     __builtin_expect((x),0)
+
+#endif