Posts
C code optimization benchmark
- Get link
- X
- Other Apps
Can you believe that the code above can be optimized to run 14 times faster on Intel Core i7 CPU and to run 40 times faster on AMD Athlon X2? #define X_SIZE 60 #define Y_SIZE 30 int matrix[X_SIZE][Y_SIZE]; void initmatrix(void) { int x,y; for (x = 0; x < X_SIZE; ++x){ for (y = 0; y < Y_SIZE; ++y){ matrix[x][y] = -1; } } } void main() { initmatrix(); } Check my post: C code optimization benchmark
Writing device drivers in Linux: A brief tutorial - Compiling Errors and Warnings
- Get link
- X
- Other Apps
The article: Writing device drivers in Linux: A brief tutorial Is a great starting point for Linux Kernel Development but it needs some simple updates. The first error you will find when compiling is: /home/peter/devel/kdpeter/2012/bricks/original-post/memory.c:3:26: fatal error: linux/config.h: No such file or directory compilation terminated. To fix, remove the line from the source code: #include <linux/config.h> Then some warnings: /home/peter/devel/kdpeter/2012/bricks/original-post/memory.c:28:3: warning: initialization from incompatible pointer type [enabled by default] /home/peter/devel/kdpeter/2012/bricks/original-post/memory.c:28:3: warning: (near initialization for ‘memory_fops.write’) [enabled by default] /home/peter/devel/kdpeter/2012/bricks/original-post/memory.c: In function ‘memory_write’: /home/peter/devel/kdpeter/2012/bricks/original-post/memory.c:110:17: warning: ignoring return value of ‘copy_from_user’, declared with attribute warn_unused...
Creating Linux Kernel Module made easy
- Get link
- X
- Other Apps
Can you believe that a two line C source code can become a Linux module? $ cat simplest_module.c #include <linux/module.h> MODULE_LICENSE("GPL"); $ cat Makefile obj-m := simplest_module.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Just "make". $ make To install your brand new bogus module: $ sudo insmod simplest_module.ko The lsmod command show that your module has been loaded: $ lsmod |grep simplest_module simplest_module 689 0 To remove the module: $ sudo rmmod simplest_module It is very simple to create a Linux Kernel Module. If you want more than a do nothing module, follow the links: Source: Writing device drivers in Linux: A brief tutorial Recommended: Writing a Simple USB Driver
Mutex vs. Semaphore, what is the difference?
- Get link
- X
- Other Apps
The Toilet Example (c) Copyright 2005, Niclas Winquist ;) Mutex: Is a key to a toilet. One person can have the key - occupy the toilet - at the time. When finished, the person gives (frees) the key to the next person in the queue. Officially: "Mutexes are typically used to serialise access to a section of re-entrant code that cannot be executed concurrently by more than one thread. A mutex object only allows one thread into a controlled section, forcing other threads which attempt to gain access to that section to wait until the first thread has exited from that section." Ref: Symbian Developer Library (A mutex is really a semaphore with value 1.) Semaphore: Is the number of free identical toilet keys. Example, say we have four toilets with identical locks and keys. The semaphore count - the count of keys - is set to 4 at beginning (all four toilets are free), then the count value is decremented as people are coming in. If all toilets are full, ie. there are n...