Skip to content

Commit 8c569ed

Browse files
cvinayakAnas Nashif
authored andcommitted
Bluetooth: Controller: Run all enqueued mayfly before disable
Controller asserted in preparation of a role event due to the previous (same or another) role event preparation being not complete. Mayfly callee was disabled in the previous event due to the preparation time being short and previous start running (higher natural priority) before all previous preparation mayfly completed. The previous start disabled mayfly to avoid Radio ISR latencies. The current role event that asserted, preempted the previous role (observer role with continuous scanning window) which runs until preemption to maximise the Radio h/w use (observer scanning until next interval). The previous preparation mayfly is still disabled when the current role preparation tries to use same mayfly instance which should be free for a new enqueue. This commit updates mayfly implementation so that mayfly callee is disabled only after all enqueued mayfly instances are run to completion. Jira: ZEP-1839 Change-id: I3e0d31422db8e47b819189110b11ebd07dd09a7c Signed-off-by: Vinayak Chettimada <[email protected]>
1 parent 364087f commit 8c569ed

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

subsys/bluetooth/controller/hci/hci_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int bt_rand(void *buf, size_t len)
8484
return 0;
8585
}
8686

87-
void mayfly_enable(uint8_t caller_id, uint8_t callee_id, uint8_t enable)
87+
void mayfly_enable_cb(uint8_t caller_id, uint8_t callee_id, uint8_t enable)
8888
{
8989
(void)caller_id;
9090

subsys/bluetooth/controller/util/mayfly.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
static struct {
1515
void *head;
1616
void *tail;
17+
union {
18+
uint32_t flags;
19+
struct {
20+
uint32_t disable_req : 1;
21+
uint32_t disable_ack : 1;
22+
};
23+
};
1724
} mft[MAYFLY_CALLEE_COUNT][MAYFLY_CALLER_COUNT];
1825

1926
static void *mfl[MAYFLY_CALLEE_COUNT][MAYFLY_CALLER_COUNT][2];
@@ -35,6 +42,20 @@ void mayfly_init(void)
3542
}
3643
}
3744

45+
void mayfly_enable(uint8_t caller_id, uint8_t callee_id, uint8_t enable)
46+
{
47+
if (enable) {
48+
mayfly_enable_cb(caller_id, callee_id, enable);
49+
} else {
50+
if (mft[callee_id][caller_id].disable_req ==
51+
mft[callee_id][caller_id].disable_ack) {
52+
mft[callee_id][caller_id].disable_req++;
53+
54+
mayfly_pend(caller_id, callee_id);
55+
}
56+
}
57+
}
58+
3859
uint32_t mayfly_enqueue(uint8_t caller_id, uint8_t callee_id, uint8_t chain,
3960
struct mayfly *m)
4061
{
@@ -90,6 +111,7 @@ uint32_t mayfly_enqueue(uint8_t caller_id, uint8_t callee_id, uint8_t chain,
90111
void mayfly_run(uint8_t callee_id)
91112
{
92113
uint8_t caller_id;
114+
uint8_t disable = 0;
93115

94116
/* iterate through each caller queue to this callee_id */
95117
caller_id = MAYFLY_CALLER_COUNT;
@@ -140,14 +162,27 @@ void mayfly_run(uint8_t callee_id)
140162
*/
141163
if (state == 1) {
142164
/* pend callee (tailchain) if mayfly queue is
143-
* not empty.
165+
* not empty or all caller queues are not
166+
* processed.
144167
*/
145-
if (link) {
168+
if (caller_id || link) {
146169
mayfly_pend(callee_id, callee_id);
147-
}
148170

149-
return;
171+
return;
172+
}
150173
}
151174
}
175+
176+
if (mft[callee_id][caller_id].disable_req !=
177+
mft[callee_id][caller_id].disable_ack) {
178+
disable = 1;
179+
180+
mft[callee_id][caller_id].disable_ack =
181+
mft[callee_id][caller_id].disable_req;
182+
}
183+
}
184+
185+
if (disable) {
186+
mayfly_enable_cb(callee_id, callee_id, 0);
152187
}
153188
}

subsys/bluetooth/controller/util/mayfly.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ struct mayfly {
1717
};
1818

1919
void mayfly_init(void);
20+
void mayfly_enable(uint8_t caller_id, uint8_t callee_id, uint8_t enable);
2021
uint32_t mayfly_enqueue(uint8_t caller_id, uint8_t callee_id, uint8_t chain,
2122
struct mayfly *m);
2223
void mayfly_run(uint8_t callee_id);
2324

24-
extern void mayfly_enable(uint8_t caller_id, uint8_t callee_id, uint8_t enable);
25+
extern void mayfly_enable_cb(uint8_t caller_id, uint8_t callee_id,
26+
uint8_t enable);
2527
extern uint32_t mayfly_is_enabled(uint8_t caller_id, uint8_t callee_id);
2628
extern uint32_t mayfly_prio_is_equal(uint8_t caller_id, uint8_t callee_id);
2729
extern void mayfly_pend(uint8_t caller_id, uint8_t callee_id);

0 commit comments

Comments
 (0)