Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"02-25-09 - Low Level Threading - Part 4.3"

7 Comments -

1 – 7 of 7
Anonymous Anonymous said...

> int _pad1[CACHE_LINE_SIZE];
> LFStack g_stack;
> int _pad2[CACHE_LINE_SIZE];

There is no guarantee that pad1, g_stack and pad2 are contiguous, right? You probably want to wrap that in a struct...

February 25, 2009 at 10:09 PM

Anonymous Anonymous said...

Fucking internet, just lost my post. Who ever head of losing a post on a preview operation!

February 26, 2009 at 7:39 AM

Blogger cbloom said...

"There is no guarantee that pad1, g_stack and pad2 are contiguous, right? You probably want to wrap that in a struct..."

I don't know if C actually says they are contiguous but in practice I believe they are 100% of the time.

But yeah I agree I wouldn't want to rely on that. (like for example I dunno if LTCG or some other weird linkages might screw this up)

February 26, 2009 at 11:12 AM

Blogger won3d said...

On recent versions of gcc/ld, you can try adding -fdata-sections to gcc and --gc-sections to ld and see if it strips the unreferenced data like it is supposed to.

February 26, 2009 at 1:52 PM

Blogger cbloom said...

Yeah I don't actually suggest that you have a "g_stack" global at file scope. I just thought it would be simpler to pretend you were talking through a global variable rather than setting up a ThreadSystem Singleton or whatever.

February 26, 2009 at 1:59 PM

Blogger won3d said...

Well, I suppose for static/auto allocated stuff, you could just use the "align" declspec/attribute?

February 26, 2009 at 2:35 PM

Blogger cbloom said...

Not exactly. I've been trying stuff using align and it's a bit of a mess.

align(64) on the *typedef* would cause the type to get padded up to a multiple of 64 bytes. If that's acceptable to you then things are pretty easy.

align(64) on the instance will align its address to 64 but won't prevent other objects from being directly after you.

So, yes if you align both the type and the instance it will get its own cache line.

But there doesn't seem to be any way to mark at the instance that it should be aligned and that the *next* value should also be aligned so that I get the whole line.

February 26, 2009 at 2:46 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.