Skip to content

Conversation

@cvinayak
Copy link
Contributor

@cvinayak cvinayak commented Jan 9, 2019

This Pull Request introduces a new, improved Link Layer based on the concept of split responsibilities:

  • The Upper Link Layer (ULL) is in charge of control procedures, inter-event scheduling and overal role management. The code for the ULL is shared among all hardware implementations.
  • The Lower Link Layer (LLL) is responsible for the intra-event scheduling and radio access.

The communication between ULL and LLL is achieved through a set of FIFOs that contain both control and data packets.

@zephyrbot
Copy link

zephyrbot commented Jan 9, 2019

All checks are passing now.

Review history of this comment for details about previous failed status.
Note that some checks might have not completed yet.

@codecov-io
Copy link

codecov-io commented Jan 9, 2019

Codecov Report

Merging #12404 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #12404   +/-   ##
=======================================
  Coverage   53.94%   53.94%           
=======================================
  Files         242      242           
  Lines       27654    27654           
  Branches     6717     6717           
=======================================
  Hits        14917    14917           
  Misses       9932     9932           
  Partials     2805     2805

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99aadec...e5d23a2. Read the comment docs.

Copy link
Member

Choose a reason for hiding this comment

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

Are those printk staatements intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tmp was a template role, this I will remove as part of the rework, this should not be part of the merge into master.

@aescolar aescolar requested review from mtpr-ot and thoh-ot January 10, 2019 11:46
Copy link
Member

Choose a reason for hiding this comment

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

If you are using this only to store ring buffers of pointers, then you could simplify by:
void* m[(cnt) + 1]; and get rid of s and sz altogether.

Copy link
Member

Choose a reason for hiding this comment

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

This would also get rid of all the multiplications in the getters/setters

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 will take relook at this implementation once I resolve all the checkpatch issues.

Copy link
Member

Choose a reason for hiding this comment

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

If you need to support non-pointer mfifos then this should be a memcpy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree.

Copy link
Member

Choose a reason for hiding this comment

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

This file needs comments on each function explaining what they do.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've documented this in #12167

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that #12167 was spun out of https://github.com/NordicPlayground/zephyr-bt/pull/26 as that was the intersection between non-split and split stack.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you @mped-oticon, that is a great effort. A while back I added the memq_link_t in order to make the code more readable, and with your comments this closes the circle.

Copy link
Member

Choose a reason for hiding this comment

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

I've documented this in #12167

That PR doesn't include mfifo but you have another branch for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me why we need a different fifo/list implementation?

Copy link
Member

@carlescufi carlescufi Jan 22, 2019

Choose a reason for hiding this comment

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

For 3 reasons:

  1. Memory efficiency and code size
  2. Latency: this is lockless unlike the kernel's FIFOs, never disables interrupts
  3. Independence from the kernel. This is only used on interrupt context, should never block or use kernel primitives

In essence this is a custom-made, highly efficient, lockless implementation for the specific purpose of exchanging data among different interrupt contexts.

Copy link
Member

Choose a reason for hiding this comment

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

This will only work with void* MFIFOs

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. I've written about this in the documentation. See prev comment.

Copy link
Member

Choose a reason for hiding this comment

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

This will only work with void* MFIFOs

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
Member

Choose a reason for hiding this comment

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

Oh nice! Will you submit this after we merge this PR?

Copy link
Member

@carlescufi carlescufi Jan 10, 2019

Choose a reason for hiding this comment

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

The problem I see with these is that the registers are typically loaded first, and then the comparison is executed:

                if (conn->llcp_req != conn->llcp_ack) {
   13916:       f890 30d0       ldrb.w  r3, [r0, #208]  ; 0xd0
   1391a:       f890 20d1       ldrb.w  r2, [r0, #209]  ; 0xd1
   1391e:       429a            cmp     r2, r3

Which means that if you get interrupted between 1391a and 1391e you will be comparing a stale value.

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 will add a commit to this PR to handle context-safety of the control procedures.

@cvinayak cvinayak changed the title Bluetooth: controller: Introduce ULL LLL architecture DNM: Bluetooth: controller: Introduce ULL LLL architecture Jan 10, 2019
@cvinayak cvinayak added the DNM This PR should not be merged (Do Not Merge) label Jan 10, 2019
@cvinayak cvinayak force-pushed the github_ull_lll branch 3 times, most recently from 444603c to 8dac0b5 Compare January 14, 2019 10:26
Copy link
Member

@carlescufi carlescufi Jan 14, 2019

Choose a reason for hiding this comment

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

On Armv7-M this would be better served by using atomic_cas() is my opinion. I am not sure about other architectures (ping @mped-oticon and @aescolar) but on Armv7-M atomic_cas() uses CONFIG_ATOMIC_OPERATIONS_BUILTIN which then uses the builtin __atomic_compare_exchange_n. This translates into the assembly below, which in my opinion is going to be smaller in size than your code once assembled.
Note that on Armv6-M atomic_cas() disables interrupts and so there you will need the software implementation you have here.

        return __atomic_compare_exchange_n(target, &old_value, new_value,
     4d4:       4b17            ldr     r3, [pc, #92]   ; (534 <bt_ready+0x74>)
     4d6:       9403            str     r4, [sp, #12]
     4d8:       2104            movs    r1, #4
     4da:       f3bf 8f5b       dmb     ish
     4de:       e853 2f00       ldrex   r2, [r3]
     4e2:       42a2            cmp     r2, r4
     4e4:       d103            bne.n   4ee <bt_ready+0x2e>
     4e6:       e843 1000       strex   r0, r1, [r3]
     4ea:       2800            cmp     r0, #0
     4ec:       d1f7            bne.n   4de <bt_ready+0x1e>

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Oticon's mcu does not have atomic_cas.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the value is incremented, should we use atomic_inc(&conn->llcp_req) ?

Copy link
Contributor

@mped-oticon mped-oticon left a comment

Choose a reason for hiding this comment

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

Remove DNM?

Copy link
Contributor

@thoh-ot thoh-ot left a comment

Choose a reason for hiding this comment

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

QACK

@cvinayak
Copy link
Contributor Author

@mped-oticon focusing on the CI failures, once its resolved I will remove the DNM

@cvinayak cvinayak force-pushed the github_ull_lll branch 2 times, most recently from 207156d to 5a24a68 Compare January 21, 2019 11:01
Copy link
Member

Choose a reason for hiding this comment

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

All header guards in Zephyr were recently changed to be constructed out of the full path. This file's should then be ZEPHYR_SUBSYS_BLUETOOTH_SHELL_HCI_H_

Copy link
Member

Choose a reason for hiding this comment

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

Actually, does this file even need a guard? Isn't it completely internal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree will remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Is it appropriate for a shell module to use printk? Isn't the recommendation to use the shell's own output APIs?

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 is an oversight, will fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is some many duplicates of this logic bellow, can't we make a helper function to check llcp_req against llcp_ack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Can we agree to create an issue and assign it to me? This is mentioned by @carlescufi to evaluate the use of atomic_CAS instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem, lets have it separately with use of atomic as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. Can we agree to create an issue and assign it to me? This is mentioned by @carlescufi to evaluate the use of atomic_CAS instead.

Note: Oticon's mcu does not have atomic_cas.
Otherwise, fully agree about helper function or macro.

Copy link
Member

Choose a reason for hiding this comment

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

shell_print() should not have a line terminator, so the \n needs to be removed

Copy link
Member

Choose a reason for hiding this comment

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

same here

@cvinayak cvinayak changed the title DNM: Bluetooth: controller: Introduce ULL LLL architecture Bluetooth: controller: Introduce ULL LLL architecture Jan 22, 2019
@cvinayak cvinayak removed the DNM This PR should not be merged (Do Not Merge) label Jan 22, 2019
Refactored the internal LL interfaces to have return value
to match the HCI error code u8_t data type.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Missing updates to old architecture implementation towards
introduction of new ULL LLL architecture.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Preliminary work done towards Mesh extensions on the old LL
architecture implementation.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Updates related to new ULL LLL controller architecture.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
This is a squash merge of commits introducing the new split
Upper Link Layer and Lower Link Layer architecture of the
Bluetooth Low Energy controller.

This introduces a new, improved Link Layer based on the
concept of split responsibilities; The Upper Link Layer
(ULL) is in charge of control procedures, inter-event
scheduling and overall role management. The code for the
ULL is shared among all hardware implementations. The
Lower Link Layer (LLL) is responsible for the intra-event
scheduling and vendor specific radio hardware access.

The communication between ULL and LLL is achieved through
a set of FIFOs that contain both control and data packets.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Signed-off-by: Alberto Escolar Piedras <[email protected]>
Signed-off-by: Wolfgang Puffitsch <[email protected]>
Signed-off-by: Morten Priess <[email protected]>
Fix the control procedure context safety by adding checks in
thread mode control path to detect pre-emption by interrupt.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
@carlescufi carlescufi merged commit 5478e82 into zephyrproject-rtos:master Jan 23, 2019
@carlescufi carlescufi mentioned this pull request Jan 24, 2019
6 tasks
@carlescufi carlescufi mentioned this pull request Mar 17, 2019
10 tasks
@cvinayak cvinayak deleted the github_ull_lll branch March 1, 2021 00:43
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.