All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Frank Oltmanns <frank@oltmanns.dev>
Cc: Michael Turquette <mturquette@baylibre.com>,
	A.s. Dong <aisheng.dong@nxp.com>, Abel Vesa <abelvesa@kernel.org>,
	Fabio Estevam <festevam@gmail.com>,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org, NXP Linux Team <linux-imx@nxp.com>,
	Peng Fan <peng.fan@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>
Subject: Re: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
Date: Wed, 14 Jun 2023 13:42:00 -0700	[thread overview]
Message-ID: <a74bc17b757fff3dea0139ffb43edffc.sboyd@kernel.org> (raw)
In-Reply-To: <87pm5yzgcr.fsf@oltmanns.dev>

Quoting Frank Oltmanns (2023-06-13 23:51:32)
> Hi Stephen,
> 
> Thank you for your feedback.
> 
> On 2023-06-13 at 12:42:05 -0700, Stephen Boyd <sboyd@kernel.org> wrote:
> > Quoting Frank Oltmanns (2023-06-13 01:36:26)
> >> In light of the recent discovery that the fractional divisor
> >> approximation does not utilize the full available range for clocks that
> >> are flagged CLK_FRAC_DIVIDER_ZERO_BASED, implement tests for the edge
> >> cases of this clock type.
> >>
> >> Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
> >> Link: https://lore.kernel.org/lkml/20230529133433.56215-1-frank@oltmanns.dev
> >
> > What is the link for?
> 
> The intention was to show why the tests were added ("In light of the
> recent discovery..."). I announced this discovery in the mail I referred
> to. Since that intention didn't come across: Should I drop the link?

Ok. You can say that and reference the link with [1] like this.

Link: https://lore.kernel.org/lkml/20230529133433.56215-1-frank@oltmanns.dev [1]

> 
> >
> >> ---
> >>  drivers/clk/clk_test.c | 69 +++++++++++++++++++++++++++++++++++++++++-
> >
> > Please make a new file, drivers/clk/clk-fractional-divider_test.c
> > instead.
> >
> >>  1 file changed, 68 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
> >> index f9a5c2964c65..b247ba841cbd 100644
> >> --- a/drivers/clk/clk_test.c
> >> +++ b/drivers/clk/clk_test.c
> >> @@ -8,6 +8,9 @@
> >>  /* Needed for clk_hw_get_clk() */
> >>  #include "clk.h"
> >>
> >> +/* Needed for clk_fractional_divider_general_approximation */
> >> +#include "clk-fractional-divider.h"
> >> +
> >>  #include <kunit/test.h>
> >>
> >>  #define DUMMY_CLOCK_INIT_RATE  (42 * 1000 * 1000)
> >> @@ -2394,6 +2397,69 @@ static struct kunit_suite clk_mux_notifier_test_suite = {
> >>         .test_cases = clk_mux_notifier_test_cases,
> >>  };
> >>
> >> +
> >> +/*
> >> + * Test that clk_fractional_divider_general_approximation will work with the
> >> + * highest available numerator and denominator.
> >> + */
> >> +static void clk_fd_test_round_rate_max_mn(struct kunit *test)
> >> +{
> >> +       struct clk_fractional_divider *fd;
> >> +       struct clk_hw *hw;
> >> +       unsigned long rate, parent_rate, m, n;
> >> +
> >> +       fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
> >> +       KUNIT_ASSERT_NOT_NULL(test, fd);
> >> +
> >> +       fd->mwidth = 3;
> >> +       fd->nwidth = 3;
> >> +
> >> +       hw = &fd->hw;
> >> +
> >> +       rate = DUMMY_CLOCK_RATE_1;
> >> +
> >> +       // Highest denominator, no flags
> >
> > Use /* this for comments */
> >
> >> +       parent_rate = 10 * DUMMY_CLOCK_RATE_1;
> >
> > Just write out the actual frequency. Don't use DUMMY_CLOCK_RATE_1 at all
> > in the test.
> 
> Sure, will do. The idea was to highlight that we want to have the parent
> running at 10 times the speed, while the divider has a maximum value of
> 7 (or 8 if zero based).

Ok. In that case, have a local variable for 'rate' that's const and then
have

	parent_rate = 10 * rate;

to make it clear. We don't need a comment for that.

> 
> >
> >> +       clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
> >> +       KUNIT_EXPECT_EQ(test, m, 1);
> >> +       KUNIT_EXPECT_EQ(test, n, 7);
> >
> > This is a different test case.
> >
> >> +
> >> +       // Highest numerator, no flags
> >> +       parent_rate = DUMMY_CLOCK_RATE_1 / 10;
> >> +       clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
> >> +       KUNIT_EXPECT_EQ(test, m, 7);
> >
> > Is 7 related to mwidth? Maybe this should be clk_div_mask(fd->mwidth)
> > instead of 7.
> 
> Yes, 7 is related to mwidth. I thought about this too, but I'm not sure
> that's the best move here. The function under test uses:
>     max_m = GENMASK(fd->mwidth - 1, 0);
>     max_n = GENMASK(fd->nwidth - 1, 0);
> 
> I come from a safety-concerned industry and as a general rule we avoid
> using functions from the code under test in our tests.

GENMASK is a macro, not a function. Does that help? In all seriousness
though, I understand not wanting to test code with the same code. This
is basic math though. Maybe it should be something like this?

	const unsigned long max_m = 8;
	const unsigned long max_n = 8;

	fd->mwidth = bits_per(max_m);
	fd->nwidth = bits_per(max_n);

This expresses that there's a maximum m and n value and we calculate the
width from that information. Then the test can expect to see that max
value come out.

> I'm doing this
> here as a hobby, but still I find it to be a good rule that I'd like to
> stick to unless asked otherwise.

Cool.

> 
> If I use the same code to generate the expected values, I'm not really
> testing my change, but only the underlying best_rational_approximation.
> 
> Instead, how about I add a comment to the test function that more
> thoroughly explains its intention?

No thanks. We shouldn't need more than a sentence indicating what the
test is testing

> 
> Something along those lines:
> 
>     /*
>      * Introduce a parent that runs at 10 times the frequency of the
>      * requested rate.
>      * m and n are 3 bits wide each.
>      * The clock has no flags set, hence the maximum value that fits in
>      * m and n is 7.
>      * Therefore, expect the highest possible divisor.
>      */
>     static void clk_fd_test_round_rate_max_m(struct kunit *test)

I'd just indicate the expected outcome in the function name.

	clk_fd_test_general_approximation_m_saturates()

and then it could be parameterized with KUNIT_ARRAY_PARAM() so that we
make sure any width saturates.

> 
>     /*
>      * Introduce a parent that runs at 1/10th the frequency of the

I'm not sure where 10 times and 1/10th came from. Is it just a magnitude
larger for simplicity?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2023-06-14 20:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13  8:36 [PATCH v2 0/2] clk: fractional-divider: Improve approximation when zero based Frank Oltmanns
2023-06-13  8:36 ` Frank Oltmanns
2023-06-13  8:36 ` [PATCH v2 1/2] " Frank Oltmanns
2023-06-13  8:36   ` Frank Oltmanns
2023-06-13  8:36 ` [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation Frank Oltmanns
2023-06-13  8:36   ` Frank Oltmanns
2023-06-13  8:49   ` Frank Oltmanns
2023-06-13  8:49     ` Frank Oltmanns
2023-06-13 12:48   ` kernel test robot
2023-06-13 12:48     ` kernel test robot
2023-06-14  8:19     ` Frank Oltmanns
2023-06-14  8:19       ` Frank Oltmanns
2023-06-14 20:02       ` Stephen Boyd
2023-06-14 20:02         ` Stephen Boyd
2023-06-15  5:16         ` Frank Oltmanns
2023-06-15  5:16           ` Frank Oltmanns
2023-06-16 19:33           ` Stephen Boyd
2023-06-16 19:33             ` Stephen Boyd
2023-06-17 16:47             ` Frank Oltmanns
2023-06-17 16:47               ` Frank Oltmanns
2023-06-13 19:42   ` Stephen Boyd
2023-06-14  6:51     ` Frank Oltmanns
2023-06-14  6:51       ` Frank Oltmanns
2023-06-14 20:42       ` Stephen Boyd [this message]

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=a74bc17b757fff3dea0139ffb43edffc.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=abelvesa@kernel.org \
    --cc=aisheng.dong@nxp.com \
    --cc=festevam@gmail.com \
    --cc=frank@oltmanns.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=peng.fan@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.