Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
scx: Add selftests for validating hotplug seq checks
Browse files Browse the repository at this point in the history
Now that we have full hotplug sequence number support, as well as the
necessary macros in compat.h, let's extend the hotplug selftest to also
validate that the sequence number can be used to detect hotplug events.

Signed-off-by: David Vernet <[email protected]>
  • Loading branch information
Byte-Lab committed Apr 11, 2024
1 parent b276ddd commit 9fabb99
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions tools/testing/selftests/sched_ext/hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "scx_test.h"
#include "util.h"

struct hotplug *skel;

const char *online_path = "/sys/devices/system/cpu/cpu1/online";

static bool is_cpu_online(void)
Expand All @@ -40,22 +38,20 @@ static enum scx_test_status setup(void **ctx)
if (!is_cpu_online())
return SCX_TEST_SKIP;

skel = hotplug__open_and_load();
if (!skel) {
SCX_ERR("Failed to open and load hotplug skel");
return SCX_TEST_FAIL;
}

return SCX_TEST_PASS;
}

static enum scx_test_status test_hotplug(bool onlining, bool cbs_defined)
{
struct hotplug *skel;
struct bpf_link *link;
long kind, code;

SCX_ASSERT(is_cpu_online());

skel = hotplug__open_and_load();
SCX_ASSERT(skel);

/* Testing the offline -> online path, so go offline before starting */
if (onlining)
toggle_online_status(0);
Expand All @@ -78,6 +74,7 @@ static enum scx_test_status test_hotplug(bool onlining, bool cbs_defined)

if (!link) {
SCX_ERR("Failed to attach scheduler");
hotplug__destroy(skel);
return SCX_TEST_FAIL;
}

Expand All @@ -93,12 +90,51 @@ static enum scx_test_status test_hotplug(bool onlining, bool cbs_defined)
toggle_online_status(1);

bpf_link__destroy(link);

UEI_RESET(skel, uei);
hotplug__destroy(skel);

return SCX_TEST_PASS;
}

static enum scx_test_status test_hotplug_attach(void)
{
struct hotplug *skel;
struct bpf_link *link;
enum scx_test_status status = SCX_TEST_PASS;
long kind, code;

SCX_ASSERT(is_cpu_online());
SCX_ASSERT(scx_hotplug_seq() > 0);

skel = SCX_OPS_OPEN(hotplug_nocb_ops, hotplug);
SCX_ASSERT(skel);

SCX_OPS_LOAD(skel, hotplug_nocb_ops, hotplug, uei);

/*
* Take the CPU offline to increment the global hotplug seq, which
* should cause attach to fail due to us setting the hotplug seq above
*/
toggle_online_status(0);
link = bpf_map__attach_struct_ops(skel->maps.hotplug_nocb_ops);

toggle_online_status(1);

SCX_ASSERT(link);
while (!UEI_EXITED(skel, uei))
sched_yield();

kind = SCX_KIND_VAL(SCX_EXIT_UNREG_KERN);
code = SCX_ECODE_VAL(SCX_ECODE_ACT_RESTART) |
SCX_ECODE_VAL(SCX_ECODE_RSN_HOTPLUG);
SCX_EQ(UEI_KIND(skel, uei), kind);
SCX_EQ(UEI_ECODE(skel, uei), code);

bpf_link__destroy(link);
hotplug__destroy(skel);

return status;
}

static enum scx_test_status run(void *ctx)
{

Expand All @@ -114,12 +150,11 @@ static enum scx_test_status run(void *ctx)

#undef HP_TEST

return SCX_TEST_PASS;
return test_hotplug_attach();
}

static void cleanup(void *ctx)
{
hotplug__destroy(skel);
toggle_online_status(1);
}

Expand Down

0 comments on commit 9fabb99

Please sign in to comment.