Skip to content

Commit 78a947f

Browse files
trondmychucklever
authored andcommitted
sunrpc: Add tracing for cache events
Add basic tracing for debugging the sunrpc cache events. Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 277f27e commit 78a947f

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

include/trace/events/sunrpc.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,39 @@ DECLARE_EVENT_CLASS(svc_deferred_event,
13351335
DEFINE_SVC_DEFERRED_EVENT(drop);
13361336
DEFINE_SVC_DEFERRED_EVENT(revisit);
13371337

1338+
DECLARE_EVENT_CLASS(cache_event,
1339+
TP_PROTO(
1340+
const struct cache_detail *cd,
1341+
const struct cache_head *h
1342+
),
1343+
1344+
TP_ARGS(cd, h),
1345+
1346+
TP_STRUCT__entry(
1347+
__field(const struct cache_head *, h)
1348+
__string(name, cd->name)
1349+
),
1350+
1351+
TP_fast_assign(
1352+
__entry->h = h;
1353+
__assign_str(name, cd->name);
1354+
),
1355+
1356+
TP_printk("cache=%s entry=%p", __get_str(name), __entry->h)
1357+
);
1358+
#define DEFINE_CACHE_EVENT(name) \
1359+
DEFINE_EVENT(cache_event, name, \
1360+
TP_PROTO( \
1361+
const struct cache_detail *cd, \
1362+
const struct cache_head *h \
1363+
), \
1364+
TP_ARGS(cd, h))
1365+
DEFINE_CACHE_EVENT(cache_entry_expired);
1366+
DEFINE_CACHE_EVENT(cache_entry_upcall);
1367+
DEFINE_CACHE_EVENT(cache_entry_update);
1368+
DEFINE_CACHE_EVENT(cache_entry_make_negative);
1369+
DEFINE_CACHE_EVENT(cache_entry_no_listener);
1370+
13381371
#endif /* _TRACE_SUNRPC_H */
13391372

13401373
#include <trace/define_trace.h>

net/sunrpc/cache.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/sunrpc/cache.h>
3333
#include <linux/sunrpc/stats.h>
3434
#include <linux/sunrpc/rpc_pipe_fs.h>
35+
#include <trace/events/sunrpc.h>
3536
#include "netns.h"
3637

3738
#define RPCDBG_FACILITY RPCDBG_CACHE
@@ -120,6 +121,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
120121
if (test_bit(CACHE_VALID, &tmp->flags) &&
121122
cache_is_expired(detail, tmp)) {
122123
sunrpc_begin_cache_remove_entry(tmp, detail);
124+
trace_cache_entry_expired(detail, tmp);
123125
freeme = tmp;
124126
break;
125127
}
@@ -176,6 +178,25 @@ static void cache_fresh_unlocked(struct cache_head *head,
176178
}
177179
}
178180

181+
static void cache_make_negative(struct cache_detail *detail,
182+
struct cache_head *h)
183+
{
184+
set_bit(CACHE_NEGATIVE, &h->flags);
185+
trace_cache_entry_make_negative(detail, h);
186+
}
187+
188+
static void cache_entry_update(struct cache_detail *detail,
189+
struct cache_head *h,
190+
struct cache_head *new)
191+
{
192+
if (!test_bit(CACHE_NEGATIVE, &new->flags)) {
193+
detail->update(h, new);
194+
trace_cache_entry_update(detail, h);
195+
} else {
196+
cache_make_negative(detail, h);
197+
}
198+
}
199+
179200
struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
180201
struct cache_head *new, struct cache_head *old, int hash)
181202
{
@@ -188,10 +209,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
188209
if (!test_bit(CACHE_VALID, &old->flags)) {
189210
spin_lock(&detail->hash_lock);
190211
if (!test_bit(CACHE_VALID, &old->flags)) {
191-
if (test_bit(CACHE_NEGATIVE, &new->flags))
192-
set_bit(CACHE_NEGATIVE, &old->flags);
193-
else
194-
detail->update(old, new);
212+
cache_entry_update(detail, old, new);
195213
cache_fresh_locked(old, new->expiry_time, detail);
196214
spin_unlock(&detail->hash_lock);
197215
cache_fresh_unlocked(old, detail);
@@ -209,10 +227,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
209227
detail->init(tmp, old);
210228

211229
spin_lock(&detail->hash_lock);
212-
if (test_bit(CACHE_NEGATIVE, &new->flags))
213-
set_bit(CACHE_NEGATIVE, &tmp->flags);
214-
else
215-
detail->update(tmp, new);
230+
cache_entry_update(detail, tmp, new);
216231
hlist_add_head(&tmp->cache_list, &detail->hash_table[hash]);
217232
detail->entries++;
218233
cache_get(tmp);
@@ -254,7 +269,7 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h
254269
spin_lock(&detail->hash_lock);
255270
rv = cache_is_valid(h);
256271
if (rv == -EAGAIN) {
257-
set_bit(CACHE_NEGATIVE, &h->flags);
272+
cache_make_negative(detail, h);
258273
cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY,
259274
detail);
260275
rv = -ENOENT;
@@ -460,6 +475,7 @@ static int cache_clean(void)
460475
continue;
461476

462477
sunrpc_begin_cache_remove_entry(ch, current_detail);
478+
trace_cache_entry_expired(current_detail, ch);
463479
rv = 1;
464480
break;
465481
}
@@ -1215,6 +1231,7 @@ static int cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
12151231
if (test_bit(CACHE_PENDING, &h->flags)) {
12161232
crq->item = cache_get(h);
12171233
list_add_tail(&crq->q.list, &detail->queue);
1234+
trace_cache_entry_upcall(detail, h);
12181235
} else
12191236
/* Lost a race, no longer PENDING, so don't enqueue */
12201237
ret = -EAGAIN;
@@ -1240,6 +1257,7 @@ int sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail,
12401257
{
12411258
if (!cache_listeners_exist(detail)) {
12421259
warn_no_listener(detail);
1260+
trace_cache_entry_no_listener(detail, h);
12431261
return -EINVAL;
12441262
}
12451263
return sunrpc_cache_pipe_upcall(detail, h);

0 commit comments

Comments
 (0)