Linux SMP Barriers

Is there something like pthread_barrier in the Linux SMP kernel?

When the kernel runs simultaneously on 2 or more processors with the same structure, a barrier (e.g. pthread_barrier) can be useful. It will stop all processors included in it until the last processor launches the barrier. From now on, all processors work again.

+3
source share
2 answers

You might get equivalent behavior with completion:

struct fake_barrier_t {
  atomic_t count;
  struct completion comp;
}

/* run before each pass */
void initialize_fake_barrier(struct fake_barrier_t* b)
{
  atomic_set(&b->count, 0);
  init_completion(&b->comp);
}

/* make all tasks sleep until nth arrives, then wake all. */
void fake_barrier(struct fake_barrier_t* b, int n)
{
  if (atomic_inc_return(&b->count) < n)
    wait_for_completion(&b->comp);
  else
    complete_all(&b->comp);
}
+5
source

I am not familiar with the pthread_barrier () construct, but the kernel has a large number of options for memory barriers.

See lxr memory barriers for documentation.

, , , - / , , . - , ? ...

+2

Source: https://habr.com/ru/post/1739559/


All Articles