Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial review of the V1.0 book text. #618

Closed
wants to merge 0 commits into from

Conversation

jvanderk
Copy link
Contributor

@jvanderk jvanderk commented Feb 20, 2022

Editorial change proposals for V1.0 book text, English version only.

Copy link
Contributor

@AfoHT AfoHT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to go through this!

I've commented on some of the smaller things, need to further study the part you've added to internal docs.

A hint, for example in the case where you had duplicate "the", you can push more commits to this branch which will update the Pull Request accordingly 👍

`bare_metal::CriticalSection` token is available as `cs`) while device specific peripherals are available through
the `core` and `device` fields of `init::Context`.
The `init` task executes after system reset (after an optionally defined `pre-init` task/code section(?)
and always occurring internal RTIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe even linking to pre_init?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand the suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I interpreted the (?) after "task/code section(?)" as seeking clarification / sources, my thought was that the link could be useful here, the link in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear, added suggestion to text. Please check, never used that syntax.

book/en/src/by-example/app_priorities.md Outdated Show resolved Hide resolved
Any available interrupt vector should work, but different hardware might have
added special properties to select interrupt priority levels, such as the
Any available interrupt vector should work. Specific devices may
allow selection of interrupt priority level, such as the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allow selection of interrupt priority level, such as the
assume internal use of some interrupt priority levels, such as the

Other suggestions welcome, but the main idea is that the user can't take any level as it is already being used by some other hardware component of that specific hardware.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not clear to me what the message of the original text was. "added properties to select ... priority" -> "to allow selection of" was intended to mean the same and break the original sentence in distinct statements. Reading your comment I would word this possibly as "Specific hardware may bind specific interrupt priorities to specific interrupt vectors outside user code control." Or something like that...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not clear to me what the message of the original text was. "added properties to select ... priority" -> "to allow selection of" was intended to mean the same and break the original sentence in distinct statements. Reading your comment I would word this possibly as "Specific hardware may bind specific interrupt priorities to specific interrupt vectors outside user code control." Or something like that...

^ Sounds good 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended text.

book/en/src/by-example/monotonic.md Outdated Show resolved Hide resolved
book/en/src/SUMMARY.md Outdated Show resolved Hide resolved
book/en/src/by-example/hardware_tasks.md Outdated Show resolved Hide resolved
book/en/src/by-example/monotonic.md Outdated Show resolved Hide resolved
book/en/src/by-example/tips_indirection.md Outdated Show resolved Hide resolved
book/en/src/internals/conceptual_view.md Outdated Show resolved Hide resolved
@@ -4,7 +4,7 @@

The `priority` argument declares the static priority of each `task`.

For Cortex-M, tasks can have priorities in the range `1..=(1 << NVIC_PRIO_BITS)`
For Cortex-M, tasks can have priorities in the range `1..(1 << NVIC_PRIO_BITS)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Rust, ..= indicates it is an inclusive range

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly that is intentional, we can provide one more priority level by disabling the interrupts globally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware of the rangeinclusive notation. Thx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you fixed it, but for me it still shows as modified and = is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@jvanderk jvanderk marked this pull request as draft February 21, 2022 21:16
@jvanderk
Copy link
Contributor Author

I'm struggling with magit---pushing commits to jvanderk/cortex-m-rtic, but I'm not sure they are visible in the pull request.

@jvanderk jvanderk marked this pull request as ready for review February 21, 2022 22:20
@jvanderk
Copy link
Contributor Author

jvanderk commented Mar 6, 2022

Please let me know if there are still open items.

I am working on getting vigilant mode working. Apologies for 'unverified' flags.

until task A completes execution. Thus, when task A completes task B resumes execution.

```text
Task Priority
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected.

Comment on lines 1 to 80
# Conceptual view

![Conceptual execution model](./conceptual_execution_model.png)

This tries to provide a high level view of how tasks are managed in
the RTIC context. It focuses on the execution flow.

At its core, RTIC leverages the NVIC subsystem of the machine to
enable time-deterministic control of code execution.

There are two queues to think about.

One queue is a software queue, which is a a set of FIFOs written in
code and managed by the RTIC framework. Individual FIFOs are
associated with different execution priority levels.

The other is a hardware-controlled queue maintained by the NVIC. If
there are two hardware interrupts pending, the highest priority code
will execute first: a "priority queue" at a hardware level.

The NVIC operates essentially independently of the CPU, outside of
the various masking and other registers that the CPU can use to ignore
specific interrupt sources.

(Are HW interrupts always of different priority? Does the HW maintain
memory of lower or same priority level interrupts to process them once
they become eligible?)

So, a hardware task initiated by and bound to a hardware interrupt is
controlled by the NVIC's queuing mechanism without direct involement
of the processor; a software-spawned task just gets put into the task
FIFO (at some priority level) for later execution whenever the current
execution priority level is low enough. If a hardware or software task
completes, RTIC checks the software queue for more tasks to run,
eventually completing all until the queue exhausts and the IDLE task
then takes over again.

The CPU's ability to set a "minimum priority level" of hardware
interrupts allows alignment of the software and hardware queues. This
masks hardware-level interrupts coming in while equal or higher
priority level software tasks are exectuting. It makes the NVIC keep
the hardware tasks interrupt pending until the software task ends (and
the CPU has lowered the minimum priority level of interrupt acceptance).

## Hardware queue: NVIC

There is a difference between a software-initiated context switch
(which is a function call in code) and an interrupt (NVIC) initiated
switch. When the NVIC generates an interrupt request, this physically
breaks the execution flow of the processor.

## Software queue: task dispatchers

The software queues are maintained by task dispatchers. They can be
thought of as "pre-wired" hardware tasks initiated by the NVIC.

Each task dispatcher keeps a queue of tasks which are ready to
execute; this queue is referred to as the ready queue. Spawning a
software task consists of adding an entry to this queue and pending
the interrupt that runs the corresponding task dispatcher. Each entry
in this queue contains a tag (enum) that identifies the task to
execute and a pointer to the message passed to the task.

You can think of the dispatchers as just calling the SW tasks as
functions.

The ready queue is a SPSC (Single Producer Single Consumer) lock-free
queue. The task dispatcher owns the consumer endpoint of the queue;
the producer endpoint is treated as a resource contended by the tasks
that can spawn other tasks. source: [Software tasks - Real-Time
Interrupt-driven
Concurrency](https://rtic.rs/0.5/book/en/internals/tasks.html).

## spawning

Any task may influence the execution context via the "spawn" API,
adding tasks to the queues for later execution.

The defined priority of the task spawned determines the queue it lands
in.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be best split out into a separate PR, as this is not part of the editorial review but entirely new content.

Included in this would be all the files added under internals

It would also simplify your work with git and tooling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I will try to remove these changes from this branch (not sure if that is correct terminology), open a new branch against the root of this branch and open a new pull request on that. Big adventure :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request should now only contain editorial changes. The conceptual model related text and graphics will be put into another pull request.

I am not sure if the history in this pull request will survive, if so if that is desirable or if that can be squashed out.

@jvanderk jvanderk marked this pull request as draft April 3, 2022 12:30
@jvanderk jvanderk changed the title Mostly editorial review of the V1.0 book text. Editorial review of the V1.0 book text. Apr 3, 2022
@jvanderk jvanderk marked this pull request as ready for review April 3, 2022 12:56
@burrbull
Copy link
Contributor

burrbull commented Apr 3, 2022

mdbook supports SVG. You don't need to convert it to PNG. Just cut margins.

![Conceptual execution model](./conceptual_execution_model.svg)

@jvanderk
Copy link
Contributor Author

jvanderk commented Apr 3, 2022

mdbook supports SVG. You don't need to convert it to PNG. Just cut margins.

![Conceptual execution model](./conceptual_execution_model.svg)

Made change and moved files to other pull request.

Copy link
Contributor

@AfoHT AfoHT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

A few questions, but really nice in general :)

@@ -29,6 +29,7 @@
- [v0.4.x to v0.5.x](./migration/migration_v4.md)
- [RTFM to RTIC](./migration/migration_rtic.md)
- [Under the hood](./internals.md)
- [Conceptual execution model](./internals/conceptual_view.md)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go with the other PR :)

Comment on lines 41 to 43

(XXX would it be a good idea to add a section on code organization,
i.e. how to break a larger application into a set of files? XXX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above

At its core RTIC is using the hardware interrupt controller ([ARM NVIC on cortex-m][NVIC])
to perform scheduling and executing tasks, and all tasks except `#[init]` and `#[idle]`
At its core RTIC is using a hardware interrupt controller ([ARM NVIC on cortex-m][NVIC])
to schedule and start execution of tasks. All tasks except `pre-init`, `#[init]` and `#[idle]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want some kind of link for the somewhat special pre-init, not RTIC specific, but cortex-m-rt #[pre_init]?

https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.pre_init.html

@AfoHT AfoHT closed this May 18, 2022
@AfoHT AfoHT self-assigned this May 18, 2022
@AfoHT
Copy link
Contributor

AfoHT commented May 18, 2022

Forgot that GitHub doesn't like that kind of move, Gerrit influences from work I guess xD

Will look into this during the day...

@AfoHT AfoHT mentioned this pull request Jan 14, 2023
bors bot added a commit that referenced this pull request Jan 25, 2023
686: Book: Editorial review r=korken89 a=AfoHT

Continuation of #618

Better late than never...

A big thanks to `@jvanderk` !

Co-authored-by: John van der Koijk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants