0

in tasklet_action routine - while handling an entry from tasklet_vec list of

core , we are atomically reading atomic_read(&t->count), i dont see
any of its uses through out the routine, what is its significant ?

if (tasklet_trylock(t)) { // check is it is not already being executed
        if (!atomic_read(&t->count)) {
            if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
                BUG();
            t->func(t->data); // call tasklet action routine
            tasklet_unlock(t);
            continue;
        }
        tasklet_unlock(t);
    }
  • `.count` field counts number of [tasklet_disable](http://lxr.free-electrons.com/source/include/linux/interrupt.h#L566) calls. – Tsyvarev Oct 16 '15 at 11:03

1 Answers1

0

The tasklet is regarded as deactivated/disabled if the count is not equal to zero.

In some architectures, the read operation does not happen in single assembly instruction. For example, if you are reading 64 bit value, the compiler might implement the read using two load instructions of assembly such that the 1st instruction reads the lower 32 bits and the 2nd instruction reads the higher 32 bits. This in turn can lead to race condition. So, atomic reads are preferred.

Karthik Balaguru
  • 7,424
  • 7
  • 48
  • 65