Having rules span multiple files
I've recently implemented support for a functionality which would allow us to remove freezing calls on kthreads on filesystems *iff* the filesystem implements support for filesystem freezing, this can be determined if the filesystem implements the fs_freeze superblock callback. So the below rule looks for the callback first, then looks to see if it has a kthread implemented, and finally on the kthread fn, it removes any freeze calls. This works quite nice on a filesystem where there is a match for all the above in one file, for example fs/ext4/super.c, however it doesn't work when say the fs_freeze is one file, and the kthread on another.
How could I get the rules to span multiple files?
@ has_freeze_fs @
identifier super_ops;
expression freeze_op;
@@
struct super_operations super_ops = {
.freeze_fs = freeze_op,
};
@ has_kthread depends on has_freeze_fs @
identifier kthread_fn;
expression task;
@@
task = kthread_run(kthread_fn, ...);
@ remove_set_freezable depends on has_kthread @
identifier has_kthread.kthread_fn;
expression time;
@@
kthread_fn(...)
{
<+...(
- set_freezable();
|
- try_to_freeze();
|
- freezable_schedule();
+ schedule();
|
- freezable_schedule_timeout(time);
+ schedule_timeout(time);
)
...+> }
Quoted 11 lines · Luis R. Rodriguez
I've recently implemented support for a functionality which would allow us to remove freezing calls on kthreads on filesystems *iff* the filesystem implements support for filesystem freezing, this can be determined if the filesystem implements the
fs_freezesuperblock callback. So the below rule looks for the callback first, then looks to see if it has a kthread implemented, and finally on the kthread fn, it removes any freeze calls. This works quite nice on a filesystem where there is a match for all the above in one file, for examplefs/ext4/super.c, however it doesn't work when say thefs_freezeis one file, and the kthread on another.How could I get the rules to span multiple files?
You mean treat multiple .c files as a single compilation unit? Just pass all those files together on the command line:
spatch foo.c bar.c
or
spatch fs/ext4/*.c
bye
michael
Quoted 47 lines · Luis R. Rodriguez
I've recently implemented support for a functionality which would allow us to remove freezing calls on kthreads on filesystems *iff* the filesystem implements support for filesystem freezing, this can be determined if the filesystem implements the
fs_freezesuperblock callback. So the below rule looks for the callback first, then looks to see if it has a kthread implemented, and finally on the kthread fn, it removes any freeze calls. This works quite nice on a filesystem where there is a match for all the above in one file, for examplefs/ext4/super.c, however it doesn't work when say thefs_freezeis one file, and the kthread on another.How could I get the rules to span multiple files?
@
has_freeze_fs@
identifiersuper_ops;
expressionfreeze_op;
@@struct
super_operationssuper_ops= {
.freeze_fs =freeze_op,
};@
has_kthreaddepends onhas_freeze_fs@
identifierkthread_fn;
expression task;
@@task =
kthread_run(kthread_fn, ...);@
remove_set_freezabledepends onhas_kthread@
identifier has_kthread.kthread_fn;
expression time;
@@
kthread_fn(...){ <+...(
(quoted diff) +0
-1- set_freezable();|
(quoted diff) +0
-1- try_to_freeze();|
(quoted diff) +1
-1- freezable_schedule(); + schedule();|
(quoted diff) +1
-1- freezable_schedule_timeout(time); + schedule_timeout(time);)
Quoted 2 lines
...+> }
If Michael's suggestion is acceptable to you, then that is the simplest. Normally I would say to do iteration, but it seems a bit awkward in this case where there is a dependency between the first two rules, but no shared metavariables, so the only real connection between them is their being in the same "place", for some definition of place.
Anohter option is to create a file with lists of file names that should be considered together. So you could have:
a/foo.ca/xyz.c
b/bar.cb/mno.cb/zzz.c
Then use --file-groups with the name of this file.
julia
Quoted 11 lines · Michael Stefaniuc
Quoted 10 lines · Luis R. Rodriguez
I've recently implemented support for a functionality which would allow us to remove freezing calls on kthreads on filesystems *iff* the filesystem implements support for filesystem freezing, this can be determined if the filesystem implements the
fs_freezesuperblock callback. So the below rule looks for the callback first, then looks to see if it has a kthread implemented, and finally on the kthread fn, it removes any freeze calls. This works quite nice on a filesystem where there is a match for all the above in one file, for examplefs/ext4/super.c, however it doesn't work when say thefs_freezeis one file, and the kthread on another.
Quoted 6 lines
Quoted 1 line
How could I get the rules to span multiple files?
You mean treat multiple .c files as a single compilation unit? Just pass all those files together on the command line:
spatchfoo.cbar.c
or
spatchfs/ext4/*.c
Neat that works, thanks!
Luis
Quoted 11 lines · Julia Lawall
Anohter option is to create a file with lists of file names that should be considered together. So you could have:
a/foo.ca/xyz.c
b/bar.cb/mno.cb/zzz.cThen use --file-groups with the name of this file.
Ah, now we just need something which given a directory or config option infers the number of associated files to that config option. :)
Luis
Quoted 7 lines · Luis R. Rodriguez
Quoted 6 lines · Julia Lawall
Anohter option is to create a file with lists of file names that should be considered together. So you could have:
a/foo.ca/xyz.c
Quoted 8 lines
Quoted 5 lines
b/bar.cb/mno.cb/zzz.cThen use --file-groups with the name of this file.
Ah, now we just need something which given a directory or config option infers the number of associated files to that config option. :)
Yes, but I have decided that that is not my problem :)
There is actually some effort in that direction in Coccinelle. There is and option --kbuild-info a file called kbuild.ml and a function called parse_kbuild_info. I don't know if it is just redundant with respect to --file-groups, or if it actually takes configuration files or make files and tries to do something with them. Maybe a project for an intern someday.
julia