tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Data layout + false sharing

On Wednesday 02 December 2009 23:26:49 Mindaugas Rasiukevicius wrote:

> Group related structures and/or their members so they will be in the same
> cache line and during synchronisation wont touch other ones?  How exactly,
> that is specific to your application.

Here is an example:

struct ptf_thread_group
        uint32_t threads_alloc; /* number of threads allocated to this group */
        uint64_t threads_status;        /* bitmask of which threads are 
busy/free. 1=busy */
        pthread_mutex_t mutex;/* protects threads_status */
        ptf_thread_t *thread_list;/* array of threads */

The above structure represents a group of threads. It is accessed every time 
application needs to schedule free threads to execute a task.

threads_alloc and thread_list variables are initialised once and stay 
constant, threads_status is updated every time a thread is assigned a task, or 
when a thread finishes a task and becomes free.

I think what I need to do is to add some padding around threads_status 
variable, so that updating it does not invalidate cache line that holds values 
for the variables that sit next to it.

What's the usual practice for doing that?

uint8_t pad0[cache_line / 8 ];
uint64_t threads_status;
uint8_t pad1[cache_line / 8];

Home | Main Index | Thread Index | Old Index