All of lore.kernel.org
 help / color / mirror / Atom feed
* [parisc-linux] Program counter from sigcontext, constructurs and -fPIC
@ 2003-04-25 17:46 Boehm, Hans
  2003-04-25 18:54 ` Carlos O'Donell
  0 siblings, 1 reply; 15+ messages in thread
From: Boehm, Hans @ 2003-04-25 17:46 UTC (permalink / raw)
  To: 'parisc-linux@lists.parisc-linux.org'; +Cc: 'Hans.Boehm@hp.com'

I have two questions arising from an attempt to port some profiling code to pa-risc.  Grant Grundler suggested I ask here.

1) I need to retrieve the pc value from the sigcontext structure passed to a timer signal handler.  In an earlier message, Paul Bame pointed me at sc_iaoq.  After a bit more reading, my conclusion was that sc_iaoq[0] should be a reasonable value to use as a sampled pc.  However I have been unable to see anything reasonable in that slot (or sc_iaoq[1] for that matter).  Presumably a struct sigcontext pointer is always passed as the third parameter to a signal handler?  And it's filled in for timer interrrupts?  What does profil() do?  (I tried to read the code, but it's hard to trace through all the configuration stuff.)

2) If I mark a C function as a constructor function, and compile it with -fPIC, it seems to run before globals are properly accessible.  The retrieval of the address of a global through the global offset table seems to return a bad address and the access faults.  Are there known issues in this area?  (The offending function actually ends up in the main program, if that matters.)

Please cc: me in the reply.

Thanks.

Hans

^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [parisc-linux] Program counter from sigcontext, constructurs and -fPIC
@ 2003-04-25 19:40 Boehm, Hans
  2003-04-25 20:52 ` Carlos O'Donell
  0 siblings, 1 reply; 15+ messages in thread
From: Boehm, Hans @ 2003-04-25 19:40 UTC (permalink / raw)
  To: 'Carlos O'Donell'
  Cc: 'parisc-linux@lists.parisc-linux.org', Boehm, Hans

> -----Original Message-----
> From: Carlos O'Donell [mailto:carlos@baldric.uwo.ca]
> 
> Hans,
> 
> What code are you porting? :)
It's a new, currently rather simple, but thread-compatible, purely user-level, profiler.  It includes some infrastructure for using hardware atomic operations in reasonably portable ways.  Need less to say, PA-RISC makes a wonderful test case.
> 
> > 1) I need to retrieve the pc value from the sigcontext 
> structure passed to a timer signal handler.  In an earlier 
> message, Paul Bame pointed me at sc_iaoq.  After a bit more 
> reading, my conclusion was that sc_iaoq[0] should be a 
> reasonable value to use as a sampled pc.  However I have been 
> unable to see anything reasonable in that slot (or sc_iaoq[1] 
> for that matter).  Presumably a struct sigcontext pointer is 
> always passed as the third parameter to a signal handler?  
> And it's filled in for timer interrrupts?  What does profil() 
> do?  (I tried to read the code, but it's hard to trace 
> through all the configuration stuff.)
> 
> A. What kernel are you using?
2.4.17-64 on spe170.testdrive.hp.com.
>  
> The reason I ask is that 64-bit kernels return broken sigcontext
> pointers (for now it stuffs 64-bit values into a 32-bit values within
> the sigcontext, rather it should take into account the fact that
> userspace or the calling threads personality is 32-bit and 
> truncate the
> register values).
It sounds like that's the problem here.  Thanks.  
> 
> What is there to understand about profil()? Based on your PC it uses
> modular arithmetic (the shift, scale, and division) to track 
> on a coarse
> scale which parts of your code are being executed.
Once you get the PC in the signal handler, that's easy.  It sounds like getting the PC from a signal handler from a 32-bit executable on a 64-bit kernel is currently impossible?  I should probably focus on 64-bit executables?  Or does profil() have a way to get around the problem?
> 
> > 2) If I mark a C function as a constructor function, and 
> compile it with -fPIC, it seems to run before globals are 
> properly accessible.  The retrieval of the address of a 
> global through the global offset table seems to return a bad 
> address and the access faults.  Are there known issues in 
> this area?  (The offending function actually ends up in the 
> main program, if that matters.)
> 
> B. Can we see the code?
> 
I haven't officially released it, since I wanted to make sure it at least passed its tests on HP Linux platforms.  I do have permission to release it, so I put a preliminary snapshot at http://hpl.hp.com/personal/Hans_Boehm/qprof/qprof-0.2.tar.gz (probably not its final location).

I believe "make check" works on X86/Itanium/Alpha, but not PA.  (Feedback on the code itself is of course also gratefully accepted.)  The only problem on PA should be running qprof_test.

Thanks.

Hans

^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [parisc-linux] Program counter from sigcontext, constructurs and -fPIC
@ 2003-04-29 21:17 Boehm, Hans
  2003-04-29 21:30 ` Carlos O'Donell
  2003-05-01  4:09 ` Grant Grundler
  0 siblings, 2 replies; 15+ messages in thread
From: Boehm, Hans @ 2003-04-29 21:17 UTC (permalink / raw)
  To: Boehm, Hans, 'parisc-linux@lists.parisc-linux.org'
  Cc: 'Carlos O'Donell'

Thanks to all the help, my profiling code seems to be much healthier now after:

1) Switching to a machine with a 2.4.20-pa28 kernel and gcc 3.2.
2) Discarding the privilege level bits from the program counter value.
3) Adding 24 bytes to the struct sigcontext pointer (?) passed as a third argument to the signal handler. (!)

Needless to say, I'm still a bit concerned about (3).  Why does the third argument to the signal handler appear to point 24 bytes BEFORE the sigcontext structure?  Does it actually point at a bigger structure?  Is the third argument to a signal handler really not a pointer to sigcontext?  Did struct sigcontext change recently, so that I'm dealing with a version mismatch?

With the 24 bytes added, I clearly get the right program counter values.  I also seem to get the right general register values.

Thanks for any insight.

Hans

> -----Original Message-----
> From: Boehm, Hans 
> Sent: Friday, April 25, 2003 12:40 PM
> To: 'Carlos O'Donell'
> Cc: 'parisc-linux@lists.parisc-linux.org'; Boehm, Hans
> Subject: RE: [parisc-linux] Program counter from sigcontext,
> constructurs and -fPIC
> 
> 
> > -----Original Message-----
> > From: Carlos O'Donell [mailto:carlos@baldric.uwo.ca]
> > 
> > Hans,
> > 
> > What code are you porting? :)
> It's a new, currently rather simple, but thread-compatible, 
> purely user-level, profiler.  It includes some infrastructure 
> for using hardware atomic operations in reasonably portable 
> ways.  Need less to say, PA-RISC makes a wonderful test case.
> > 
> > > 1) I need to retrieve the pc value from the sigcontext 
> > structure passed to a timer signal handler.  In an earlier 
> > message, Paul Bame pointed me at sc_iaoq.  After a bit more 
> > reading, my conclusion was that sc_iaoq[0] should be a 
> > reasonable value to use as a sampled pc.  However I have been 
> > unable to see anything reasonable in that slot (or sc_iaoq[1] 
> > for that matter).  Presumably a struct sigcontext pointer is 
> > always passed as the third parameter to a signal handler?  
> > And it's filled in for timer interrrupts?  What does profil() 
> > do?  (I tried to read the code, but it's hard to trace 
> > through all the configuration stuff.)
> > 
> > A. What kernel are you using?
> 2.4.17-64 on spe170.testdrive.hp.com.
> >  
> > The reason I ask is that 64-bit kernels return broken sigcontext
> > pointers (for now it stuffs 64-bit values into a 32-bit 
> values within
> > the sigcontext, rather it should take into account the fact that
> > userspace or the calling threads personality is 32-bit and 
> > truncate the
> > register values).
> It sounds like that's the problem here.  Thanks.  
> > 
> > What is there to understand about profil()? Based on your PC it uses
> > modular arithmetic (the shift, scale, and division) to track 
> > on a coarse
> > scale which parts of your code are being executed.
> Once you get the PC in the signal handler, that's easy.  It 
> sounds like getting the PC from a signal handler from a 
> 32-bit executable on a 64-bit kernel is currently impossible? 
>  I should probably focus on 64-bit executables?  Or does 
> profil() have a way to get around the problem?
> > 
...

^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [parisc-linux] Program counter from sigcontext, constructurs and -fPIC
@ 2003-04-30  0:52 Boehm, Hans
  0 siblings, 0 replies; 15+ messages in thread
From: Boehm, Hans @ 2003-04-30  0:52 UTC (permalink / raw)
  To: 'Carlos O'Donell', Grant Grundler
  Cc: Boehm, Hans, 'parisc-linux@lists.parisc-linux.org'

The struct sigcontext seems to match the declarations I'm seeing and what dbx is seeing.

I think you should be able to reproduce the problem fairly simply by:

1) Downloading http://www.hpl.hp.com/personal/Hans_Boehm/qprof/qprof-0.2.tar.gz
2) Unpacking
3) "make qprof_test" with a recent gcc; this should only take a few seconds.  This doesn't use much of the source code, or uses it in only trivial ways.
4) gdb ./qprof_test
5) break PROF_pc_sample_list_handler; run
6) Look at the handler arguments, particularly the third one.

The corresponding sigaction call is also in prof_utils.c, the same file that contains the above function.  All of the relevant code is either in prof_utils.c and prof_main.c.

(If everything worked, this would report PC samples that are off by 3, since it doesn't contain the privilege level fix.)

Hans

> -----Original Message-----
> From: Carlos O'Donell [mailto:carlos@baldric.uwo.ca]
> Sent: Tuesday, April 29, 2003 5:31 PM
> To: Grant Grundler
> Cc: Boehm, Hans; 'parisc-linux@lists.parisc-linux.org'
> Subject: Re: [parisc-linux] Program counter from sigcontext,
> constructurs and -fPIC
> 
> 
> 
> g,
> 
> > no - he's using:
> > grundler@debian:~$ uname -a
> > Linux debian 2.4.20-pa28 #39 Wed Mar 12 19:24:25 PST 2003 
> parisc unknown
> > unknown GNU/Linux
> 
> Perfect.
>  
> > It's possible the kernel-headers he's using aren't clean.
> > Just in case, can you tell me which ones he should be using?
> 
> /usr/inlcude/asm/sigcontext.h should define it to be:
> 
> /* We will add more stuff here as it becomes necessary, until we know
>    it works. */
> struct sigcontext {
>         unsigned long sc_flags;
>         unsigned long sc_gr[32]; /* PSW in sc_gr[0] */
>         unsigned long long sc_fr[32]; /* FIXME, do we need 
> other state info? */
>         unsigned long sc_iasq[2];
>         unsigned long sc_iaoq[2];
>         unsigned long sc_sar; /* cr11 */
> };
> 
> Which is used to define an identical mcontext.
> 
> > ii  libc6          2.3.1-16       GNU C Library: Shared 
> libraries and Timezone
> > ii  libc6-dev      2.3.1-16       GNU C Library: 
> Development Libraries and Hea
> 
> Perfect.
> 
> > I'm ok with updating to -17 if you promise it won't do evil things
> > to my box. ;^)
> 
> Don't touch -17, the _Unwind_Find_FDE code broke and it's doing damage
> to things like 'vi' ... *sigh* I haven't even looked into this (looks
> like gcc/glibc clashes again).
> 
> c.
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2003-05-05  6:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-25 17:46 [parisc-linux] Program counter from sigcontext, constructurs and -fPIC Boehm, Hans
2003-04-25 18:54 ` Carlos O'Donell
  -- strict thread matches above, loose matches on Subject: below --
2003-04-25 19:40 Boehm, Hans
2003-04-25 20:52 ` Carlos O'Donell
2003-04-29 21:17 Boehm, Hans
2003-04-29 21:30 ` Carlos O'Donell
2003-04-29 22:13   ` Grant Grundler
2003-04-30  0:31     ` Carlos O'Donell
2003-04-30  5:18       ` Grant Grundler
2003-04-30  7:15       ` Joel Soete
2003-04-30 18:12         ` Carlos O'Donell
2003-05-03 20:48           ` Joel Soete
2003-05-05  6:08             ` Joel Soete
2003-05-01  4:09 ` Grant Grundler
2003-04-30  0:52 Boehm, Hans

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.