From: Dave Jiang <dave.jiang@intel.com>
To: linux-cxl@vger.kernel.org
Cc: alison.schofield@intel.com, vishal.l.verma@intel.com,
ira.weiny@intel.com, bwidawsk@kernel.org,
dan.j.williams@intel.com
Subject: [PATCH 7/7] ndctl: cxl: add monitor command to cxl
Date: Wed, 14 Sep 2022 13:48:30 -0700 [thread overview]
Message-ID: <166318851033.3087953.1487642256782771767.stgit@djiang5-desk3.ch.intel.com> (raw)
In-Reply-To: <166318836385.3087953.6809315284050736931.stgit@djiang5-desk3.ch.intel.com>
Connect the monitoring functionality to the cxl monitor command. Add basic
functionality to the cxl monitor command where it can be launched as a daemon
and logging can be designated to stdout or a file.
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
cxl/builtin.h | 1 +
cxl/cxl.c | 1 +
cxl/monitor.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/cxl/builtin.h b/cxl/builtin.h
index b28c2213993b..34c5cfb49051 100644
--- a/cxl/builtin.h
+++ b/cxl/builtin.h
@@ -22,4 +22,5 @@ int cmd_create_region(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_enable_region(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_disable_region(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_destroy_region(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx);
#endif /* _CXL_BUILTIN_H_ */
diff --git a/cxl/cxl.c b/cxl/cxl.c
index dd1be7a054a1..3be7026f43d3 100644
--- a/cxl/cxl.c
+++ b/cxl/cxl.c
@@ -76,6 +76,7 @@ static struct cmd_struct commands[] = {
{ "enable-region", .c_fn = cmd_enable_region },
{ "disable-region", .c_fn = cmd_disable_region },
{ "destroy-region", .c_fn = cmd_destroy_region },
+ { "monitor", .c_fn = cmd_monitor },
};
int main(int argc, const char **argv)
diff --git a/cxl/monitor.c b/cxl/monitor.c
index e030542a3fe8..e185d15254ec 100644
--- a/cxl/monitor.c
+++ b/cxl/monitor.c
@@ -34,9 +34,12 @@
const char *systems[] = { "cxl_events", "cxl_aer", NULL };
static struct monitor {
+ const char *log;
struct log_ctx ctx;
FILE *log_file;
bool human;
+ bool verbose;
+ bool daemon;
} monitor;
static void log_standard(struct log_ctx *ctx, int priority, const char *file,
@@ -163,3 +166,70 @@ epoll_err:
free(events);
return rc;
}
+
+int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
+{
+ const struct option options[] = {
+ OPT_FILENAME('l', "log", &monitor.log,
+ "<file> | standard",
+ "where to output the monitor's notification"),
+ OPT_BOOLEAN('\0', "daemon", &monitor.daemon,
+ "run cxl monitor as a daemon"),
+ OPT_BOOLEAN('u', "human", &monitor.human,
+ "use human friendly output formats"),
+ OPT_BOOLEAN('v', "verbose", &monitor.verbose,
+ "emit extra debug messages to log"),
+ OPT_END(),
+ };
+ const char * const u[] = {
+ "cxl monitor [<options>]",
+ NULL
+ };
+ const char *prefix ="./";
+ int rc = 0, i;
+
+ argc = parse_options_prefix(argc, argv, prefix, options, u, 0);
+ for (i = 0; i < argc; i++)
+ error("unknown parameter \"%s\"\n", argv[i]);
+ if (argc)
+ usage_with_options(u, options);
+
+ log_init(&monitor.ctx, "cxl/monitor", "CXL_MONITOR_LOG");
+ monitor.ctx.log_fn = log_standard;
+
+ if (monitor.verbose)
+ monitor.ctx.log_priority = LOG_DEBUG;
+ else
+ monitor.ctx.log_priority = LOG_INFO;
+
+ if (monitor.log) {
+ if (strncmp(monitor.log, "./", 2) != 0)
+ fix_filename(prefix, (const char **)&monitor.log);
+ if (strncmp(monitor.log, "./standard", 10) == 0) {
+ monitor.ctx.log_fn = log_standard;
+ } else {
+ monitor.log_file = fopen(monitor.log, "a+");
+ if (!monitor.log_file) {
+ rc = -errno;
+ error("open %s failed: %d\n", monitor.log, rc);
+ goto out;
+ }
+ monitor.ctx.log_fn = log_file;
+ }
+ }
+
+ if (monitor.daemon) {
+ if (daemon(0, 0) != 0) {
+ err(&monitor, "daemon start failed\n");
+ goto out;
+ }
+ info(&monitor, "cxl monitor daemon started.\n");
+ }
+
+ rc = monitor_event(ctx);
+
+out:
+ if (monitor.log_file)
+ fclose(monitor.log_file);
+ return rc;
+}
next prev parent reply other threads:[~2022-09-14 20:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 20:47 [PATCH 0/7] ndctl: cxl: add monitor support for trace events Dave Jiang
2022-09-14 20:47 ` [PATCH 1/7] ndctl: cxl: add helper function to parse trace event to json object Dave Jiang
2022-10-31 20:01 ` Alison Schofield
2022-10-31 21:37 ` Dave Jiang
2022-11-02 21:01 ` Ira Weiny
2022-09-14 20:48 ` [PATCH 2/7] ndctl: cxl: add helper to parse through all current events Dave Jiang
2022-10-31 20:05 ` Alison Schofield
2022-09-14 20:48 ` [PATCH 3/7] ndctl: cxl: add common function to enable event trace Dave Jiang
2022-09-14 20:48 ` [PATCH 4/7] ndctl: cxl: add common function to disable " Dave Jiang
2022-09-14 20:48 ` [PATCH 5/7] ndctl: cxl: add monitor function for event trace events Dave Jiang
2022-09-19 18:26 ` Alison Schofield
2022-09-14 20:48 ` [PATCH 6/7] ndctl: cxl: add logging functions for monitor Dave Jiang
2022-09-15 15:55 ` Nathan Fontenot
2022-09-15 16:02 ` Dave Jiang
2022-09-14 20:48 ` Dave Jiang [this message]
2022-09-14 22:19 ` [PATCH 0/7] ndctl: cxl: add monitor support for trace events Dave Jiang
2022-09-14 23:04 ` Verma, Vishal L
2022-09-22 14:21 ` Jonathan Cameron
2022-09-22 14:45 ` Dave Jiang
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=166318851033.3087953.1487642256782771767.stgit@djiang5-desk3.ch.intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=bwidawsk@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.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;
as well as URLs for NNTP newsgroup(s).