[NSWI004] dprintk makes my code stable
Petr Tuma
petr.tuma at d3s.mff.cuni.cz
Sat Oct 24 17:42:26 CEST 2020
Hi,
check the C modifier "volatile" and think about the possible difference in optimizations the compiler can do when you (1) have a loop that calls a complex function in a different compilation unit vs (2) have a loop that is quite simple and the compiler can see all variable manipulation.
https://barrgroup.com/embedded-systems/how-to/c-volatile-keyword
Petr
On 24/10/2020 07:46, Jura Pelc wrote:
> So have here awkward behaving of code.
>
>
> I have a block of code where originally was `dprintk` for debugging and everything was fine.
> But when I tried to remove it (for the sanity of debug output) kernel crashed. (Both with `.configure.py --debug`)
> I can't see why this is happing and most importantly WHY IS THIS HAPPENING?
>
> both `print` and `dprintk` should not apply any change.
>
>
> This is a copy of the issue: https://gitlab.mff.cuni.cz/teaching/nswi004/2020/team-please_dont/-/issues/15 <https://gitlab.mff.cuni.cz/teaching/nswi004/2020/team-please_dont/-/issues/15>
> related to branch https://gitlab.mff.cuni.cz/teaching/nswi004/2020/team-please_dont/-/tree/bugfix/K-15 <https://gitlab.mff.cuni.cz/teaching/nswi004/2020/team-please_dont/-/tree/bugfix/K-15>
>
> file: `heap.c/search_heap_size`
> When running with `dprintk`, code will run smoothly and the result is expected.
> ```c
> *((int*)scanner) = 0xC0FFEE;
> dprintk("Scanning: 0x%x (%x)\n", scanner, *((int*)scanner));
> if(*((int*)scanner) != 0xC0FFEE)
> ```
>
> ``` shell
> [DEBUG src/mm/heap.c:24 search_heap_size()] Scanning: 0x800fb130 (c0ffee)
> [DEBUG src/mm/heap.c:24 search_heap_size()] Scanning: 0x800fc130 (c0ffee)
> [DEBUG src/mm/heap.c:24 search_heap_size()] Scanning: 0x800fd130 (c0ffee)
> [DEBUG src/mm/heap.c:24 search_heap_size()] Scanning: 0x800fe130 (c0ffee)
> [DEBUG src/mm/heap.c:24 search_heap_size()] Scanning: 0x800ff130 (c0ffee)
> [DEBUG src/mm/heap.c:24 search_heap_size()] Scanning: 0x80100130 (c0ffee)
> [DEBUG src/mm/heap.c:27 search_heap_size()] NonMatch: 0x80100130 (ffffffff)
> [DEBUG src/mm/heap.c:149 heap_init()] heap_begin: 0x80001130
> [DEBUG src/mm/heap.c:150 heap_init()] heap_end: 0x800ff130
> [DEBUG src/mm/heap.c:151 heap_init()] heap size: 1016 bytes
> Hello world!
> <msim> Alert: XHLT: Machine halt
>
> Cycles: 229951
> ```
>
>
>
> When running **Without** `dprintk`, code will fail during the process.
> ```c
> *((int*)scanner) = 0xC0FFEE;
> //dprintk("Scanning: 0x%x (%x)\n", scanner, *((int*)scanner));
> if(*((int*)scanner) != 0xC0FFEE)
> ```
>
> ``` shell
> <msim> Alert: XRD: Register dump
> processor 0
> 0 0 at 0 v0 ffffffffc0000f20 v1 c0ffee a0 0
> a1 0 a2 0 a3 0 t0 0 t1 0
> t2 0 t3 0 t4 0 t5 0 t6 0
> t7 0 s0 0 s1 0 s2 0 s3 0
> s4 0 s5 0 s6 0 s7 0 t8 0
> t9 0 k0 ff01 k1 0 gp ffffffff80000000 sp ffffffff800003e8
> fp 0 ra ffffffff80000440 pc ffffffff80000180 lo 0 hi 0
> <msim> Alert: XINT: Interactive mode
> [msim]
> ```
>
>
> --
>
> S pozdravem Jiří Pelc
> Matematicko-fyzikální fakulta
> Univerzita Karlova
>
> _______________________________________________
> NSWI004 mailing list
> NSWI004 at d3s.mff.cuni.cz
> https://d3s.mff.cuni.cz/mailman/listinfo/nswi004
>
More information about the NSWI004
mailing list