1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/stdinc.h" 7 #include "spdk/env.h" 8 #include "spdk/scheduler.h" 9 10 #include "spdk_internal/event.h" 11 #include "spdk_internal/init.h" 12 13 static void 14 scheduler_subsystem_init(void) 15 { 16 int rc = 0; 17 18 /* Set the defaults */ 19 if (spdk_scheduler_get() == NULL) { 20 rc = spdk_scheduler_set("static"); 21 } 22 23 spdk_subsystem_init_next(rc); 24 } 25 26 static void 27 scheduler_subsystem_fini(void) 28 { 29 spdk_scheduler_set_period(0); 30 spdk_scheduler_set(NULL); 31 32 spdk_subsystem_fini_next(); 33 } 34 35 static void 36 scheduler_write_config_json(struct spdk_json_write_ctx *w) 37 { 38 struct spdk_scheduler *scheduler; 39 uint64_t scheduler_period; 40 41 assert(w != NULL); 42 43 scheduler = spdk_scheduler_get(); 44 if (scheduler == NULL) { 45 SPDK_ERRLOG("Unable to get scheduler info\n"); 46 return; 47 } 48 49 scheduler_period = spdk_scheduler_get_period(); 50 51 spdk_json_write_array_begin(w); 52 53 spdk_json_write_object_begin(w); 54 spdk_json_write_named_string(w, "method", "framework_set_scheduler"); 55 spdk_json_write_named_object_begin(w, "params"); 56 spdk_json_write_named_string(w, "name", scheduler->name); 57 if (scheduler_period != 0) { 58 spdk_json_write_named_uint32(w, "period", scheduler_period); 59 } 60 spdk_json_write_object_end(w); 61 spdk_json_write_object_end(w); 62 63 spdk_json_write_array_end(w); 64 } 65 66 static struct spdk_subsystem g_spdk_subsystem_scheduler = { 67 .name = "scheduler", 68 .init = scheduler_subsystem_init, 69 .fini = scheduler_subsystem_fini, 70 .write_config_json = scheduler_write_config_json, 71 }; 72 73 SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_scheduler); 74