libnm: add ethtool channels properties

ethtool "channels" parameters can be used to configure multiple queues
for a NIC, which helps to improve performances. Until now, users had
to use dispatcher scripts to change those parameters. Introduce native
support in NetworkManager by adding the following properties:

 - ethtool.channels-rx
 - ethtool.channels-tx
 - ethtool.channels-other
 - ethtool.channels-combined
This commit is contained in:
Beniamino Galvani 2023-10-11 18:12:13 +02:00 committed by Íñigo Huguet
parent 48eaee471f
commit 80dd179ffd
13 changed files with 113 additions and 2 deletions

View file

@ -1346,6 +1346,7 @@ write_ethtool_setting(NMConnection *connection, shvarFile *ifcfg, GError **error
guint32 u32;
gboolean b;
gboolean any_option = FALSE;
char prop_name[300];
s_con = nm_connection_get_setting_connection(connection);
if (s_con) {
@ -1426,6 +1427,18 @@ write_ethtool_setting(NMConnection *connection, shvarFile *ifcfg, GError **error
any_option = TRUE;
}
is_first = TRUE;
for (ethtool_id = _NM_ETHTOOL_ID_CHANNELS_FIRST; ethtool_id <= _NM_ETHTOOL_ID_CHANNELS_LAST;
ethtool_id++) {
if (nm_setting_option_get_uint32(NM_SETTING(s_ethtool),
nm_ethtool_data[ethtool_id]->optname,
&u32)) {
nm_sprintf_buf(prop_name, "ethtool.%s", nm_ethtool_data[ethtool_id]->optname);
set_error_unsupported(error, connection, prop_name, FALSE);
return FALSE;
}
}
if (!any_option) {
/* Write an empty dummy "-A" option without arguments. This is to
* ensure that the reader will create an (all default) NMSettingEthtool.

View file

@ -3623,6 +3623,11 @@ test_roundtrip_ethtool(void)
optname = nm_ethtool_data[ethtool_id]->optname;
vtype = nm_ethtool_id_get_variant_type(ethtool_id);
if (nm_ethtool_optname_is_channels(optname)) {
/* Not supported */
continue;
}
if (NM_IN_SET(ethtool_id,
NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX,
NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX)) {

View file

@ -124,14 +124,23 @@ typedef enum {
NM_ETHTOOL_ID_RING_TX,
_NM_ETHTOOL_ID_RING_LAST = NM_ETHTOOL_ID_RING_TX,
_NM_ETHTOOL_ID_LAST = _NM_ETHTOOL_ID_RING_LAST,
_NM_ETHTOOL_ID_CHANNELS_FIRST = _NM_ETHTOOL_ID_RING_LAST + 1,
NM_ETHTOOL_ID_CHANNELS_RX = _NM_ETHTOOL_ID_CHANNELS_FIRST,
NM_ETHTOOL_ID_CHANNELS_TX,
NM_ETHTOOL_ID_CHANNELS_OTHER,
NM_ETHTOOL_ID_CHANNELS_COMBINED,
_NM_ETHTOOL_ID_CHANNELS_LAST = NM_ETHTOOL_ID_CHANNELS_COMBINED,
_NM_ETHTOOL_ID_LAST = _NM_ETHTOOL_ID_CHANNELS_LAST,
_NM_ETHTOOL_ID_COALESCE_NUM =
(_NM_ETHTOOL_ID_COALESCE_LAST - _NM_ETHTOOL_ID_COALESCE_FIRST + 1),
_NM_ETHTOOL_ID_FEATURE_NUM = (_NM_ETHTOOL_ID_FEATURE_LAST - _NM_ETHTOOL_ID_FEATURE_FIRST + 1),
_NM_ETHTOOL_ID_RING_NUM = (_NM_ETHTOOL_ID_RING_LAST - _NM_ETHTOOL_ID_RING_FIRST + 1),
_NM_ETHTOOL_ID_PAUSE_NUM = (_NM_ETHTOOL_ID_PAUSE_LAST - _NM_ETHTOOL_ID_PAUSE_FIRST + 1),
_NM_ETHTOOL_ID_NUM = (_NM_ETHTOOL_ID_LAST - _NM_ETHTOOL_ID_FIRST + 1),
_NM_ETHTOOL_ID_CHANNELS_NUM =
(_NM_ETHTOOL_ID_CHANNELS_LAST - _NM_ETHTOOL_ID_CHANNELS_FIRST + 1),
_NM_ETHTOOL_ID_NUM = (_NM_ETHTOOL_ID_LAST - _NM_ETHTOOL_ID_FIRST + 1),
} NMEthtoolID;
#define _NM_ETHTOOL_ID_FEATURE_AS_IDX(ethtool_id) ((ethtool_id) -_NM_ETHTOOL_ID_FEATURE_FIRST)
@ -143,6 +152,7 @@ typedef enum {
NM_ETHTOOL_TYPE_FEATURE,
NM_ETHTOOL_TYPE_RING,
NM_ETHTOOL_TYPE_PAUSE,
NM_ETHTOOL_TYPE_CHANNELS,
} NMEthtoolType;
/****************************************************************************/
@ -171,6 +181,12 @@ nm_ethtool_id_is_pause(NMEthtoolID id)
return id >= _NM_ETHTOOL_ID_PAUSE_FIRST && id <= _NM_ETHTOOL_ID_PAUSE_LAST;
}
static inline gboolean
nm_ethtool_id_is_channels(NMEthtoolID id)
{
return id >= _NM_ETHTOOL_ID_CHANNELS_FIRST && id <= _NM_ETHTOOL_ID_CHANNELS_LAST;
}
/*****************************************************************************/
typedef enum {

View file

@ -106,11 +106,19 @@ const NMEthtoolData *const nm_ethtool_data[_NM_ETHTOOL_ID_NUM + 1] = {
ETHT_DATA(RING_RX_JUMBO),
ETHT_DATA(RING_RX_MINI),
ETHT_DATA(RING_TX),
ETHT_DATA(CHANNELS_RX),
ETHT_DATA(CHANNELS_TX),
ETHT_DATA(CHANNELS_OTHER),
ETHT_DATA(CHANNELS_COMBINED),
[_NM_ETHTOOL_ID_NUM] = NULL,
};
static const guint8 _by_name[_NM_ETHTOOL_ID_NUM] = {
/* sorted by optname. */
NM_ETHTOOL_ID_CHANNELS_COMBINED,
NM_ETHTOOL_ID_CHANNELS_OTHER,
NM_ETHTOOL_ID_CHANNELS_RX,
NM_ETHTOOL_ID_CHANNELS_TX,
NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX,
NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX,
NM_ETHTOOL_ID_COALESCE_PKT_RATE_HIGH,
@ -291,6 +299,8 @@ nm_ethtool_id_to_type(NMEthtoolID id)
return NM_ETHTOOL_TYPE_RING;
if (nm_ethtool_id_is_pause(id))
return NM_ETHTOOL_TYPE_PAUSE;
if (nm_ethtool_id_is_channels(id))
return NM_ETHTOOL_TYPE_CHANNELS;
return NM_ETHTOOL_TYPE_UNKNOWN;
}
@ -302,6 +312,7 @@ nm_ethtool_id_get_variant_type(NMEthtoolID ethtool_id)
case NM_ETHTOOL_TYPE_FEATURE:
case NM_ETHTOOL_TYPE_PAUSE:
return G_VARIANT_TYPE_BOOLEAN;
case NM_ETHTOOL_TYPE_CHANNELS:
case NM_ETHTOOL_TYPE_COALESCE:
case NM_ETHTOOL_TYPE_RING:
return G_VARIANT_TYPE_UINT32;

View file

@ -104,6 +104,11 @@ G_BEGIN_DECLS
#define NM_ETHTOOL_OPTNAME_PAUSE_RX "pause-rx"
#define NM_ETHTOOL_OPTNAME_PAUSE_TX "pause-tx"
#define NM_ETHTOOL_OPTNAME_CHANNELS_RX "channels-rx"
#define NM_ETHTOOL_OPTNAME_CHANNELS_TX "channels-tx"
#define NM_ETHTOOL_OPTNAME_CHANNELS_OTHER "channels-other"
#define NM_ETHTOOL_OPTNAME_CHANNELS_COMBINED "channels-combined"
/*****************************************************************************/
G_END_DECLS

View file

@ -1947,4 +1947,5 @@ global:
libnm_1_46_0 {
global:
nm_access_point_get_bandwidth;
nm_ethtool_optname_is_channels;
} libnm_1_44_0;

View file

@ -104,6 +104,11 @@ G_BEGIN_DECLS
#define NM_ETHTOOL_OPTNAME_PAUSE_RX "pause-rx"
#define NM_ETHTOOL_OPTNAME_PAUSE_TX "pause-tx"
#define NM_ETHTOOL_OPTNAME_CHANNELS_RX "channels-rx"
#define NM_ETHTOOL_OPTNAME_CHANNELS_TX "channels-tx"
#define NM_ETHTOOL_OPTNAME_CHANNELS_OTHER "channels-other"
#define NM_ETHTOOL_OPTNAME_CHANNELS_COMBINED "channels-combined"
/*****************************************************************************/
G_END_DECLS

View file

@ -1292,6 +1292,22 @@
dbus-type="u"
is-setting-option="1"
/>
<property name="channels-rx"
dbus-type="u"
is-setting-option="1"
/>
<property name="channels-tx"
dbus-type="u"
is-setting-option="1"
/>
<property name="channels-other"
dbus-type="u"
is-setting-option="1"
/>
<property name="channels-combined"
dbus-type="u"
is-setting-option="1"
/>
</setting>
<setting name="generic"
gtype="NMSettingGeneric"

View file

@ -75,6 +75,22 @@ nm_ethtool_optname_is_ring(const char *optname)
return optname && nm_ethtool_id_is_ring(nm_ethtool_id_get_by_name(optname));
}
/**
* nm_ethtool_optname_is_channels:
* @optname: (nullable): the option name to check
*
* Checks whether @optname is a valid option name for a channels setting.
*
* Returns: %TRUE, if @optname is valid
*
* Since: 1.46
*/
gboolean
nm_ethtool_optname_is_channels(const char *optname)
{
return optname && nm_ethtool_id_is_channels(nm_ethtool_id_get_by_name(optname));
}
/**
* nm_ethtool_optname_is_pause:
* @optname: (nullable): the option name to check

View file

@ -26,6 +26,9 @@ gboolean nm_ethtool_optname_is_ring(const char *optname);
NM_AVAILABLE_IN_1_32
gboolean nm_ethtool_optname_is_pause(const char *optname);
NM_AVAILABLE_IN_1_46
gboolean nm_ethtool_optname_is_channels(const char *optname);
/*****************************************************************************/
#define NM_TYPE_SETTING_ETHTOOL (nm_setting_ethtool_get_type())

View file

@ -4422,6 +4422,7 @@ _get_fcn_ethtool(ARGS_GET_FCN)
RETURN_UNSUPPORTED_GET_TYPE();
switch (nm_ethtool_id_to_type(ethtool_id)) {
case NM_ETHTOOL_TYPE_CHANNELS:
case NM_ETHTOOL_TYPE_COALESCE:
case NM_ETHTOOL_TYPE_RING:
if (!nm_setting_option_get_uint32(setting, nm_ethtool_data[ethtool_id]->optname, &u32)) {
@ -4459,6 +4460,7 @@ _set_fcn_ethtool(ARGS_SET_FCN)
goto do_unset;
switch (nm_ethtool_id_to_type(ethtool_id)) {
case NM_ETHTOOL_TYPE_CHANNELS:
case NM_ETHTOOL_TYPE_COALESCE:
case NM_ETHTOOL_TYPE_RING:
i64 = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXUINT32, -1);
@ -5928,6 +5930,10 @@ static const NMMetaPropertyInfo *const property_infos_ETHTOOL[] = {
PROPERTY_INFO_ETHTOOL (RING_RX_JUMBO),
PROPERTY_INFO_ETHTOOL (RING_RX_MINI),
PROPERTY_INFO_ETHTOOL (RING_TX),
PROPERTY_INFO_ETHTOOL (CHANNELS_RX),
PROPERTY_INFO_ETHTOOL (CHANNELS_TX),
PROPERTY_INFO_ETHTOOL (CHANNELS_OTHER),
PROPERTY_INFO_ETHTOOL (CHANNELS_COMBINED),
NULL,
};

View file

@ -112,6 +112,7 @@ get_ethtool_format(const NMMetaPropertyInfo *prop_info)
ethtool_id = prop_info->property_typ_data->subtype.ethtool.ethtool_id;
switch (nm_ethtool_id_to_type(ethtool_id)) {
case NM_ETHTOOL_TYPE_CHANNELS:
case NM_ETHTOOL_TYPE_COALESCE:
case NM_ETHTOOL_TYPE_RING:
return g_strdup("integer");
@ -309,6 +310,7 @@ append_ethtool_valid_values(const NMMetaPropertyInfo *prop_info, GPtrArray *vali
ethtool_id = prop_info->property_typ_data->subtype.ethtool.ethtool_id;
switch (nm_ethtool_id_to_type(ethtool_id)) {
case NM_ETHTOOL_TYPE_CHANNELS:
case NM_ETHTOOL_TYPE_COALESCE:
case NM_ETHTOOL_TYPE_RING:
g_ptr_array_add(valid_values, g_strdup_printf("0 - %u", G_MAXUINT32));

View file

@ -1040,6 +1040,18 @@
<property name="ring-tx"
format="integer"
values="0 - 4294967295" />
<property name="channels-rx"
format="integer"
values="0 - 4294967295" />
<property name="channels-tx"
format="integer"
values="0 - 4294967295" />
<property name="channels-other"
format="integer"
values="0 - 4294967295" />
<property name="channels-combined"
format="integer"
values="0 - 4294967295" />
</setting>
<setting name="generic" >
</setting>