comp.lang.ada
 help / color / mirror / Atom feed
* Mixing Ada and c
@ 2009-09-25 16:19 Mike
  2009-09-26 20:46 ` Maciej Sobczak
  0 siblings, 1 reply; 3+ messages in thread
From: Mike @ 2009-09-25 16:19 UTC (permalink / raw)


I have a c main program which does socket communications and calls and
ada program which generates the data to be sent over the wire. What
I've noticed is that the ada portion of the program runs almost twice
as slow when linked with the c main  than when run in stand alone with
an ada driver. Is there a general reason that ada code in general runs
more slowly when linked with and called by a c program?

Thanks in advance
Mike



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

* Re: Mixing Ada and c
  2009-09-25 16:19 Mixing Ada and c Mike
@ 2009-09-26 20:46 ` Maciej Sobczak
  2009-09-30  2:00   ` Greg Bek
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej Sobczak @ 2009-09-26 20:46 UTC (permalink / raw)


On 25 Wrz, 18:19, Mike <michael_ta...@yahoo.com> wrote:

> I have a c main program which does socket communications and calls and
> ada program which generates the data to be sent over the wire. What
> I've noticed is that the ada portion of the program runs almost twice
> as slow when linked with the c main  than when run in stand alone with
> an ada driver. Is there a general reason that ada code in general runs
> more slowly when linked with and called by a c program?

I have no idea whether this is relevant, but you might want to check
whether the C thread (the one calling Ada) was registered at the Ada
runtime. If not, then some of the operations might be trying to use
the information that is not available and then failing over to
alternative strategies.
Again, I have no idea if this is the case, but I can easily imagine
the slowdown caused this way.
I am also interested in the actual reasons for what you see.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



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

* Re: Mixing Ada and c
  2009-09-26 20:46 ` Maciej Sobczak
@ 2009-09-30  2:00   ` Greg Bek
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Bek @ 2009-09-30  2:00 UTC (permalink / raw)


Maciej Sobczak wrote:
> On 25 Wrz, 18:19, Mike <michael_ta...@yahoo.com> wrote:
> 
>> I have a c main program which does socket communications and calls and
>> ada program which generates the data to be sent over the wire. What
>> I've noticed is that the ada portion of the program runs almost twice
>> as slow when linked with the c main  than when run in stand alone with
>> an ada driver. Is there a general reason that ada code in general runs
>> more slowly when linked with and called by a c program?
> 
> I have no idea whether this is relevant, but you might want to check
> whether the C thread (the one calling Ada) was registered at the Ada
> runtime. If not, then some of the operations might be trying to use
> the information that is not available and then failing over to
> alternative strategies.
> Again, I have no idea if this is the case, but I can easily imagine
> the slowdown caused this way.
> I am also interested in the actual reasons for what you see.
> 
> --
> Maciej Sobczak * www.msobczak.com * www.inspirel.com
> 
> Database Access Library for Ada: www.inspirel.com/soci-ada

When an Ada subprogram is called there is usually a significant amount 
of context needed for the subprogram to operate correctly:
eg:	Stack Limit
	Exception Tables
	Memory Pools
	Floating Point Unit configuration

If you use an Ada main program, then a subprogram can safely assume that 
all this context has been established correctly.

But as soon as you put a pragma Export on the subprogram, then the Ada 
compiler has to assume that it could be called from any where, and that 
no assumptions about context can be made.  So usually you will suffer a 
performance penalty as the subprogram establishes an Ada context.

For example, on a processor with a reasonable register set (ie: not 
Intel), the stack limit may be stored in a fixed register location, 
making stack limit checks very quick in a pure Ada context, however if 
called from C, then the compiler will have to generate code to load the 
stack limit from a known memory address somewhere in the Ada runtime.

You can use pragma Suppress creatively to speed up some code, but as 
always your mileage will vary.

Greg



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

end of thread, other threads:[~2009-09-30  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-25 16:19 Mixing Ada and c Mike
2009-09-26 20:46 ` Maciej Sobczak
2009-09-30  2:00   ` Greg Bek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox