Skip to content

Commit adf8300

Browse files
Add synchronization before reading system counter
The initial code implemetation applied loose synchronization before reading the system counter and in some situations it was too loose and would allow the system counter to be read too early or too late to be useful as a timing measurement. This commit attempts to implement a very agressive synchronization prior to any system counter read that might be used for a timing calculation. The agressive synchronization includes both a dsb and an isb instruction prior to reading the system counter. In situations where the system counter was just being read for non-timing critical purposes, all synchronization has been removed. Signed-off-by: Rod Frazer <rod.frazer@intel.com>
1 parent a28a39a commit adf8300

39 files changed

+579
-9
lines changed

common_sw/linux_apps/boot_app.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ int main(void)
586586

587587
menu_loop:
588588
asm volatile (
589+
"dsb sy\n"
590+
"isb\n"
589591
"mrs %[cntvct_el0], cntvct_el0\n"
590592
: [cntvct_el0] "=r" (cntvct_el0)
591593
);

common_sw/linux_apps/config_clk.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ void do_the_interesting_thing(struct config_clk_s *config_clk,
167167

168168
/* aquire generic timer value and config clock counter */
169169
asm volatile (
170+
"dsb sy\n"
171+
"isb\n"
170172
"mrs %[start_time], cntvct_el0\n"
171173
: [start_time] "=r" (start_time)
172174
);
@@ -178,6 +180,8 @@ void do_the_interesting_thing(struct config_clk_s *config_clk,
178180
do {
179181
/* aquire generic timer value and config clock counter */
180182
asm volatile (
183+
"dsb sy\n"
184+
"isb\n"
181185
"mrs %[cur_time], cntvct_el0\n"
182186
: [cur_time] "=r" (cur_time)
183187
);

common_sw/linux_apps/emac.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,23 @@ void do_the_interesting_thing(struct hps_emac_s *hps_emac,
491491
/* wait for software reset to clear or timeout */
492492
asm volatile (
493493
"dsb sy\n"
494+
"isb\n"
494495
"mrs %[start_time], cntvct_el0\n"
495496
: [start_time] "=r" (start_time)
496497
);
497498

498499
asm volatile (
500+
"dsb sy\n"
501+
"isb\n"
499502
"mrs %[temp], cntvct_el0\n"
500503
: [temp] "=r" (temp)
501504
);
502505
timeout = temp + (cntfrq_el0 / 1000);
503506

504507
do {
505508
asm volatile (
509+
"dsb sy\n"
510+
"isb\n"
506511
"mrs %[temp], cntvct_el0\n"
507512
: [temp] "=r" (temp)
508513
);
@@ -597,12 +602,15 @@ void do_the_interesting_thing(struct hps_emac_s *hps_emac,
597602
/* mark the time */
598603
asm volatile (
599604
"dsb sy\n"
605+
"isb\n"
600606
"mrs %[start_time], cntvct_el0\n"
601607
: [start_time] "=r" (start_time)
602608
);
603609

604610
/* wait for the DMA to idle, timeout after 1ms */
605611
asm volatile (
612+
"dsb sy\n"
613+
"isb\n"
606614
"mrs %[temp], cntvct_el0\n"
607615
: [temp] "=r" (temp)
608616
);
@@ -612,6 +620,8 @@ void do_the_interesting_thing(struct hps_emac_s *hps_emac,
612620
((EMAC0_DMA_CH0_BASE + DMA_CH0_Status_OFST) & 0x3FFF)));
613621
while((temp_32 & 0x00000040) == 0) {
614622
asm volatile (
623+
"dsb sy\n"
624+
"isb\n"
615625
"mrs %[temp], cntvct_el0\n"
616626
: [temp] "=r" (temp)
617627
);
@@ -626,6 +636,7 @@ void do_the_interesting_thing(struct hps_emac_s *hps_emac,
626636
/* mark the time */
627637
asm volatile (
628638
"dsb sy\n"
639+
"isb\n"
629640
"mrs %[end_time], cntvct_el0\n"
630641
: [end_time] "=r" (end_time)
631642
);
@@ -644,6 +655,7 @@ void do_the_interesting_thing(struct hps_emac_s *hps_emac,
644655
/* mark the time */
645656
asm volatile (
646657
"dsb sy\n"
658+
"isb\n"
647659
"mrs %[start_time], cntvct_el0\n"
648660
: [start_time] "=r" (start_time)
649661
);
@@ -659,6 +671,7 @@ void do_the_interesting_thing(struct hps_emac_s *hps_emac,
659671
/* mark the time */
660672
asm volatile (
661673
"dsb sy\n"
674+
"isb\n"
662675
"mrs %[end_time], cntvct_el0\n"
663676
: [end_time] "=r" (end_time)
664677
);

common_sw/linux_apps/f2h_bridge.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
566566

567567
/* fill the initial buffer with a randomized data pattern */
568568
asm volatile (
569-
"dsb sy\n"
570569
"mrs %[temp], cntvct_el0\n"
571570
: [temp] "=r" (temp)
572571
);
@@ -606,13 +605,15 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
606605
/* mark the time */
607606
asm volatile (
608607
"dsb sy\n"
608+
"isb\n"
609609
"mrs %[start_time], cntvct_el0\n"
610610
: [start_time] "=r" (start_time)
611611
);
612612

613613
/* wait for the DMA to idle, timeout after 1ms */
614614
asm volatile (
615615
"dsb sy\n"
616+
"isb\n"
616617
"mrs %[temp], cntvct_el0\n"
617618
: [temp] "=r" (temp)
618619
);
@@ -625,6 +626,7 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
625626
while((temp_32 & 0x00000001) == 0x00000001) {
626627
asm volatile (
627628
"dsb sy\n"
629+
"isb\n"
628630
"mrs %[temp], cntvct_el0\n"
629631
: [temp] "=r" (temp)
630632
);
@@ -641,6 +643,7 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
641643
/* mark the time */
642644
asm volatile (
643645
"dsb sy\n"
646+
"isb\n"
644647
"mrs %[end_time], cntvct_el0\n"
645648
: [end_time] "=r" (end_time)
646649
);
@@ -685,13 +688,15 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
685688
/* mark the time */
686689
asm volatile (
687690
"dsb sy\n"
691+
"isb\n"
688692
"mrs %[start_time], cntvct_el0\n"
689693
: [start_time] "=r" (start_time)
690694
);
691695

692696
/* wait for the DMA to idle, timeout after 1ms */
693697
asm volatile (
694698
"dsb sy\n"
699+
"isb\n"
695700
"mrs %[temp], cntvct_el0\n"
696701
: [temp] "=r" (temp)
697702
);
@@ -704,6 +709,7 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
704709
while((temp_32 & 0x00000001) == 0x00000001) {
705710
asm volatile (
706711
"dsb sy\n"
712+
"isb\n"
707713
"mrs %[temp], cntvct_el0\n"
708714
: [temp] "=r" (temp)
709715
);
@@ -721,6 +727,7 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
721727
/* mark the time */
722728
asm volatile (
723729
"dsb sy\n"
730+
"isb\n"
724731
"mrs %[end_time], cntvct_el0\n"
725732
: [end_time] "=r" (end_time)
726733
);
@@ -736,6 +743,7 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
736743
/* mark the time */
737744
asm volatile (
738745
"dsb sy\n"
746+
"isb\n"
739747
"mrs %[start_time], cntvct_el0\n"
740748
: [start_time] "=r" (start_time)
741749
);
@@ -750,6 +758,7 @@ void do_the_interesting_thing(struct f2h_bridge_s *f2h_bridge,
750758
/* mark the time */
751759
asm volatile (
752760
"dsb sy\n"
761+
"isb\n"
753762
"mrs %[end_time], cntvct_el0\n"
754763
: [end_time] "=r" (end_time)
755764
);
@@ -838,7 +847,6 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
838847

839848
/* fill the initial buffer with a randomized data pattern */
840849
asm volatile (
841-
"dsb sy\n"
842850
"mrs %[temp], cntvct_el0\n"
843851
: [temp] "=r" (temp)
844852
);
@@ -891,6 +899,7 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
891899
/* mark the time */
892900
asm volatile (
893901
"dsb sy\n"
902+
"isb\n"
894903
"mrs %[start_time], cntvct_el0\n"
895904
: [start_time] "=r" (start_time)
896905
);
@@ -904,6 +913,7 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
904913
/* mark the time */
905914
asm volatile (
906915
"dsb sy\n"
916+
"isb\n"
907917
"mrs %[end_time], cntvct_el0\n"
908918
: [end_time] "=r" (end_time)
909919
);
@@ -992,6 +1002,7 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
9921002
/* mark the time */
9931003
asm volatile (
9941004
"dsb sy\n"
1005+
"isb\n"
9951006
"mrs %[start_time], cntvct_el0\n"
9961007
: [start_time] "=r" (start_time)
9971008
);
@@ -1005,6 +1016,7 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
10051016
/* mark the time */
10061017
asm volatile (
10071018
"dsb sy\n"
1019+
"isb\n"
10081020
"mrs %[end_time], cntvct_el0\n"
10091021
: [end_time] "=r" (end_time)
10101022
);
@@ -1051,6 +1063,7 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
10511063
/* mark the time */
10521064
asm volatile (
10531065
"dsb sy\n"
1066+
"isb\n"
10541067
"mrs %[start_time], cntvct_el0\n"
10551068
: [start_time] "=r" (start_time)
10561069
);
@@ -1065,6 +1078,7 @@ void do_the_interesting_thing_irq(struct f2h_bridge_s *f2h_bridge,
10651078
/* mark the time */
10661079
asm volatile (
10671080
"dsb sy\n"
1081+
"isb\n"
10681082
"mrs %[end_time], cntvct_el0\n"
10691083
: [end_time] "=r" (end_time)
10701084
);

common_sw/linux_apps/f2h_irq.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ void do_the_interesting_thing(struct f2h_irq_s *f2h_irq,
303303

304304
/* mark the time */
305305
asm volatile (
306+
"dsb sy\n"
307+
"isb\n"
306308
"mrs %[start_time], cntvct_el0\n"
307309
: [start_time] "=r" (start_time)
308310
);
@@ -317,6 +319,8 @@ void do_the_interesting_thing(struct f2h_irq_s *f2h_irq,
317319

318320
/* mark the time */
319321
asm volatile (
322+
"dsb sy\n"
323+
"isb\n"
320324
"mrs %[end_time], cntvct_el0\n"
321325
: [end_time] "=r" (end_time)
322326
);

common_sw/linux_apps/f2h_irq_handler.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ void do_the_interesting_thing(struct f2h_irq_hndlr_s *f2h_irq_hndlr,
280280
/* mark the time */
281281
asm volatile (
282282
"dsb sy\n"
283+
"isb\n"
283284
"mrs %[start_time], cntvct_el0\n"
284285
: [start_time] "=r" (start_time)
285286
);
@@ -288,6 +289,8 @@ void do_the_interesting_thing(struct f2h_irq_hndlr_s *f2h_irq_hndlr,
288289
end_time = start_time + (cntfrq_el0 / 50);
289290
while(1) {
290291
asm volatile (
292+
"dsb sy\n"
293+
"isb\n"
291294
"mrs %[temp_time], cntvct_el0\n"
292295
: [temp_time] "=r" (temp_time)
293296
);
@@ -298,6 +301,7 @@ void do_the_interesting_thing(struct f2h_irq_hndlr_s *f2h_irq_hndlr,
298301
/* mark the time */
299302
asm volatile (
300303
"dsb sy\n"
304+
"isb\n"
301305
"mrs %[start_time], cntvct_el0\n"
302306
: [start_time] "=r" (start_time)
303307
);
@@ -313,6 +317,8 @@ void do_the_interesting_thing(struct f2h_irq_hndlr_s *f2h_irq_hndlr,
313317
while(*((volatile uint32_t *)(map->uio_mmap_addr +
314318
(HPS_GP_OUT_BASE & 0xFFF))) != 0) {
315319
asm volatile (
320+
"dsb sy\n"
321+
"isb\n"
316322
"mrs %[temp_time], cntvct_el0\n"
317323
: [temp_time] "=r" (temp_time)
318324
);
@@ -326,6 +332,7 @@ void do_the_interesting_thing(struct f2h_irq_hndlr_s *f2h_irq_hndlr,
326332
/* mark the time */
327333
asm volatile (
328334
"dsb sy\n"
335+
"isb\n"
329336
"mrs %[end_time], cntvct_el0\n"
330337
: [end_time] "=r" (end_time)
331338
);

0 commit comments

Comments
 (0)