From: Wei Li <liwei391@huawei.com>
To: <linux-trace-kernel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
<xiexiuqi@huawei.com>
Subject: [PATCH v2 1/2] tracing: Allow custom read/write processing in trace_min_max_{write,read}()
Date: Thu, 21 Nov 2024 10:18:22 +0800 [thread overview]
Message-ID: <20241121021823.1237741-2-liwei391@huawei.com> (raw)
In-Reply-To: <20241121021823.1237741-1-liwei391@huawei.com>
The 'trace_min_max_fops' implements a generic function to read/write u64
values from tracefs, add support of custom read/write processing to allow
special requirements.
Signed-off-by: Wei Li <liwei391@huawei.com>
---
kernel/trace/trace.c | 13 ++++++++++---
kernel/trace/trace.h | 2 ++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2b64b3ec67d9..ab5ea6d7148c 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -7689,8 +7689,12 @@ trace_min_max_write(struct file *filp, const char __user *ubuf, size_t cnt, loff
if (param->max && val > *param->max)
err = -EINVAL;
- if (!err)
- *param->val = val;
+ if (!err) {
+ if (unlikely(param->write))
+ param->write(param->val, val);
+ else
+ *param->val = val;
+ }
if (param->lock)
mutex_unlock(param->lock);
@@ -7723,7 +7727,10 @@ trace_min_max_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppo
if (!param)
return -EFAULT;
- val = *param->val;
+ if (unlikely(param->read))
+ val = param->read(param->val);
+ else
+ val = *param->val;
if (cnt > sizeof(buf))
cnt = sizeof(buf);
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index c866991b9c78..2aaf3030c466 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -2159,6 +2159,8 @@ static inline void sanitize_event_name(char *name)
struct trace_min_max_param {
struct mutex *lock;
u64 *val;
+ u64 (*read)(u64 *val);
+ void (*write)(u64 *val, u64 data);
u64 *min;
u64 *max;
};
--
2.25.1
next prev parent reply other threads:[~2024-11-21 2:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-21 2:18 [PATCH v2 0/2] tracing: Fix deadlock in hwlat tracer Wei Li
2024-11-21 2:18 ` Wei Li [this message]
2024-12-11 3:56 ` [PATCH v2 1/2] tracing: Allow custom read/write processing in trace_min_max_{write,read}() Steven Rostedt
2024-11-21 2:18 ` [PATCH v2 2/2] tracing/hwlat: Fix deadlock in cpuhp processing Wei Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241121021823.1237741-2-liwei391@huawei.com \
--to=liwei391@huawei.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=xiexiuqi@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox