@@ -17,7 +17,6 @@ use drv_i2c_api::ResponseCode;
1717use drv_i2c_devices:: raa229620a:: { self , Raa229620A } ;
1818use ringbuf:: * ;
1919use serde:: Serialize ;
20- use task_packrat_api:: { self , Packrat } ;
2120use userlib:: { sys_get_timer, units, TaskId } ;
2221
2322pub ( super ) struct VCore {
@@ -162,18 +161,31 @@ impl VCore {
162161 Ok ( ( ) )
163162 }
164163
165- pub fn handle_pmbus_alert ( & self , mut rails : Rails , now : u64 ) {
164+ pub fn handle_pmbus_alert (
165+ & self ,
166+ mut rails : Rails ,
167+ now : u64 ,
168+ ereport_buf : & mut [ u8 ] ,
169+ ) {
166170 ringbuf_entry ! ( Trace :: PmbusAlert {
167171 timestamp: now,
168172 rails,
169173 } ) ;
170174
171- let cpu0_state =
172- self . record_pmbus_status ( now, Rail :: VddcrCpu0 , rails. vddcr_cpu0 ) ;
175+ let cpu0_state = self . record_pmbus_status (
176+ now,
177+ Rail :: VddcrCpu0 ,
178+ rails. vddcr_cpu0 ,
179+ ereport_buf,
180+ ) ;
173181 rails. vddcr_cpu0 |= cpu0_state. faulted ;
174182
175- let cpu1_state =
176- self . record_pmbus_status ( now, Rail :: VddcrCpu1 , rails. vddcr_cpu1 ) ;
183+ let cpu1_state = self . record_pmbus_status (
184+ now,
185+ Rail :: VddcrCpu1 ,
186+ rails. vddcr_cpu1 ,
187+ ereport_buf,
188+ ) ;
177189 rails. vddcr_cpu1 |= cpu1_state. faulted ;
178190
179191 if cpu0_state. input_fault || cpu1_state. input_fault {
@@ -246,6 +258,7 @@ impl VCore {
246258 now : u64 ,
247259 rail : Rail ,
248260 alerted : bool ,
261+ ereport_buf : & mut [ u8 ] ,
249262 ) -> RegulatorState {
250263 use pmbus:: commands:: raa229620a:: STATUS_WORD ;
251264
@@ -372,7 +385,18 @@ impl VCore {
372385 status,
373386 pwr_good : power_good,
374387 } ;
375- deliver_ereport ( rail, & self . packrat , & ereport) ;
388+ match self . packrat . serialize_ereport ( & ereport, ereport_buf) {
389+ Ok ( len) => ringbuf_entry ! ( Trace :: EreportSent ( rail, len) ) ,
390+ Err ( task_packrat_api:: EreportSerializeError :: Packrat {
391+ len,
392+ err,
393+ } ) => {
394+ ringbuf_entry ! ( Trace :: EreportLost ( rail, len, err) )
395+ }
396+ Err ( task_packrat_api:: EreportSerializeError :: Serialize ( _) ) => {
397+ ringbuf_entry ! ( Trace :: EreportTooBig ( rail) )
398+ }
399+ }
376400
377401 RegulatorState {
378402 faulted,
@@ -432,25 +456,3 @@ fn retry_i2c_txn<T>(
432456 }
433457 }
434458}
435-
436- // This is in its own function so that the ereport buffer is only on the stack
437- // while we're using it, and not for the entireity of `record_pmbus_status`,
438- // which calls into a bunch of other functions. This may reduce our stack depth
439- // a bit.
440- #[ inline( never) ]
441- fn deliver_ereport (
442- rail : Rail ,
443- packrat : & Packrat ,
444- data : & impl serde:: Serialize ,
445- ) {
446- let mut ereport_buf = [ 0u8 ; 256 ] ;
447- match packrat. serialize_ereport ( data, & mut ereport_buf[ ..] ) {
448- Ok ( len) => ringbuf_entry ! ( Trace :: EreportSent ( rail, len) ) ,
449- Err ( task_packrat_api:: EreportSerializeError :: Packrat { len, err } ) => {
450- ringbuf_entry ! ( Trace :: EreportLost ( rail, len, err) )
451- }
452- Err ( task_packrat_api:: EreportSerializeError :: Serialize ( _) ) => {
453- ringbuf_entry ! ( Trace :: EreportTooBig ( rail) )
454- }
455- }
456- }
0 commit comments