Зачем kfifo нужен smp_wmb даже при наличии spin_lock_irqsave в ядре версии 4.9.37 ⇐ Linux
Зачем kfifo нужен smp_wmb даже при наличии spin_lock_irqsave в ядре версии 4.9.37
there are two section codes in kernel lib/kfifo.c as below:
#define kfifo_in_spinlocked(fifo, buf, n, lock) \ ({ \ unsigned long __flags; \ unsigned int __ret; \ spin_lock_irqsave(lock, __flags); \ __ret = kfifo_in(fifo, buf, n); \ spin_unlock_irqrestore(lock, __flags); \ __ret; \ }) static void kfifo_copy_in(struct __kfifo *fifo, const void *src, unsigned int len, unsigned int off) { unsigned int size = fifo->mask + 1; unsigned int esize = fifo->esize; unsigned int l; off &= fifo->mask; if (esize != 1) { off *= esize; size *= esize; len *= esize; } l = min(len, size - off); memcpy(fifo->data + off, src, l); memcpy(fifo->data, src + l, len - l); /* * make sure that the data in the fifo is up to date before * incrementing the fifo->in index counter */ smp_wmb(); } the function kfifo_in in kfifo_in_spinlocked will eventually call kfifo_copy_in function, my question is why even with spin_lock_irqsave, smp_wmb is needed? cpu got spin lock makes other cpu stall,so it can modified variables and data address exclusivly, when it unlock, others cpu can get the newest data and data address? why smp_wmb is needed?
Источник: https://stackoverflow.com/questions/780 ... sion-4-9-3
there are two section codes in kernel lib/kfifo.c as below:
#define kfifo_in_spinlocked(fifo, buf, n, lock) \ ({ \ unsigned long __flags; \ unsigned int __ret; \ spin_lock_irqsave(lock, __flags); \ __ret = kfifo_in(fifo, buf, n); \ spin_unlock_irqrestore(lock, __flags); \ __ret; \ }) static void kfifo_copy_in(struct __kfifo *fifo, const void *src, unsigned int len, unsigned int off) { unsigned int size = fifo->mask + 1; unsigned int esize = fifo->esize; unsigned int l; off &= fifo->mask; if (esize != 1) { off *= esize; size *= esize; len *= esize; } l = min(len, size - off); memcpy(fifo->data + off, src, l); memcpy(fifo->data, src + l, len - l); /* * make sure that the data in the fifo is up to date before * incrementing the fifo->in index counter */ smp_wmb(); } the function kfifo_in in kfifo_in_spinlocked will eventually call kfifo_copy_in function, my question is why even with spin_lock_irqsave, smp_wmb is needed? cpu got spin lock makes other cpu stall,so it can modified variables and data address exclusivly, when it unlock, others cpu can get the newest data and data address? why smp_wmb is needed?
Источник: https://stackoverflow.com/questions/780 ... sion-4-9-3
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение