* [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression @ 2025-07-01 13:18 Ahmad Fatoum 2025-07-01 13:18 ` [PATCH 2/2] console: fix loose coupling between getchar and is_timeout delays Ahmad Fatoum 2025-07-02 6:35 ` [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression Sascha Hauer 0 siblings, 2 replies; 3+ messages in thread From: Ahmad Fatoum @ 2025-07-01 13:18 UTC (permalink / raw) To: barebox; +Cc: Ahmad Fatoum This makes the constants potentially usable in more places than before. While at it, move the definitions to the start of the header to make them usable within. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- include/clock.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/clock.h b/include/clock.h index e28870b1e84b..db20877571a4 100644 --- a/include/clock.h +++ b/include/clock.h @@ -6,6 +6,12 @@ #include <linux/time.h> #include <linux/bitops.h> +#define SECOND (1000ULL * 1000 * 1000) +#define MSECOND (1000ULL * 1000) +#define USECOND (1000ULL) + +#define HZ SECOND + #define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0) struct clocksource { @@ -51,12 +57,6 @@ static inline void clocksource_srand(void) } #endif -#define SECOND ((uint64_t)(1000 * 1000 * 1000)) -#define MSECOND ((uint64_t)(1000 * 1000)) -#define USECOND ((uint64_t)(1000)) - -#define HZ SECOND - extern uint64_t time_beginning; /* -- 2.39.5 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] console: fix loose coupling between getchar and is_timeout delays 2025-07-01 13:18 [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression Ahmad Fatoum @ 2025-07-01 13:18 ` Ahmad Fatoum 2025-07-02 6:35 ` [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression Sascha Hauer 1 sibling, 0 replies; 3+ messages in thread From: Ahmad Fatoum @ 2025-07-01 13:18 UTC (permalink / raw) To: barebox; +Cc: Ahmad Fatoum We always want to run pollers while waiting in getchar(). This is already the case, because the delay chosen in getchar is the minimum scheduling delay used in is_timeout. To make the relation more obvious, define a constant for the minimum scheduling delay and use it at both places. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- common/clock.c | 2 +- common/console.c | 4 ++-- include/clock.h | 9 +++++++++ include/linux/minmax.h | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/clock.c b/common/clock.c index 931a96865140..87109f3efc2e 100644 --- a/common/clock.c +++ b/common/clock.c @@ -169,7 +169,7 @@ int is_timeout(uint64_t start_ns, uint64_t time_offset_ns) { int ret = is_timeout_non_interruptible(start_ns, time_offset_ns); - if (time_offset_ns >= 100 * USECOND) + if (time_offset_ns >= SCHED_TIMEOUT_MIN) resched(); return ret; diff --git a/common/console.c b/common/console.c index 24f1500a6558..393183a72514 100644 --- a/common/console.c +++ b/common/console.c @@ -548,8 +548,8 @@ int getchar(void) start = get_time_ns(); } - if (is_timeout(start, 100 * USECOND) && - kfifo_len(console_input_fifo)) + if (is_timeout_interruptible(start, 100 * USECOND) && + kfifo_len(console_input_fifo)) break; } diff --git a/include/clock.h b/include/clock.h index db20877571a4..ca69535e9185 100644 --- a/include/clock.h +++ b/include/clock.h @@ -4,6 +4,7 @@ #include <types.h> #include <linux/time.h> +#include <linux/minmax.h> #include <linux/bitops.h> #define SECOND (1000ULL * 1000 * 1000) @@ -42,6 +43,14 @@ uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant); int is_timeout(uint64_t start_ns, uint64_t time_offset_ns); int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns); +#define SCHED_TIMEOUT_MIN (100 * USECOND) + +static inline int is_timeout_interruptible(uint64_t start_ns, + uint64_t time_offset_ns) +{ + return is_timeout(start_ns, max(SCHED_TIMEOUT_MIN, time_offset_ns)); +} + void arm_architected_timer_udelay(unsigned long us); void ndelay(unsigned long nsecs); diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 9b6ddad7b3f6..8c114029d23a 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MINMAX_H #define _LINUX_MINMAX_H +#include <linux/compiler.h> #include <linux/const.h> /* -- 2.39.5 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression 2025-07-01 13:18 [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression Ahmad Fatoum 2025-07-01 13:18 ` [PATCH 2/2] console: fix loose coupling between getchar and is_timeout delays Ahmad Fatoum @ 2025-07-02 6:35 ` Sascha Hauer 1 sibling, 0 replies; 3+ messages in thread From: Sascha Hauer @ 2025-07-02 6:35 UTC (permalink / raw) To: barebox, Ahmad Fatoum On Tue, 01 Jul 2025 15:18:01 +0200, Ahmad Fatoum wrote: > This makes the constants potentially usable in more places than before. > > While at it, move the definitions to the start of the header to make them > usable within. > > Applied, thanks! [1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression https://git.pengutronix.de/cgit/barebox/commit/?id=c5263b57ae3b (link may not be stable) [2/2] console: fix loose coupling between getchar and is_timeout delays https://git.pengutronix.de/cgit/barebox/commit/?id=25eb5d04442a (link may not be stable) Best regards, -- Sascha Hauer <s.hauer@pengutronix.de> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-02 7:51 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-07-01 13:18 [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression Ahmad Fatoum 2025-07-01 13:18 ` [PATCH 2/2] console: fix loose coupling between getchar and is_timeout delays Ahmad Fatoum 2025-07-02 6:35 ` [PATCH 1/2] clock: make SECOND/MSECOND/USECOND constants a constant expression Sascha Hauer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox