mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <sw617.shin@samsung.com>
To: "'Sam Protsenko'" <semen.protsenko@linaro.org>
Cc: <krzk@kernel.org>, <alim.akhtar@samsung.com>,
	<wim@linux-watchdog.org>, <linux@roeck-us.net>,
	<khwan.seo@samsung.com>, <dongil01.park@samsung.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-samsung-soc@vger.kernel.org>,
	<linux-watchdog@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v4 2/4] watchdog: s3c2410_wdt: Fix max_timeout being calculated larger
Date: Tue, 5 Aug 2025 13:22:57 +0900	[thread overview]
Message-ID: <000a01dc05c0$9f0ab110$dd201330$@samsung.com> (raw)
In-Reply-To: <CAPLW+4nRh9DEnkhunG68xvGdaNJswC8fN4v4uBA1Aaao_5pxfw@mail.gmail.com>

On Saturday, August 2, 2025 at 1:12 PM Sam Protsenko <semen.protsenko@linaro.org> wrote:

> How about something like this instead?
> 
> 8<--------------------------------------------------------------------->8
> static inline unsigned int s3c2410wdt_max_timeout(unsigned long freq) {
>     const u64 div_max = (S3C2410_WTCON_PRESCALE_MAX + 1) *
>                 S3C2410_WTCON_MAXDIV; /* 32768 */
>     const u64 n_max = S3C2410_WTCNT_MAXCNT * div_max;
>     u64 t_max = n_max / freq;
> 
>     if (t_max > UINT_MAX)
>         t_max = UINT_MAX;
> 
>     return (unsigned int)t_max;
> }
> 8<--------------------------------------------------------------------->8
> 
> This implementation's result:
>   - is never greater than real timeout, as it loses the decimal part after
> integer division in t_max
>   - much closer to the real timeout value, as it benefits from very big
> n_max in the numerator (this is the main trick here)
>   - prepared for using 32-bit max counter value in your next patch, as it
> uses u64 type for calculations
> 
> For example, at the clock frequency of 33 kHz:
>   - real timeout is: 65074.269 sec
>   - old function returns: 65535 sec
>   - your function returns: 32767 sec
>   - the suggested function returns: 65074 sec

Thank you for your feedback.
I'll make the code changes as follows in the next patch set:

static inline unsigned int s3c2410wdt_max_timeout(struct s3c2410_wdt *wdt)
 {
        const unsigned long freq = s3c2410wdt_get_freq(wdt);
+       const u64 div_max = (S3C2410_WTCON_PRESCALE_MAX + 1) *
+                       S3C2410_WTCON_MAXDIV;
+       const u64 n_max = S3C2410_WTCNT_MAXCNT * div_max;
+       u64 t_max = n_max / freq;

-       return S3C2410_WTCNT_MAXCNT / (freq / (S3C2410_WTCON_PRESCALE_MAX + 1)
-                                      / S3C2410_WTCON_MAXDIV);
+       if (t_max > UINT_MAX)
+               t_max = UINT_MAX;
+
+       return (unsigned int)t_max;
 }


  reply	other threads:[~2025-08-05  4:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20250724081336epcas2p30ba9afd1e78d9bbb60f44d24d1cf0acb@epcas2p3.samsung.com>
2025-07-24  8:08 ` [PATCH v4 0/4] Increase max timeout value of s3c2410 watchdog Sangwook Shin
     [not found]   ` <CGME20250724081336epcas2p31c2e3cbed1d3a7bf30a9fb664e6cb92b@epcas2p3.samsung.com>
2025-07-24  8:08     ` [PATCH v4 1/4] watchdog: s3c2410_wdt: Replace hardcoded values with macro definitions Sangwook Shin
     [not found]   ` <CGME20250724081336epcas2p38e95932ddc5c702e05a6436f05582993@epcas2p3.samsung.com>
2025-07-24  8:08     ` [PATCH v4 2/4] watchdog: s3c2410_wdt: Fix max_timeout being calculated larger Sangwook Shin
2025-08-02  4:11       ` Sam Protsenko
2025-08-05  4:22         ` sw617.shin [this message]
2025-08-05  4:47           ` Guenter Roeck
2025-08-05  5:03             ` Sam Protsenko
2025-08-05  7:26               ` sw617.shin
2025-08-05 13:30                 ` Guenter Roeck
2025-08-05 22:53                 ` Sam Protsenko
2025-08-06  4:51                   ` sw617.shin
     [not found]   ` <CGME20250724081337epcas2p31f594b6e9ab87e24c94f11dea4070956@epcas2p3.samsung.com>
2025-07-24  8:08     ` [PATCH v4 3/4] watchdog: s3c2410_wdt: Increase max timeout value of watchdog Sangwook Shin
2025-08-02  4:36       ` Sam Protsenko
2025-08-05  4:23         ` sw617.shin
2025-08-05  4:51           ` Sam Protsenko
     [not found]   ` <CGME20250724081337epcas2p430db7d7514b8cc05e41001f17b8b0d45@epcas2p4.samsung.com>
2025-07-24  8:08     ` [PATCH v4 4/4] watchdog: s3c2410_wdt: exynosautov9: Enable supported features Sangwook Shin
2025-08-02  4:39       ` Sam Protsenko

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='000a01dc05c0$9f0ab110$dd201330$@samsung.com' \
    --to=sw617.shin@samsung.com \
    --cc=alim.akhtar@samsung.com \
    --cc=dongil01.park@samsung.com \
    --cc=khwan.seo@samsung.com \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=semen.protsenko@linaro.org \
    --cc=wim@linux-watchdog.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

all inboxes | Powered by JetHome®