Skip to content

Commit 1b13a51

Browse files
committed
Make more ringbufs zero-initialized, saving flash
To simplify its implementation, ringbuf currently requires every ringbuf to be declared with an initialization element. It creates a static array containing that element. If that element is represented as zero, that goes in BSS and is zero-initialized with the rest of BSS. If that element is represented as anything other than zero, the compiler creates a full-sized "initialization image" copy of the ringbuf _in flash_ that it can then memcpy into RAM on startup. Using the default Rust enum representation, the easiest way to get a ringbuf initialized to non-zero bytes is to put its initialization sentinel value (e.g. None) as the last variant in the enum. Unfortunately, this is super common. This commit moves all the ones I could find, which should reduce flash usage in a bunch of cases.
1 parent f908b60 commit 1b13a51

File tree

35 files changed

+42
-43
lines changed

35 files changed

+42
-43
lines changed

app/cosmo/src/tracing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ enum Event {
2727

2828
#[derive(Copy, Clone, PartialEq)]
2929
enum Trace {
30-
Event(Event),
3130
None,
31+
Event(Event),
3232
}
3333

3434
ringbuf!(Trace, 128, Trace::None);

app/gimlet/src/tracing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ enum Event {
2727

2828
#[derive(Copy, Clone, PartialEq)]
2929
enum Trace {
30-
Event(Event),
3130
None,
31+
Event(Event),
3232
}
3333

3434
ringbuf!(Trace, 128, Trace::None);

drv/cosmo-seq-server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ task_slot!(PACKRAT, packrat);
3838

3939
#[derive(Copy, Clone, PartialEq, Count)]
4040
enum Trace {
41+
#[count(skip)]
42+
None,
4143
FpgaInit,
4244
StartFailed(#[count(children)] SeqError),
4345
ContinueBitstreamLoad(usize),
@@ -78,8 +80,6 @@ enum Trace {
7880
sp5r3: bool,
7981
sp5r4: bool,
8082
},
81-
#[count(skip)]
82-
None,
8383
}
8484
counted_ringbuf!(Trace, 128, Trace::None);
8585

drv/gimlet-seq-server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ enum I2cTxn {
6767

6868
#[derive(Copy, Clone, PartialEq, Count)]
6969
enum Trace {
70+
#[count(skip)]
71+
None,
7072
Ice40Rails(bool, bool),
7173
IdentValid(#[count(children)] bool),
7274
ChecksumValid(#[count(children)] bool),
@@ -150,8 +152,6 @@ enum Trace {
150152
retries_remaining: u8,
151153
},
152154
StartFailed(#[count(children)] SeqError),
153-
#[count(skip)]
154-
None,
155155
}
156156

157157
counted_ringbuf!(Trace, 128, Trace::None);

drv/gimlet-seq-server/src/vcore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct VCore {
4141

4242
#[derive(Copy, Clone, PartialEq)]
4343
enum Trace {
44+
None,
4445
Initializing,
4546
Initialized,
4647
LimitLoaded,
@@ -49,7 +50,6 @@ enum Trace {
4950
Fault,
5051
Reading { timestamp: u64, volts: units::Volts },
5152
Error(ResponseCode),
52-
None,
5353
}
5454

5555
ringbuf!(Trace, 120, Trace::None);

drv/grapefruit-seq-server/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ task_slot!(LOADER, spartan7_loader);
2222

2323
#[derive(Copy, Clone, PartialEq, Count)]
2424
enum Trace {
25-
MacsAlreadySet(MacAddressBlock),
26-
IdentityAlreadySet(VpdIdentity),
27-
2825
#[count(skip)]
2926
None,
27+
28+
MacsAlreadySet(MacAddressBlock),
29+
IdentityAlreadySet(VpdIdentity),
3030
}
3131

3232
counted_ringbuf!(Trace, 128, Trace::None);

drv/i2c-devices/src/adm1272.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ impl core::fmt::Display for Adm1272 {
8181

8282
#[derive(Copy, Clone, PartialEq)]
8383
enum Trace {
84+
None,
8485
Coefficients(pmbus::Coefficients),
8586
Config(adm1272::PMON_CONFIG::CommandData),
8687
WriteConfig(adm1272::PMON_CONFIG::CommandData),
87-
None,
8888
}
8989

9090
ringbuf!(Trace, 8, Trace::None);

drv/i2c-devices/src/ds2482.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ pub enum Error {
6767

6868
#[derive(Copy, Clone, PartialEq)]
6969
enum Trace {
70+
None,
7071
Read(Register, u8),
7172
ReadError(Register, ResponseCode),
7273
Command(Command),
7374
CommandError(Command, ResponseCode),
74-
None,
7575
}
7676

7777
ringbuf!(Trace, 196, Trace::None);

drv/i2c-devices/src/emc2305.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ fn write_reg16(
216216

217217
#[derive(Copy, Clone, PartialEq)]
218218
enum Trace {
219+
None,
219220
ZeroTach(Fan),
220221
TachOverflow(u32),
221222
BadFanCount(u8),
222-
None,
223223
}
224224

225225
ringbuf!(Trace, 6, Trace::None);

drv/i2c-devices/src/lm5066.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ impl core::fmt::Display for Lm5066 {
101101

102102
#[derive(Copy, Clone, PartialEq)]
103103
pub enum Trace {
104+
None,
104105
CurrentCoefficients(pmbus::Coefficients),
105106
PowerCoefficients(pmbus::Coefficients),
106107
DeviceSetup(lm5066::DEVICE_SETUP::CommandData),
107-
None,
108108
}
109109

110110
ringbuf!(Trace, 8, Trace::None);

0 commit comments

Comments
 (0)