I wrote programs to count page error times on a linux system. More precisely, the core of time performs the function __do_page_fault .
And somehow I wrote two global variables called pfcount_at_beg and pfcount_at_end , which increase once when the __do_page_fault function __do_page_fault executed in different places of the function.
To illustrate, a modified function has the following form:
unsigned long pfcount_at_beg = 0; unsigned long pfcount_at_end = 0; static void __kprobes __do_page_fault(...) { struct vm_area_sruct *vma; ...
I expected pfcount_at_end to be less than pfcount_at_beg.
Because, I think, every time the kernel executes pfcount_at_end++ code instructions, it had to execute pfcount_at_beg++ (every function starts from the very beginning of the code).
On the other hand, since there are many conditional return between these two lines of code.
However, the result is the opposite. The value of pfcount_at_end greater than the value of pfcount_at_beg .
I use printk to print these kernel variables through self- syscall . And I wrote a user level program to call system call .
Here is my simple syscall and user program:
Is there anyone who knows what exactly happened during this?
Now I have changed the code to make pfcount_at_beg and pfcount_at_end static . However, the result has not changed, i.e. The value of pfcount_at_end greater than the value of pfcount_at_beg . Perhaps this may be due to the intra-atomic increment operation. Would it be better if I used read-write lock?
source share