comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: About good practice: Should protected objects be small?
Date: Sun, 5 Nov 2017 21:41:29 -0800 (PST)
Date: 2017-11-05T21:41:29-08:00	[thread overview]
Message-ID: <e4020e78-9fd0-4ee3-802a-8cc203bcff81@googlegroups.com> (raw)
In-Reply-To: <5b65b9f0-25d9-449a-b7eb-d1fc112f293f@googlegroups.com>

On Friday, October 20, 2017 at 10:50:44 AM UTC-4, reinert wrote:
> I am testing out using protected objects.
> 
> Is it reasonable good practice to keep protected objects small?
> It seems like for me (?) and stubs ("is separate") is not allowed there.

Not really the question asked, but it can jump up and bite you.  You really want the size of the protected object to be a multiple of hash lines on the actual hardware.  Compilers do this by allocating the storage for any protected object on a cache line boundary.  But that is not guaranteed. Worse, the compiler might be generating x86 code and have no idea what the actual cache line size is.  It is always possible to add Junk, usually under that name ;-), so that each protected value takes one cache line.  (Usually 64, 128, or 256 bytes, you can determine it at run-time.*)  Getting the beginning of the value cache boundary aligned can be done by aligning the protected record even if some of the data is never accessed.

If you want to get really fancy, you can use non-temporal loads and stores to avoid loading and saving the entire cache line. I don't know if any Ada compilers do that for protected objects, and doing it yourself is a bad idea on large projects.

* I have a function that does that for x86 will post if asked. It assumes that if the CPUID instruction does not support this, just return 64, which is usually right for very old x86 CPUs.

  parent reply	other threads:[~2017-11-06  5:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-20 14:50 About good practice: Should protected objects be small? reinert
2017-10-20 18:27 ` Niklas Holsti
2017-10-20 19:21   ` Dmitry A. Kazakov
2017-10-21  4:12   ` reinert
2017-11-06  5:41 ` Robert Eachus [this message]
2017-11-06  8:27   ` Niklas Holsti
2017-11-12  4:16     ` Robert Eachus
replies disabled

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