linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Latypov <dlatypov@google.com>
To: David Gow <davidgow@google.com>
Cc: Brendan Higgins <brendan.higgins@linux.dev>,
	Shuah Khan <skhan@linuxfoundation.org>,
	kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	linux-doc@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v3 1/3] kunit: Provide a static key to check if KUnit is actively running tests
Date: Mon, 21 Nov 2022 17:31:03 -0800	[thread overview]
Message-ID: <CAGS_qxqyyH-v4wMJyD1phPP2YA5_6L98C-t4cJtt_SYsSvR3Ag@mail.gmail.com> (raw)
In-Reply-To: <20221119081252.3864249-1-davidgow@google.com>

On Sat, Nov 19, 2022 at 12:13 AM David Gow <davidgow@google.com> wrote:
>
> KUnit does a few expensive things when enabled. This hasn't been a
> problem because KUnit was only enabled on test kernels, but with a few
> people enabling (but not _using_) KUnit on production systems, we need a
> runtime way of handling this.
>
> Provide a 'kunit_running' static key (defaulting to false), which allows
> us to hide any KUnit code behind a static branch. This should reduce the
> performance impact (on other code) of having KUnit enabled to a single
> NOP when no tests are running.
>
> Note that, while it looks unintuitive, tests always run entirely within
> __kunit_test_suites_init(), so it's safe to decrement the static key at
> the end of this function, rather than in __kunit_test_suites_exit(),
> which is only there to clean up results in debugfs.
>
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Daniel Latypov <dlatypov@google.com>

I didn't know anything about the static key support in the kernel
before this patch.
But from what I read and saw of other uses, this looks good to me.

One small question/nit about how we declare the key below.

<snip>

> +/* Static key: true if any KUnit tests are currently running */
> +extern struct static_key_false kunit_running;

Is there any documented preference between this and
  DECLARE_STATIC_KEY_FALSE(kunit_running);
?

I see 89 instances of this macro and 45 of `extern struct static_key_false`.
So I'd vote for the macro since it seems like the newer approach and
more common.

Daniel

  parent reply	other threads:[~2022-11-22  1:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-19  8:12 [PATCH v3 1/3] kunit: Provide a static key to check if KUnit is actively running tests David Gow
2022-11-19  8:12 ` [PATCH v3 2/3] kunit: Use the static key when retrieving the current test David Gow
2022-11-22  2:21   ` Daniel Latypov
2022-11-22  3:16     ` David Gow
2022-11-23 16:59       ` Daniel Latypov
2022-11-23 15:48   ` Sadiya Kazi
2022-11-19  8:12 ` [PATCH v3 3/3] mm: slub: test: Use the kunit_get_current_test() function David Gow
2022-11-24 10:43   ` Hyeonggon Yoo
2022-11-25  8:33     ` David Gow
2022-11-22  1:31 ` Daniel Latypov [this message]
2022-11-22  2:33   ` [PATCH v3 1/3] kunit: Provide a static key to check if KUnit is actively running tests David Gow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGS_qxqyyH-v4wMJyD1phPP2YA5_6L98C-t4cJtt_SYsSvR3Ag@mail.gmail.com \
    --to=dlatypov@google.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).