Re: Tickless operation during idle

2016-04-12 Thread Neel Natu
Hi,

Sterling asked me to go into a bit of detail about the implementation so
here goes:

When the idle task is running it is an indication that there isn't any
useful

work to be done at this time.


Useful work can be created by:

1. an interrupt requesting service OR

2. when tasks scheduled in the future are now runnable.


With respect to (1) there isn't any way for the OS to know when an interrupt

might be activated. However with respect to (2) the OS certainly knows how

long until a particular task awakens or how long until a callout handler

needs to run.


The APIs 'os_sched_wakeup_ticks()' and 'os_callout_wakeup_ticks()' return

the number of ticks until the earliest task or callout become active. These

APIs are used by 'os_idle_task()' to determine whether to transition from

periodic to tickless mode. The OS will transition to tickless mode if there

is no useful work for at least 100 msec (arbitrary). The idle task also

imposes a limit on how long the cpu remains in tickless mode (currently set

to 10 minutes, also arbitrary).


The transition to/from tickless mode is done by the MCU-specific function

'os_tick_idle(idleticks)'. Typically it will set up a one-shot timer to wake

up the CPU after a duration equivalent to 'idleticks' has elapsed. Finally,

it enters a low power idle state using a CPU-specific mechanism. For e.g.

ARM processors use the 'WFI' instruction for this purpose.


Note that 'os_tick_idle()' is an advisory API:

- it may return immediately without doing anything

- it may not transition into tickless mode

- it may transition to tickless mode but return before 'idleticks' have
elapsed


The only guarantee made by 'os_tick_idle()' is that it will sleep for no
more

than 'idleticks' and that the OS time is up-to-date when it returns.


A related change is to define 'OS_TICKS_PER_SEC' in MCU-specific header
file.

This is needed because the capabilities of the underlying periodic timer

dictate the appropriate timer frequency.


best

Neel

On Thu, Apr 7, 2016 at 1:59 PM, Neel Natu <n...@nahannisys.com> wrote:

> Hi,
>
> I just opened a pull request that implements tickless operation during
> idle:
> https://github.com/apache/incubator-mynewt-core/pull/34
>
> The motivation is to reduce power consumption by putting the CPU to sleep
> when the OS does not have any useful work to do. At the moment the power
> saving only extends to the CPU but hopefully this provides a foundation to
> add off-cpu peripherals and i/o going forward.
>
> If you have any comments let me know and we can iterate on the patch.
>
> best
> Neel
>


Pull request: fix building and running 'sim' on Linux

2016-03-10 Thread Neel Natu
Hi,

I have opened a pull request against 'incubator-mynewt-core/develop'. This
is a set of 4 commits that fix building and running 'sim' on Linux (Ubuntu
14.04 specifically).

I did this with the "legacy" newt tool and after copying
'compiler/sim/linux-compiler.yml' to 'compiler/sim/pkg.yml'.

Pull request is at: https://github.com/apache/incubator-mynewt-core/pull/16

Please review and let me know if there are any issues need to be fixed
before merging.

best
Neel


Pull request #11

2016-03-04 Thread Neel Natu
Hi,

I just created a pull request for a couple of changes:
https://github.com/apache/incubator-mynewt-larva/pull/11

0796ef2

:
Support building "sim" with compiler optimization greater than -O0. This is
interesting because the compiler actually emits useful warnings at higher
levels.

fb3520e

:
Fix a benign race in os_sched() where the task that is run next may not be
the highest priority runnable task.

Let me know if there are any comments and I'll be happy to iterate on the
changes.

best
Neel


Introduction and first contribution

2016-03-03 Thread Neel Natu
Hi,

My name is Neel Natu and I recently started hacking on Apache Mynewt. I
have been lurking on the dev list, digesting the documentation, making
simple changes to the OS etc and its been a pleasant experience thus far.

My first contribution is adding wallclock time support to Mynewt:
https://github.com/apache/incubator-mynewt-larva/pull/8

Let me know if there are any concerns with the design or coding style and I
can iterate on it.

If not, then please commit :-)

best
Neel