Skip to contentSkip to conversation

Building Kernel with -O0

DISCUSSION Bodo Eggert 3 participants 4 messages Sep 10, 2008 – Sep 12, 2008 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 5 lines · linux-os (Dick Johnson)

If you have to single-step through kernel procedures, you are not writing proper code for a kernel. Furthermore, even when using the kernel debugger, you are not executing the exact same path that would be executed without the debugger attached.

I sometimes single-step in order to verify my (userspace) code, instead of just throwing random test data at it. It's easier and makes me feel better. OTOH, -O2 never was a problem if I used it, so I don't strongly vote for enabling -O0.

#5 lore raw

2008/9/10 Bodo Eggert <[email protected]>:

Quoted 8 lines
Quoted 5 lines · linux-os (Dick Johnson)

If you have to single-step through kernel procedures, you are not writing proper code for a kernel. Furthermore, even when using the kernel debugger, you are not executing the exact same path that would be executed without the debugger attached.

Quoted 6 lines

I sometimes single-step in order to verify my (userspace) code, instead of just throwing random test data at it. It's easier and makes me feel better. OTOH, -O2 never was a problem if I used it, so I don't strongly vote for enabling -O0.

--

I had compiled linux-2.6.23 with -O0 for kgdb only with little modifications, it's running with no error for a long time. I'am not a linux expert, I think talented kernel hackers can make kernel to compile with -O0 easly but for some reason they dont want to do it. Debug is much understandable for me (and for most people I think) with -O0. Linux kernel programming ability is not a gift, of course you can learn the code with printks and reading, but which age are we living in?

Emin

#6 lore raw
Quoted 25 lines · emin ak

2008/9/10 Bodo Eggert <[email protected]>:

Quoted 8 lines
Quoted 5 lines · linux-os (Dick Johnson)

If you have to single-step through kernel procedures, you are not writing proper code for a kernel. Furthermore, even when using the kernel debugger, you are not executing the exact same path that would be executed without the debugger attached.

Quoted 6 lines

I sometimes single-step in order to verify my (userspace) code, instead of just throwing random test data at it. It's easier and makes me feel better. OTOH, -O2 never was a problem if I used it, so I don't strongly vote for enabling -O0.

--

I had compiled linux-2.6.23 with -O0 for kgdb only with little modifications, it's running with no error for a long time. I'am not a linux expert, I think talented kernel hackers can make kernel to compile with -O0 easly but for some reason they dont want to do it. Debug is much understandable for me (and for most people I think) with -O0. Linux kernel programming ability is not a gift, of course you can learn the code with printks and reading, but which age are we living in?

Quoted 2 lines

Emin

Well, to use the ** kernel ** to single-
step through the ** kernel ** is
really not going to be much more than an
exercise. It's not going to find the bugs
that are likely to exist in kernel code.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.25.17 on an i686 machine (4786.38 BogoMips). My book : http://www.AbominableFirebug.com/
_

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

#7 lore raw
Quoted 12 lines · linux-os (Dick Johnson)
Quoted 9 lines · emin ak

2008/9/10 Bodo Eggert <[email protected]>:

Quoted 8 lines
Quoted 5 lines · linux-os (Dick Johnson)

If you have to single-step through kernel procedures, you are not writing proper code for a kernel. Furthermore, even when using the kernel debugger, you are not executing the exact same path that would be executed without the debugger attached.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I sometimes single-step in order to verify my (userspace) code, instead of just throwing random test data at it. It's easier and makes me feel better. OTOH, -O2 never was a problem if I used it, so I don't strongly vote for enabling -O0.

Let me steal a bit of bandwidth and explain what I mean about writing kernel code.

What is often lost to new people who want to develop kernel code is that you can write and test many pieces of kernel code within a "friendly" user-mode environment.

Suppose you need to write a driver for a complex I/O subsystem that is accessed over the PCI bus.

This seems difficult until you understand that the starting piece of code will be something to find your device and access its registers. This can usually be (mostly) copied from another existing driver.

Once its memory-mapped registers have been uncovered, you can implement mmap() in your driver and then access them from a user-space program you write, reading/writing setting bits and observing the hardware behavior well before you write actual driver code. Parts of the code that you develop in user- space will eventually be cut and pasted
into your kernel driver code.

You are not going to be able to write your interrupt service routines in user-mode but they can still be in your driver code in which you implemented mmap(). They just do a printk() and attempt to reset your hardware for the next interrupt. If it doesn't work, you can experiment in user-mode, writing to registers, until you have satisfied the hardware so the next interrupt will properly occur.

If you write drivers in this manner, you will not have code that doesn't work in the kernel code. It may not work exactly as you want, but it will work well enough so that a few printks will allow you to get its real-time operation working as expected.

Warning! Do NOT leave hardware registers exposed to user-mode access like Windows does. Your initial memory- mapping was to help develop kernel code, not to create a user-mode driver! Such code would be called a "layering violation..."

Cheers,
Dick Johnson
Penguin : Linux version 2.6.25.17 on an i686 machine (4786.38 BogoMips). My book : http://www.AbominableFirebug.com/
_

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.