xref: /spdk/test/event/scheduler/scheduler_plugin.py (revision c680e3a05b1a903c18bf3f75b732765607126f45)
1#  SPDX-License-Identifier: BSD-3-Clause
2#  Copyright (C) 2021 Intel Corporation.
3#  All rights reserved.
4
5from spdk.rpc.client import print_json
6
7
8def thread_create(args):
9    params = {'active': args.active}
10    if args.name:
11        params['name'] = args.name
12    if args.cpu_mask:
13        params['cpu_mask'] = args.cpu_mask
14    return args.client.call('scheduler_thread_create', params)
15
16
17def create_thread(args):
18    print_json(thread_create(args))
19
20
21def thread_set_active(args):
22    params = {'thread_id': args.thread_id, 'active': args.active}
23    return args.client.call('scheduler_thread_set_active', params)
24
25
26def thread_delete(args):
27    params = {'thread_id': args.thread_id}
28    return args.client.call('scheduler_thread_delete', params)
29
30
31def spdk_rpc_plugin_initialize(subparsers):
32    p = subparsers.add_parser('scheduler_thread_create', help='Create spdk thread')
33    p.add_argument('-n', '--name', help='Name of spdk thread and poller')
34    p.add_argument('-m', '--cpu_mask', help='CPU mask for spdk thread')
35    p.add_argument('-a', '--active', help='Percent of time thread is active', type=int)
36    p.set_defaults(func=create_thread)
37
38    p = subparsers.add_parser('scheduler_thread_set_active', help='Change percent of time the spdk thread is active')
39    p.add_argument('thread_id', help='spdk_thread id', type=int)
40    p.add_argument('active', help='Percent of time thread is active', type=int)
41    p.set_defaults(func=thread_set_active)
42
43    p = subparsers.add_parser('scheduler_thread_delete', help='Delete spdk thread')
44    p.add_argument('thread_id', help='spdk_thread id', type=int)
45    p.set_defaults(func=thread_delete)
46