0

I want to do 32 bytes transaction to/from PCIe device inside the Linux driver. Compiling Intel AVX instrinsics for Linux Device Driver with GCC

Code:

base_4 = ioremap(bar_data->bar_paddr[4], bar_data->bar_len[4]);

test_ptr = kmalloc(128, GFP_KERNEL);
if (!test_ptr) {
    printk("test_ptr : kmalloc failed \n");
    return -ENOMEM;
}

memset (test_ptr, 1, 128);

kernel_fpu_begin();   
_mm256_storeu_si256((__m256i*)base_4, *(((__m256i*)test_ptr) + 0));
_mm_mfence();

kernel_fpu_end();

Building the file gives error:

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/mm_malloc.h:27:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
           ^
compilation terminated.

Makefile:

obj-m += memsule.o

ccflags-y := -mavx -mmmx -msse -mpreferred-stack-boundary=4

KDIR = /lib/modules/$(shell uname -r)/build

all:
    make -C $(KDIR) M=$(shell pwd) modules

clean:
    make -C $(KDIR)  M=$(shell pwd) clean

Is there any other method How to use the assembly instruction vmovdqa m256, ymm?

I tried this way

 asm volatile("vmovdqa base_4,test_ptr");

but got error:

 Error: too many memory references for `vmovdqa'

How to use the assembly code in C properly?

red0ct
  • 4,840
  • 3
  • 17
  • 44
Rahul K V
  • 41
  • 4
  • Your error looks similar to the one, noted in [the comment](https://stackoverflow.com/questions/29240450/compiling-intel-avx-instrinsics-for-linux-device-driver-with-gcc#comment46692454_29240920). It seems that [the answer](https://stackoverflow.com/a/29240920/3440745) you are following is not correct. – Tsyvarev Sep 07 '20 at 11:16
  • 1
    `stdlib.h` is user space header. You may not use it for kernel modules. – 0andriy Sep 07 '20 at 12:17
  • Using GNU C inline asm is possible, but you of course need to use valid asm instructions, and with GNU C Extended asm syntax to tell the compiler what operands you want. https://stackoverflow.com/tags/x86/info. Kernel code is unique in that you maybe should *not* tell the kernel about XMM/YMM registers you clobber, though. – Peter Cordes Sep 07 '20 at 12:20
  • Oops, meant to link https://stackoverflow.com/tags/inline-assembly/info for info on how to access local vars in GNU C inline asm. You'll want to `vmovdqu` load into a register and then store. – Peter Cordes Sep 07 '20 at 12:43
  • how to use this instruction? – Rahul K V Sep 07 '20 at 13:39
  • Is it worth saving and restoring state to move 32-bytes? – stark Sep 08 '20 at 14:57
  • @stark don't forget we are talking about IO over PCI bus which is extremely slow. – 0andriy Sep 09 '20 at 20:58

0 Answers0