Skip to content

Commit 07bbe08

Browse files
committed
ftrace: Remove "filter_hash" parameter from __ftrace_hash_rec_update()
While adding comments to the function __ftrace_hash_rec_update() and trying to describe in detail what the parameter for "filter_hash" does, I realized that it basically does exactly the same thing (but differently) if it is set or not! If it is set, the idea was the ops->filter_hash was being updated, and the code should focus on the functions that are in the ops->filter_hash and add them. But it still had to pay attention to the functions in the ops->notrace_hash, to ignore them. If it was cleared, it focused on the ops->notrace_hash, and would add functions that were not in the ops->notrace_hash but would still keep functions in the "ops->filter_hash". Basically doing the same thing. In reality, the __ftrace_hash_rec_update() only needs to either remove the functions associated to the give ops (if "inc" is set) or remove them (if "inc" is cleared). It has to pay attention to both the filter_hash and notrace_hash regardless. Remove the "filter_hash" parameter from __filter_hash_rec_update() and comment the function for what it really is doing. Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Tested-by: Mark Rutland <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 3afd801 commit 07bbe08

File tree

1 file changed

+38
-64
lines changed

1 file changed

+38
-64
lines changed

kernel/trace/ftrace.c

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,10 +1384,8 @@ alloc_and_copy_ftrace_hash(int size_bits, struct ftrace_hash *hash)
13841384
return NULL;
13851385
}
13861386

1387-
static void
1388-
ftrace_hash_rec_disable_modify(struct ftrace_ops *ops, int filter_hash);
1389-
static void
1390-
ftrace_hash_rec_enable_modify(struct ftrace_ops *ops, int filter_hash);
1387+
static void ftrace_hash_rec_disable_modify(struct ftrace_ops *ops);
1388+
static void ftrace_hash_rec_enable_modify(struct ftrace_ops *ops);
13911389

13921390
static int ftrace_hash_ipmodify_update(struct ftrace_ops *ops,
13931391
struct ftrace_hash *new_hash);
@@ -1475,11 +1473,11 @@ ftrace_hash_move(struct ftrace_ops *ops, int enable,
14751473
* Remove the current set, update the hash and add
14761474
* them back.
14771475
*/
1478-
ftrace_hash_rec_disable_modify(ops, enable);
1476+
ftrace_hash_rec_disable_modify(ops);
14791477

14801478
rcu_assign_pointer(*dst, new_hash);
14811479

1482-
ftrace_hash_rec_enable_modify(ops, enable);
1480+
ftrace_hash_rec_enable_modify(ops);
14831481

14841482
return 0;
14851483
}
@@ -1702,12 +1700,21 @@ static bool skip_record(struct dyn_ftrace *rec)
17021700
!(rec->flags & FTRACE_FL_ENABLED);
17031701
}
17041702

1703+
/*
1704+
* This is the main engine to the ftrace updates to the dyn_ftrace records.
1705+
*
1706+
* It will iterate through all the available ftrace functions
1707+
* (the ones that ftrace can have callbacks to) and set the flags
1708+
* in the associated dyn_ftrace records.
1709+
*
1710+
* @inc: If true, the functions associated to @ops are added to
1711+
* the dyn_ftrace records, otherwise they are removed.
1712+
*/
17051713
static bool __ftrace_hash_rec_update(struct ftrace_ops *ops,
1706-
int filter_hash,
17071714
bool inc)
17081715
{
17091716
struct ftrace_hash *hash;
1710-
struct ftrace_hash *other_hash;
1717+
struct ftrace_hash *notrace_hash;
17111718
struct ftrace_page *pg;
17121719
struct dyn_ftrace *rec;
17131720
bool update = false;
@@ -1719,35 +1726,16 @@ static bool __ftrace_hash_rec_update(struct ftrace_ops *ops,
17191726
return false;
17201727

17211728
/*
1722-
* In the filter_hash case:
17231729
* If the count is zero, we update all records.
17241730
* Otherwise we just update the items in the hash.
1725-
*
1726-
* In the notrace_hash case:
1727-
* We enable the update in the hash.
1728-
* As disabling notrace means enabling the tracing,
1729-
* and enabling notrace means disabling, the inc variable
1730-
* gets inversed.
17311731
*/
1732-
if (filter_hash) {
1733-
hash = ops->func_hash->filter_hash;
1734-
other_hash = ops->func_hash->notrace_hash;
1735-
if (ftrace_hash_empty(hash))
1736-
all = true;
1737-
} else {
1738-
inc = !inc;
1739-
hash = ops->func_hash->notrace_hash;
1740-
other_hash = ops->func_hash->filter_hash;
1741-
/*
1742-
* If the notrace hash has no items,
1743-
* then there's nothing to do.
1744-
*/
1745-
if (ftrace_hash_empty(hash))
1746-
return false;
1747-
}
1732+
hash = ops->func_hash->filter_hash;
1733+
notrace_hash = ops->func_hash->notrace_hash;
1734+
if (ftrace_hash_empty(hash))
1735+
all = true;
17481736

17491737
do_for_each_ftrace_rec(pg, rec) {
1750-
int in_other_hash = 0;
1738+
int in_notrace_hash = 0;
17511739
int in_hash = 0;
17521740
int match = 0;
17531741

@@ -1759,26 +1747,17 @@ static bool __ftrace_hash_rec_update(struct ftrace_ops *ops,
17591747
* Only the filter_hash affects all records.
17601748
* Update if the record is not in the notrace hash.
17611749
*/
1762-
if (!other_hash || !ftrace_lookup_ip(other_hash, rec->ip))
1750+
if (!notrace_hash || !ftrace_lookup_ip(notrace_hash, rec->ip))
17631751
match = 1;
17641752
} else {
17651753
in_hash = !!ftrace_lookup_ip(hash, rec->ip);
1766-
in_other_hash = !!ftrace_lookup_ip(other_hash, rec->ip);
1754+
in_notrace_hash = !!ftrace_lookup_ip(notrace_hash, rec->ip);
17671755

17681756
/*
1769-
* If filter_hash is set, we want to match all functions
1770-
* that are in the hash but not in the other hash.
1771-
*
1772-
* If filter_hash is not set, then we are decrementing.
1773-
* That means we match anything that is in the hash
1774-
* and also in the other_hash. That is, we need to turn
1775-
* off functions in the other hash because they are disabled
1776-
* by this hash.
1757+
* We want to match all functions that are in the hash but
1758+
* not in the other hash.
17771759
*/
1778-
if (filter_hash && in_hash && !in_other_hash)
1779-
match = 1;
1780-
else if (!filter_hash && in_hash &&
1781-
(in_other_hash || ftrace_hash_empty(other_hash)))
1760+
if (in_hash && !in_notrace_hash)
17821761
match = 1;
17831762
}
17841763
if (!match)
@@ -1884,24 +1863,21 @@ static bool __ftrace_hash_rec_update(struct ftrace_ops *ops,
18841863
return update;
18851864
}
18861865

1887-
static bool ftrace_hash_rec_disable(struct ftrace_ops *ops,
1888-
int filter_hash)
1866+
static bool ftrace_hash_rec_disable(struct ftrace_ops *ops)
18891867
{
1890-
return __ftrace_hash_rec_update(ops, filter_hash, 0);
1868+
return __ftrace_hash_rec_update(ops, 0);
18911869
}
18921870

1893-
static bool ftrace_hash_rec_enable(struct ftrace_ops *ops,
1894-
int filter_hash)
1871+
static bool ftrace_hash_rec_enable(struct ftrace_ops *ops)
18951872
{
1896-
return __ftrace_hash_rec_update(ops, filter_hash, 1);
1873+
return __ftrace_hash_rec_update(ops, 1);
18971874
}
18981875

1899-
static void ftrace_hash_rec_update_modify(struct ftrace_ops *ops,
1900-
int filter_hash, int inc)
1876+
static void ftrace_hash_rec_update_modify(struct ftrace_ops *ops, int inc)
19011877
{
19021878
struct ftrace_ops *op;
19031879

1904-
__ftrace_hash_rec_update(ops, filter_hash, inc);
1880+
__ftrace_hash_rec_update(ops, inc);
19051881

19061882
if (ops->func_hash != &global_ops.local_hash)
19071883
return;
@@ -1915,20 +1891,18 @@ static void ftrace_hash_rec_update_modify(struct ftrace_ops *ops,
19151891
if (op == ops)
19161892
continue;
19171893
if (op->func_hash == &global_ops.local_hash)
1918-
__ftrace_hash_rec_update(op, filter_hash, inc);
1894+
__ftrace_hash_rec_update(op, inc);
19191895
} while_for_each_ftrace_op(op);
19201896
}
19211897

1922-
static void ftrace_hash_rec_disable_modify(struct ftrace_ops *ops,
1923-
int filter_hash)
1898+
static void ftrace_hash_rec_disable_modify(struct ftrace_ops *ops)
19241899
{
1925-
ftrace_hash_rec_update_modify(ops, filter_hash, 0);
1900+
ftrace_hash_rec_update_modify(ops, 0);
19261901
}
19271902

1928-
static void ftrace_hash_rec_enable_modify(struct ftrace_ops *ops,
1929-
int filter_hash)
1903+
static void ftrace_hash_rec_enable_modify(struct ftrace_ops *ops)
19301904
{
1931-
ftrace_hash_rec_update_modify(ops, filter_hash, 1);
1905+
ftrace_hash_rec_update_modify(ops, 1);
19321906
}
19331907

19341908
/*
@@ -3051,7 +3025,7 @@ int ftrace_startup(struct ftrace_ops *ops, int command)
30513025
return ret;
30523026
}
30533027

3054-
if (ftrace_hash_rec_enable(ops, 1))
3028+
if (ftrace_hash_rec_enable(ops))
30553029
command |= FTRACE_UPDATE_CALLS;
30563030

30573031
ftrace_startup_enable(command);
@@ -3093,7 +3067,7 @@ int ftrace_shutdown(struct ftrace_ops *ops, int command)
30933067
/* Disabling ipmodify never fails */
30943068
ftrace_hash_ipmodify_disable(ops);
30953069

3096-
if (ftrace_hash_rec_disable(ops, 1))
3070+
if (ftrace_hash_rec_disable(ops))
30973071
command |= FTRACE_UPDATE_CALLS;
30983072

30993073
ops->flags &= ~FTRACE_OPS_FL_ENABLED;

0 commit comments

Comments
 (0)