Skip to content

Commit

Permalink
Merge pull request oracle#29 from drakenclimber/test
Browse files Browse the repository at this point in the history
Merge adaptived pull requests
  • Loading branch information
drakenclimber authored Dec 5, 2024
2 parents fdabb01 + 5cc9c5f commit 8b7c84e
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 54 deletions.
1 change: 1 addition & 0 deletions adaptived/doc/internal/list-of-built-in-effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Parameters that accept long long or float also support some human-readable forma
| [logger](../../src/effects/logger.c) | Given an array of files, write their contents to "logfile" | <ul><li>"logfile" (string) - Output file to store the log data</li><li>"max_file_size" (int - optional) - Maximum amount of data that will be copied from each source file. Defaults to 32kB if not specified</li><li>"files" (array)<ul><li>"file" (string) - file to copy</li></ul></li><li>"separator_prefix" (string - optional) - If specified, this string will be written each time this effect triggers</li><li>"date_format" (string - optional) - If specified, the date will be written in the specified format each time the effect triggers</li><li>"utc" (boolean - optional) - If specified, the date will be recorded in UTC time. Otherwise, the machine's localtime() will be used</li><li>"separator_postfix" (string - optional) - If specified, this string will be written each time this effect triggers</li><li>"file_separator" (string - optional) -If specified, this string will be written between each file being logged</li></ul> | [ftest 043](../../tests/ftests/043-effect-logger-no-separators.json)<br />[ftest 044](../../tests/ftests/044-effect-logger-date-format.json) | |
| [print](../../src/effects/print.c) | Print a message to a file | <ul><li>"message" (string - optional) - message to output</li><li>"file" (string) - file to write to. Currently only supports "stdout" or "stderr"</li></ul> | [Jimmy Buffett Example](../examples/jimmy-buffett-config.json) | |
| [print_schedstat](../../src/effects/print_schedstat.c) | Print schedstat to a file | <ul><li>"file" (string) - file to write to. Currently only supports "stdout" or "stderr"</li></ul> | [ftest 054](../../tests/ftests/054-effect-print_schedstat.json) | |
| [sd_bus_setting](../../src/effects/sd_bus_setting.c) | Operate on sd_bus properties | <ul><li>"target" (string) - cgroup slice name or scope name</li><li>"setting" (string) - sd_bus property name (e.g. MemoryMax)</li><li>"value" (string, long long, or double) - value to write to the property. If the operator is set to add or subtract, this value will be added/subtracted from the current value of the property</li><li>"operator" (string) - add, subtract, or set</li><li>"limit" (string, long long, or double - optional) - if provided, this effect will use the value as an upper or lower limit when the operator is set to add or subtract, respectfully</li><li>"validate" (boolean - optional) - if true, the setting effect will read from the property to ensure the value was properly set</li><li>"runtime" (boolean - optional) - if true, make changes only temporarily, so that they are lost on the next reboot.</ul> | [ftest 1000](../../tests/ftests/1000-sudo-effect-sd_bus_setting_set_int.json)<br />[ftest 1001](../../tests/ftests/1001-sudo-effect-sd_bus_setting_add_int.json)<br />[ftest 1002](../../tests/ftests/1002-sudo-effect-sd_bus_setting_sub_int.json)<br />[ftest 1003](../../tests/ftests/1003-sudo-effect-sd_bus_setting-CPUQuota.json)<br />[ftest 1004](../../tests/ftests/1004-sudo-effect-sd_bus_setting_add_int_infinity.json)<br />[ftest 1005](../../tests/ftests/1005-sudo-effect-sd_bus_setting_sub_infinity.json)<br />[ftest 1006](../../tests/ftests/1006-sudo-effect-sd_bus_setting_set_int_scope.json)<br />[ftest 1007](../../tests/ftests/1007-sudo-effect-sd_bus_setting_set_str.json) | |
| [setting](../../src/effects/cgroup_setting.c) | Write to a setting file | <ul><li>"setting" (string) - full path to the setting</li><li>"value" (string, long long, or double) - value to write to the setting file. If the operator is set to add or subtract, this value will be added/subtracted from the current value of setting</li><li>"operator" (string) - add, subtract, or set</li><li>"limit" (string, long long, or double - optional) - if provided, this effect will use the value as an upper or lower limit when the operator is set to add or subtract, respectfully</li><li>"validate" (boolean - optional) - if true, the setting effect will read from the setting file to ensure the value was properly set</li></ul> | [ftest 055](../../tests/ftests/055-effect-setting_set_int.json)<br />[ftest 056](../../tests/ftests/056-effect-setting_add_int.json)<br />[ftest 057](../../tests/ftests/057-effect-setting_sub_int.json) | Shares a code base with the cgroup effect code |
| [signal](../../src/effects/kill_processes.c) | Send a signal to the process(es) that match the user-specified process name(s) | <ul><li>"proc_names" (array)<ul><li>"name" (string) - process name (as found in /proc/{pid}/stat)</li></ul></li><li>"signal" (int - optional) - signal to send to the processes being killed. Curently only supports integers. Default - 10 (i.e. SIGUSR1)</li></ul> | [ftest_069](../../tests/ftests/069-effect-signal.json) | |
| [snooze](../../src/effects/snooze.c) | Once the cause(s) in a rule have triggered, snooze (i.e. ignore any more triggers) for a specified duration | <ul><li>"duration" (int) - how long to ignore triggers, in interval milliseconds</li></ul> | [ftest 010](../../tests/ftests/010-snooze_effect.json) | |
Expand Down
1 change: 1 addition & 0 deletions adaptived/include/adaptived-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ int adaptived_farray_linear_regression(float * const array, int array_len, int i
int interp_x, float * const interp_y);

#define ADAPTIVED_CGROUP_FLAGS_VALIDATE 0x1
#define ADAPTIVED_CGROUP_FLAGS_RUNTIME 0x2 /* systemctl --runtime: make changes only temporarily */

/**
* Write a long long value to a cgroup setting
Expand Down
30 changes: 29 additions & 1 deletion adaptived/src/effects/sd_bus_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct cg_opts {

enum effect_op_enum op;

bool runtime;
bool limit_provided;
struct adaptived_cgroup_value limit; /* optional */
bool validate;
Expand All @@ -69,6 +70,7 @@ int sd_bus_setting_init(struct adaptived_effect * const eff, struct json_object
opts->value.type = ADAPTIVED_CGVAL_CNT;
opts->limit.type = ADAPTIVED_CGVAL_CNT;
opts->limit_provided = false;
opts->runtime = false;

ret = adaptived_parse_string(args_obj, "target", &target_str);
if (ret)
Expand Down Expand Up @@ -152,6 +154,15 @@ int sd_bus_setting_init(struct adaptived_effect * const eff, struct json_object
}
}

ret = adaptived_parse_bool(args_obj, "runtime", &opts->runtime);
if (ret == -ENOENT) {
opts->runtime = false;
ret = 0;
} else if (ret) {
adaptived_err("Failed to parse the sd_bus_setting runtime arg: %d\n", ret);
goto error;
}

ret = adaptived_parse_bool(args_obj, "validate", &opts->validate);
if (ret == -ENOENT) {
opts->validate = false;
Expand Down Expand Up @@ -212,6 +223,9 @@ static int add(const struct cg_opts * const opts, struct adaptived_cgroup_value
if (opts->validate)
cgflags |= ADAPTIVED_CGROUP_FLAGS_VALIDATE;

if (opts->runtime)
cgflags |= ADAPTIVED_CGROUP_FLAGS_RUNTIME;

ret = adaptived_sd_bus_set_ll(opts->target, opts->setting, sum, cgflags);
if (ret)
return ret;
Expand Down Expand Up @@ -244,6 +258,9 @@ static int subtract(const struct cg_opts * const opts, struct adaptived_cgroup_v
if (opts->validate)
cgflags |= ADAPTIVED_CGROUP_FLAGS_VALIDATE;

if (opts->runtime)
cgflags |= ADAPTIVED_CGROUP_FLAGS_RUNTIME;

ret = adaptived_sd_bus_set_ll(opts->target, opts->setting, diff, cgflags);
if (ret)
return ret;
Expand Down Expand Up @@ -292,6 +309,8 @@ static int _sd_bus_setting_main(struct adaptived_effect * const eff)
case EOP_SET:
if (opts->validate)
cgflags |= ADAPTIVED_CGROUP_FLAGS_VALIDATE;
if (opts->runtime)
cgflags |= ADAPTIVED_CGROUP_FLAGS_RUNTIME;

ret = adaptived_sd_bus_set_value(opts->target, opts->setting, &opts->value, cgflags);
if (ret)
Expand All @@ -318,6 +337,9 @@ int sd_bus_setting_main(struct adaptived_effect * const eff)
if (ret)
return ret;

if (opts->runtime)
cgflags |= ADAPTIVED_CGROUP_FLAGS_RUNTIME;

ret = adaptived_sd_bus_set_ll(opts->target, opts->setting, ll_value, cgflags);
if (ret)
return ret;
Expand All @@ -332,8 +354,14 @@ int sd_bus_setting_main(struct adaptived_effect * const eff)
ret = adaptived_get_meminfo_field(PROC_MEMINFO, "MemTotal", &ll_value);
if (ret)
return ret;

cgflags = ADAPTIVED_CGROUP_FLAGS_VALIDATE;

if (opts->runtime)
cgflags |= ADAPTIVED_CGROUP_FLAGS_RUNTIME;

ret = adaptived_sd_bus_set_ll(opts->target, opts->setting, ll_value,
ADAPTIVED_CGROUP_FLAGS_VALIDATE);
cgflags);
if (ret)
return ret;
adaptived_dbg("%s: %s at max. Changed to %lld\n", __func__, opts->setting, ll_value);
Expand Down
2 changes: 2 additions & 0 deletions adaptived/src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ static int parse_json(struct adaptived_ctx * const ctx, const char * const buf)

obj = json_tokener_parse_verbose(buf, &err);
if (!obj || err) {
if (err)
adaptived_err("%s: %s\n", __func__, json_tokener_error_desc(err));
ret = -EINVAL;
goto out;
}
Expand Down
18 changes: 13 additions & 5 deletions adaptived/src/utils/sd_bus_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ static int property_assignment(sd_bus_message *m, cgroupType t, const char *prop
}

static int set_property(const char *name, const char *property,
const struct adaptived_cgroup_value * const value)
const struct adaptived_cgroup_value * const value, bool arg_runtime)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *m = NULL;
sd_bus *bus;
int r;
cgroupType t;

adaptived_dbg("set_property: name=%s, property=%s\n", name, property);
adaptived_dbg("set_property: name=%s, property=%s, arg_runtime=%d\n", name, property, arg_runtime);

r = sd_bus_default_system(&bus);
if (r < 0) {
Expand All @@ -264,7 +264,7 @@ static int set_property(const char *name, const char *property,
return t;
}

r = sd_bus_message_append(m, "sb", name, false);
r = sd_bus_message_append(m, "sb", name, arg_runtime);
if (r < 0) {
adaptived_err("set_property: sd_bus_message_append() failed, r=%d\n", r);
return r;
Expand Down Expand Up @@ -359,6 +359,7 @@ API int adaptived_sd_bus_set_ll(const char * const target, const char * const pr
{
struct adaptived_cgroup_value val;
int ret = 0;
bool arg_runtime = false;

if (!target || !property)
return -EINVAL;
Expand All @@ -368,7 +369,10 @@ API int adaptived_sd_bus_set_ll(const char * const target, const char * const pr
val.type = ADAPTIVED_CGVAL_LONG_LONG;
val.value.ll_value = value;

ret = set_property(target, property, &val);
if (flags & ADAPTIVED_CGROUP_FLAGS_RUNTIME)
arg_runtime = true;

ret = set_property(target, property, &val, arg_runtime);
if (ret < 0)
return ret;

Expand All @@ -395,6 +399,7 @@ API int adaptived_sd_bus_set_str(const char * const target, const char * const p
{
struct adaptived_cgroup_value val;
int ret = 0;
bool arg_runtime = false;

if (!target || !property || !value)
return -EINVAL;
Expand All @@ -404,7 +409,10 @@ API int adaptived_sd_bus_set_str(const char * const target, const char * const p
val.type = ADAPTIVED_CGVAL_STR;
val.value.str_value = (char *)value;

ret = set_property(target, property, &val);
if (flags & ADAPTIVED_CGROUP_FLAGS_RUNTIME)
arg_runtime = true;

ret = set_property(target, property, &val, arg_runtime);
if (ret < 0)
return ret;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": 89997312,
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"target": "sudo1001.slice",
"setting": "MemoryMax",
"value": 89997312,
"operator": "set"
"operator": "set",
"runtime": true
}
},
{
Expand All @@ -26,7 +27,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "add",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"target": "sudo1002.slice",
"setting": "MemoryMax",
"value": 89997312,
"operator": "set"
"operator": "set",
"runtime": true
}
},
{
Expand All @@ -26,7 +27,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "subtract",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"target": "sudo1003.slice",
"setting": "CPUQuotaPeriodSec",
"value": "1s",
"operator": "set"
"operator": "set",
"runtime": true
}
},
{
Expand All @@ -25,7 +26,8 @@
"target": "sudo1003.slice",
"setting": "CPUQuota",
"value": "44%",
"operator": "set"
"operator": "set",
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": "infinity",
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
},
{
Expand All @@ -27,7 +28,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "add",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": "infinity",
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
},
{
Expand All @@ -27,7 +28,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "subtract",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": 89997312,
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "DevicePolicy",
"value": "closed",
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Loading

0 comments on commit 8b7c84e

Please sign in to comment.