Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 1 addition & 50 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,6 @@ jobs:
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

distcheck_cgv1:
name: Adaptived make distcheck v1
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
with:
submodules: false
- name: Initialize the directory
uses: ./.github/actions/setup-adaptived
- name: Run make distcheck
run: cd adaptived && make distcheck
- name: Display test logs
if: ${{ failure() }}
run: |
cat adaptived/adaptived-*/_build/sub/tests/ftests/ftests-wrapper.sh.log
cat adaptived/adaptived-*/_build/sub/tests/ftests/ftests-c-wrapper.sh.log

distcheck_cgv2:
name: Adaptived make distcheck v2
runs-on: ubuntu-latest
Expand All @@ -121,37 +103,6 @@ jobs:
cat adaptived/adaptived-*/_build/sub/tests/ftests/ftests-wrapper.sh.log
cat adaptived/adaptived-*/_build/sub/tests/ftests/ftests-c-wrapper.sh.log

functional_tests_cgv1:
name: Adaptived Functional Tests v1
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
with:
submodules: false
- name: Fail on all warnings
run: |
CFLAGS=-Werror
export CFLAGS
- name: Initialize the directory
uses: ./.github/actions/setup-adaptived
- name: Run functional tests
run: cd adaptived && make check
- name: Display test logs
if: ${{ always() }}
run: |
cat adaptived/tests/ftests/ftests-wrapper.sh.log
cat adaptived/tests/ftests/ftests-c-wrapper.sh.log
- name: Collate code coverage results
uses: ./.github/actions/code-coverage
- name: Upload code coverage results
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.total
flag-name: "Adaptived Functional Tests - cgv1"
parallel: True

functional_tests_cgv2:
name: Adaptived Functional Tests v2
runs-on: ubuntu-latest
Expand Down Expand Up @@ -186,7 +137,7 @@ jobs:
finalize:
name: Finalize the test run
if: ${{ always() }}
needs: [functional_tests_cgv1, functional_tests_cgv2]
needs: [functional_tests_cgv2]
runs-on: ubuntu-latest
steps:
- name: Finalize code coverage results
Expand Down
88 changes: 88 additions & 0 deletions adaptived/include/adaptived.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ enum adaptived_attr {
ADAPTIVED_ATTR_CNT
};

enum adaptived_sdata_type {
/*
* Custom data. Can be used by registered functions without forcing a recompile
* of adaptived
*/
ADAPTIVED_SDATA_CUSTOM = 0,
ADAPTIVED_SDATA_STR,
ADAPTIVED_SDATA_CGROUP,
ADAPTIVED_SDATA_NAME_VALUE,

ADAPTIVED_SDATA_CNT
};

enum adaptived_sdata_flags {
ADAPTIVED_SDATAF_PERSIST = 0x1
};

/**
* Function to free a custom shared data structure. Not needed for any other
* shared data type, as adaptived knows how to free built-in data types.
*/
typedef void (*adaptived_sdata_free)(void * const data);

enum adaptived_cgroup_value_type {
ADAPTIVED_CGVAL_STR = 0,
ADAPTIVED_CGVAL_LONG_LONG,
Expand All @@ -89,6 +112,11 @@ struct adaptived_cgroup_value {
} value;
};

struct adaptived_name_and_value {
char *name;
struct adaptived_cgroup_value *value;
};

struct adaptived_rule_stats {
int cause_cnt;
int effect_cnt;
Expand Down Expand Up @@ -459,6 +487,66 @@ int adaptived_load_rule(struct adaptived_ctx * const ctx, struct adaptived_rule
*/
int adaptived_unload_rule(struct adaptived_ctx * const ctx, const char * const name);

/**
* Method to write shared data to a cause. Data can be used by downstream effect(s)
* @param cse adaptived cause structure
* @param type shared data enumeration describing the type of data being store
* @param data pointer to the data to be stored
* @param free_fn Function to free the shared data. Only needed for custom data types
* @param flags See enum adaptived_sdata_flags
*
* @note - shared data is deleted/freed at the end of each adaptive main loop unless
* the persist flag is set
* @note - freeing of data is done by free(), so the *data pointer must be created
* via malloc. It would be possible to avoid this by creating a new type,
* e.g. ADAPTIVED_SDATA_INT, and adding handling for it in free_shared_data().
* @note - persist can be used to share data bidirectionally between a cause and some
* effect(s). Use with caution, as this tightly couples these causes and
* effect(s).
*/
int adaptived_write_shared_data(struct adaptived_cause * const cse,
enum adaptived_sdata_type type, void *data,
adaptived_sdata_free free_fn,
uint32_t flags);

/**
* Update shared data
* @param cse adaptived cause structure
* @param index shared data object index
* @param type shared data enumeration describing the type of data being store
* @param data pointer to the data to be stored
* @param flags See enum adaptived_sdata_flags
*
* @note - If the data pointer is changed, it's up to the caller of this function
* to ensure that the previous *data pointer is freed.
*/
int adaptived_update_shared_data(struct adaptived_cause * const cse, int index,
enum adaptived_sdata_type type, void *data,
uint32_t flags);

/**
* Get the number of shared data objects in this cause
* @param cse adaptived cause
*
* @return number of shared data objects
*/
int adaptived_get_shared_data_cnt(const struct adaptived_cause * const cse);

/**
* Retrieve one shared data object from the cause
* @param cse adaptived cause
* @param index shared data object index
* @param type Output parameter that tells what type of data is stored in this object
* @param data Output parameter that contains the stored data
* @param flags See enum adaptived_sdata_flags
*
* @note You do not need to free the data in the shared data object. adaptived will
* automatically do that at the end of each main processing loop
*/
int adaptived_get_shared_data(const struct adaptived_cause * const cse, int index,
enum adaptived_sdata_type * const type, void **data,
uint32_t * const flags);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
2 changes: 2 additions & 0 deletions adaptived/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ SOURCES = \
parse.c \
pressure.h \
rule.c \
shared_data.c \
shared_data.h \
utils/cgroup_utils.c \
utils/sd_bus_utils.c \
utils/file_utils.c \
Expand Down
6 changes: 6 additions & 0 deletions adaptived/src/cause.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ struct adaptived_cause {
struct json_object *json; /* only used when building a rule at runtime */
struct adaptived_cause *next;

/*
* Data that can be shared between causes and effects. It is freed/deleted
* at the end of each adaptived_loop() loop
*/
struct shared_data *sdata;

/* private data store for each cause plugin */
void *data;
};
Expand Down
21 changes: 20 additions & 1 deletion adaptived/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <adaptived.h>

#include "adaptived-internal.h"
#include "shared_data.h"
#include "defines.h"

void cleanup(struct adaptived_ctx *ctx);
Expand Down Expand Up @@ -426,6 +427,18 @@ API int adaptived_register_injection_function(struct adaptived_ctx * const ctx,
return 0;
}

static void free_rule_shared_data(struct adaptived_rule * const rule, bool force_delete)
{
struct adaptived_cause *cse;

cse = rule->causes;

while(cse) {
free_shared_data(cse, force_delete);
cse = cse->next;
}
}

API int adaptived_loop(struct adaptived_ctx * const ctx, bool parse)
{
struct adaptived_effect *eff;
Expand Down Expand Up @@ -534,7 +547,7 @@ API int adaptived_loop(struct adaptived_ctx * const ctx, bool parse)
}
}


free_rule_shared_data(rule, false);
rule = rule->next;
}

Expand Down Expand Up @@ -567,6 +580,12 @@ API int adaptived_loop(struct adaptived_ctx * const ctx, bool parse)
}

out:
rule = ctx->rules;
while (rule) {
free_rule_shared_data(rule, true);
rule = rule->next;
}

pthread_mutex_unlock(&ctx->ctx_mutex);

return ret;
Expand Down
Loading
Loading