Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7942

InnoDB: abuse of UNIV_LIKELY()/UNIV_UNLIKELY()

Details

    Description

      UNIV_LIKELY()/UNIV_UNLIKELY() hints are supposed to improve branch prediction. They're defined in InnoDB as following:

      /* Tell the compiler that 'expr' probably evaluates to 'constant'. */
      # define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
      /* Tell the compiler that cond is likely to hold */
      #define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
      /* Tell the compiler that cond is unlikely to hold */
      #define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)

      In other words they're expected to work only if cond evaluates to TRUE or FALSE,
      see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html.

      However there're a few conditions that may evaluate to different values, e.g.:

      page/page0zip.cc:		if (UNIV_LIKELY(c_stream->avail_in)) {
      page/page0zip.cc:			if (UNIV_LIKELY(c_stream->avail_in)) {
      dict/dict0mem.cc:		if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {

      Either fix condition or fix UNIV_LIKELY() to evaluate condition to bool (see likely() in my_global.h).
      Note: we'll gain little to nothing in terms of performance out of this. But at least we'll have correct use of these compiler hints.

      Attachments

        Activity

          svoj Sergey Vojtovich created issue -
          svoj Sergey Vojtovich made changes -
          Field Original Value New Value
          Epic Link MDEV-7941 [ 50796 ]
          svoj Sergey Vojtovich made changes -
          Affects Version/s 10.1 [ 16100 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.1 [ 16100 ]
          jplindst Jan Lindström (Inactive) made changes -
          Status Open [ 1 ] In Progress [ 3 ]

          commit 58e8db2eb398a812e2894d28db4173a4f67fea06
          Author: Jan Lindström <jan.lindstrom@mariadb.com>
          Date: Mon May 11 14:29:14 2015 +0300

          MDEV-7942: InnoDB: abuse of UNIV_LIKELY()/UNIV_UNLIKELY()

          UNIV_LIKELY()/UNIV_UNLIKELY() hints are supposed to improve branch prediction.
          Currently, they're expected to work only if cond evaluates to TRUE or FALSE.

          However there're a few conditions that may evaluate to different values, e.g.:

          page/page0zip.cc: if (UNIV_LIKELY(c_stream->avail_in)) {
          page/page0zip.cc: if (UNIV_LIKELY(c_stream->avail_in)) {
          dict/dict0mem.cc: if (UNIV_LIKELY && UNIV_UNLIKELY(!table->col_names)) {

          Fixed these conditions so that they evaluate TRUE/FALSE.

          jplindst Jan Lindström (Inactive) added a comment - commit 58e8db2eb398a812e2894d28db4173a4f67fea06 Author: Jan Lindström <jan.lindstrom@mariadb.com> Date: Mon May 11 14:29:14 2015 +0300 MDEV-7942 : InnoDB: abuse of UNIV_LIKELY()/UNIV_UNLIKELY() UNIV_LIKELY()/UNIV_UNLIKELY() hints are supposed to improve branch prediction. Currently, they're expected to work only if cond evaluates to TRUE or FALSE. However there're a few conditions that may evaluate to different values, e.g.: page/page0zip.cc: if (UNIV_LIKELY(c_stream->avail_in)) { page/page0zip.cc: if (UNIV_LIKELY(c_stream->avail_in)) { dict/dict0mem.cc: if (UNIV_LIKELY && UNIV_UNLIKELY(!table->col_names)) { Fixed these conditions so that they evaluate TRUE/FALSE.
          jplindst Jan Lindström (Inactive) made changes -
          Component/s Storage Engine - InnoDB [ 10129 ]
          Component/s Storage Engine - XtraDB [ 10135 ]
          Fix Version/s 10.1.5 [ 18813 ]
          Fix Version/s 10.1 [ 16100 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 60397 ] MariaDB v3 [ 63402 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 63402 ] MariaDB v4 [ 149025 ]

          People

            jplindst Jan Lindström (Inactive)
            svoj Sergey Vojtovich
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.