Segmentation fault with rdtsc, but not in debug mode of gcc 4.7
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu (mostly), CentOS (when I have to)
Posts: 12
Rep:
Segmentation fault with rdtsc, but not in debug mode of gcc 4.7
I was fooling around a bit with getting timing from the TSC using gcc 4.7 on a 1.8GHz system. I wanted to find the overhead for various operations (such as just reading the TSC).
Code:
Code:
unsigned long hi, lo;
__asm__ __volatile__ ("cpuid;rdtsc" : "=a"(lo), "=d"(hi)):
This runs fine in debug mode, but give a segfault in any non-debug mode.
What's really strange is that the segfault occurs two (C++) lines later, in code that looks like this:
Code:
std::cerr << "TSC read complete" << std::endl; // <== this is output
std::cerr << "now incrementing counter" << std::endl; // <== never gets here
I'm not sure this is TSC related. Could be just general I/O problem?
I'm using gcc 4.7.
Any clues?
Last edited by CelticFiddler; 12-18-2012 at 02:56 PM.
Reason: refine problem
Distribution: Ubuntu (mostly), CentOS (when I have to)
Posts: 12
Original Poster
Rep:
Quote:
Originally Posted by pan64
is this code multithreaded? is it threadsafe? do you have a coredump? have you tried to analyze it?
Single threaded. The entire embedded system is intended to be single-threaded by design.
Probably not threadsafe.
No coredump file produced, just segfault and abort.
I spent some time trying to track down where the exact location of the segfault was, but that's as far as I've gotten so far. I recall seeing a requirement for certain gcc settings being required for using inb_p(), & outb_p(), so I will be revisiting that to see how to set the compiler options in u++/TheIDE.
I know about that one. In addition to the information on that page, you must use ioperm on port 0x80 also. If you don't, any of the "_p" I/O instructions will segfault, even in debug mode. I found out about that through a question here -- I don't recall ever seeing that tidbit in any documentation.
The problem I'm having is that the program does *NOT* segfault in debug mode, but will segfault if I compile without debug.
I am using TheIDE/Upp for development, and I'm not 100% certain what options are included in non-debug builds. However, the only options that I see that are recommended for use with the I/O instruction are -O and -O2, which I think are turned *OFF* for the debug builds. So the mystery remains. I'm ok for now, but there will come a time when I have to get this to run in a non-debug mode.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.