2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2020-09-11 08:02:36 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/likely.h"
|
|
|
|
|
|
|
|
#include "spdk_internal/event.h"
|
2021-05-06 14:33:09 +00:00
|
|
|
#include "spdk/thread.h"
|
2020-09-11 08:02:36 +00:00
|
|
|
|
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/env.h"
|
2021-08-06 09:17:16 +00:00
|
|
|
#include "spdk/scheduler.h"
|
2020-09-11 08:02:36 +00:00
|
|
|
|
|
|
|
static int
|
2021-07-13 11:22:12 +00:00
|
|
|
init(void)
|
2020-09-11 08:02:36 +00:00
|
|
|
{
|
2021-08-06 09:17:16 +00:00
|
|
|
return spdk_governor_set("dpdk_governor");
|
2020-09-11 08:02:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 11:22:12 +00:00
|
|
|
static void
|
|
|
|
deinit(void)
|
2020-09-11 08:02:36 +00:00
|
|
|
{
|
2021-08-06 09:17:16 +00:00
|
|
|
spdk_governor_set(NULL);
|
2020-09-11 08:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-20 08:53:36 +00:00
|
|
|
balance(struct spdk_scheduler_core_info *cores, uint32_t core_count)
|
2020-09-11 08:02:36 +00:00
|
|
|
{
|
2021-07-13 11:22:12 +00:00
|
|
|
struct spdk_governor *governor;
|
2020-09-11 08:02:36 +00:00
|
|
|
struct spdk_scheduler_core_info *core;
|
|
|
|
struct spdk_governor_capabilities capabilities;
|
2021-05-24 17:08:32 +00:00
|
|
|
uint32_t i;
|
2020-09-11 08:02:36 +00:00
|
|
|
int rc;
|
|
|
|
|
2021-08-06 09:17:16 +00:00
|
|
|
governor = spdk_governor_get();
|
2021-07-15 12:53:29 +00:00
|
|
|
assert(governor != NULL);
|
|
|
|
|
2020-09-11 08:02:36 +00:00
|
|
|
/* Gather active/idle statistics */
|
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
core = &cores[i];
|
|
|
|
|
|
|
|
rc = governor->get_core_capabilities(core->lcore, &capabilities);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("failed to get capabilities for core: %u\n", core->lcore);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-22 15:33:01 +00:00
|
|
|
if (core->current_busy_tsc < (core->current_idle_tsc / 1000)) {
|
2020-09-11 08:02:36 +00:00
|
|
|
rc = governor->set_core_freq_min(core->lcore);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("setting to minimal frequency for core %u failed\n", core->lcore);
|
|
|
|
}
|
2021-11-22 15:33:01 +00:00
|
|
|
} else if (core->current_idle_tsc > core->current_busy_tsc) {
|
2020-09-11 08:02:36 +00:00
|
|
|
rc = governor->core_freq_down(core->lcore);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("lowering frequency for core %u failed\n", core->lcore);
|
|
|
|
}
|
2021-11-22 15:33:01 +00:00
|
|
|
} else if (core->current_idle_tsc < (core->current_busy_tsc / 1000)) {
|
2020-09-11 08:02:36 +00:00
|
|
|
rc = governor->set_core_freq_max(core->lcore);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("setting to maximal frequency for core %u failed\n", core->lcore);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rc = governor->core_freq_up(core->lcore);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("increasing frequency for core %u failed\n", core->lcore);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_scheduler gscheduler = {
|
|
|
|
.name = "gscheduler",
|
|
|
|
.init = init,
|
|
|
|
.deinit = deinit,
|
|
|
|
.balance = balance,
|
|
|
|
};
|
|
|
|
|
2021-01-13 14:04:52 +00:00
|
|
|
SPDK_SCHEDULER_REGISTER(gscheduler);
|