简体   繁体   中英

Can I use <stdatomic.h> from C11 in Linux driver, or do I must to use Linux functions of memory-barriers?

Can I use #include <stdatomic.h> and atomic_thread_fence() with memory_order from C11 in Linux driver (kernel-space), or do I must to use Linux functions of memory-barriers:

Using:

  • Linux-kernel 2.6.18 or greater
  • GCC 4.7.2 or greater

If you are writing kernel code, you should do it in C, and do it in the version of C required by the current kernel (shipping gcc). If you want to get it accepted into mainline (or write it as if it were going to get accepted), you should use the Linux functions. You will also find that they work without unexpected surprises, and you will get better debugging help.

Summary: use the linux functions.

EDIT: It seems not to work. With or without does not make any difference. Driver may compile but the lib will fallback to plain integers or NOP


It seems to work.

atomic_store() and atomic_load() provide the threads synchronization I need between the kernel module driver and the userland program. What is not sure is that if a fallback method is employed, I mean, usage of standard integer and regular assembly instructions by the compiler.

Feel free to give a look in source codes in functions: intelfreq.c / Core_Cycle() and corefreqd.c / Core_Cycle()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM