LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
LinkBack Search this Thread
Old 12-18-2012, 02:28 PM   #1
CelticFiddler
LQ Newbie
 
Registered: Aug 2012
Location: Plano, TX
Distribution: Debian 6
Posts: 11

Rep: Reputation: Disabled
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
 
Old 12-19-2012, 06:56 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,000

Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
is this code multithreaded? is it threadsafe? do you have a coredump? have you tried to analyze it?
 
Old 12-19-2012, 02:31 PM   #3
CelticFiddler
LQ Newbie
 
Registered: Aug 2012
Location: Plano, TX
Distribution: Debian 6
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
Old 12-20-2012, 04:48 AM   #4
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,000

Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
inp_b may cause segfault: http://linux.about.com/library/cmd/blcmdl2_inb_p.htm
 
Old 12-20-2012, 08:35 AM   #5
CelticFiddler
LQ Newbie
 
Registered: Aug 2012
Location: Plano, TX
Distribution: Debian 6
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
Old 12-20-2012, 08:51 AM   #6
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,000

Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
If you can try valgrind it can help you to locate such problems also.
 
  


Reply

Tags
segmentation fault, timer


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] SEGMENTATION FAULT using gcc 4.4.4 -O2 , works with gcc 4.1.0 -O2 or gcc 4.4.4 -O1 amir1981 Programming 36 07-26-2010 06:07 PM
disable debug mode in gcc arunachalam Linux - Software 1 09-09-2007 01:20 PM
Segmentation Fault and Gcc compiler skarland Linux - Newbie 2 02-14-2007 09:52 AM
compiling in gcc goes well, gives segmentation fault jshine Programming 6 12-19-2004 01:08 AM
gcc / segmentation fault skeletal29 Linux - Software 0 05-05-2002 04:05 AM


All times are GMT -5. The time now is 11:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration