summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-14 09:16:31 +0200
committerThomas Haller <thaller@redhat.com>2020-05-20 21:27:15 +0200
commit2f7914c8375a2aa182813e86beb6bae8b6853a4a (patch)
tree562b4046f7bad77bdebf41942d7e5d90d5812dcd
parent82fb3a9c5de15180530804bf718ad2b7d2dbf078 (diff)
downloadNetworkManager-2f7914c8375a2aa182813e86beb6bae8b6853a4a.tar.gz
device: in _ethtool_coalesce_set() only fetch current coalesce settings if needed
In the common case, the user doesn't set any coalesce options. Avoid always fetching the current settings, unless they are actually needed.
-rw-r--r--src/devices/nm-device.c88
-rw-r--r--src/platform/nm-platform.c17
-rw-r--r--src/platform/nm-platform.h8
3 files changed, 43 insertions, 70 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 418641358d..ab87f4646c 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -866,48 +866,6 @@ _ethtool_features_set (NMDevice *self,
ethtool_state->features = g_steal_pointer (&features);
}
-static gboolean
-_ethtool_init_coalesce (NMDevice *self,
- NMPlatform *platform,
- NMSettingEthtool *s_ethtool,
- NMEthtoolCoalesceState *coalesce)
-{
- GHashTable *hash;
- GHashTableIter iter;
- const char *name;
- GVariant *variant;
- gsize n_coalesce_set = 0;
-
- nm_assert (self);
- nm_assert (platform);
- nm_assert (coalesce);
- nm_assert (NM_IS_SETTING_ETHTOOL (s_ethtool));
-
- hash = _nm_setting_gendata_hash (NM_SETTING (s_ethtool), FALSE);
- if (!hash)
- return FALSE;
-
- g_hash_table_iter_init (&iter, hash);
- while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) {
- if (!g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32))
- continue;
- if (!nm_ethtool_optname_is_coalesce (name))
- continue;
-
- if (!nm_platform_ethtool_init_coalesce (platform,
- coalesce,
- name,
- g_variant_get_uint32(variant))) {
- _LOGW (LOGD_DEVICE, "ethtool: invalid coalesce setting %s", name);
- return FALSE;
- }
- ++n_coalesce_set;
-
- }
-
- return !!n_coalesce_set;
-}
-
static void
_ethtool_coalesce_reset (NMDevice *self,
NMPlatform *platform,
@@ -939,25 +897,49 @@ _ethtool_coalesce_set (NMDevice *self,
{
NMEthtoolCoalesceState coalesce_old;
NMEthtoolCoalesceState coalesce_new;
+ gboolean has_old = FALSE;
+ GHashTable *hash;
+ GHashTableIter iter;
+ const char *name;
+ GVariant *variant;
- nm_assert (ethtool_state);
nm_assert (NM_IS_DEVICE (self));
nm_assert (NM_IS_PLATFORM (platform));
nm_assert (NM_IS_SETTING_ETHTOOL (s_ethtool));
+ nm_assert (ethtool_state);
+ nm_assert (!ethtool_state->coalesce);
- if (!nm_platform_ethtool_get_link_coalesce (platform,
- ethtool_state->ifindex,
- &coalesce_old)) {
- _LOGW (LOGD_DEVICE, "ethtool: failure getting coalesce settings (cannot read)");
+ hash = _nm_setting_gendata_hash (NM_SETTING (s_ethtool), FALSE);
+ if (!hash)
return;
- }
- coalesce_new = coalesce_old;
+ g_hash_table_iter_init (&iter, hash);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) {
+ NMEthtoolID ethtool_id = nm_ethtool_id_get_by_name (name);
+
+ if (!nm_ethtool_id_is_coalesce (ethtool_id))
+ continue;
+
+ if (!has_old) {
+ if (!nm_platform_ethtool_get_link_coalesce (platform,
+ ethtool_state->ifindex,
+ &coalesce_old)) {
+ _LOGW (LOGD_DEVICE, "ethtool: failure getting coalesce settings (cannot read)");
+ return;
+ }
+ has_old = TRUE;
+ coalesce_new = coalesce_old;
+ }
+
+ nm_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32));
+
+ nm_platform_ethtool_init_coalesce (platform,
+ &coalesce_new,
+ ethtool_id,
+ g_variant_get_uint32 (variant));
+ }
- if (!_ethtool_init_coalesce (self,
- platform,
- s_ethtool,
- &coalesce_new))
+ if (!has_old)
return;
ethtool_state->coalesce = nm_memdup (&coalesce_old, sizeof (coalesce_old));
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 596f08542e..7b9457f7a5 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -3227,20 +3227,13 @@ nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
return nmp_utils_ethtool_get_coalesce (ifindex, coalesce);
}
-gboolean
+void
nm_platform_ethtool_init_coalesce (NMPlatform *self,
NMEthtoolCoalesceState *coalesce,
- const char *option_name,
+ int ethtool_id,
guint32 value)
{
- NMEthtoolID ethtool_id;
-
- g_return_val_if_fail (coalesce, FALSE);
- g_return_val_if_fail (option_name, FALSE);
-
- ethtool_id = nm_ethtool_id_get_by_name (option_name);
-
- g_return_val_if_fail (nm_ethtool_id_is_coalesce (ethtool_id), FALSE);
+ nm_assert (coalesce);
switch (ethtool_id) {
case NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX:
@@ -3310,10 +3303,8 @@ nm_platform_ethtool_init_coalesce (NMPlatform *self,
coalesce->tx_coalesce_usecs_low = value;
break;
default:
- g_return_val_if_reached (FALSE);
+ g_return_if_reached ();
}
-
- return TRUE;
}
gboolean
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 8957de429c..041bc87448 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1960,10 +1960,10 @@ gboolean nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
int ifindex,
NMEthtoolCoalesceState *coalesce);
-gboolean nm_platform_ethtool_init_coalesce (NMPlatform *self,
- NMEthtoolCoalesceState *coalesce,
- const char *option_name,
- guint32 value);
+void nm_platform_ethtool_init_coalesce (NMPlatform *self,
+ NMEthtoolCoalesceState *coalesce,
+ int ethtool_id,
+ guint32 value);
gboolean nm_platform_ethtool_set_coalesce (NMPlatform *self,
int ifindex,