Skip to content

Commit

Permalink
Add example of using static_key_enabled to patch-author-guild.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wardenjohn authored and zhangyongde.zyd committed Mar 13, 2024
1 parent 4077d87 commit 075ecb9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions doc/patch-author-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,41 @@ This can be done by replacing any usages of `static_branch_likely()`,
`static_branch_unlikely()`, `static_key_true()`, and `static_key_false()` with
`static_key_enabled()` in the patch file.

There is an example of using `static_key_enabled()` to replace the static key in the patch file:
This is an static key used in the patch file:
```
static inline bool memcg_kmem_enabled(void)
{
return static_branch_unlikely(&memcg_kmem_enabled_key);
}
```

We can use `static_key_enabled()` to rewrite the macros `static_branch_likely` as follows:
```
#define static_branch_unlikely(x) unlikely(static_key_enabled(&(x)->key))
```

However, using the following method to fix the static key error also work:
```
static inline bool memcg_kmem_enabled(void)
{
return unlikely(&(&memcg_kmem_enabled_key)->key);
}
```

Changing the definition in header file may cause too much changes in the object invoked this macros eventhough we have no changes effect them,
which is not a good choice to rewrite the original definition.
So, we can define a new function for our patch function to fix static_key.
```
static inline bool memcg_kmem_enabled_new(void)
{
return unlikely(&(&memcg_kmem_enabled_key)->key);
}
```
The patch function invoke `memcg_kmem_enabled_new` can avoid changes to other extraneous functions.



### Static calls

Similarly, static calls are not supported when the corresponding static call
Expand Down

0 comments on commit 075ecb9

Please sign in to comment.