From: Breno Leitao <leitao@debian.org>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
Breno Leitao <leitao@debian.org>,
max@kutsevol.com, thepacketgeek@gmail.com, vlad.wing@gmail.com,
davej@codemonkey.org.uk
Subject: [PATCH net-next 2/4] netconsole: Add option to auto-populate CPU number in userdata
Date: Wed, 13 Nov 2024 07:10:53 -0800 [thread overview]
Message-ID: <20241113-netcon_cpu-v1-2-d187bf7c0321@debian.org> (raw)
In-Reply-To: <20241113-netcon_cpu-v1-0-d187bf7c0321@debian.org>
Add a new option to the netconsole subsystem to automatically populate
the CPU number that is sending the log message in the userdata field.
When enabled, this feature will append a "cpu=<cpu_number>" entry to the
userdata string, allowing the receiver to demultiplex and differentiate
between messages sent from different CPUs. This is particularly useful
when dealing with parallel log output that gets intermixed on the
receiver side.
The new option is added as a flag in the enum userdata_auto and can be
controlled through the populate_cpu_nr sysfs attribute in the netconsole
target's configfs hierarchy. The main benefits of this change are:
* Improved log message demultiplexing for parallel output.
* Better visibility into which CPU a particular log message originated
from.
Create userdata_auto as an bitwise enum, since I have immediate plans to
expand it.
Since the CPU id doesn't need to be precise, do not disable preemption
when getting the CPU id.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netconsole.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 965712d65a014c60f91bf35e48f1b112f66b8439..861e8988b8db4f29ae3de02222c9131059694aba 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -90,6 +90,14 @@ static DEFINE_MUTEX(target_cleanup_list_lock);
*/
static struct console netconsole_ext;
+/* Fields requiring kernel auto-population in userdata.
+ * The fields are designed as bitwise flags, allowing multiple fields to be set
+ */
+enum userdata_auto {
+ /* Populate CPU number that is sending the message */
+ AUTO_CPU_NR = BIT(0),
+};
+
/**
* struct netconsole_target - Represents a configured netconsole target.
* @list: Links this target into the target_list.
@@ -97,6 +105,7 @@ static struct console netconsole_ext;
* @userdata_group: Links to the userdata configfs hierarchy
* @userdata_complete: Cached, formatted string of append
* @userdata_length: String length of userdata_complete
+ * @userdata_auto: Kernel auto-populated bitwise fields in userdata.
* @enabled: On / off knob to enable / disable target.
* Visible from userspace (read-write).
* We maintain a strict 1:1 correspondence between this and
@@ -123,6 +132,7 @@ struct netconsole_target {
struct config_group userdata_group;
char userdata_complete[MAX_USERDATA_ENTRY_LENGTH * MAX_USERDATA_ITEMS];
size_t userdata_length;
+ enum userdata_auto userdata_auto;
#endif
bool enabled;
bool extended;
@@ -371,6 +381,18 @@ static ssize_t remote_mac_show(struct config_item *item, char *buf)
return sysfs_emit(buf, "%pM\n", to_target(item)->np.remote_mac);
}
+static ssize_t populate_cpu_nr_show(struct config_item *item, char *buf)
+{
+ struct netconsole_target *nt = to_target(item->ci_parent);
+ bool cpu_nr_enabled;
+
+ mutex_lock(&dynamic_netconsole_mutex);
+ cpu_nr_enabled = nt->userdata_auto & AUTO_CPU_NR;
+ mutex_unlock(&dynamic_netconsole_mutex);
+
+ return sysfs_emit(buf, "%d\n", cpu_nr_enabled);
+}
+
/*
* This one is special -- targets created through the configfs interface
* are not enabled (and the corresponding netpoll activated) by default.
@@ -726,6 +748,15 @@ static void update_userdata(struct netconsole_target *nt)
MAX_USERDATA_ENTRY_LENGTH, " %s=%s\n",
item->ci_name, udm_item->value);
}
+
+ /* Check if CPU NR should be populated, and append it to the user
+ * dictionary.
+ */
+ if (child_count < MAX_USERDATA_ITEMS && nt->userdata_auto & AUTO_CPU_NR)
+ scnprintf(&nt->userdata_complete[complete_idx],
+ MAX_USERDATA_ENTRY_LENGTH, " cpu=%u\n",
+ raw_smp_processor_id());
+
nt->userdata_length = strnlen(nt->userdata_complete,
sizeof(nt->userdata_complete));
}
@@ -757,7 +788,36 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf,
return ret;
}
+static ssize_t populate_cpu_nr_store(struct config_item *item, const char *buf,
+ size_t count)
+{
+ struct netconsole_target *nt = to_target(item->ci_parent);
+ bool cpu_nr_enabled;
+ ssize_t ret;
+
+ if (!nt)
+ return -EINVAL;
+
+ mutex_lock(&dynamic_netconsole_mutex);
+ ret = kstrtobool(buf, &cpu_nr_enabled);
+ if (ret)
+ goto out_unlock;
+
+ if (cpu_nr_enabled)
+ nt->userdata_auto |= AUTO_CPU_NR;
+ else
+ nt->userdata_auto &= ~AUTO_CPU_NR;
+
+ update_userdata(nt);
+
+ ret = strnlen(buf, count);
+out_unlock:
+ mutex_unlock(&dynamic_netconsole_mutex);
+ return ret;
+}
+
CONFIGFS_ATTR(userdatum_, value);
+CONFIGFS_ATTR(, populate_cpu_nr);
static struct configfs_attribute *userdatum_attrs[] = {
&userdatum_attr_value,
@@ -819,6 +879,7 @@ static void userdatum_drop(struct config_group *group, struct config_item *item)
}
static struct configfs_attribute *userdata_attrs[] = {
+ &attr_populate_cpu_nr,
NULL,
};
--
2.43.5
next prev parent reply other threads:[~2024-11-13 15:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 15:10 [PATCH net-next 0/4] netconsole: Add support for CPU population Breno Leitao
2024-11-13 15:10 ` [PATCH net-next 1/4] netconsole: Ensure dynamic_netconsole_mutex is held during userdata update Breno Leitao
2024-11-13 15:10 ` Breno Leitao [this message]
2024-11-19 2:33 ` [PATCH net-next 2/4] netconsole: Add option to auto-populate CPU number in userdata Jakub Kicinski
2024-11-19 17:07 ` Breno Leitao
2024-12-04 16:52 ` Breno Leitao
2024-11-13 15:10 ` [PATCH net-next 3/4] netconsole: docs: Add documentation for CPU number auto-population Breno Leitao
2024-11-13 15:10 ` [PATCH net-next 4/4] netconsole: selftest: Validate CPU number auto-population in userdata Breno Leitao
2024-11-19 2:35 ` Jakub Kicinski
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=20241113-netcon_cpu-v1-2-d187bf7c0321@debian.org \
--to=leitao@debian.org \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=davej@codemonkey.org.uk \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=max@kutsevol.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=thepacketgeek@gmail.com \
--cc=vlad.wing@gmail.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