From patchwork Thu Nov 10 00:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E606FC433FE for ; Thu, 10 Nov 2022 00:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbiKJAHj (ORCPT ); Wed, 9 Nov 2022 19:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232147AbiKJAHg (ORCPT ); Wed, 9 Nov 2022 19:07:36 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6537C18B13 for ; Wed, 9 Nov 2022 16:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038855; x=1699574855; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KTcf9Jz6Ov8SqHJS+xOJqORQ8ow/mqJlAXNoct1UmG0=; b=bKifKZ3eY2E6NzNJFkmX8PEx0Cj+JlsEO5C8RM96sL1jSChTiMlW418s wslM9qXLaJ6dpSyPuLsM9tJR2jxolCD3+jspYZndH5o9O9+TOFbXdEPLv 4PAu+OScv9rzooV2X7f51AcHjNZ8itYCJ86lwLVx0QM9wp0MllmXMvnc3 uk5kIupY4q7IX5DFr3jphjg+GDshqZOynEEr+LikVzniFdFNtJRResAwV 9znVfVZuxoGyXRQSprpKaH64BhJy6StlDKZ73mSyGfzay9kI4GWbfwyiH WYajgCHUnsNnJc61Irv4iHOjUzWmE06ZYKkGCnFMPD4VxPDrtS/CqlMX0 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="308783340" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="308783340" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:35 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="631442515" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="631442515" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:34 -0800 Subject: [PATCH v5 1/7] ndctl: cxl: add helper function to parse trace event to json object From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:07:34 -0700 Message-ID: <166803885399.145141.7371810852032502111.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add the helper function that parses a trace event captured by libtraceevent in a tep handle. All the parsed fields are added to a json object. The json object is added to the provided list in the input parameter. Tested-by: Alison Schofield Signed-off-by: Dave Jiang --- cxl/event_trace.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++ cxl/event_trace.h | 14 ++++ cxl/meson.build | 2 + meson.build | 1 4 files changed, 210 insertions(+) create mode 100644 cxl/event_trace.c create mode 100644 cxl/event_trace.h diff --git a/cxl/event_trace.c b/cxl/event_trace.c new file mode 100644 index 000000000000..3c9fb684139a --- /dev/null +++ b/cxl/event_trace.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2022, Intel Corp. All rights reserved. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "event_trace.h" + +#define _GNU_SOURCE +#include + +static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags) +{ + bool sign = flags & TEP_FIELD_IS_SIGNED; + int64_t val = 0; + + /* special case 64 bit as the call depends on sign */ + if (elem_size == 8) { + if (sign) + return json_object_new_int64(*(int64_t *)num); + else + return json_object_new_uint64(*(uint64_t *)num); + } + + /* All others fit in a signed 64 bit */ + switch (elem_size) { + case 1: + if (sign) + val = *(int8_t *)num; + else + val = *(uint8_t *)num; + break; + case 2: + if (sign) + val = *(int16_t *)num; + else + val = *(uint16_t *)num; + break; + case 4: + if (sign) + val = *(int32_t *)num; + else + val = *(uint32_t *)num; + break; + default: + /* + * Odd sizes are converted in the kernel to one of the above. + * It is an error to see them here. + */ + return NULL; + } + + return json_object_new_int64(val); +} + +static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, + struct list_head *jlist_head) +{ + struct json_object *jevent, *jobj, *jarray; + struct tep_format_field **fields; + struct jlist_node *jnode; + int i, j, rc = 0; + + jnode = malloc(sizeof(*jnode)); + if (!jnode) + return -ENOMEM; + + jevent = json_object_new_object(); + if (!jevent) { + rc = -ENOMEM; + goto err_jnode; + } + jnode->jobj = jevent; + + fields = tep_event_fields(event); + if (!fields) { + rc = -ENOENT; + goto err_jevent; + } + + jobj = json_object_new_string(event->system); + if (!jobj) { + rc = -ENOMEM; + goto err_jevent; + } + json_object_object_add(jevent, "system", jobj); + + jobj = json_object_new_string(event->name); + if (!jobj) { + rc = -ENOMEM; + goto err_jevent; + } + json_object_object_add(jevent, "event", jobj); + + jobj = json_object_new_uint64(record->ts); + if (!jobj) { + rc = -ENOMEM; + goto err_jevent; + } + json_object_object_add(jevent, "timestamp", jobj); + + for (i = 0; fields[i]; i++) { + struct tep_format_field *f = fields[i]; + int len; + + if (f->flags & TEP_FIELD_IS_STRING) { + char *str; + + str = tep_get_field_raw(NULL, event, f->name, record, &len, 0); + if (!str) + continue; + + jobj = json_object_new_string(str); + if (!jobj) { + rc = -ENOMEM; + goto err_jevent; + } + + json_object_object_add(jevent, f->name, jobj); + } else if (f->flags & TEP_FIELD_IS_ARRAY) { + unsigned char *data; + int chunks; + + data = tep_get_field_raw(NULL, event, f->name, record, &len, 0); + if (!data) + continue; + + jarray = json_object_new_array(); + if (!jarray) { + rc = -ENOMEM; + goto err_jevent; + } + + chunks = f->size / f->elementsize; + for (j = 0; j < chunks; j++) { + jobj = num_to_json(data, f->elementsize, f->flags); + if (!jobj) { + json_object_put(jarray); + return -ENOMEM; + } + json_object_array_add(jarray, jobj); + data += f->elementsize; + } + + json_object_object_add(jevent, f->name, jarray); + } else { /* single number */ + unsigned char *data; + char *tmp; + + data = tep_get_field_raw(NULL, event, f->name, record, &len, 0); + if (!data) + continue; + + /* check to see if we have a UUID */ + tmp = strcasestr(f->type, "uuid_t"); + if (tmp) { + char uuid[40]; + + uuid_unparse(data, uuid); + jobj = json_object_new_string(uuid); + if (!jobj) { + rc = -ENOMEM; + goto err_jevent; + } + + json_object_object_add(jevent, f->name, jobj); + continue; + } + + jobj = num_to_json(data, f->elementsize, f->flags); + if (!jobj) { + rc = -ENOMEM; + goto err_jevent; + } + + json_object_object_add(jevent, f->name, jobj); + } + } + + list_add_tail(jlist_head, &jnode->list); + return 0; + +err_jevent: + json_object_put(jevent); +err_jnode: + free(jnode); + return rc; +} diff --git a/cxl/event_trace.h b/cxl/event_trace.h new file mode 100644 index 000000000000..00975a0b5680 --- /dev/null +++ b/cxl/event_trace.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2022 Intel Corporation. All rights reserved. */ +#ifndef __CXL_EVENT_TRACE_H__ +#define __CXL_EVENT_TRACE_H__ + +#include +#include + +struct jlist_node { + struct json_object *jobj; + struct list_node list; +}; + +#endif diff --git a/cxl/meson.build b/cxl/meson.build index f2474aaa6e2e..8c7733431613 100644 --- a/cxl/meson.build +++ b/cxl/meson.build @@ -7,6 +7,7 @@ cxl_src = [ 'memdev.c', 'json.c', 'filter.c', + 'event_trace.c', ] cxl_tool = executable('cxl', @@ -19,6 +20,7 @@ cxl_tool = executable('cxl', kmod, json, versiondep, + traceevent, ], install : true, install_dir : rootbindir, diff --git a/meson.build b/meson.build index 20a646d135c7..f611e0bdd7f3 100644 --- a/meson.build +++ b/meson.build @@ -142,6 +142,7 @@ kmod = dependency('libkmod') libudev = dependency('libudev') uuid = dependency('uuid') json = dependency('json-c') +traceevent = dependency('libtraceevent') if get_option('docs').enabled() if get_option('asciidoctor').enabled() asciidoc = find_program('asciidoctor', required : true) From patchwork Thu Nov 10 00:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAE91C433FE for ; Thu, 10 Nov 2022 00:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbiKJAHm (ORCPT ); Wed, 9 Nov 2022 19:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232143AbiKJAHl (ORCPT ); Wed, 9 Nov 2022 19:07:41 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F09DB17A99 for ; Wed, 9 Nov 2022 16:07:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038860; x=1699574860; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bgE4cV4pKoNmNhtTJt9gbdSlFsN0Knt7pJIFCKeiaoU=; b=GQnsv2L4wOYJlvopdTl53JrItMHWC88SCwCm4LW296ZugUl0x2VYEKZH xDuK0bLaQRhsBn6zWFZ7wT/JBwZodd7d3ODgzho+/40hOA/Cf5fFqjqOO v4j2WAxBviy6QxS9VVQsGBy4QI4foZ1FVxKysYpUpXjZhIbqsibtZNQvA bsglmpgHNH20wiAi38H8UdMPbDYCcpSNvev2EgFrxOkOreNCkpP+hqoXv LQpnW97fZQXLwUZ6KCL3XFye7nZfUU0Haoh9sQr9KPhOA8mq1N0moLmzD m3yI4uXzSihM4fqs8ak4436eqzv0sblavKWs42sjCVpFpdmyZX9llukT/ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="375403408" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="375403408" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:40 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="631442541" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="631442541" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:40 -0800 Subject: [PATCH v5 2/7] ndctl: cxl: add helper to parse through all current events From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:07:39 -0700 Message-ID: <166803885992.145141.11751557821515668416.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add common function to iterate through and extract the events in the current trace buffer. The function uses tracefs_iterate_raw_events() from libtracefs to go through all the events loaded into a tep_handle. A callback is provided to the API call in order to parse the event. For cxl monitor, the "system" or category of trace event, in this case "cxl", is provided in order to filter for the CXL events. Tested-by: Alison Schofield Signed-off-by: Dave Jiang --- cxl/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ cxl/event_trace.h | 10 ++++++++++ cxl/meson.build | 1 + meson.build | 2 ++ 4 files changed, 50 insertions(+) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index 3c9fb684139a..d7bbd3cf4946 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "event_trace.h" #define _GNU_SOURCE @@ -191,3 +192,39 @@ err_jnode: free(jnode); return rc; } + +static int cxl_event_parse(struct tep_event *event, struct tep_record *record, + int cpu, void *ctx) +{ + struct event_ctx *event_ctx = (struct event_ctx *)ctx; + + /* Filter out all the events that the caller isn't interested in. */ + if (strcmp(event->system, event_ctx->system) != 0) + return 0; + + if (event_ctx->event_name) { + if (strcmp(event->name, event_ctx->event_name) != 0) + return 0; + } + + if (event_ctx->parse_event) + return event_ctx->parse_event(event, record, + &event_ctx->jlist_head); + + return cxl_event_to_json(event, record, &event_ctx->jlist_head); +} + +int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx) +{ + struct tep_handle *tep; + int rc; + + tep = tracefs_local_events(NULL); + if (!tep) + return -ENOMEM; + + rc = tracefs_iterate_raw_events(tep, inst, NULL, 0, cxl_event_parse, + ectx); + tep_free(tep); + return rc; +} diff --git a/cxl/event_trace.h b/cxl/event_trace.h index 00975a0b5680..e83737de0ad5 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -11,4 +11,14 @@ struct jlist_node { struct list_node list; }; +struct event_ctx { + const char *system; + struct list_head jlist_head; + const char *event_name; /* optional */ + int (*parse_event)(struct tep_event *event, struct tep_record *record, + struct list_head *jlist_head); /* optional */ +}; + +int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); + #endif diff --git a/cxl/meson.build b/cxl/meson.build index 8c7733431613..c59876262e76 100644 --- a/cxl/meson.build +++ b/cxl/meson.build @@ -21,6 +21,7 @@ cxl_tool = executable('cxl', json, versiondep, traceevent, + tracefs, ], install : true, install_dir : rootbindir, diff --git a/meson.build b/meson.build index f611e0bdd7f3..c204c8ac52de 100644 --- a/meson.build +++ b/meson.build @@ -143,6 +143,8 @@ libudev = dependency('libudev') uuid = dependency('uuid') json = dependency('json-c') traceevent = dependency('libtraceevent') +tracefs = dependency('libtracefs') + if get_option('docs').enabled() if get_option('asciidoctor').enabled() asciidoc = find_program('asciidoctor', required : true) From patchwork Thu Nov 10 00:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038174 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B45EC4332F for ; Thu, 10 Nov 2022 00:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232038AbiKJAHs (ORCPT ); Wed, 9 Nov 2022 19:07:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbiKJAHr (ORCPT ); Wed, 9 Nov 2022 19:07:47 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE0BF1EEEE for ; Wed, 9 Nov 2022 16:07:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038867; x=1699574867; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ehcg6U+XkUNEWruYQ06r5bcfAbWgr36pgmxI+ZpPk9M=; b=Z7501CheK0EwNm8kRQkfA0A326/lSL5xpOzNbuacf673EcrL4jLeMR2J strmqdwjdE4M8659Xc236RXggDl/RM2OBXYFnfycOysijApvekrVFoACz GiLDVwqxe6qD/ExKyO7mV5iJ/OhyipXWdO8uEbU4EtcK+tI6cbKrhet0O 9O3Uc2ghYdMAlWObefkqr7EvuSjoS804cCPEADLVam1g14HzvjcZwiqVG 4K2fU16ZvBe56D+9TJ6ttpxIabhV14NYDbzEqfS7VhC9LGFS6WSDjUPz9 Hvu23gI1CIMtWhwzsJ2pwHGb3FADoTM0d3v1fioACbqMgKzEq/YBPUNtG Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="312287935" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="312287935" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="631442549" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="631442549" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:46 -0800 Subject: [PATCH v5 3/7] ndctl: cxl: add common function to enable/disable event trace From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:07:45 -0700 Message-ID: <166803886584.145141.15515518810880150458.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add a common function for cxl command to enable and disable event tracing for the instance created. Will only enable "cxl" system. Signed-off-by: Dave Jiang --- cxl/event_trace.c | 21 +++++++++++++++++++++ cxl/event_trace.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index d7bbd3cf4946..a973a1f62d35 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -228,3 +228,24 @@ int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx) tep_free(tep); return rc; } + +int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, + const char *event) +{ + int rc; + + rc = tracefs_event_enable(inst, system, event); + if (rc == -1) + return -errno; + + if (tracefs_trace_is_on(inst)) + return 0; + + tracefs_trace_on(inst); + return 0; +} + +int cxl_event_tracing_disable(struct tracefs_instance *inst) +{ + return tracefs_trace_off(inst); +} diff --git a/cxl/event_trace.h b/cxl/event_trace.h index e83737de0ad5..ec6267202c8b 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -20,5 +20,8 @@ struct event_ctx { }; int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); +int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, + const char *event); +int cxl_event_tracing_disable(struct tracefs_instance *inst); #endif From patchwork Thu Nov 10 00:07:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65B8DC4332F for ; Thu, 10 Nov 2022 00:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbiKJAHz (ORCPT ); Wed, 9 Nov 2022 19:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232163AbiKJAHx (ORCPT ); Wed, 9 Nov 2022 19:07:53 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80BA618E1C for ; Wed, 9 Nov 2022 16:07:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038872; x=1699574872; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0Kq7b8Z3+KZEttxPX6Z4PVMSmmT8ijpwlx3QuzqVpc0=; b=iOA7zggSITqXq1yu6HiRLwxFqKfl/xccO5zVeqWSnMdYVslAG2sW8LUV +fcadA3C95+gMmiTTAKoIrtD0urPPvFRMU4R+mJOKhzIIGbI1K1gAjE9q sgYrLaXMcwv9KK7NzJ4Nb4Q6tFFjCOJhf6VnjOeB5Y8t+jrog8WIjy29g cFvBbJNbRGI9R6oMZ7jZ3Lt/+lAP8K8CZwEEauobaX7lZ83Lf1E8T236n 583GeH/NEU7i0iHQu5TW6wkPL4ksVHjyKw+dTiraNTRhwrsf3fE6ot6IE sz9LGOafEHTrGhr+aJshHt35H77u2GiVDdXzo3vJhOzr2jnOykrk8VRLF Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="337909827" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="337909827" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:52 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="882130216" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="882130216" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:51 -0800 Subject: [PATCH v5 4/7] ndctl: move common logging functions from ndctl/monitor.c to util/log.c From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:07:51 -0700 Message-ID: <166803887168.145141.3780565277727044591.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Since cxl/monitor.c will be using same logging functions that ndctl/monitor.c will be using, move common functions to util/log.c. Signed-off-by: Dave Jiang --- ndctl/monitor.c | 41 ++++------------------------------------- util/log.c | 34 ++++++++++++++++++++++++++++++++++ util/log.h | 8 +++++++- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 54678d6100b9..89903def63d4 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -33,7 +33,6 @@ static struct monitor { const char *log; const char *configs; const char *dimm_event; - FILE *log_file; bool daemon; bool human; bool verbose; @@ -61,38 +60,6 @@ do { \ VERSION, __func__, __LINE__, ##__VA_ARGS__); \ } while (0) -static void log_syslog(struct log_ctx *ctx, int priority, const char *file, - int line, const char *fn, const char *format, va_list args) -{ - vsyslog(priority, format, args); -} - -static void log_standard(struct log_ctx *ctx, int priority, const char *file, - int line, const char *fn, const char *format, va_list args) -{ - if (priority == 6) - vfprintf(stdout, format, args); - else - vfprintf(stderr, format, args); -} - -static void log_file(struct log_ctx *ctx, int priority, const char *file, - int line, const char *fn, const char *format, va_list args) -{ - FILE *f = monitor.log_file; - - if (priority != LOG_NOTICE) { - struct timespec ts; - - clock_gettime(CLOCK_REALTIME, &ts); - fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid()); - vfprintf(f, format, args); - } else - vfprintf(f, format, args); - - fflush(f); -} - static struct json_object *dimm_event_to_json(struct monitor_dimm *mdimm) { struct json_object *jevent, *jobj; @@ -648,8 +615,8 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx) else 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) { + monitor.ctx.log_file = fopen(monitor.log, "a+"); + if (!monitor.ctx.log_file) { error("open %s failed\n", monitor.log); rc = -errno; goto out; @@ -694,8 +661,8 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx) rc = monitor_event(ctx, &mfa); out: - if (monitor.log_file) - fclose(monitor.log_file); + if (monitor.ctx.log_file) + fclose(monitor.ctx.log_file); if (path) free(path); return rc; diff --git a/util/log.c b/util/log.c index 61ac509f4ac5..d4eef0a1fc5c 100644 --- a/util/log.c +++ b/util/log.c @@ -2,11 +2,45 @@ // Copyright (C) 2016-2020, Intel Corporation. All rights reserved. #include #include +#include #include #include #include +#include #include +void log_syslog(struct log_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, va_list args) +{ + vsyslog(priority, format, args); +} + +void log_standard(struct log_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, va_list args) +{ + if (priority == 6) + vfprintf(stdout, format, args); + else + vfprintf(stderr, format, args); +} + +void log_file(struct log_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, va_list args) +{ + FILE *f = ctx->log_file; + + if (priority != LOG_NOTICE) { + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, &ts); + fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, + getpid()); + } + + vfprintf(f, format, args); + fflush(f); +} + void do_log(struct log_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, ...) { diff --git a/util/log.h b/util/log.h index 28f1c7bfcea4..6e09b0dc6494 100644 --- a/util/log.h +++ b/util/log.h @@ -14,9 +14,15 @@ struct log_ctx { log_fn log_fn; const char *owner; int log_priority; + FILE *log_file; }; - +void log_syslog(struct log_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, va_list args); +void log_standard(struct log_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, va_list args); +void log_file(struct log_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, va_list args); void do_log(struct log_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, ...) __attribute__((format(printf, 6, 7))); From patchwork Thu Nov 10 00:07:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39156C4332F for ; Thu, 10 Nov 2022 00:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232181AbiKJAIO (ORCPT ); Wed, 9 Nov 2022 19:08:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbiKJAIC (ORCPT ); Wed, 9 Nov 2022 19:08:02 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E90418E21 for ; Wed, 9 Nov 2022 16:07:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038878; x=1699574878; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SmObFSUKhAvOi9RG1lZX2VYePNpLXwzKEIb2Ji9XQOg=; b=mgmpU79t/Bs0OecYEvHgsGFeP4arbx34trSWfBSifgBW+hwY5Ln0a/Tp EF7U2iyPkeLQqb01URY+EHyhFIwAt874CZN5TEY0NH0WUkwOt1q/lGAa0 6CX2yTo52T0YecaWn7LiDmRac5+sHPDyaSkEOEjtKAqOG0o9MJut3Ajn2 7QS5dUrJwKWgVeVfJ3wJK+yJndee4T0aLxa5GqIZ34P0cE9E8VP6QdmwD i98EtW6iYMma18dOlVsCZup0ZmJsxRIfChNZyXCqglb7DWMcVGfMB+6rY rVa+Jv/z20iS0YALyTMYDh2kbZN6OUtzr4mcy9nlDA1sUvmvefiaetGtq Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="373272995" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="373272995" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="882130254" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="882130254" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:07:57 -0800 Subject: [PATCH v5 5/7] ndctl: cxl: add monitor command for event trace events From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:07:57 -0700 Message-ID: <166803887731.145141.12691742774548909895.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add function that creates an event trace instance and utilize the cxl event trace common functions to extract interested events from the trace buffer. The monitoring function will pend on an epoll fd and wait for new events to appear in the trace buffer. 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 --- cxl/builtin.h | 1 cxl/cxl.c | 1 cxl/meson.build | 1 cxl/monitor.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 cxl/monitor.c 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/meson.build b/cxl/meson.build index c59876262e76..eb8b2b1070ed 100644 --- a/cxl/meson.build +++ b/cxl/meson.build @@ -8,6 +8,7 @@ cxl_src = [ 'json.c', 'filter.c', 'event_trace.c', + 'monitor.c', ] cxl_tool = executable('cxl', diff --git a/cxl/monitor.c b/cxl/monitor.c new file mode 100644 index 000000000000..31e6f98f5299 --- /dev/null +++ b/cxl/monitor.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2022, Intel Corp. All rights reserved. +/* Some bits copied from ndctl monitor code */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* reuse the core log helpers for the monitor logger */ +#ifndef ENABLE_LOGGING +#define ENABLE_LOGGING +#endif +#ifndef ENABLE_DEBUG +#define ENABLE_DEBUG +#endif +#include + +#include "event_trace.h" + +static const char *cxl_system = "cxl"; +const char *default_log = "/var/log/cxl-monitor.log"; + +static struct monitor { + const char *log; + struct log_ctx ctx; + FILE *log_file; + bool human; + bool verbose; + bool daemon; +} monitor; + +static int monitor_event(struct cxl_ctx *ctx) +{ + int fd, epollfd, rc = 0, timeout = -1; + struct epoll_event ev, *events; + struct tracefs_instance *inst; + struct event_ctx ectx; + int jflag; + + events = calloc(1, sizeof(struct epoll_event)); + if (!events) { + err(&monitor, "alloc for events error\n"); + return -ENOMEM; + } + + epollfd = epoll_create1(0); + if (epollfd == -1) { + rc = -errno; + err(&monitor, "epoll_create1() error: %d\n", rc); + goto epoll_err; + } + + inst = tracefs_instance_create("cxl_monitor"); + if (!inst) { + rc = -errno; + err(&monitor, "tracefs_instance_create( failed: %d\n", rc); + goto inst_err; + } + + fd = tracefs_instance_file_open(inst, "trace_pipe", -1); + if (fd < 0) { + rc = fd; + err(&monitor, "tracefs_instance_file_open() err: %d\n", rc); + goto inst_file_err; + } + + memset(&ev, 0, sizeof(ev)); + ev.events = EPOLLIN; + ev.data.fd = fd; + + if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) != 0) { + rc = -errno; + err(&monitor, "epoll_ctl() error: %d\n", rc); + goto epoll_ctl_err; + } + + rc = cxl_event_tracing_enable(inst, cxl_system, NULL); + if (rc < 0) { + err(&monitor, "cxl_trace_event_enable() failed: %d\n", rc); + goto event_en_err; + } + + memset(&ectx, 0, sizeof(ectx)); + ectx.system = cxl_system; + if (monitor.human) + jflag = JSON_C_TO_STRING_PRETTY; + else + jflag = JSON_C_TO_STRING_PLAIN; + + while (1) { + struct jlist_node *jnode, *next; + + rc = epoll_wait(epollfd, events, 1, timeout); + if (rc < 0) { + rc = -errno; + if (errno != EINTR) + err(&monitor, "epoll_wait error: %d\n", -errno); + break; + } + + list_head_init(&ectx.jlist_head); + rc = cxl_parse_events(inst, &ectx); + if (rc < 0) + goto parse_err; + + if (list_empty(&ectx.jlist_head)) + continue; + + list_for_each_safe(&ectx.jlist_head, jnode, next, list) { + notice(&monitor, "%s\n", + json_object_to_json_string_ext(jnode->jobj, jflag)); + list_del(&jnode->list); + json_object_put(jnode->jobj); + free(jnode); + } + } + +parse_err: + rc = cxl_event_tracing_disable(inst); +event_en_err: +epoll_ctl_err: + close(fd); +inst_file_err: + tracefs_instance_free(inst); +inst_err: + close(epollfd); +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, + " | 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 []", + 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.daemon) { + monitor.ctx.log_fn = log_standard; + } else { + const char *log = monitor.log; + + if (!monitor.log) + log = default_log; + monitor.log_file = fopen(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; +} From patchwork Thu Nov 10 00:08:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3029CC4332F for ; Thu, 10 Nov 2022 00:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232163AbiKJAIS (ORCPT ); Wed, 9 Nov 2022 19:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232177AbiKJAIN (ORCPT ); Wed, 9 Nov 2022 19:08:13 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EBC18B13 for ; Wed, 9 Nov 2022 16:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038885; x=1699574885; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9bYf4uzMvSiwyh8AUjn4qN7a2n9nebGOpPbY+vozG/0=; b=dYv2O9DdjPx2iWqbQnI8yE3ug3w2sKWNF/OVbE85aEDEO+JnYgrcc05F 3XvHR2hnRg+r849GyrNhqCRtUtGms+fbjIjJL8KK9zybKJwXbZQp+x1Df /Ynqk85Gjv7S9XqpSZkzW0+zFAQH8gaqu1bAE76+3GXDxLW32rz4Q/Y1G Lmf8NTpsGav4fQy0qkqVofrWSr4lco4ivbYoihY5q6el0rcWmplwJs1kL hSQXe5GxXjJoNvq0eucv96UYzN73Ng2/jMSUczxFMdsLgJrLVUUIBuQ23 1nRMDR0Gci9sas9EaM/Dxb71KoFkD1L7XN+uhQHFGUuLMtvD8fnjVD+9s Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="312928108" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="312928108" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:08:04 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="882130295" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="882130295" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:08:03 -0800 Subject: [PATCH v5 6/7] ndctl: cxl: add systemd service for monitor From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:08:02 -0700 Message-ID: <166803888294.145141.16866651060328585251.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add a systemd service file for cxl monitor to start the monitoring service on boot initialization. Add the installation setup for the service file. Signed-off-by: Dave Jiang --- cxl/cxl-monitor.service | 9 +++++++++ cxl/meson.build | 4 ++++ ndctl.spec.in | 1 + 3 files changed, 14 insertions(+) create mode 100644 cxl/cxl-monitor.service diff --git a/cxl/cxl-monitor.service b/cxl/cxl-monitor.service new file mode 100644 index 000000000000..66de39d883be --- /dev/null +++ b/cxl/cxl-monitor.service @@ -0,0 +1,9 @@ +[Unit] +Description=CXL Monitor Daemon + +[Service] +Type=simple +ExecStart=/usr/bin/cxl monitor + +[Install] +WantedBy=multi-user.target diff --git a/cxl/meson.build b/cxl/meson.build index eb8b2b1070ed..fc2e946707a8 100644 --- a/cxl/meson.build +++ b/cxl/meson.build @@ -11,6 +11,10 @@ cxl_src = [ 'monitor.c', ] +if get_option('systemd').enabled() + install_data('cxl-monitor.service', install_dir : systemdunitdir) +endif + cxl_tool = executable('cxl', cxl_src, include_directories : root_inc, diff --git a/ndctl.spec.in b/ndctl.spec.in index cfcafa2ba816..c883317c5ce7 100644 --- a/ndctl.spec.in +++ b/ndctl.spec.in @@ -194,6 +194,7 @@ fi %{_bindir}/cxl %{_mandir}/man1/cxl* %{bashcompdir}/cxl +%{_unitdir}/cxl-monitor.service %files -n LNAME %defattr(-,root,root) From patchwork Thu Nov 10 00:08:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13038178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63BFCC433FE for ; Thu, 10 Nov 2022 00:08:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231828AbiKJAIV (ORCPT ); Wed, 9 Nov 2022 19:08:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232208AbiKJAIP (ORCPT ); Wed, 9 Nov 2022 19:08:15 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1EE29804 for ; Wed, 9 Nov 2022 16:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668038890; x=1699574890; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yAOtC6k/Gr4dNTMKOO78BnW1LvIBCpDNKx2BQ5dyxfA=; b=Y2g2+mwFaNlON/Wefkcy31PGG9kFnvCcCtDIhlgJf89Gnp4/QxARxl/F JvmWCDJCQq8+v/Gxr7fMa9jvg34vpY8d87tsLodi2Q++135V3UfzYEDEs KDCjtOycyVwgDlC/mMvSscMwdcPcOusepMLe0qLlVsHiBZ00sAX7kzqDs 31ave6olKE02iFlgS4LAlE0WEeSG2ym4WIcQmUrkr377x5Dggs3P/nVgR E5J/27VULiiX6THT8/dLbxdzd2HbIcAKhskFUl6FG4K4tVu1vRIsiOdpy dyNs1N+z/K4QLXaaRtl6X2s7tSmXdIcJ7z4VBjDGX6D7mywHySpPY15Ce w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="294502189" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="294502189" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:08:10 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="882130336" X-IronPort-AV: E=Sophos;i="5.96,152,1665471600"; d="scan'208";a="882130336" Received: from djiang5-desk3.ch.intel.com ([143.182.136.137]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 16:08:09 -0800 Subject: [PATCH v5 7/7] ndctl: cxl: add man page documentation for monitor From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rostedt@goodmis.org Date: Wed, 09 Nov 2022 17:08:09 -0700 Message-ID: <166803888924.145141.2305759221442551251.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> References: <166803877747.145141.11853418648969334939.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/1.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add man page documentation to explain the usage of cxl monitor. Signed-off-by: Dave Jiang --- Documentation/cxl/cxl-monitor.txt | 62 +++++++++++++++++++++++++++++++++++++ Documentation/cxl/meson.build | 1 + 2 files changed, 63 insertions(+) create mode 100644 Documentation/cxl/cxl-monitor.txt diff --git a/Documentation/cxl/cxl-monitor.txt b/Documentation/cxl/cxl-monitor.txt new file mode 100644 index 000000000000..3fc992e4d4d9 --- /dev/null +++ b/Documentation/cxl/cxl-monitor.txt @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-monitor(1) +============== + +NAME +---- +cxl-monitor - Monitor the CXL trace events + +SYNOPSIS +-------- +[verse] +'cxl monitor' [] + +DESCRIPTION +----------- +cxl-monitor is used for monitoring the CXL trace events emitted by +the kernel and convert them to json objects and dumping the json format +notifications to standard output or a logfile. + +EXAMPLES +-------- + +Run a monitor as a daemon to monitor events and output to a log file. +[verse] +cxl monitor --daemon --log=/var/log/cxl-monitor.log + +Run a monitor as a one-shot command and output the notifications to stdio. +[verse] +cxl monitor + +Run a monitor daemon as a system service +[verse] +systemctl start cxl-monitor.service + +OPTIONS +------- +-l:: +--log=:: + Send log messages to the specified destination. + - "": + Send log messages to specified . When fopen() is not able + to open , log messages will be forwarded to syslog. + - "standard": + Send messages to standard output. + +The default log destination is '/var/log/cxl-monitor.log' if "--daemon" is specified, +otherwise 'standard'. Note that standard and relative path for +will not work if "--daemon" is specified. + +--daemon:: + Run a monitor as a daemon. + +include::verbose-option.txt[] + +include::human-option.txt[] + +include::../copyright.txt[] + +SEE ALSO +-------- +linkcxl:cxl-list[1] diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build index 147ea7130211..a6d77ab8cbc2 100644 --- a/Documentation/cxl/meson.build +++ b/Documentation/cxl/meson.build @@ -45,6 +45,7 @@ cxl_manpages = [ 'cxl-disable-region.txt', 'cxl-enable-region.txt', 'cxl-destroy-region.txt', + 'cxl-monitor.txt', ] foreach man : cxl_manpages