udev/net: several cleanups for config_parse_rps_cpu_mask()
- Previously, `LinkConfig.rps_cpu_mask == NULL` indicates setting RPS will be skipped, but now make the condition is changed to `LinkConfig.rps_cpu_mask.set == NULL`. Then, we can avoid allocating CPUSet when something configured. - When "disable" or "all", now allocate a temporal object, and then replace with it. No functional change, just refactoring.
This commit is contained in:
+19
-23
@@ -12,7 +12,6 @@
|
||||
#include "condition.h"
|
||||
#include "conf-files.h"
|
||||
#include "conf-parser.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "creds-util.h"
|
||||
#include "device-private.h"
|
||||
#include "device-util.h"
|
||||
@@ -78,7 +77,7 @@ static LinkConfig* link_config_free(LinkConfig *config) {
|
||||
free(config->alias);
|
||||
free(config->wol_password_file);
|
||||
erase_and_free(config->wol_password);
|
||||
cpu_set_free(config->rps_cpu_mask);
|
||||
cpu_set_done(&config->rps_cpu_mask);
|
||||
|
||||
ordered_hashmap_free(config->sr_iov_by_section);
|
||||
|
||||
@@ -954,10 +953,10 @@ static int link_apply_rps_cpu_mask(Link *link) {
|
||||
}
|
||||
|
||||
/* Skip if the config is not specified. */
|
||||
if (!config->rps_cpu_mask)
|
||||
if (!config->rps_cpu_mask.set)
|
||||
return 0;
|
||||
|
||||
mask_str = cpu_set_to_mask_string(config->rps_cpu_mask);
|
||||
mask_str = cpu_set_to_mask_string(&config->rps_cpu_mask);
|
||||
if (!mask_str)
|
||||
return log_oom();
|
||||
|
||||
@@ -1369,8 +1368,7 @@ int config_parse_rps_cpu_mask(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(cpu_set_freep) CPUSet *allocated = NULL;
|
||||
CPUSet *mask, **rps_cpu_mask = ASSERT_PTR(data);
|
||||
CPUSet *mask = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
@@ -1378,38 +1376,36 @@ int config_parse_rps_cpu_mask(
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*rps_cpu_mask = cpu_set_free(*rps_cpu_mask);
|
||||
cpu_set_done(mask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*rps_cpu_mask)
|
||||
mask = *rps_cpu_mask;
|
||||
else {
|
||||
allocated = new0(CPUSet, 1);
|
||||
if (!allocated)
|
||||
if (streq(rvalue, "disable")) {
|
||||
_cleanup_(cpu_set_done) CPUSet c = {};
|
||||
|
||||
r = cpu_set_realloc(&c, 1);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
mask = allocated;
|
||||
return cpu_set_done_and_replace(*mask, c);
|
||||
}
|
||||
|
||||
if (streq(rvalue, "disable"))
|
||||
cpu_set_done(mask);
|
||||
if (streq(rvalue, "all")) {
|
||||
_cleanup_(cpu_set_done) CPUSet c = {};
|
||||
|
||||
else if (streq(rvalue, "all")) {
|
||||
r = cpu_set_add_all(mask);
|
||||
r = cpu_set_add_all(&c);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to create CPU affinity mask representing \"all\" cpus, ignoring: %m");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
r = parse_cpu_set_extend(rvalue, mask, /* warn= */ true, unit, filename, line, lvalue);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
return cpu_set_done_and_replace(*mask, c);
|
||||
}
|
||||
|
||||
if (allocated)
|
||||
*rps_cpu_mask = TAKE_PTR(allocated);
|
||||
r = parse_cpu_set_extend(rvalue, mask, /* warn= */ true, unit, filename, line, lvalue);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "cpu-set-util.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "ethtool-util.h"
|
||||
#include "forward.h"
|
||||
@@ -110,7 +111,7 @@ struct LinkConfig {
|
||||
uint32_t eee_advertise[N_ADVERTISE];
|
||||
|
||||
/* Rx RPS CPU mask */
|
||||
CPUSet *rps_cpu_mask;
|
||||
CPUSet rps_cpu_mask;
|
||||
|
||||
/* SR-IOV */
|
||||
uint32_t sr_iov_num_vfs;
|
||||
|
||||
Reference in New Issue
Block a user