Skip to content

Commit

Permalink
Merge pull request #86 from embassy-rs/tune-defaults
Browse files Browse the repository at this point in the history
tune some defaults for attribute queues
  • Loading branch information
lulf authored Aug 22, 2024
2 parents 12645f7 + 292e3e0 commit c980d4c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
8 changes: 4 additions & 4 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ controller-host-flow-control = []

# BEGIN AUTOGENERATED CONFIG FEATURES
# Generated by gen_config.py. DO NOT EDIT.
l2cap-rx-queue-size-1 = [] # Default
l2cap-rx-queue-size-1 = []
l2cap-rx-queue-size-2 = []
l2cap-rx-queue-size-4 = []
l2cap-rx-queue-size-8 = []
l2cap-rx-queue-size-8 = [] # Default
l2cap-rx-queue-size-16 = []
l2cap-rx-queue-size-32 = []
l2cap-rx-queue-size-64 = []

l2cap-rx-packet-pool-size-1 = []
l2cap-rx-packet-pool-size-2 = [] # Default
l2cap-rx-packet-pool-size-2 = []
l2cap-rx-packet-pool-size-4 = []
l2cap-rx-packet-pool-size-8 = []
l2cap-rx-packet-pool-size-8 = [] # Default
l2cap-rx-packet-pool-size-16 = []
l2cap-rx-packet-pool-size-32 = []
l2cap-rx-packet-pool-size-64 = []
Expand Down
4 changes: 2 additions & 2 deletions host/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{env, fs};
static CONFIGS: &[(&str, usize)] = &[
// BEGIN AUTOGENERATED CONFIG FEATURES
// Generated by gen_config.py. DO NOT EDIT.
("L2CAP_RX_QUEUE_SIZE", 1),
("L2CAP_RX_PACKET_POOL_SIZE", 2),
("L2CAP_RX_QUEUE_SIZE", 8),
("L2CAP_RX_PACKET_POOL_SIZE", 8),
// END AUTOGENERATED CONFIG FEATURES
];

Expand Down
4 changes: 2 additions & 2 deletions host/gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def feature(name, default, min=None, max=None, pow2=None, vals=None, factors=[])
)


feature("l2cap_rx_queue_size", default=1, min=1, max=64, pow2=True)
feature("l2cap_rx_packet_pool_size", default=2, min=1, max=512, pow2=True)
feature("l2cap_rx_queue_size", default=8, min=1, max=64, pow2=True)
feature("l2cap_rx_packet_pool_size", default=8, min=1, max=512, pow2=True)

# ========= Update Cargo.toml

Expand Down
18 changes: 5 additions & 13 deletions host/src/channel_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,7 @@ impl<'d, const RXQ: usize> ChannelManager<'d, RXQ> {
buf: &mut [u8],
ble: &BleHost<'d, T>,
) -> Result<usize, BleHostError<T::Error>> {
let mut n_received = 1;
let packet = self.receive_pdu(chan, ble).await?;
let len = packet.len;
let packet = self.receive_pdu(chan).await?;

let (first, data) = packet.as_ref().split_at(2);
let remaining: u16 = u16::from_le_bytes([first[0], first[1]]);
Expand All @@ -494,8 +492,7 @@ impl<'d, const RXQ: usize> ChannelManager<'d, RXQ> {

// We have some k-frames to reassemble
while remaining > 0 {
let packet = self.receive_pdu(chan, ble).await?;
n_received += 1;
let packet = self.receive_pdu(chan).await?;
let to_copy = packet.len.min(buf.len() - pos);
if to_copy > 0 {
buf[pos..pos + to_copy].copy_from_slice(&packet.as_ref()[..to_copy]);
Expand All @@ -508,14 +505,10 @@ impl<'d, const RXQ: usize> ChannelManager<'d, RXQ> {
Ok(pos)
}

async fn receive_pdu<T: Controller>(
&self,
chan: ChannelIndex,
ble: &BleHost<'_, T>,
) -> Result<Pdu, BleHostError<T::Error>> {
async fn receive_pdu(&self, chan: ChannelIndex) -> Result<Pdu, Error> {
match self.inbound[chan.0 as usize].receive().await {
Some(pdu) => Ok(pdu),
None => Err(Error::ChannelClosed.into()),
None => Err(Error::ChannelClosed),
}
}

Expand Down Expand Up @@ -546,9 +539,8 @@ impl<'d, const RXQ: usize> ChannelManager<'d, RXQ> {
grant.confirm(1);

let chunks = remaining.chunks(mps as usize);
let num_chunks = chunks.len();

for (i, chunk) in chunks.enumerate() {
for chunk in chunks {
let len = encode(chunk, &mut p_buf[..], peer_cid, None)?;
hci.send(&p_buf[..len]).await?;
grant.confirm(1);
Expand Down
16 changes: 9 additions & 7 deletions host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ pub struct BleHost<'d, T> {
pub(crate) connections: ConnectionManager<'d>,
pub(crate) reassembly: PacketReassembly<'d>,
pub(crate) channels: ChannelManager<'d, { config::L2CAP_RX_QUEUE_SIZE }>,
pub(crate) att_inbound: Channel<NoopRawMutex, (ConnHandle, Pdu), 1>,
#[cfg(feature = "gatt")]
pub(crate) att_inbound: Channel<NoopRawMutex, (ConnHandle, Pdu), { config::L2CAP_RX_QUEUE_SIZE }>,
pub(crate) rx_pool: &'static dyn GlobalPacketPool,
outbound: Channel<NoopRawMutex, (ConnHandle, Pdu), 4>,

Expand Down Expand Up @@ -190,7 +191,7 @@ impl<'d> AdvState<'d> {
let mut terminated = 0;
for entry in state.handles.iter() {
match entry {
AdvHandleState::Terminated(handle) => {
AdvHandleState::Terminated(_) => {
terminated += 1;
}
AdvHandleState::None => {
Expand Down Expand Up @@ -241,6 +242,7 @@ where
&mut host_resources.channels_rx[..],
),
rx_pool: &host_resources.rx_pool,
#[cfg(feature = "gatt")]
att_inbound: Channel::new(),
#[cfg(feature = "scan")]
scanner: Channel::new(),
Expand Down Expand Up @@ -482,15 +484,15 @@ where
Ok(())
}

async fn stop_scan(&self, config: &ScanConfig<'_>) -> Result<(), BleHostError<T::Error>>
async fn stop_scan(&self) -> Result<(), BleHostError<T::Error>>
where
T: ControllerCmdSync<LeSetScanEnable>,
{
self.command(LeSetScanEnable::new(false, false)).await?;
Ok(())
}

async fn stop_scan_ext(&self, config: &ScanConfig<'_>) -> Result<(), BleHostError<T::Error>>
async fn stop_scan_ext(&self) -> Result<(), BleHostError<T::Error>>
where
T: ControllerCmdSync<LeSetExtScanEnable>,
{
Expand Down Expand Up @@ -519,7 +521,7 @@ where
let Some(report) = self.scanner.receive().await else {
return Err(Error::Timeout.into());
};
self.stop_scan_ext(config).await?;
self.stop_scan_ext().await?;
Ok(report)
}

Expand All @@ -538,7 +540,7 @@ where
let Some(report) = self.scanner.receive().await else {
return Err(Error::Timeout.into());
};
self.stop_scan(config).await?;
self.stop_scan().await?;
Ok(report)
}

Expand Down Expand Up @@ -1047,7 +1049,7 @@ where
}
Either4::Third(_) => {
// trace!("[host] cancelling create connection");
if let Err(e) = self.command(LeCreateConnCancel::new()).await {
if let Err(_) = self.command(LeCreateConnCancel::new()).await {
// Signal to ensure no one is stuck
self.connect_command_state.canceled();
}
Expand Down
1 change: 0 additions & 1 deletion host/src/l2cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl<'d> L2capChannel<'d> {
config: &L2capChannelConfig,
) -> Result<Self, BleHostError<T::Error>>
where {
let handle = connection.handle();
ble.channels
.create(
connection.handle(),
Expand Down

0 comments on commit c980d4c

Please sign in to comment.