From: Colin Patrick McCabe Date: Mon, 6 Dec 2010 22:43:44 +0000 (-0800) Subject: logging: optimize with likely/unlikely macros X-Git-Tag: v0.25~463^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c94e0d2d38b687c7bc0929a6647459d27ff1882f;p=ceph.git logging: optimize with likely/unlikely macros Signed-off-by: Colin McCabe --- diff --git a/src/common/debug.h b/src/common/debug.h index f75537b4f123..2cb5dee7b56e 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -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 +#include 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 index 000000000000..e8146a3f69eb --- /dev/null +++ b/src/common/likely.h @@ -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