adding a sleep / timer in a kernel module - kernel-module

I need to do task at regular intervals in a kernel module after the module has loaded. How do I achieve that. The examples on the web show a hello world in the init_module and exit_module. I have not seen any literature on how to code regularly occuring events inside a kernel module. Can someone please provide inputs?
Thanks

Have a look at this article for Linux: Kernel APIs, Part 3: Timers and lists in the 2.6 kernel
It has an example module that uses both the simple timer API, and highres timers.

Take a look at chapter 7 of LDD:
http://lwn.net/Kernel/LDD3/

Take a look at this timer tutorial for linux kernel

Related

process identification with Modelica models and PID controller design

I try to build a PID controller for a valve in my model, I plan to do some process identification, get the system response to a step pulse and the transfer function of the system, then I could design the PID controller. But I am not sure if there is a Modelica library for this kind of job, or I need to do this manually.
My question is :
Is there any good reference examples for me?
There is an example in the Dymola manual to tune a controller of an airplane. It is found in the design library, more precisely: Design.Optimization.Examples.ControllerDesign_F14. The documentation is found in the Dymola Manual 2, Chapter 3 up to Dymola 2020x.
Another option is the commercial library "Optimization" developed by DLR which has enhanced capabilities, but comes with some cost...
What you need to perform a step response is a controller which can be put in 'manual' mode. The free library https://github.com/mbonvini/IndustrialControlSystems gives you that.

How to profile in the Linux kernel or use the perf_event*.[hc] framework?

I have noticed there are some profiling source code under arch/arm/kernel:
perf_event.c
perf_event_cpu.c
perf_event_v6.c
perf_event_v7.c
perf_event_xscale.c
I can't understand the hierarchy of those files and how can I use them? can I assume they are always exists and use them in a kernel module? my kernel module runs on Cortex-A7 or Cortex-A15 cores.
There seems to be a lot of very useful things under /arch/arm/kernel/ directory but no documentation about the capabilities ? how comes ?
Perf_event does provide an API that can be used programmatically, but the documentation is sparse at best. Vince Weaver made the best resource for using the perf_event API here: http://web.eece.maine.edu/~vweaver/projects/perf_events/
He also provides some example code for recording counters.
However your best bet is to use an API that wraps perf_event and makes it more accessible, like PAPI (http://icl.cs.utk.edu/papi/)
EDIT: Since you want to do this from a kernel module, PAPI will not be available. The perf_event API still is, however.
The functionality in the perf_* files is used by/provided for tools like oprofile and perf tools.
And no, they are not ALWAYS available, as there is a config option (CONFIG_PERF_EVENTS) to enable/disable performance measurements.
The functionality is not really meant to be used from another driver. I'm pretty sure that will "upset" any user of oprofile or perf.

threads calling other programs

I recently worked on two things : receiving data from the serial port (TinyOS and seriallisten) and capturing frames from a webcam (OpenCV). Now I want to use both together. I want to use modify the video quality according to the rssi received on the serial port.
I've been told that I can create a program which creates thread that would call the methods I previously used : camcapture.c and seriallisten.c, but I don't know how to do this.
Can someone explain it ?
Thanks
You should look int Boost Threads. There are examples on the web on how to create a program and use Boost Threads to call either a class method or a non-class static method.
About using C++ library in C code, this stackoverflow post may be helpful. I guess using extern scope operator is the magic here. C++ cross-compiler is designed using C, so backward conversion is not impossible.
If you hit success in using C++ into C
Wikipedia listed these for Multithreading libraries for C++. I guess it is worth visiting those and see what is good. Boost is still the best IMPO.
P.S. You should checkout intel's Threading Building Block TBB too. They are quite good and simple. Open source projects such as OpenCV uses tbb for their multithreaded class ops. the link is here

how to implement new scheduling scheme in linux kernel

I am new to Linux kernel development
can anyone tell me how to implement a new scheduling scheme in linux kernel?
Which files do I need to change etc . A step by step guide would be helpfull
A step by step guide? no problem boss.
read Process Scheduling.
How to create a new Linux kernel scheduler
you can set your zero task to get familiar with these function list:

implementing include/sched.h functions

I wanted to study how threads can be assigned manually to specific cores on a multi core machine. I found that include/sched.h defines some macros and functions (sched_setaffinity, etc.)that can help for this. However, the functions are extern'ed and I can't find their definitions. Are those functions implemented anywhere? If yes, where and is it possible to override the default implementation? If no, how can I implement them?
And would adding new implementation imply that I have to recompile my Linux kernel?
The code for sched_setaffinity is in the kernel. The header file just provides the prototype to call it, and the library which satisfies it just forwards the call to the system.
Check the code for BFS which should show you how to implement your own CPU scheduler.
//edit yes adding a new scheduler impl means you have to recompile your kernel, however you can always just test it with qemu -kernel /path/to/new/kerenl -initrd something to make sure your code doesn't crash right away before testing it on the real machine.

Resources