free(config->alias);
free(config->wol_password_file);
erase_and_free(config->wol_password);
+ cpu_set_free(config->rps_cpu_mask);
ordered_hashmap_free_with_destructor(config->sr_iov_by_section, sr_iov_free);
return 0;
}
+static int link_apply_rps_cpu_mask(Link *link) {
+ _cleanup_free_ char *mask_str = NULL;
+ LinkConfig *config;
+ int r;
+
+ assert(link);
+ config = ASSERT_PTR(link->config);
+
+ /* Skip if the config is not specified. */
+ if (!config->rps_cpu_mask)
+ return 0;
+
+ mask_str = cpu_set_to_mask_string(config->rps_cpu_mask);
+ if (!mask_str)
+ return log_oom();
+
+ log_link_debug(link, "Applying RPS CPU mask: %s", mask_str);
+
+ /* Currently, this will set CPU mask to all rx queue of matched device. */
+ FOREACH_DEVICE_SYSATTR(link->device, attr) {
+ const char *c;
+
+ c = path_startswith(attr, "queues/");
+ if (!c)
+ continue;
+
+ c = startswith(c, "rx-");
+ if (!c)
+ continue;
+
+ c += strcspn(c, "/");
+
+ if (!path_equal(c, "/rps_cpus"))
+ continue;
+
+ r = sd_device_set_sysattr_value(link->device, attr, mask_str);
+ if (r < 0)
+ log_link_warning_errno(link, r, "Failed to write %s sysfs attribute, ignoring: %m", attr);
+ }
+
+ return 0;
+}
+
static int link_apply_udev_properties(Link *link, bool test) {
LinkConfig *config;
sd_device *device;
if (r < 0)
return r;
+ r = link_apply_rps_cpu_mask(link);
+ if (r < 0)
+ return r;
+
return 0;
}
return 0;
}
+int config_parse_rps_cpu_mask(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ _cleanup_(cpu_set_freep) CPUSet *allocated = NULL;
+ CPUSet *mask, **rps_cpu_mask = ASSERT_PTR(data);
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ *rps_cpu_mask = cpu_set_free(*rps_cpu_mask);
+ return 0;
+ }
+
+ if (*rps_cpu_mask)
+ mask = *rps_cpu_mask;
+ else {
+ allocated = new0(CPUSet, 1);
+ if (!allocated)
+ return log_oom();
+
+ mask = allocated;
+ }
+
+ if (streq(rvalue, "disable")) {
+ cpu_set_reset(mask);
+ return 0;
+ }
+
+ if (streq(rvalue, "all")) {
+ r = cpu_mask_add_all(mask);
+ 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;
+ }
+
+ if (allocated)
+ *rps_cpu_mask = TAKE_PTR(allocated);
+
+ return 0;
+}
+
static const char* const mac_address_policy_table[_MAC_ADDRESS_POLICY_MAX] = {
[MAC_ADDRESS_POLICY_PERSISTENT] = "persistent",
[MAC_ADDRESS_POLICY_RANDOM] = "random",