* [PATCH 2/3] led: core: Initialize blink_next_event with 0
2018-12-07 7:30 [PATCH 1/3] led: core: Don't call get_time_us() twice Andrey Smirnov
@ 2018-12-07 7:30 ` Andrey Smirnov
2018-12-07 7:30 ` [PATCH 3/3] led: core: Make use of ARRAY_AND_SIZE Andrey Smirnov
2018-12-10 8:54 ` [PATCH 1/3] led: core: Don't call get_time_us() twice Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Andrey Smirnov @ 2018-12-07 7:30 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
A simpler way to make pattern to trigger immediately is to initialize
blink_next_event to 0 instead of current time value. Save a function
call and convert the code to do just that.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/led/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/led/core.c b/drivers/led/core.c
index f11504ace..34c514be8 100644
--- a/drivers/led/core.c
+++ b/drivers/led/core.c
@@ -177,7 +177,7 @@ int led_blink_pattern(struct led *led, const unsigned int *pattern,
pattern_len * sizeof(*led->blink_states));
led->blink_nr_states = pattern_len;
led->blink_next_state = 0;
- led->blink_next_event = get_time_ns();
+ led->blink_next_event = 0;
led->blink = 1;
led->flash = 0;
--
2.19.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] led: core: Make use of ARRAY_AND_SIZE
2018-12-07 7:30 [PATCH 1/3] led: core: Don't call get_time_us() twice Andrey Smirnov
2018-12-07 7:30 ` [PATCH 2/3] led: core: Initialize blink_next_event with 0 Andrey Smirnov
@ 2018-12-07 7:30 ` Andrey Smirnov
2018-12-10 8:54 ` [PATCH 1/3] led: core: Don't call get_time_us() twice Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Andrey Smirnov @ 2018-12-07 7:30 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/led/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/led/core.c b/drivers/led/core.c
index 34c514be8..431966d06 100644
--- a/drivers/led/core.c
+++ b/drivers/led/core.c
@@ -188,7 +188,7 @@ int led_blink(struct led *led, unsigned int on_ms, unsigned int off_ms)
{
unsigned int pattern[] = {on_ms, off_ms};
- return led_blink_pattern(led, pattern, 2);
+ return led_blink_pattern(led, ARRAY_AND_SIZE(pattern));
}
int led_flash(struct led *led, unsigned int duration_ms)
@@ -196,7 +196,7 @@ int led_flash(struct led *led, unsigned int duration_ms)
unsigned int pattern[] = {duration_ms, 0};
int ret;
- ret = led_blink_pattern(led, pattern, 2);
+ ret = led_blink_pattern(led, ARRAY_AND_SIZE(pattern));
if (ret)
return ret;
--
2.19.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] led: core: Don't call get_time_us() twice
2018-12-07 7:30 [PATCH 1/3] led: core: Don't call get_time_us() twice Andrey Smirnov
2018-12-07 7:30 ` [PATCH 2/3] led: core: Initialize blink_next_event with 0 Andrey Smirnov
2018-12-07 7:30 ` [PATCH 3/3] led: core: Make use of ARRAY_AND_SIZE Andrey Smirnov
@ 2018-12-10 8:54 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-12-10 8:54 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
On Thu, Dec 06, 2018 at 11:30:57PM -0800, Andrey Smirnov wrote:
> The code doesn't seem to be time-sensitive enough to warrant calling
> get_time_ns() twice instead of caching its value and using it no both
> places.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> drivers/led/core.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/led/core.c b/drivers/led/core.c
> index a388e6b36..f11504ace 100644
> --- a/drivers/led/core.c
> +++ b/drivers/led/core.c
> @@ -127,12 +127,13 @@ static void led_blink_func(struct poller_struct *poller)
> struct led *led;
>
> list_for_each_entry(led, &leds, list) {
> + const uint64_t now = get_time_ns();
> int on;
>
> if (!led->blink && !led->flash)
> continue;
>
> - if (led->blink_next_event > get_time_ns()) {
> + if (led->blink_next_event > now) {
> continue;
> }
>
> @@ -140,7 +141,7 @@ static void led_blink_func(struct poller_struct *poller)
> if (on)
> on = led->max_value;
>
> - led->blink_next_event = get_time_ns() +
> + led->blink_next_event = now +
> (led->blink_states[led->blink_next_state] * MSECOND);
> led->blink_next_state = (led->blink_next_state + 1) %
> led->blink_nr_states;
> --
> 2.19.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread